fix: ignored models

This commit is contained in:
DSPOM
2022-08-12 16:08:03 +02:00
parent 02b68e7ef8
commit 663a0c49d7
6 changed files with 72 additions and 40 deletions
+36 -13
View File
@@ -11,6 +11,7 @@ Author: 1985 Wayne A. Christopher
/* Note: Must include shlwapi.h before ngspice header defining BOOL due /* Note: Must include shlwapi.h before ngspice header defining BOOL due
* to conflict */ * to conflict */
#include <stdio.h>
#ifdef _WIN32 #ifdef _WIN32
#include <shlwapi.h> /* for definition of PathIsRelativeA() */ #include <shlwapi.h> /* for definition of PathIsRelativeA() */
#pragma comment(lib, "Shlwapi.lib") #pragma comment(lib, "Shlwapi.lib")
@@ -1547,6 +1548,8 @@ struct inp_read_t inp_read( FILE *fp, int call_depth, const char *dir_name,
!ciprefix("wrdata", buffer) && !ciprefix("wrdata", buffer) &&
!ciprefix(".lib", buffer) && !ciprefix(".inc", buffer) && !ciprefix(".lib", buffer) && !ciprefix(".inc", buffer) &&
!ciprefix("codemodel", buffer) && !ciprefix("codemodel", buffer) &&
!ciprefix("osdi", buffer) &&
!ciprefix("pre_osdi", buffer) &&
!ciprefix("echo", buffer) && !ciprefix("shell", buffer) && !ciprefix("echo", buffer) && !ciprefix("shell", buffer) &&
!ciprefix("source", buffer) && !ciprefix("cd ", buffer) && !ciprefix("source", buffer) && !ciprefix("cd ", buffer) &&
!ciprefix("load", buffer) && !ciprefix("setcs", buffer)) { !ciprefix("load", buffer) && !ciprefix("setcs", buffer)) {
@@ -2368,6 +2371,8 @@ static char *get_subckt_model_name(char *line)
name = skip_non_ws(line); // eat .subckt|.model name = skip_non_ws(line); // eat .subckt|.model
name = skip_ws(name); name = skip_ws(name);
end_ptr = skip_non_ws(name); end_ptr = skip_non_ws(name);
return copy_substring(name, end_ptr); return copy_substring(name, end_ptr);
@@ -2417,14 +2422,29 @@ static char *get_model_type(char *line)
} }
static char *get_adevice_model_name(char *line) static char *get_adevice_model_name(char *line, struct nscope *scope)
{ {
char *ptr_end, *ptr_beg; char *beg_ptr, *end_ptr, *name;
int i = 0;
ptr_end = skip_back_ws(strchr(line, '\0'), line); beg_ptr = skip_non_ws(line); /* eat device name */
ptr_beg = skip_back_non_ws(ptr_end, line); beg_ptr = skip_ws(beg_ptr);
return copy_substring(ptr_beg, ptr_end); for (i = 0; i < 30; i++) { /* skip the terminals */
end_ptr = skip_non_ws(beg_ptr);
name = copy_substring(beg_ptr, end_ptr);
if (inp_find_model(scope, name)){
return name;
}else if (beg_ptr == end_ptr){
break;
}
end_ptr = skip_ws(end_ptr);
beg_ptr = end_ptr;
}
return NULL;
} }
@@ -2643,7 +2663,7 @@ static void get_subckts_for_subckt(struct card *start_card, char *subckt_name,
nlist_adjoin(used_subckts, inst_subckt_name); nlist_adjoin(used_subckts, inst_subckt_name);
} }
else if (*line == 'a') { else if (*line == 'a') {
char *model_name = get_adevice_model_name(line); char *model_name = get_adevice_model_name( line, card->level);
nlist_adjoin(used_models, model_name); nlist_adjoin(used_models, model_name);
} }
else if (has_models) { else if (has_models) {
@@ -2729,7 +2749,7 @@ void comment_out_unused_subckt_models(struct card *start_card)
nlist_adjoin(used_subckts, subckt_name); nlist_adjoin(used_subckts, subckt_name);
} }
else if (*line == 'a') { else if (*line == 'a') {
char *model_name = get_adevice_model_name(line); char *model_name = get_adevice_model_name(line, card->level);
nlist_adjoin(used_models, model_name); nlist_adjoin(used_models, model_name);
} }
else if (has_models) { else if (has_models) {
@@ -10065,9 +10085,12 @@ void inp_rem_unused_models(struct nscope *root, struct card *deck)
/* num_terminals may be 0 for a elements */ /* num_terminals may be 0 for a elements */
if ((num_terminals != 0) || (*curr_line == 'a')) { if ((num_terminals != 0) || (*curr_line == 'a')) {
char *elem_model_name; char *elem_model_name;
if (*curr_line == 'a') if (*curr_line == 'a'){
elem_model_name = get_adevice_model_name(curr_line); elem_model_name = get_adevice_model_name( curr_line, card->level);
else if (!elem_model_name){
continue;
}
}else
elem_model_name = get_model_name(curr_line, num_terminals); elem_model_name = get_model_name(curr_line, num_terminals);
/* ignore certain cases, for example /* ignore certain cases, for example
@@ -10108,7 +10131,7 @@ void inp_rem_unused_models(struct nscope *root, struct card *deck)
* only correct UTF-8. It also spots UTF-8 sequences that could cause * only correct UTF-8. It also spots UTF-8 sequences that could cause
* trouble if converted to UTF-16, namely surrogate characters * trouble if converted to UTF-16, namely surrogate characters
* (U+D800..U+DFFF) and non-Unicode positions (U+FFFE..U+FFFF). * (U+D800..U+DFFF) and non-Unicode positions (U+FFFE..U+FFFF).
* In addition we check for some ngspice-specific characters like µ etc.*/ * In addition we check for some ngspice-specific characters like etc.*/
#ifndef EXT_ASC #ifndef EXT_ASC
static unsigned char* static unsigned char*
utf8_check(unsigned char *s) utf8_check(unsigned char *s)
@@ -10118,12 +10141,12 @@ utf8_check(unsigned char *s)
/* 0xxxxxxx */ /* 0xxxxxxx */
s++; s++;
else if (*s == 0xb5) { else if (*s == 0xb5) {
/* translate ansi micro µ to u */ /* translate ansi micro to u */
*s = 'u'; *s = 'u';
s++; s++;
} }
else if (s[0] == 0xc2 && s[1] == 0xb5) { else if (s[0] == 0xc2 && s[1] == 0xb5) {
/* translate utf-8 micro µ to u */ /* translate utf-8 micro to u */
s[0] = 'u'; s[0] = 'u';
/* remove second byte */ /* remove second byte */
unsigned char *y = s + 1; unsigned char *y = s + 1;
+1 -2
View File
@@ -1,7 +1,6 @@
{ {
extern "C" extern "C"
{ {
osdi_init_log_message; osdi_log;
osdi_finish_log_message;
}; };
}; };
+9 -6
View File
@@ -42,11 +42,15 @@
#define EVAL_RET_FLAG_FINISH 4 #define EVAL_RET_FLAG_FINISH 4
#define EVAL_RET_FLAG_STOP 8 #define EVAL_RET_FLAG_STOP 8
#define LOG_LVL_MASK 8
#define LOG_LVL_DEBUG 0 #define LOG_LVL_DEBUG 0
#define LOG_LVL_INFO 1 #define LOG_LVL_DISPLAY 1
#define LOG_LVL_WARN 2 #define LOG_LVL_INFO 2
#define LOG_LVL_ERR 3 #define LOG_LVL_WARN 3
#define LOG_LVL_FATAL 4 #define LOG_LVL_ERR 4
#define LOG_LVL_FATAL 5
#define LOG_FMT_ERR 16
#define INIT_ERR_OUT_OF_BOUNDS 1 #define INIT_ERR_OUT_OF_BOUNDS 1
@@ -161,6 +165,5 @@ typedef struct OsdiDescriptor {
extern FILE *osdi_init_log_message(void *handle, uint32_t lvl); extern void osdi_log(void *handle, char* msg, uint32_t lvl);
extern void osdi_finish_log_message(void *handle, FILE *stream, uint32_t lvl);
+22 -15
View File
@@ -11,10 +11,12 @@
#include "ngspice/ngspice.h" #include "ngspice/ngspice.h"
#include "ngspice/typedefs.h" #include "ngspice/typedefs.h"
#include "osdi.h"
#include "osdidefs.h" #include "osdidefs.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
/* /*
@@ -171,34 +173,39 @@ extern SPICEdev *osdi_create_spicedev(const OsdiRegistryEntry *entry) {
return OSDIinfo; return OSDIinfo;
} }
extern FILE *osdi_init_log_message(void *handle_, uint32_t lvl) { extern void osdi_log(void *handle_, char *msg, uint32_t lvl) {
OsdiNgspiceHandle *handle = handle_; OsdiNgspiceHandle *handle = handle_;
switch (lvl) { FILE *dst = stdout;
switch (lvl & LOG_LVL_MASK) {
case LOG_LVL_DEBUG: case LOG_LVL_DEBUG:
fprintf(stdout, "OSDI(debug) %s: ", handle->name); printf("OSDI(debug) %s: ", handle->name);
break;
case LOG_LVL_DISPLAY:
printf("OSDI %s: ", handle->name);
break; break;
case LOG_LVL_INFO: case LOG_LVL_INFO:
fprintf(stdout, "OSDI(info) %s: ", handle->name); printf("OSDI(info) %s: ", handle->name);
break; break;
case LOG_LVL_WARN: case LOG_LVL_WARN:
fprintf(stdout, "OSDI(warn) %s: ", handle->name); fprintf(stderr, "OSDI(warn) %s: ", handle->name);
dst = stderr;
break; break;
case LOG_LVL_ERR: case LOG_LVL_ERR:
fprintf(stderr, "OSDI(err) %s: ", handle->name); fprintf(stderr, "OSDI(err) %s: ", handle->name);
return stderr; dst = stderr;
break;
case LOG_LVL_FATAL: case LOG_LVL_FATAL:
fprintf(stderr, "OSDI(fatal) %s: ", handle->name); fprintf(stderr, "OSDI(fatal) %s: ", handle->name);
return stderr; dst = stderr;
break;
default: default:
fprintf(stdout, "OSDI(unkown) %s", handle->name); fprintf(stderr, "OSDI(unkown) %s", handle->name);
break; break;
} }
return stdout;
}
extern void osdi_finish_log_message(void *handle, FILE *stream, uint32_t lvl) { if (lvl & LOG_FMT_ERR) {
fprintf(dst, "failed to format\"%s\"\n", msg);
NG_IGNORE(handle); } else {
NG_IGNORE(stream); fprintf(dst, "%s", msg);
NG_IGNORE(lvl); }
} }
+1 -1
View File
@@ -115,7 +115,7 @@ extern int OSDImParam(int param, IFvalue *value, GENmodel *modelPtr) {
} }
void *model = osdi_model_data(modelPtr); void *model = osdi_model_data(modelPtr);
void *dst = descr->access(model, model, (uint32_t)param, ACCESS_FLAG_SET); void *dst = descr->access(NULL, model, (uint32_t)param, ACCESS_FLAG_SET);
return osdi_write_param(dst, value, param, descr); return osdi_write_param(dst, value, param, descr);
} }
+3 -3
View File
@@ -53,9 +53,9 @@ void INP2A(CKTcircuit *ckt, INPtables *tab, struct card *current) {
if (i >= 2) { if (i >= 2) {
txfree(INPgetMod(ckt, token, &thismodel, tab)); txfree(INPgetMod(ckt, token, &thismodel, tab));
/* check if using model binning -- pass in line since need 'l' and 'w' */ /* /1* check if using model binning -- pass in line since need 'l' and 'w' *1/ */
if (!thismodel) /* if (!thismodel) */
txfree(INPgetModBin(ckt, token, &thismodel, tab, line)); /* txfree(INPgetModBin(ckt, token, &thismodel, tab, line)); */
if (thismodel) { if (thismodel) {
INPinsert(&token, tab); INPinsert(&token, tab);