Fix a bug where a node name is mis-identified as the model for
an OSDI device and remove a limit on node count. Problem was reported by user Sam in ngspice-users.
This commit is contained in:
parent
b41b8a48c3
commit
629d1f5462
|
|
@ -5248,9 +5248,7 @@ int get_number_terminals(char *c)
|
||||||
return i - 2;
|
return i - 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'p': /* recognition of up to 100 cpl nodes */
|
case 'p': /* Recognition of up to 100 cpl nodes */
|
||||||
/* find the last token in the line*/
|
|
||||||
|
|
||||||
for (i = j = 0; (i < 100) && (*c != '\0'); ++i) {
|
for (i = j = 0; (i < 100) && (*c != '\0'); ++i) {
|
||||||
inst = gettok_instance(&c);
|
inst = gettok_instance(&c);
|
||||||
if (strchr(inst, '='))
|
if (strchr(inst, '='))
|
||||||
|
|
@ -5326,27 +5324,21 @@ int get_number_terminals(char *c)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef OSDI
|
#ifdef OSDI
|
||||||
case 'n': /* Recognize an unknown number of nodes by stopping at tokens with '=' */
|
case 'n':
|
||||||
{
|
/* Find the last non-parameter token in the line. */
|
||||||
char* cc, * ccfree;
|
|
||||||
|
|
||||||
cc = copy(c);
|
for (i = 0; *c != '\0' && *c != '='; ++i) {
|
||||||
/* required to make m= 1 a single token m=1 */
|
inst = gettok_instance(&c);
|
||||||
ccfree = cc = inp_remove_ws(cc);
|
if (strchr(inst, '=')) {
|
||||||
|
tfree(inst);
|
||||||
/* Find the first token with "off", "tnodeout", "thermal" or "=" */
|
|
||||||
for (i = 0; (i < 20) && (*cc != '\0'); ++i) {
|
|
||||||
inst = gettok_instance(&cc);
|
|
||||||
if (i > 2 && (strchr(inst, '='))) {
|
|
||||||
txfree(inst);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
txfree(inst);
|
tfree(inst);
|
||||||
}
|
}
|
||||||
tfree(ccfree);
|
if (*c == '=')
|
||||||
|
--i; // Counted a parameter name.
|
||||||
return i - 2;
|
return i - 2;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -22,79 +22,96 @@ void INP2N(CKTcircuit *ckt, INPtables *tab, struct card *current) {
|
||||||
* [IC=<val>,<val>,<val>]
|
* [IC=<val>,<val>,<val>]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int type; /* the type the model says it is */
|
int type; /* Model type. */
|
||||||
char *line; /* the part of the current line left to parse */
|
char *line; /* Unparsed part of the current line. */
|
||||||
char *name; /* the resistor's name */
|
char *name; /* Device instance name. */
|
||||||
// limit to at most 20 nodes
|
int error; /* Temporary error code. */
|
||||||
const int max_i = 20;
|
int numnodes; /* Flag indicating 4 or 5 (or 6 or 7) nodes. */
|
||||||
CKTnode *node[20];
|
GENinstance *fast; /* Pointer to the actual instance. */
|
||||||
int error; /* error code temporary */
|
int waslead; /* Funny unlabeled number was found. */
|
||||||
int numnodes; /* flag indicating 4 or 5 (or 6 or 7) nodes */
|
double leadval; /* Value of unlabeled number. */
|
||||||
GENinstance *fast; /* pointer to the actual instance */
|
INPmodel *thismodel; /* Pointer to model description for user's model. */
|
||||||
int waslead; /* flag to indicate that funny unlabeled number was found */
|
GENmodel *mdfast; /* Pointer to the actual model. */
|
||||||
double leadval; /* actual value of unlabeled number */
|
IFdevice *dev;
|
||||||
INPmodel *thismodel; /* pointer to model description for user's model */
|
CKTnode *node;
|
||||||
GENmodel *mdfast; /* pointer to the actual model */
|
char *c, *token = NULL, *prev = NULL, *pprev = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
line = current->line;
|
line = current->line;
|
||||||
|
|
||||||
INPgetNetTok(&line, &name, 1);
|
INPgetNetTok(&line, &name, 1);
|
||||||
INPinsert(&name, tab);
|
INPinsert(&name, tab);
|
||||||
|
|
||||||
for (i = 0;; i++) {
|
/* Find the last non-parameter token in the line. */
|
||||||
char *token;
|
|
||||||
INPgetNetTok(&line, &token, 1);
|
|
||||||
|
|
||||||
/* We have single terminal Verilog-A modules */
|
c = line;
|
||||||
if (i >= 1) {
|
for (i = 0; *c != '\0'; ++i) {
|
||||||
txfree(INPgetMod(ckt, token, &thismodel, tab));
|
tfree(pprev);
|
||||||
|
pprev = prev;
|
||||||
|
prev = token;
|
||||||
|
token = gettok_instance(&c);
|
||||||
|
if (strchr(token, '='))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (*c) {
|
||||||
|
tfree(token); // A parameter or starts with '='.
|
||||||
|
if (*c == '=') {
|
||||||
|
/* Now prev points to a parameter pprev is the model. */
|
||||||
|
|
||||||
/* /1* check if using model binning -- pass in line since need 'l' and 'w' *1/ */
|
--i;
|
||||||
/* if (!thismodel) */
|
token = pprev;
|
||||||
/* txfree(INPgetModBin(ckt, token, &thismodel, tab, line)); */
|
tfree(prev);
|
||||||
|
} else {
|
||||||
if (thismodel) {
|
token = prev;
|
||||||
INPinsert(&token, tab);
|
tfree(pprev);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (i >= max_i) {
|
|
||||||
LITERR("could not find a valid modelname");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
INPtermInsert(ckt, &token, tab, &node[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We have single terminal Verilog-A modules */
|
||||||
|
|
||||||
|
if (i >= 2) {
|
||||||
|
c = INPgetMod(ckt, token, &thismodel, tab);
|
||||||
|
if (c) {
|
||||||
|
LITERR(c);
|
||||||
|
tfree(c);
|
||||||
|
tfree(token);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tfree(token);
|
||||||
|
if (i < 2 || !thismodel) {
|
||||||
|
LITERR("could not find a valid modelname");
|
||||||
|
return;
|
||||||
|
}
|
||||||
type = thismodel->INPmodType;
|
type = thismodel->INPmodType;
|
||||||
mdfast = thismodel->INPmodfast;
|
mdfast = thismodel->INPmodfast;
|
||||||
IFdevice *dev = ft_sim->devices[type];
|
dev = ft_sim->devices[type];
|
||||||
|
|
||||||
if (!dev->registry_entry) {
|
if (!dev->registry_entry) {
|
||||||
LITERR("incorrect model type! Expected OSDI device");
|
LITERR("incorrect model type! Expected OSDI device");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0) {
|
numnodes = i - 1;
|
||||||
LITERR("not enough nodes");
|
if (numnodes > *dev->terms) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i > *dev->terms) {
|
|
||||||
LITERR("too many nodes connected to instance");
|
LITERR("too many nodes connected to instance");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
numnodes = i;
|
|
||||||
|
|
||||||
IFC(newInstance, (ckt, mdfast, &fast, name));
|
IFC(newInstance, (ckt, mdfast, &fast, name));
|
||||||
|
|
||||||
for (i = 0; i < *dev->terms; i++)
|
/* Rescan to process nodes. */
|
||||||
if (i < numnodes)
|
|
||||||
IFC(bindNode, (ckt, fast, i + 1, node[i]));
|
|
||||||
else
|
|
||||||
GENnode(fast)[i] = -1;
|
|
||||||
|
|
||||||
|
for (i = 0; i < *dev->terms; i++) {
|
||||||
|
if (i < numnodes) {
|
||||||
|
token = gettok_instance(&line);
|
||||||
|
INPtermInsert(ckt, &token, tab, &node); // Consumes token
|
||||||
|
IFC(bindNode, (ckt, fast, i + 1, node));
|
||||||
|
} else {
|
||||||
|
GENnode(fast)[i] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
token = gettok_instance(&line); // Eat model name.
|
||||||
|
tfree(token);
|
||||||
PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab));
|
PARSECALL((&line, ckt, type, fast, &leadval, &waslead, tab));
|
||||||
if (waslead)
|
if (waslead)
|
||||||
LITERR(" error: no unlabeled parameter permitted on osdi devices\n");
|
LITERR(" error: no unlabeled parameter permitted on osdi devices\n");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue