diff --git a/ChangeLog b/ChangeLog index 1932fc5b9..f002f9d49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 2010-03-07 Holger Vogt * inpcom.c: test for .end improved (comments are now allowed in .end line) * xpressn.c: adding fcn sgn() to numparam function lib + * inpptree.h,asrcacld.c,asrcload.c,asrcpzld.c,asrcset.c,ifeval.c,inpptree-parser.c, + inpptree-parser.h,inpptree-parser.y,inpptree.c: patch R. Larice, add time and temper + variables to B source 2010-03-07 Dietmar Warning * analysis/ninteg.c: limiting exp() in noise integration to prevent overflow and NAN diff --git a/src/include/inpptree.h b/src/include/inpptree.h index 26e34fffc..da87580a6 100644 --- a/src/include/inpptree.h +++ b/src/include/inpptree.h @@ -70,6 +70,9 @@ typedef struct INPparseNode { #define PT_VAR 8 #define PT_COMMA 10 #define PT_TERN 11 +#define PT_TIME 12 +#define PT_TEMPERATURE 13 +#define PT_FREQUENCY 14 /* These are the functions that we support. */ diff --git a/src/spicelib/devices/asrc/asrcacld.c b/src/spicelib/devices/asrc/asrcacld.c index a02459962..e742cf458 100644 --- a/src/spicelib/devices/asrc/asrcacld.c +++ b/src/spicelib/devices/asrc/asrcacld.c @@ -19,14 +19,14 @@ ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt) { /* - * Actually load the current voltage value into the + * Actually load the current voltage value into the * sparse matrix previously provided. The values have * been precomputed and stored with the instance model. */ - ASRCmodel *model = (ASRCmodel*)inModel; + ASRCmodel *model = (ASRCmodel*) inModel; ASRCinstance *here; - int i, v_first, j; + int i, j; double *derivs; double rhs; @@ -36,32 +36,33 @@ ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt) /* loop through all the instances of the model */ for (here = model->ASRCinstances; here != NULL ; here = here->ASRCnextInstance) { - if (here->ASRCowner != ARCHme) continue; - + + if (here->ASRCowner != ARCHme) + continue; + /* * Get the function and its derivatives from the - * field in the instance structure. The field is + * field in the instance structure. The field is * an array of doubles holding the rhs, and the * entries of the jacobian. */ - v_first = 1; j=0; derivs = here->ASRCacValues; rhs = (here->ASRCacValues)[here->ASRCtree->numVars]; - for(i=0; i < here->ASRCtree->numVars; i++){ - switch(here->ASRCtree->varTypes[i]){ + if( here->ASRCtype == ASRC_VOLTAGE) { + *(here->ASRCposptr[j++]) += 1.0; + *(here->ASRCposptr[j++]) -= 1.0; + *(here->ASRCposptr[j++]) -= 1.0; + *(here->ASRCposptr[j++]) += 1.0; + } + + for(i=0; i < here->ASRCtree->numVars; i++) { + switch(here->ASRCtree->varTypes[i]) { case IF_INSTANCE: - if( here->ASRCtype == ASRC_VOLTAGE){ + if( here->ASRCtype == ASRC_VOLTAGE) { /* CCVS */ - if(v_first){ - *(here->ASRCposptr[j++]) += 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) += 1.0; - v_first = 0; - } *(here->ASRCposptr[j++]) -= derivs[i]; } else{ /* CCCS */ @@ -70,15 +71,8 @@ ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt) } break; case IF_NODE: - if(here->ASRCtype == ASRC_VOLTAGE){ + if(here->ASRCtype == ASRC_VOLTAGE) { /* VCVS */ - if( v_first){ - *(here->ASRCposptr[j++]) += 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) += 1.0; - v_first = 0; - } *(here->ASRCposptr[j++]) -= derivs[i]; } else { /*VCCS*/ @@ -92,5 +86,6 @@ ASRCacLoad(GENmodel *inModel, CKTcircuit *ckt) } } } + return(OK); } diff --git a/src/spicelib/devices/asrc/asrcload.c b/src/spicelib/devices/asrc/asrcload.c index 8a2097760..61732195c 100644 --- a/src/spicelib/devices/asrc/asrcload.c +++ b/src/spicelib/devices/asrc/asrcload.c @@ -20,15 +20,13 @@ int ASRCload(GENmodel *inModel, CKTcircuit *ckt) { - /* actually load the current voltage value into the - * sparse matrix previously provided + /* actually load the current voltage value into the + * sparse matrix previously provided */ - ASRCmodel *model = (ASRCmodel*)inModel; + ASRCmodel *model = (ASRCmodel*) inModel; ASRCinstance *here; - int i, v_first, j, branch; - int node_num; - int size; + int i, j; double rhs; /* loop through all the Arbitrary source models */ @@ -38,12 +36,12 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt) for (here = model->ASRCinstances; here != NULL ; here=here->ASRCnextInstance) { - if (here->ASRCowner != ARCHme) continue; - + if (here->ASRCowner != ARCHme) + continue; + /* - * Get the function and its derivatives evaluated + * Get the function and its derivatives evaluated */ - v_first = 1; i = here->ASRCtree->numVars; if (asrc_nvals < i) { if (asrc_nvals) { @@ -60,95 +58,82 @@ ASRCload(GENmodel *inModel, CKTcircuit *ckt) /* * Fill the vector of values from the previous solution */ - for( i=0; i < here->ASRCtree->numVars; i++){ - if( here->ASRCtree->varTypes[i] == IF_INSTANCE){ - branch = CKTfndBranch(ckt, - here->ASRCtree->vars[i].uValue); - asrc_vals[i] = *(ckt->CKTrhsOld+branch); + for( i=0; i < here->ASRCtree->numVars; i++) + if( here->ASRCtree->varTypes[i] == IF_INSTANCE) { + int branch = CKTfndBranch(ckt, here->ASRCtree->vars[i].uValue); + asrc_vals[i] = *(ckt->CKTrhsOld + branch); } else { - node_num = ((CKTnode *)(here->ASRCtree->vars[i]. - nValue))->number; - asrc_vals[i] = *(ckt->CKTrhsOld+node_num); - } - } - - if ((*(here->ASRCtree->IFeval))(here->ASRCtree,ckt->CKTgmin, &rhs, - asrc_vals,asrc_derivs) == OK) - { - - /* The convergence test */ - here->ASRCprev_value = rhs; - - /* The ac load precomputation and storage */ - - if (ckt->CKTmode & MODEINITSMSIG) { - size = (here->ASRCtree->numVars)+1 ; - here->ASRCacValues = NEWN(double, size); - for ( i = 0; i < here->ASRCtree->numVars; i++){ - here->ASRCacValues[i] = asrc_derivs[i]; - } + int node_num = ((CKTnode *)(here->ASRCtree->vars[i]. nValue))->number; + asrc_vals[i] = *(ckt->CKTrhsOld + node_num); } - for(i=0; i < here->ASRCtree->numVars; i++) { - rhs -= (asrc_vals[i] * asrc_derivs[i]); - switch(here->ASRCtree->varTypes[i]){ - case IF_INSTANCE: - if( here->ASRCtype == ASRC_VOLTAGE){ - /* CCVS */ - if(v_first){ - *(here->ASRCposptr[j++]) += 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) += 1.0; - v_first = 0; - } - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - } else{ - /* CCCS */ - *(here->ASRCposptr[j++]) += asrc_derivs[i]; - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - } - break; - - case IF_NODE: - if(here->ASRCtype == ASRC_VOLTAGE) { - /* VCVS */ - if( v_first){ - *(here->ASRCposptr[j++]) += 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) += 1.0; - v_first = 0; - } - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - } else { - /*VCCS*/ - *(here->ASRCposptr[j++]) += asrc_derivs[i]; - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - } - break; - - default: - return(E_BADPARM); - } - } - - /* Insert the RHS */ - if( here->ASRCtype == ASRC_VOLTAGE){ - *(ckt->CKTrhs+(here->ASRCbranch)) += rhs; - } else { - *(ckt->CKTrhs+(here->ASRCposNode)) -= rhs; - *(ckt->CKTrhs+(here->ASRCnegNode)) += rhs; - } - - /* Store the rhs for small signal analysis */ - if (ckt->CKTmode & MODEINITSMSIG){ - here->ASRCacValues[here->ASRCtree->numVars] = rhs; - } - } else{ + if ((*(here->ASRCtree->IFeval))(here->ASRCtree,ckt->CKTgmin, &rhs, asrc_vals,asrc_derivs) != OK) return(E_BADPARM); + + /* The convergence test */ + here->ASRCprev_value = rhs; + + /* The ac load precomputation and storage */ + + if (ckt->CKTmode & MODEINITSMSIG) { + int size = (here->ASRCtree->numVars) + 1 ; + here->ASRCacValues = NEWN(double, size); + for ( i = 0; i < here->ASRCtree->numVars; i++) + here->ASRCacValues[i] = asrc_derivs[i]; } - } + + if( here->ASRCtype == ASRC_VOLTAGE) { + *(here->ASRCposptr[j++]) += 1.0; + *(here->ASRCposptr[j++]) -= 1.0; + *(here->ASRCposptr[j++]) -= 1.0; + *(here->ASRCposptr[j++]) += 1.0; + } + + for(i=0; i < here->ASRCtree->numVars; i++) { + rhs -= (asrc_vals[i] * asrc_derivs[i]); + + switch(here->ASRCtree->varTypes[i]) { + case IF_INSTANCE: + if( here->ASRCtype == ASRC_VOLTAGE) { + /* CCVS */ + *(here->ASRCposptr[j++]) -= asrc_derivs[i]; + } else{ + /* CCCS */ + *(here->ASRCposptr[j++]) += asrc_derivs[i]; + *(here->ASRCposptr[j++]) -= asrc_derivs[i]; + } + break; + + case IF_NODE: + if(here->ASRCtype == ASRC_VOLTAGE) { + /* VCVS */ + *(here->ASRCposptr[j++]) -= asrc_derivs[i]; + } else { + /*VCCS*/ + *(here->ASRCposptr[j++]) += asrc_derivs[i]; + *(here->ASRCposptr[j++]) -= asrc_derivs[i]; + } + break; + + default: + return(E_BADPARM); + } + } + + /* Insert the RHS */ + if( here->ASRCtype == ASRC_VOLTAGE) { + *(ckt->CKTrhs+(here->ASRCbranch)) += rhs; + } else { + *(ckt->CKTrhs+(here->ASRCposNode)) -= rhs; + *(ckt->CKTrhs+(here->ASRCnegNode)) += rhs; + } + + /* Store the rhs for small signal analysis */ + if (ckt->CKTmode & MODEINITSMSIG) { + here->ASRCacValues[here->ASRCtree->numVars] = rhs; + } + } } + return(OK); } diff --git a/src/spicelib/devices/asrc/asrcpzld.c b/src/spicelib/devices/asrc/asrcpzld.c index 592ee5e00..16769f282 100644 --- a/src/spicelib/devices/asrc/asrcpzld.c +++ b/src/spicelib/devices/asrc/asrcpzld.c @@ -14,15 +14,14 @@ Author: 1987 Kanwar Jit Singh int ASRCpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) - /* actually load the current voltage value into the - * sparse matrix previously provided + /* actually load the current voltage value into the + * sparse matrix previously provided */ { - ASRCmodel *model = (ASRCmodel*)inModel; + ASRCmodel *model = (ASRCmodel*) inModel; ASRCinstance *here; double value; - int i, v_first, j, branch; - int node_num; + int i, j; /* loop through all the Arbitrary source models */ for( ; model != NULL; model = model->ASRCnextModel ) { @@ -30,84 +29,73 @@ ASRCpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s) /* loop through all the instances of the model */ for (here = model->ASRCinstances; here != NULL ; here=here->ASRCnextInstance) - { - if (here->ASRCowner != ARCHme) continue; - j = 0; + { + if (here->ASRCowner != ARCHme) + continue; + + j = 0; + /* Get the function evaluated and the derivatives too */ - v_first = 1; - i = here->ASRCtree->numVars; - if (asrc_nvals < i) { - if (asrc_nvals) { - FREE(asrc_vals); - FREE(asrc_derivs); - } - asrc_nvals = i; - asrc_vals = NEWN(double, i); - asrc_derivs = NEWN(double, i); - } + i = here->ASRCtree->numVars; + if (asrc_nvals < i) { + if (asrc_nvals) { + FREE(asrc_vals); + FREE(asrc_derivs); + } + asrc_nvals = i; + asrc_vals = NEWN(double, i); + asrc_derivs = NEWN(double, i); + } /* Fill the vector of values from the previous solution */ - for( i=0; i < here->ASRCtree->numVars; i++){ - if( here->ASRCtree->varTypes[i] == IF_INSTANCE){ - branch = CKTfndBranch(ckt,here->ASRCtree->vars[i].uValue); - asrc_vals[i] = *(ckt->CKTrhsOld+branch); + for( i=0; i < here->ASRCtree->numVars; i++) { + if( here->ASRCtree->varTypes[i] == IF_INSTANCE) { + int branch = CKTfndBranch(ckt,here->ASRCtree->vars[i].uValue); + asrc_vals[i] = *(ckt->CKTrhsOld + branch); } else { - node_num = ((CKTnode *)(here->ASRCtree->vars[i].nValue))-> - number; - asrc_vals[i] = *(ckt->CKTrhsOld+node_num); + int node_num = ((CKTnode *)(here->ASRCtree->vars[i].nValue)) -> number; + asrc_vals[i] = *(ckt->CKTrhsOld + node_num); } } - if( (*(here->ASRCtree->IFeval))(here->ASRCtree, ckt->CKTgmin, - &value, asrc_vals, asrc_derivs) == OK){ - for(i=0; i < here->ASRCtree->numVars; i++){ - switch(here->ASRCtree->varTypes[i]){ - case IF_INSTANCE: - if( here->ASRCtype == ASRC_VOLTAGE){ - /* CCVS */ - if(v_first){ - *(here->ASRCposptr[j++]) += 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) += 1.0; - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - v_first = 0; - } else { - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - } - } else { - /* CCCS */ - *(here->ASRCposptr[j++]) += asrc_derivs[i]; - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - } - break; - case IF_NODE: - if(here->ASRCtype == ASRC_VOLTAGE){ - /* VCVS */ - if( v_first){ - *(here->ASRCposptr[j++]) += 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) -= 1.0; - *(here->ASRCposptr[j++]) += 1.0; - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - v_first = 0; - } else { - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - } - } else { - /* VCCS */ - *(here->ASRCposptr[j++]) += asrc_derivs[i]; - *(here->ASRCposptr[j++]) -= asrc_derivs[i]; - } - break; - default: - return(E_BADPARM); - } - } - } else { + if((*(here->ASRCtree->IFeval))(here->ASRCtree, ckt->CKTgmin, &value, asrc_vals, asrc_derivs) != OK) return(E_BADPARM); + + if( here->ASRCtype == ASRC_VOLTAGE) { + *(here->ASRCposptr[j++]) += 1.0; + *(here->ASRCposptr[j++]) -= 1.0; + *(here->ASRCposptr[j++]) -= 1.0; + *(here->ASRCposptr[j++]) += 1.0; + } + + for(i=0; i < here->ASRCtree->numVars; i++) { + switch(here->ASRCtree->varTypes[i]) { + case IF_INSTANCE: + if( here->ASRCtype == ASRC_VOLTAGE) { + /* CCVS */ + *(here->ASRCposptr[j++]) -= asrc_derivs[i]; + } else { + /* CCCS */ + *(here->ASRCposptr[j++]) += asrc_derivs[i]; + *(here->ASRCposptr[j++]) -= asrc_derivs[i]; + } + break; + case IF_NODE: + if(here->ASRCtype == ASRC_VOLTAGE) { + /* VCVS */ + *(here->ASRCposptr[j++]) -= asrc_derivs[i]; + } else { + /* VCCS */ + *(here->ASRCposptr[j++]) += asrc_derivs[i]; + *(here->ASRCposptr[j++]) -= asrc_derivs[i]; + } + break; + default: + return(E_BADPARM); + } } } } + return(OK); } diff --git a/src/spicelib/devices/asrc/asrcset.c b/src/spicelib/devices/asrc/asrcset.c index fdbd9fa68..a764bf7ae 100644 --- a/src/spicelib/devices/asrc/asrcset.c +++ b/src/spicelib/devices/asrc/asrcset.c @@ -62,6 +62,16 @@ if((here->ptr = SMPmakeElt(matrix,here->first,((CKTnode*)(second))->number))\ in the vector of the positions of the SMP */ if (!here->ASRCtree) return E_PARMVAL; + + if( here->ASRCtype == ASRC_VOLTAGE) { + here->ASRCposptr = (double **) + REALLOC(here->ASRCposptr, (sizeof(double *)*(j+5))); + TSTALLOC(ASRCposptr[j++],ASRCposNode,ASRCbranch); + TSTALLOC(ASRCposptr[j++],ASRCnegNode,ASRCbranch); + TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCnegNode); + TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCposNode); + } + for( i=0; i < here->ASRCtree->numVars; i++){ switch(here->ASRCtree->varTypes[i]){ case IF_INSTANCE: @@ -78,12 +88,6 @@ if((here->ptr = SMPmakeElt(matrix,here->first,((CKTnode*)(second))->number))\ if( here->ASRCtype == ASRC_VOLTAGE){ /* CCVS */ if(v_first){ - here->ASRCposptr = (double **) - REALLOC(here->ASRCposptr, (sizeof(double *)*(j+5))); - TSTALLOC(ASRCposptr[j++],ASRCposNode,ASRCbranch); - TSTALLOC(ASRCposptr[j++],ASRCnegNode,ASRCbranch); - TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCnegNode); - TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCposNode); TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCcont_br); v_first = 0; } else{ @@ -105,12 +109,6 @@ if((here->ptr = SMPmakeElt(matrix,here->first,((CKTnode*)(second))->number))\ if( here->ASRCtype == ASRC_VOLTAGE){ /* VCVS */ if(v_first){ - here->ASRCposptr = (double **) - REALLOC(here->ASRCposptr, (sizeof(double *) * (j+5))); - TSTALLOC(ASRCposptr[j++],ASRCposNode,ASRCbranch); - TSTALLOC(ASRCposptr[j++],ASRCnegNode,ASRCbranch); - TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCnegNode); - TSTALLOC(ASRCposptr[j++],ASRCbranch,ASRCposNode); MY_TSTALLOC(ASRCposptr[j++],ASRCbranch,here->ASRCtree->vars[i].nValue); v_first = 0; } else{ diff --git a/src/spicelib/parser/ifeval.c b/src/spicelib/parser/ifeval.c index 21aa35129..a7bca3b99 100644 --- a/src/spicelib/parser/ifeval.c +++ b/src/spicelib/parser/ifeval.c @@ -12,6 +12,7 @@ $Id$ #include "iferrmsg.h" #include "inpptree.h" #include "inp.h" +#include "cktdefs.h" /* Uncomment to allow tracing */ /*#define TRACE*/ @@ -123,6 +124,21 @@ PTeval(INPparseNode * tree, double gmin, double *res, double *vals) } break; + case PT_TIME: + *res = ((CKTcircuit*) tree->data) -> CKTtime; + break; + + case PT_TEMPERATURE: + *res = ((CKTcircuit*) tree->data) -> CKTtemp; + break; + + case PT_FREQUENCY: + /*((ACAN*)ckt->CKTcurJob)->ACsaveFreq;*/ +// *res = ((ACAN*)((CKTcircuit*) tree->data)->CKTcurJob)->ACsaveFreq; + /*ckt->CKTomega = 2.0 * M_PI *freq;*/ + *res = (((CKTcircuit*) tree->data) -> CKTomega)/2./M_PI; + break; + default: fprintf(stderr, "Internal Error: bad node type %d\n", tree->type); return (E_PANIC); diff --git a/src/spicelib/parser/inpptree-parser.c b/src/spicelib/parser/inpptree-parser.c index 3cd18bcfd..d90455b60 100644 --- a/src/spicelib/parser/inpptree-parser.c +++ b/src/spicelib/parser/inpptree-parser.c @@ -83,9 +83,9 @@ #include "inpptree-parser.h" extern int PTlex (YYSTYPE *lvalp, char **line); - extern int PTparse (char **line, struct INPparseNode **retval); + extern int PTparse (char **line, struct INPparseNode **retval, void *ckt); - static void PTerror (char **line, struct INPparseNode **retval, char const *); + static void PTerror (char **line, struct INPparseNode **retval, void *ckt, char const *); #if defined (_MSC_VER) # define __func__ __FUNCTION__ /* __func__ is C99, but MSC can't */ @@ -142,7 +142,7 @@ typedef union YYSTYPE { /* Line 222 of yacc.c */ -#line 29 "inpptree-parser.y" +#line 30 "inpptree-parser.y" double num; const char *str; @@ -455,9 +455,9 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 57, 57, 61, 62, 64, 65, 66, 67, 68, - 70, 72, 74, 76, 81, 82, 83, 84, 85, 86, - 88, 92, 96, 101, 102 + 0, 58, 58, 62, 63, 65, 66, 67, 68, 69, + 71, 73, 75, 77, 82, 83, 84, 85, 86, 87, + 89, 93, 97, 102, 103 }; #endif @@ -618,7 +618,7 @@ do \ } \ else \ { \ - yyerror (line, retval, YY_("syntax error: cannot back up")); \ + yyerror (line, retval, ckt, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) @@ -698,7 +698,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, line, retval); \ + Type, Value, line, retval, ckt); \ YYFPRINTF (stderr, "\n"); \ } \ } while (YYID (0)) @@ -712,21 +712,23 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, char **line, struct INPparseNode **retval) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, char **line, struct INPparseNode **retval, void *ckt) #else static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep, line, retval) +yy_symbol_value_print (yyoutput, yytype, yyvaluep, line, retval, ckt) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; char **line; struct INPparseNode **retval; + void *ckt; #endif { if (!yyvaluep) return; YYUSE (line); YYUSE (retval); + YYUSE (ckt); # ifdef YYPRINT if (yytype < YYNTOKENS) YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); @@ -748,15 +750,16 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, line, retval) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, char **line, struct INPparseNode **retval) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, char **line, struct INPparseNode **retval, void *ckt) #else static void -yy_symbol_print (yyoutput, yytype, yyvaluep, line, retval) +yy_symbol_print (yyoutput, yytype, yyvaluep, line, retval, ckt) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; char **line; struct INPparseNode **retval; + void *ckt; #endif { if (yytype < YYNTOKENS) @@ -764,7 +767,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, line, retval) else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, line, retval); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, line, retval, ckt); YYFPRINTF (yyoutput, ")"); } @@ -807,14 +810,15 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule, char **line, struct INPparseNode **retval) +yy_reduce_print (YYSTYPE *yyvsp, int yyrule, char **line, struct INPparseNode **retval, void *ckt) #else static void -yy_reduce_print (yyvsp, yyrule, line, retval) +yy_reduce_print (yyvsp, yyrule, line, retval, ckt) YYSTYPE *yyvsp; int yyrule; char **line; struct INPparseNode **retval; + void *ckt; #endif { int yynrhs = yyr2[yyrule]; @@ -828,7 +832,7 @@ yy_reduce_print (yyvsp, yyrule, line, retval) YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) - , line, retval); + , line, retval, ckt); YYFPRINTF (stderr, "\n"); } } @@ -836,7 +840,7 @@ yy_reduce_print (yyvsp, yyrule, line, retval) # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyvsp, Rule, line, retval); \ + yy_reduce_print (yyvsp, Rule, line, retval, ckt); \ } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that @@ -1087,20 +1091,22 @@ yysyntax_error (char *yyresult, int yystate, int yychar) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, char **line, struct INPparseNode **retval) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, char **line, struct INPparseNode **retval, void *ckt) #else static void -yydestruct (yymsg, yytype, yyvaluep, line, retval) +yydestruct (yymsg, yytype, yyvaluep, line, retval, ckt) const char *yymsg; int yytype; YYSTYPE *yyvaluep; char **line; struct INPparseNode **retval; + void *ckt; #endif { YYUSE (yyvaluep); YYUSE (line); YYUSE (retval); + YYUSE (ckt); if (!yymsg) yymsg = "Deleting"; @@ -1123,7 +1129,7 @@ int yyparse (); #endif #else /* ! YYPARSE_PARAM */ #if defined __STDC__ || defined __cplusplus -int yyparse (char **line, struct INPparseNode **retval); +int yyparse (char **line, struct INPparseNode **retval, void *ckt); #else int yyparse (); #endif @@ -1151,12 +1157,13 @@ yyparse (YYPARSE_PARAM) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int -yyparse (char **line, struct INPparseNode **retval) +yyparse (char **line, struct INPparseNode **retval, void *ckt) #else int -yyparse (line, retval) +yyparse (line, retval, ckt) char **line; struct INPparseNode **retval; + void *ckt; #endif #endif { @@ -1411,84 +1418,84 @@ yyreduce: case 2: /* Line 1455 of yacc.c */ -#line 57 "inpptree-parser.y" +#line 58 "inpptree-parser.y" { *retval = (yyvsp[(1) - (1)].pnode); ;} break; case 3: /* Line 1455 of yacc.c */ -#line 61 "inpptree-parser.y" +#line 62 "inpptree-parser.y" { (yyval.pnode) = mknnode((yyvsp[(1) - (1)].num)); ;} break; case 4: /* Line 1455 of yacc.c */ -#line 62 "inpptree-parser.y" - { (yyval.pnode) = mksnode((yyvsp[(1) - (1)].str)); ;} +#line 63 "inpptree-parser.y" + { (yyval.pnode) = mksnode((yyvsp[(1) - (1)].str), ckt); ;} break; case 5: /* Line 1455 of yacc.c */ -#line 64 "inpptree-parser.y" +#line 65 "inpptree-parser.y" { (yyval.pnode) = mkbnode("+", (yyvsp[(1) - (3)].pnode), (yyvsp[(3) - (3)].pnode)); ;} break; case 6: /* Line 1455 of yacc.c */ -#line 65 "inpptree-parser.y" +#line 66 "inpptree-parser.y" { (yyval.pnode) = mkbnode("-", (yyvsp[(1) - (3)].pnode), (yyvsp[(3) - (3)].pnode)); ;} break; case 7: /* Line 1455 of yacc.c */ -#line 66 "inpptree-parser.y" +#line 67 "inpptree-parser.y" { (yyval.pnode) = mkbnode("*", (yyvsp[(1) - (3)].pnode), (yyvsp[(3) - (3)].pnode)); ;} break; case 8: /* Line 1455 of yacc.c */ -#line 67 "inpptree-parser.y" +#line 68 "inpptree-parser.y" { (yyval.pnode) = mkbnode("/", (yyvsp[(1) - (3)].pnode), (yyvsp[(3) - (3)].pnode)); ;} break; case 9: /* Line 1455 of yacc.c */ -#line 68 "inpptree-parser.y" +#line 69 "inpptree-parser.y" { (yyval.pnode) = mkbnode("^", (yyvsp[(1) - (3)].pnode), (yyvsp[(3) - (3)].pnode)); ;} break; case 10: /* Line 1455 of yacc.c */ -#line 70 "inpptree-parser.y" +#line 71 "inpptree-parser.y" { (yyval.pnode) = (yyvsp[(2) - (3)].pnode); ;} break; case 11: /* Line 1455 of yacc.c */ -#line 72 "inpptree-parser.y" +#line 73 "inpptree-parser.y" { (yyval.pnode) = mkfnode("-",(yyvsp[(2) - (2)].pnode)); ;} break; case 12: /* Line 1455 of yacc.c */ -#line 74 "inpptree-parser.y" +#line 75 "inpptree-parser.y" { (yyval.pnode) = mkfnode((yyvsp[(1) - (4)].str), (yyvsp[(3) - (4)].pnode)); ;} break; case 13: /* Line 1455 of yacc.c */ -#line 76 "inpptree-parser.y" +#line 77 "inpptree-parser.y" { (yyval.pnode) = mkfnode("ternary_fcn", mkbnode(",", mkbnode(",", (yyvsp[(1) - (5)].pnode), (yyvsp[(3) - (5)].pnode)), @@ -1498,49 +1505,49 @@ yyreduce: case 14: /* Line 1455 of yacc.c */ -#line 81 "inpptree-parser.y" +#line 82 "inpptree-parser.y" { (yyval.pnode) = mkfnode("eq0", mkbnode("-",(yyvsp[(1) - (3)].pnode),(yyvsp[(3) - (3)].pnode))); ;} break; case 15: /* Line 1455 of yacc.c */ -#line 82 "inpptree-parser.y" +#line 83 "inpptree-parser.y" { (yyval.pnode) = mkfnode("ne0", mkbnode("-",(yyvsp[(1) - (3)].pnode),(yyvsp[(3) - (3)].pnode))); ;} break; case 16: /* Line 1455 of yacc.c */ -#line 83 "inpptree-parser.y" +#line 84 "inpptree-parser.y" { (yyval.pnode) = mkfnode("gt0", mkbnode("-",(yyvsp[(1) - (3)].pnode),(yyvsp[(3) - (3)].pnode))); ;} break; case 17: /* Line 1455 of yacc.c */ -#line 84 "inpptree-parser.y" +#line 85 "inpptree-parser.y" { (yyval.pnode) = mkfnode("lt0", mkbnode("-",(yyvsp[(1) - (3)].pnode),(yyvsp[(3) - (3)].pnode))); ;} break; case 18: /* Line 1455 of yacc.c */ -#line 85 "inpptree-parser.y" +#line 86 "inpptree-parser.y" { (yyval.pnode) = mkfnode("ge0", mkbnode("-",(yyvsp[(1) - (3)].pnode),(yyvsp[(3) - (3)].pnode))); ;} break; case 19: /* Line 1455 of yacc.c */ -#line 86 "inpptree-parser.y" +#line 87 "inpptree-parser.y" { (yyval.pnode) = mkfnode("le0", mkbnode("-",(yyvsp[(1) - (3)].pnode),(yyvsp[(3) - (3)].pnode))); ;} break; case 20: /* Line 1455 of yacc.c */ -#line 88 "inpptree-parser.y" +#line 89 "inpptree-parser.y" { (yyval.pnode) = mkfnode("ne0", mkbnode("+", mkfnode("ne0", (yyvsp[(1) - (3)].pnode)), @@ -1550,7 +1557,7 @@ yyreduce: case 21: /* Line 1455 of yacc.c */ -#line 92 "inpptree-parser.y" +#line 93 "inpptree-parser.y" { (yyval.pnode) = mkfnode("eq0", mkbnode("+", mkfnode("eq0", (yyvsp[(1) - (3)].pnode)), @@ -1560,21 +1567,21 @@ yyreduce: case 22: /* Line 1455 of yacc.c */ -#line 96 "inpptree-parser.y" +#line 97 "inpptree-parser.y" { (yyval.pnode) = mkfnode("eq0", (yyvsp[(2) - (2)].pnode)); ;} break; case 24: /* Line 1455 of yacc.c */ -#line 102 "inpptree-parser.y" +#line 103 "inpptree-parser.y" { (yyval.pnode) = mkbnode(",", (yyvsp[(1) - (3)].pnode), (yyvsp[(3) - (3)].pnode)); ;} break; /* Line 1455 of yacc.c */ -#line 1578 "inpptree-parser.c" +#line 1585 "inpptree-parser.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -1609,7 +1616,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (line, retval, YY_("syntax error")); + yyerror (line, retval, ckt, YY_("syntax error")); #else { YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); @@ -1633,11 +1640,11 @@ yyerrlab: if (0 < yysize && yysize <= yymsg_alloc) { (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (line, retval, yymsg); + yyerror (line, retval, ckt, yymsg); } else { - yyerror (line, retval, YY_("syntax error")); + yyerror (line, retval, ckt, YY_("syntax error")); if (yysize != 0) goto yyexhaustedlab; } @@ -1661,7 +1668,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, line, retval); + yytoken, &yylval, line, retval, ckt); yychar = YYEMPTY; } } @@ -1717,7 +1724,7 @@ yyerrlab1: yydestruct ("Error: popping", - yystos[yystate], yyvsp, line, retval); + yystos[yystate], yyvsp, line, retval, ckt); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1752,7 +1759,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (line, retval, YY_("memory exhausted")); + yyerror (line, retval, ckt, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -1760,7 +1767,7 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, line, retval); + yytoken, &yylval, line, retval, ckt); /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -1768,7 +1775,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, line, retval); + yystos[*yyssp], yyvsp, line, retval, ckt); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1786,13 +1793,13 @@ yyreturn: /* Line 1675 of yacc.c */ -#line 104 "inpptree-parser.y" +#line 105 "inpptree-parser.y" /* Called by yyparse on error. */ static void -PTerror (char **line, struct INPparseNode **retval, char const *s) +PTerror (char **line, struct INPparseNode **retval, void *ckt, char const *s) { fprintf (stderr, "%s: %s\n", __func__, s); } diff --git a/src/spicelib/parser/inpptree-parser.h b/src/spicelib/parser/inpptree-parser.h index 84b70da1d..b2e39e3c2 100644 --- a/src/spicelib/parser/inpptree-parser.h +++ b/src/spicelib/parser/inpptree-parser.h @@ -60,7 +60,7 @@ typedef union YYSTYPE { /* Line 1740 of yacc.c */ -#line 29 "inpptree-parser.y" +#line 30 "inpptree-parser.y" double num; const char *str; diff --git a/src/spicelib/parser/inpptree-parser.y b/src/spicelib/parser/inpptree-parser.y index 6ef761d19..adfc8a697 100644 --- a/src/spicelib/parser/inpptree-parser.y +++ b/src/spicelib/parser/inpptree-parser.y @@ -4,9 +4,9 @@ #include "inpptree-parser.h" extern int PTlex (YYSTYPE *lvalp, char **line); - extern int PTparse (char **line, struct INPparseNode **retval); + extern int PTparse (char **line, struct INPparseNode **retval, void *ckt); - static void PTerror (char **line, struct INPparseNode **retval, char const *); + static void PTerror (char **line, struct INPparseNode **retval, void *ckt, char const *); #if defined (_MSC_VER) # define __func__ __FUNCTION__ /* __func__ is C99, but MSC can't */ @@ -25,6 +25,7 @@ %lex-param {char **line} %parse-param {struct INPparseNode **retval} +%parse-param {void *ckt} %union { double num; @@ -59,7 +60,7 @@ expression: exp: TOK_NUM { $$ = mknnode($1); } - | TOK_STR { $$ = mksnode($1); } + | TOK_STR { $$ = mksnode($1, ckt); } | exp '+' exp { $$ = mkbnode("+", $1, $3); } | exp '-' exp { $$ = mkbnode("-", $1, $3); } @@ -106,7 +107,7 @@ nonempty_arglist: /* Called by yyparse on error. */ static void -PTerror (char **line, struct INPparseNode **retval, char const *s) +PTerror (char **line, struct INPparseNode **retval, void *ckt, char const *s) { fprintf (stderr, "%s: %s\n", __func__, s); } diff --git a/src/spicelib/parser/inpptree.c b/src/spicelib/parser/inpptree.c index 467f3fd3b..ec2fe6142 100644 --- a/src/spicelib/parser/inpptree.c +++ b/src/spicelib/parser/inpptree.c @@ -20,7 +20,7 @@ static INPparseNode *mkbnode(const char *opstr, INPparseNode * arg1, INPparseNode * arg2); static INPparseNode *mkfnode(const char *fname, INPparseNode * arg); static INPparseNode *mknnode(double number); -static INPparseNode *mksnode(const char *string); +static INPparseNode *mksnode(const char *string, void *ckt); static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum); #include "inpptree-parser.c" @@ -130,7 +130,7 @@ INPgetTree(char **line, INPparseTree ** pt, void *ckt, INPtables * tab) fprintf(stderr,"%s, line = \"%s\"\n", __func__, *line); #endif - rv = PTparse(line, &p); + rv = PTparse(line, &p, ckt); if (rv || !PTcheck(p)) { *pt = NULL; @@ -168,6 +168,9 @@ static INPparseNode *PTdifferentiate(INPparseNode * p, int varnum) INPparseNode *arg1 = NULL, *arg2, *newp; switch (p->type) { + case PT_TIME: + case PT_TEMPERATURE: + case PT_FREQUENCY: case PT_CONSTANT: newp = mkcon((double) 0); break; @@ -607,6 +610,9 @@ static int PTcheck(INPparseNode * p) case PT_PLACEHOLDER: return (0); + case PT_TIME: + case PT_TEMPERATURE: + case PT_FREQUENCY: case PT_CONSTANT: case PT_VAR: return (1); @@ -891,7 +897,7 @@ static INPparseNode *mknnode(double number) /* String node. */ -static INPparseNode *mksnode(const char *string) +static INPparseNode *mksnode(const char *string, void *ckt) { int i, j; char buf[128], *s; @@ -905,6 +911,24 @@ static INPparseNode *mksnode(const char *string) p = (INPparseNode *) MALLOC(sizeof(INPparseNode)); + if(!strcmp("time", buf)) { + p->type = PT_TIME; + p->data = ckt; + return p; + } + + if(!strcmp("temper", buf)) { + p->type = PT_TEMPERATURE; + p->data = ckt; + return p; + } + + if(!strcmp("hertz", buf)) { + p->type = PT_FREQUENCY; + p->data = ckt; + return p; + } + /* First see if it's something special. */ for (i = 0; i < ft_sim->numSpecSigs; i++) if (!strcmp(ft_sim->specSigs[i], buf)) @@ -1114,6 +1138,18 @@ void INPptPrint(char *str, IFparseTree * ptree) void printTree(INPparseNode * pt) { switch (pt->type) { + case PT_TIME: + printf("time(ckt = %p)", pt->data); + break; + + case PT_TEMPERATURE: + printf("temperature(ckt = %p)", pt->data); + break; + + case PT_FREQUENCY: + printf("frequency(ckt = %p)", pt->data); + break; + case PT_CONSTANT: printf("%g", pt->constant); break;