upgraded some codemodels to instance parameters + default model

This commit is contained in:
Florian Ballenegger 2020-10-06 23:57:07 +02:00
parent 043484a19d
commit 840ba9dc29
19 changed files with 113 additions and 45 deletions

View File

@ -1987,9 +1987,11 @@ static char *get_adevice_model_name(char *line)
break; /* found model */ break; /* found model */
} }
if(ptr_beg == line) 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); 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') { else if (*line == 'a') {
char *model_name = get_adevice_model_name(line); 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) { else if (has_models) {
int num_terminals = get_number_terminals(line); 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') { else if (*line == 'a') {
char *model_name = get_adevice_model_name(line); 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) { else if (has_models) {
/* This is a preliminary version, until we have found a /* 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 /* ignore certain cases, for example
* C5 node1 node2 42.0 * 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 = struct modellist *m =
inp_find_model(card->level, elem_model_name); 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); elem_model_name);
} }
} }
if(elem_model_name)
tfree(elem_model_name); tfree(elem_model_name);
} }
} }

View File

@ -142,7 +142,7 @@ extern struct coreInfo_t coreInfo; /* cmexport.c */
#ifdef NDEV #ifdef NDEV
#include "ndev/ndevitf.h" #include "ndev/ndevitf.h"
#endif #endif
#define TRACE
static SPICEdev *(*static_devices[])(void) = { static SPICEdev *(*static_devices[])(void) = {
/* URC device MUST precede both resistors and capacitors */ /* URC device MUST precede both resistors and capacitors */
get_urc_info, get_urc_info,
@ -415,7 +415,9 @@ int load_opus(const char *name)
SPICEdev **devs; SPICEdev **devs;
Evt_Udn_Info_t **udns; Evt_Udn_Info_t **udns;
funptr_t fetch; 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); lib = dlopen(name, RTLD_NOW);
if (!lib) { if (!lib) {
msg = dlerror(); msg = dlerror();

View File

@ -48,7 +48,7 @@ Limits: - -
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both
PARAMETER_TABLE: PARAMETER_TABLE:
@ -61,7 +61,7 @@ Limits: - -
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both
PARAMETER_TABLE: PARAMETER_TABLE:
@ -75,4 +75,5 @@ Limits: - -
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both

View File

@ -48,7 +48,7 @@ Limits: - -
Vector: yes yes Vector: yes yes
Vector_Bounds: in in Vector_Bounds: in in
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both
PARAMETER_TABLE: PARAMETER_TABLE:
@ -62,5 +62,6 @@ Limits: - -
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both

View File

@ -48,6 +48,7 @@ Limits: - -
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both

View File

@ -47,7 +47,7 @@ Limits: - -
Vector: yes yes Vector: yes yes
Vector_Bounds: in in Vector_Bounds: in in
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both
PARAMETER_TABLE: PARAMETER_TABLE:
@ -61,5 +61,6 @@ Limits: - -
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both

View File

@ -82,7 +82,7 @@ Limits: [1e-12 -] [0 2]
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: model both
PARAMETER_TABLE: PARAMETER_TABLE:

View File

@ -94,7 +94,7 @@ Limits: [1e-12 -] [0 2]
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: model both
PARAMETER_TABLE: PARAMETER_TABLE:

View File

@ -46,6 +46,7 @@ Limits: [1e-12 -] [1e-12 -]
Vector: yes yes Vector: yes yes
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both
PARAMETER_TABLE: PARAMETER_TABLE:
@ -58,6 +59,8 @@ Limits: - -
Vector: yes yes Vector: yes yes
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both
PARAMETER_TABLE: PARAMETER_TABLE:
@ -69,6 +72,7 @@ Limits: -
Vector: no Vector: no
Vector_Bounds: - Vector_Bounds: -
Null_Allowed: no Null_Allowed: no
Parameter_Scope: both
STATIC_VAR_TABLE: STATIC_VAR_TABLE:

View File

@ -94,7 +94,7 @@ Limits: [1e-12 -] [0 2]
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: model both
PARAMETER_TABLE: PARAMETER_TABLE:

View File

@ -46,6 +46,7 @@ Limits: [1e-12 -] [1e-12 -]
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: both both
PARAMETER_TABLE: PARAMETER_TABLE:
@ -58,6 +59,8 @@ Limits: -
Vector: no Vector: no
Vector_Bounds: - Vector_Bounds: -
Null_Allowed: yes Null_Allowed: yes
Parameter_Scope: both
PARAMETER_TABLE: PARAMETER_TABLE:
@ -69,6 +72,7 @@ Limits: -
Vector: no Vector: no
Vector_Bounds: - Vector_Bounds: -
Null_Allowed: no Null_Allowed: no
Parameter_Scope: both
STATIC_VAR_TABLE: STATIC_VAR_TABLE:

View File

@ -47,6 +47,7 @@ Limits: -
Vector: no Vector: no
Vector_Bounds: - Vector_Bounds: -
Null_Allowed: no Null_Allowed: no
Parameter_Scope: both
PARAMETER_TABLE: PARAMETER_TABLE:
@ -59,6 +60,7 @@ Limits: -
Vector: no Vector: no
Vector_Bounds: - Vector_Bounds: -
Null_Allowed: no Null_Allowed: no
Parameter_Scope: both
STATIC_VAR_TABLE: STATIC_VAR_TABLE:

View File

@ -94,7 +94,7 @@ Limits: [1e-12 -] [0 2]
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: model both
PARAMETER_TABLE: PARAMETER_TABLE:

View File

@ -106,7 +106,7 @@ Limits: [1e-12 -] [0 2]
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: model both
PARAMETER_TABLE: PARAMETER_TABLE:

View File

@ -82,7 +82,7 @@ Limits: [1e-12 -] [0 2]
Vector: no no Vector: no no
Vector_Bounds: - - Vector_Bounds: - -
Null_Allowed: yes yes Null_Allowed: yes yes
Parameter_Scope: model both
PARAMETER_TABLE: PARAMETER_TABLE:

View File

@ -26,3 +26,5 @@ d_tff
d_tristate d_tristate
d_xnor d_xnor
d_xor d_xor
d_const
da_switch

View File

@ -55,6 +55,8 @@ NON-STANDARD FEATURES
#include "ngspice/evt.h" #include "ngspice/evt.h"
#include "ngspice/evtproto.h" #include "ngspice/evtproto.h"
#include "ngspice/iferrmsg.h"
extern int *DEVicesfl; /*flags for the devices */ extern int *DEVicesfl; /*flags for the devices */
static void MIFinit_inst(MIFmodel *mdfast, MIFinstance *fast); static void MIFinit_inst(MIFmodel *mdfast, MIFinstance *fast);
@ -160,7 +162,7 @@ and error checks are performed.
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
extern INPmodel *modtab; extern INPmodel *modtab;
#define TRACE
void void
MIF_INP2A ( MIF_INP2A (
CKTcircuit *ckt, /* circuit structure to put mod/inst structs in */ CKTcircuit *ckt, /* circuit structure to put mod/inst structs in */
@ -190,7 +192,6 @@ MIF_INP2A (
MIFmodel *mdfast; /* pointer to model struct */ MIFmodel *mdfast; /* pointer to model struct */
MIFinstance *fast[1]; /* pointer to instance 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_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 */ Mif_Param_Info_t *param_info; /* for faster access to param info struct */
@ -202,7 +203,6 @@ MIF_INP2A (
/* SDB debug statement */ /* SDB debug statement */
printf("In MIF_INP2A, line to process = %s . . . \n", current->line); printf("In MIF_INP2A, line to process = %s . . . \n", current->line);
#endif #endif
printf("->modtab %p\n", modtab);
/* get the line text from the card struct */ /* get the line text from the card struct */
line = current->line; line = current->line;
@ -214,7 +214,6 @@ MIF_INP2A (
name = copy(MIFgettok(&line)); name = copy(MIFgettok(&line));
INPinsert(&name, tab); 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 last token on the line (i.e. model name) and put it into "model" */
/* locate the model name */ /* locate the model name */
@ -227,32 +226,77 @@ MIF_INP2A (
while(linetmp > current->line && isspace_c(*linetmp)); while(linetmp > current->line && isspace_c(*linetmp));
if(*linetmp == '=') if(*linetmp == '=')
break; break;
printf("model updated to %s, char %c, modtab %p\n", tmp_token, *linetmp,modtab);
model = tmp_token; model = tmp_token;
} }
printf("->modtab %p\n", modtab);
/* make sure the model name was there. */ /* make sure the model name was there. */
if(model == NULL) { if(model == NULL) {
LITERR("Missing model on A type device"); LITERR("Missing model on A type device");
gc_end(); gc_end();
return; return;
} }
mdfast = NULL;
if(model[0]=='!') {
/* if model name starts with !, use or create a default model */
IFuid defmodUid;
/* if model name starts with !, use or create a default model */ type = CKTtypelook(&model[1]);
/* TODO */ 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);
/* Locate model from pass 1. If it hasn't been processed yet, */ for(entry=ckt->CKThead[type];entry;entry=entry->GENnextModel) {
/* allocate a structure in ckt for it, process its parameters */ if(strcmp(entry->GENmodName, model)==0) {
/* and return a pointer to its structure in 'thismodel' */ mdfast=(MIFmodel*) entry;
current->error = MIFgetMod(ckt, model, &thismodel, tab); break;
if(current->error) { }
gc_end(); }
return; }
/* 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); /* type and modfast is set above */
/* get the integer index into the DEVices data array for this */ if(0) printf("Device type %d\n", type);
/* model */
type = thismodel->INPmodType;
if((type >= DEVmaxnum) || DEVicesfl[type] == 0) { if((type >= DEVmaxnum) || DEVicesfl[type] == 0) {
LITERR("Invalid model type for A type device"); LITERR("Invalid model type for A type device");
gc_end(); gc_end();
@ -260,7 +304,6 @@ MIF_INP2A (
} }
/* create a new structure for this instance in ckt */ /* create a new structure for this instance in ckt */
mdfast = (MIFmodel*) thismodel->INPmodfast;
IFC(newInstance, (ckt, (GENmodel*)mdfast, (GENinstance **)fast, name)); IFC(newInstance, (ckt, (GENmodel*)mdfast, (GENinstance **)fast, name));
@ -369,7 +412,13 @@ MIF_INP2A (
continue; /* iterate */ continue; /* iterate */
} else { } else {
/* set the null flag to false */ /* 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; 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); if(0) printf("will set parameter %s to xspice instance\n", DEVices[type]->DEVpublic.instanceParms[i].keyword);
parm = INPgetValue(ckt, &line, dataType, tab); 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)); IFC(setInstanceParm, (ckt, (GENinstance*)inst, DEVices[type]->DEVpublic.instanceParms[i].id, parm, NULL));
/*GCA(INPapName, (ckt, job->JOBtype, job, ana->analysisParms[i].keyword, parm)); */ /*GCA(INPapName, (ckt, job->JOBtype, job, ana->analysisParms[i].keyword, parm)); */
} }

View File

@ -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 defaulted later by MIFsetup(). The function returns NULL when
successful, and an error string on failure. successful, and an error string on failure.
*/ */
#define TRACE
char *MIFgetMod( char *MIFgetMod(
CKTcircuit *ckt, /* The circuit structure */ CKTcircuit *ckt, /* The circuit structure */

View File

@ -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 */ /* Arrange for access to MIF specific data in the model */
inst = (MIFinstance*) inst_in; inst = (MIFinstance*) inst_in;
model = MIFmodPtr(inst); model = MIFmodPtr(inst);
printf("Mif param %d\n", param_index);
/* Get model type */ /* Get model type */
mod_type = model->MIFmodType; mod_type = model->MIFmodType;
if((mod_type < 0) || (mod_type >= DEVmaxnum)) if((mod_type < 0) || (mod_type >= DEVmaxnum))