From 840ba9dc29c53787e1f2b4fb816c15aabbfe7f6b Mon Sep 17 00:00:00 2001 From: Florian Ballenegger Date: Tue, 6 Oct 2020 23:57:07 +0200 Subject: [PATCH] upgraded some codemodels to instance parameters + default model --- src/frontend/inpcom.c | 16 ++-- src/spicelib/devices/dev.c | 6 +- src/xspice/icm/analog/int/ifspec.ifs | 5 +- src/xspice/icm/analog/mult/ifspec.ifs | 3 +- src/xspice/icm/analog/slew/ifspec.ifs | 1 + src/xspice/icm/analog/summer/ifspec.ifs | 3 +- src/xspice/icm/digital/d_dff/ifspec.ifs | 2 +- src/xspice/icm/digital/d_dlatch/ifspec.ifs | 2 +- src/xspice/icm/digital/d_genlut/ifspec.ifs | 4 + src/xspice/icm/digital/d_jkff/ifspec.ifs | 2 +- src/xspice/icm/digital/d_lut/ifspec.ifs | 4 + src/xspice/icm/digital/d_source/ifspec.ifs | 2 + src/xspice/icm/digital/d_srff/ifspec.ifs | 2 +- src/xspice/icm/digital/d_srlatch/ifspec.ifs | 2 +- src/xspice/icm/digital/d_tff/ifspec.ifs | 2 +- src/xspice/icm/digital/modpath.lst | 2 + src/xspice/mif/mif_inp2.c | 97 ++++++++++++++++----- src/xspice/mif/mifgetmod.c | 1 - src/xspice/mif/mifpara.c | 2 +- 19 files changed, 113 insertions(+), 45 deletions(-) diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index 5ada38012..860823d59 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -1987,9 +1987,11 @@ static char *get_adevice_model_name(char *line) break; /* found model */ } if(ptr_beg == line) - return copy_substring(ptr_beg,ptr_beg); /* did not found the model */ + return NULL; /* did not found the model */ + if(ptr_beg[0]=='!') + return NULL; /* use a default model - do not translate */ - printf("adev mod name: %s\n", ptr_beg); + if(0) printf("adev mod name: %s\n", ptr_beg); return copy_substring(ptr_beg, ptr_end); } @@ -2186,7 +2188,7 @@ static void get_subckts_for_subckt(struct card *start_card, char *subckt_name, } else if (*line == 'a') { char *model_name = get_adevice_model_name(line); - nlist_adjoin(used_models, model_name); + if(model_name) nlist_adjoin(used_models, model_name); } else if (has_models) { int num_terminals = get_number_terminals(line); @@ -2268,7 +2270,7 @@ static void comment_out_unused_subckt_models(struct card *start_card) } else if (*line == 'a') { char *model_name = get_adevice_model_name(line); - nlist_adjoin(used_models, model_name); + if(model_name) nlist_adjoin(used_models, model_name); } else if (has_models) { /* This is a preliminary version, until we have found a @@ -8761,7 +8763,7 @@ static void inp_rem_unused_models(struct nscope *root, struct card *deck) /* ignore certain cases, for example * C5 node1 node2 42.0 */ - if (is_a_modelname(elem_model_name)) { + if (elem_model_name && is_a_modelname(elem_model_name)) { struct modellist *m = inp_find_model(card->level, elem_model_name); @@ -8778,8 +8780,8 @@ static void inp_rem_unused_models(struct nscope *root, struct card *deck) elem_model_name); } } - - tfree(elem_model_name); + if(elem_model_name) + tfree(elem_model_name); } } diff --git a/src/spicelib/devices/dev.c b/src/spicelib/devices/dev.c index 26bd79d33..5a029e45c 100644 --- a/src/spicelib/devices/dev.c +++ b/src/spicelib/devices/dev.c @@ -142,7 +142,7 @@ extern struct coreInfo_t coreInfo; /* cmexport.c */ #ifdef NDEV #include "ndev/ndevitf.h" #endif -#define TRACE + static SPICEdev *(*static_devices[])(void) = { /* URC device MUST precede both resistors and capacitors */ get_urc_info, @@ -415,7 +415,9 @@ int load_opus(const char *name) SPICEdev **devs; Evt_Udn_Info_t **udns; funptr_t fetch; -printf("loading code model lib %s\n", name); +#ifdef TRACE + printf("loading code model lib %s\n", name); +#endif lib = dlopen(name, RTLD_NOW); if (!lib) { msg = dlerror(); diff --git a/src/xspice/icm/analog/int/ifspec.ifs b/src/xspice/icm/analog/int/ifspec.ifs index bdb75c475..743bbd432 100644 --- a/src/xspice/icm/analog/int/ifspec.ifs +++ b/src/xspice/icm/analog/int/ifspec.ifs @@ -48,7 +48,7 @@ Limits: - - Vector: no no Vector_Bounds: - - Null_Allowed: yes yes - +Parameter_Scope: both both PARAMETER_TABLE: @@ -61,7 +61,7 @@ Limits: - - Vector: no no Vector_Bounds: - - Null_Allowed: yes yes - +Parameter_Scope: both both PARAMETER_TABLE: @@ -75,4 +75,5 @@ Limits: - - Vector: no no Vector_Bounds: - - Null_Allowed: yes yes +Parameter_Scope: both both diff --git a/src/xspice/icm/analog/mult/ifspec.ifs b/src/xspice/icm/analog/mult/ifspec.ifs index 8f4044ec5..2bc3f327f 100644 --- a/src/xspice/icm/analog/mult/ifspec.ifs +++ b/src/xspice/icm/analog/mult/ifspec.ifs @@ -48,7 +48,7 @@ Limits: - - Vector: yes yes Vector_Bounds: in in Null_Allowed: yes yes - +Parameter_Scope: both both PARAMETER_TABLE: @@ -62,5 +62,6 @@ Limits: - - Vector: no no Vector_Bounds: - - Null_Allowed: yes yes +Parameter_Scope: both both diff --git a/src/xspice/icm/analog/slew/ifspec.ifs b/src/xspice/icm/analog/slew/ifspec.ifs index e76e44452..e2aca44cd 100644 --- a/src/xspice/icm/analog/slew/ifspec.ifs +++ b/src/xspice/icm/analog/slew/ifspec.ifs @@ -48,6 +48,7 @@ Limits: - - Vector: no no Vector_Bounds: - - Null_Allowed: yes yes +Parameter_Scope: both both diff --git a/src/xspice/icm/analog/summer/ifspec.ifs b/src/xspice/icm/analog/summer/ifspec.ifs index dfcaf5dea..a0337421b 100644 --- a/src/xspice/icm/analog/summer/ifspec.ifs +++ b/src/xspice/icm/analog/summer/ifspec.ifs @@ -47,7 +47,7 @@ Limits: - - Vector: yes yes Vector_Bounds: in in Null_Allowed: yes yes - +Parameter_Scope: both both PARAMETER_TABLE: @@ -61,5 +61,6 @@ Limits: - - Vector: no no Vector_Bounds: - - Null_Allowed: yes yes +Parameter_Scope: both both diff --git a/src/xspice/icm/digital/d_dff/ifspec.ifs b/src/xspice/icm/digital/d_dff/ifspec.ifs index bcd038fe3..dcbf2f38e 100644 --- a/src/xspice/icm/digital/d_dff/ifspec.ifs +++ b/src/xspice/icm/digital/d_dff/ifspec.ifs @@ -82,7 +82,7 @@ Limits: [1e-12 -] [0 2] Vector: no no Vector_Bounds: - - Null_Allowed: yes yes - +Parameter_Scope: model both PARAMETER_TABLE: diff --git a/src/xspice/icm/digital/d_dlatch/ifspec.ifs b/src/xspice/icm/digital/d_dlatch/ifspec.ifs index 868f54fbe..1de2ac055 100644 --- a/src/xspice/icm/digital/d_dlatch/ifspec.ifs +++ b/src/xspice/icm/digital/d_dlatch/ifspec.ifs @@ -94,7 +94,7 @@ Limits: [1e-12 -] [0 2] Vector: no no Vector_Bounds: - - Null_Allowed: yes yes - +Parameter_Scope: model both PARAMETER_TABLE: diff --git a/src/xspice/icm/digital/d_genlut/ifspec.ifs b/src/xspice/icm/digital/d_genlut/ifspec.ifs index c29c537be..7be18c8fd 100644 --- a/src/xspice/icm/digital/d_genlut/ifspec.ifs +++ b/src/xspice/icm/digital/d_genlut/ifspec.ifs @@ -46,6 +46,7 @@ Limits: [1e-12 -] [1e-12 -] Vector: yes yes Vector_Bounds: - - Null_Allowed: yes yes +Parameter_Scope: both both PARAMETER_TABLE: @@ -58,6 +59,8 @@ Limits: - - Vector: yes yes Vector_Bounds: - - Null_Allowed: yes yes +Parameter_Scope: both both + PARAMETER_TABLE: @@ -69,6 +72,7 @@ Limits: - Vector: no Vector_Bounds: - Null_Allowed: no +Parameter_Scope: both STATIC_VAR_TABLE: diff --git a/src/xspice/icm/digital/d_jkff/ifspec.ifs b/src/xspice/icm/digital/d_jkff/ifspec.ifs index 7183d65aa..97f3e8267 100644 --- a/src/xspice/icm/digital/d_jkff/ifspec.ifs +++ b/src/xspice/icm/digital/d_jkff/ifspec.ifs @@ -94,7 +94,7 @@ Limits: [1e-12 -] [0 2] Vector: no no Vector_Bounds: - - Null_Allowed: yes yes - +Parameter_Scope: model both PARAMETER_TABLE: diff --git a/src/xspice/icm/digital/d_lut/ifspec.ifs b/src/xspice/icm/digital/d_lut/ifspec.ifs index 05f6ca6e0..14769d394 100644 --- a/src/xspice/icm/digital/d_lut/ifspec.ifs +++ b/src/xspice/icm/digital/d_lut/ifspec.ifs @@ -46,6 +46,7 @@ Limits: [1e-12 -] [1e-12 -] Vector: no no Vector_Bounds: - - Null_Allowed: yes yes +Parameter_Scope: both both PARAMETER_TABLE: @@ -58,6 +59,8 @@ Limits: - Vector: no Vector_Bounds: - Null_Allowed: yes +Parameter_Scope: both + PARAMETER_TABLE: @@ -69,6 +72,7 @@ Limits: - Vector: no Vector_Bounds: - Null_Allowed: no +Parameter_Scope: both STATIC_VAR_TABLE: diff --git a/src/xspice/icm/digital/d_source/ifspec.ifs b/src/xspice/icm/digital/d_source/ifspec.ifs index bc91adc8f..09a113322 100644 --- a/src/xspice/icm/digital/d_source/ifspec.ifs +++ b/src/xspice/icm/digital/d_source/ifspec.ifs @@ -47,6 +47,7 @@ Limits: - Vector: no Vector_Bounds: - Null_Allowed: no +Parameter_Scope: both PARAMETER_TABLE: @@ -59,6 +60,7 @@ Limits: - Vector: no Vector_Bounds: - Null_Allowed: no +Parameter_Scope: both STATIC_VAR_TABLE: diff --git a/src/xspice/icm/digital/d_srff/ifspec.ifs b/src/xspice/icm/digital/d_srff/ifspec.ifs index f8abcabf1..585768d71 100644 --- a/src/xspice/icm/digital/d_srff/ifspec.ifs +++ b/src/xspice/icm/digital/d_srff/ifspec.ifs @@ -94,7 +94,7 @@ Limits: [1e-12 -] [0 2] Vector: no no Vector_Bounds: - - Null_Allowed: yes yes - +Parameter_Scope: model both PARAMETER_TABLE: diff --git a/src/xspice/icm/digital/d_srlatch/ifspec.ifs b/src/xspice/icm/digital/d_srlatch/ifspec.ifs index 2041d98a9..8ef3fcf11 100644 --- a/src/xspice/icm/digital/d_srlatch/ifspec.ifs +++ b/src/xspice/icm/digital/d_srlatch/ifspec.ifs @@ -106,7 +106,7 @@ Limits: [1e-12 -] [0 2] Vector: no no Vector_Bounds: - - Null_Allowed: yes yes - +Parameter_Scope: model both PARAMETER_TABLE: diff --git a/src/xspice/icm/digital/d_tff/ifspec.ifs b/src/xspice/icm/digital/d_tff/ifspec.ifs index 7a5a57843..f8ff2a5aa 100644 --- a/src/xspice/icm/digital/d_tff/ifspec.ifs +++ b/src/xspice/icm/digital/d_tff/ifspec.ifs @@ -82,7 +82,7 @@ Limits: [1e-12 -] [0 2] Vector: no no Vector_Bounds: - - Null_Allowed: yes yes - +Parameter_Scope: model both PARAMETER_TABLE: diff --git a/src/xspice/icm/digital/modpath.lst b/src/xspice/icm/digital/modpath.lst index 38d193a83..b07cba7e0 100644 --- a/src/xspice/icm/digital/modpath.lst +++ b/src/xspice/icm/digital/modpath.lst @@ -26,3 +26,5 @@ d_tff d_tristate d_xnor d_xor +d_const +da_switch diff --git a/src/xspice/mif/mif_inp2.c b/src/xspice/mif/mif_inp2.c index 3bb005cf4..2668dcab4 100644 --- a/src/xspice/mif/mif_inp2.c +++ b/src/xspice/mif/mif_inp2.c @@ -55,6 +55,8 @@ NON-STANDARD FEATURES #include "ngspice/evt.h" #include "ngspice/evtproto.h" +#include "ngspice/iferrmsg.h" + extern int *DEVicesfl; /*flags for the devices */ static void MIFinit_inst(MIFmodel *mdfast, MIFinstance *fast); @@ -160,7 +162,7 @@ and error checks are performed. -------------------------------------------------------------------------*/ extern INPmodel *modtab; -#define TRACE + void MIF_INP2A ( CKTcircuit *ckt, /* circuit structure to put mod/inst structs in */ @@ -190,7 +192,6 @@ MIF_INP2A ( MIFmodel *mdfast; /* pointer to model struct */ MIFinstance *fast[1]; /* pointer to instance struct */ - INPmodel *thismodel; /* pointer to model struct */ Mif_Conn_Info_t *conn_info; /* for faster access to conn info struct */ Mif_Param_Info_t *param_info; /* for faster access to param info struct */ @@ -202,7 +203,6 @@ MIF_INP2A ( /* SDB debug statement */ printf("In MIF_INP2A, line to process = %s . . . \n", current->line); #endif - printf("->modtab %p\n", modtab); /* get the line text from the card struct */ line = current->line; @@ -214,7 +214,6 @@ MIF_INP2A ( name = copy(MIFgettok(&line)); INPinsert(&name, tab); - printf("->modtab %p\n", modtab); /* locate the last token on the line (i.e. model name) and put it into "model" */ /* locate the model name */ @@ -227,32 +226,77 @@ MIF_INP2A ( while(linetmp > current->line && isspace_c(*linetmp)); if(*linetmp == '=') break; - printf("model updated to %s, char %c, modtab %p\n", tmp_token, *linetmp,modtab); model = tmp_token; } - printf("->modtab %p\n", modtab); /* make sure the model name was there. */ if(model == NULL) { LITERR("Missing model on A type device"); gc_end(); return; } - - /* if model name starts with !, use or create a default model */ - /* TODO */ - - /* Locate model from pass 1. If it hasn't been processed yet, */ - /* allocate a structure in ckt for it, process its parameters */ - /* and return a pointer to its structure in 'thismodel' */ - current->error = MIFgetMod(ckt, model, &thismodel, tab); - if(current->error) { - gc_end(); - return; + mdfast = NULL; + if(model[0]=='!') { + /* if model name starts with !, use or create a default model */ + IFuid defmodUid; + + type = CKTtypelook(&model[1]); + if (type<0 || type >= DEVmaxnum) { + LITERR("Codemodel type not found"); + gc_end(); + return; + } + if(0) printf("model type for %s is %d. Currently:\n", model, type); + { + char* key; + GENmodel *entry; + NGHASHITER iter; + NGHASH_FIRST(&iter); + if(0) while(entry=(GENmodel*) nghash_enumeratekRE(ckt->MODnameHash,(void**) &key, &iter)) + printf(" %s/%s\n",key,entry->GENmodName); + + for(entry=ckt->CKThead[type];entry;entry=entry->GENnextModel) { + if(strcmp(entry->GENmodName, model)==0) { + mdfast=(MIFmodel*) entry; + break; + } + } + } + /* find or create a default model */ + error = E_EXISTS; + if(mdfast==NULL) { + error = IFnewUid(ckt, &defmodUid, NULL, &model[0], UID_MODEL, NULL); + if(!error) + error = ft_sim->newModel ( ckt, type, + (GENmodel**) &mdfast, defmodUid); + } + if(error && error!=E_EXISTS) { + LITERR("Could not create or find default model"); + gc_end(); + return; + } + /* gtri modification: allocate and initialize MIF specific model struct items */ + if(error != E_EXISTS) { + mdfast->num_param = DEVices[type]->DEVpublic.num_param; + mdfast->param = TMALLOC(Mif_Param_Data_t *, mdfast->num_param); + for(i = 0; i < mdfast->num_param; i++) { + mdfast->param[i] = TMALLOC(Mif_Param_Data_t, 1); + mdfast->param[i]->is_null = MIF_TRUE; + mdfast->param[i]->size = 0; + mdfast->param[i]->element = NULL; + } + } + } else { + /* Locate model from pass 1. If it hasn't been processed yet, */ + /* allocate a structure in ckt for it, process its parameters */ + /* and return a pointer to its structure in 'thismodel' */ + INPmodel *thismodel; /* pointer to model struct */ + current->error = MIFgetMod(ckt, model, &thismodel, tab); + if(current->error) {gc_end(); return;} + type = thismodel->INPmodType; + mdfast = (MIFmodel*) thismodel->INPmodfast; } - printf("Device type %d\n", thismodel->INPmodType); - /* get the integer index into the DEVices data array for this */ - /* model */ - type = thismodel->INPmodType; + /* type and modfast is set above */ + if(0) printf("Device type %d\n", type); if((type >= DEVmaxnum) || DEVicesfl[type] == 0) { LITERR("Invalid model type for A type device"); gc_end(); @@ -260,7 +304,6 @@ MIF_INP2A ( } /* create a new structure for this instance in ckt */ - mdfast = (MIFmodel*) thismodel->INPmodfast; IFC(newInstance, (ckt, (GENmodel*)mdfast, (GENinstance **)fast, name)); @@ -369,7 +412,13 @@ MIF_INP2A ( continue; /* iterate */ } else { /* set the null flag to false */ - fast[0]->conn[i]->is_null = MIF_FALSE; + if(fast[0]->conn[i]) + fast[0]->conn[i]->is_null = MIF_FALSE; + else { + LITERR("Expected one more connection"); + int e = *((int*) NULL); + gc_end(); return; + } } @@ -1078,7 +1127,7 @@ MIFinp2_params(char *line, CKTcircuit *ckt, INPtables *tab, struct card *current int dataType = DEVices[type]->DEVpublic.instanceParms[i].dataType; if(0) printf("will set parameter %s to xspice instance\n", DEVices[type]->DEVpublic.instanceParms[i].keyword); parm = INPgetValue(ckt, &line, dataType, tab); - printf("MIFinp2_params set %s id=%d i#%d\n", name, DEVices[type]->DEVpublic.instanceParms[i].id,i); + if(0) printf("MIFinp2_params set %s id=%d i#%d\n", name, DEVices[type]->DEVpublic.instanceParms[i].id,i); IFC(setInstanceParm, (ckt, (GENinstance*)inst, DEVices[type]->DEVpublic.instanceParms[i].id, parm, NULL)); /*GCA(INPapName, (ckt, job->JOBtype, job, ana->analysisParms[i].keyword, parm)); */ } diff --git a/src/xspice/mif/mifgetmod.c b/src/xspice/mif/mifgetmod.c index 565a95475..28cb472b7 100644 --- a/src/xspice/mif/mifgetmod.c +++ b/src/xspice/mif/mifgetmod.c @@ -79,7 +79,6 @@ the .model card are not filled in by this function. They are defaulted later by MIFsetup(). The function returns NULL when successful, and an error string on failure. */ -#define TRACE char *MIFgetMod( CKTcircuit *ckt, /* The circuit structure */ diff --git a/src/xspice/mif/mifpara.c b/src/xspice/mif/mifpara.c index 8e0ab4ea7..fe4331fc0 100644 --- a/src/xspice/mif/mifpara.c +++ b/src/xspice/mif/mifpara.c @@ -57,7 +57,7 @@ MIFParam(int param_index, IFvalue *value, GENinstance *inst_in, IFvalue *select) /* Arrange for access to MIF specific data in the model */ inst = (MIFinstance*) inst_in; model = MIFmodPtr(inst); -printf("Mif param %d\n", param_index); + /* Get model type */ mod_type = model->MIFmodType; if((mod_type < 0) || (mod_type >= DEVmaxnum))