From 0e61b7ccc00fc80ffcb919b18bb1bda0c86cb807 Mon Sep 17 00:00:00 2001 From: h_vogt Date: Sat, 7 Mar 2009 15:49:51 +0000 Subject: [PATCH] collect info for dyn. mem arrays in numparam --- ChangeLog | 6 ++++ src/frontend/inpcom.c | 29 ++++++++++++++--- src/frontend/numparam/numpaif.h | 2 ++ src/frontend/numparam/numparam.h | 2 +- src/frontend/numparam/spicenum.c | 56 +++++++++++++++++--------------- src/frontend/numparam/xpressn.c | 3 +- src/frontend/subckt.c | 26 ++++++++++----- 7 files changed, 82 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 130507514..7e9be43d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-03-07 Holger Vogt + * spicenum.c inpcom.c subckt.c xpressn.c numpaif.h numparam.h general.h + Collect information to allow dynamic memory allocation for numparam + ( Still to be implementd ! ) + Defined in inpcom.c: dynmaxline dynnLen dynMaxckt dynsubst + 2009-03-03 Dietmar Warning * tests/bsim3/*_sim/*.out: adapt output format to spice3 numdgt convention, most tests are running except tran tests and op-amp ac test. diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index f277d6c7d..9cd025b21 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -90,6 +90,16 @@ static char *func_macro[5000]; static int num_functions; static int num_parameters[1000]; +/* Collect information for dynamic allocation of numparam arrays */ +/* number of lines in input deck */ +int dynmaxline; /* inpcom.c 1524 */ +/* max. line length in input deck */ +int dynnLen; /* inpcom.c 1526 */ + /* number of lines in deck after expansion */ +int dynMaxckt = 0; /* subckt.c 307 */ +/* number of parameter substitutions */ +long dynsubst; /* spicenum.c 221 */ + /* static declarations */ static char * readline(FILE *fd); static int get_number_terminals( char *c ); @@ -990,8 +1000,9 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) FILE *newfp; #if defined(TRACE) || defined(OUTDECK) FILE *fdo; +#endif struct line *tmp_ptr1 = NULL; -#endif + int i, j; bool found_library, found_lib_name, found_end = FALSE, shell_eol_continuation = FALSE; bool dir_name_flag = FALSE; @@ -1510,15 +1521,25 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) inp_add_control_section(working, &line_number); } *data = cc; + + /* get max. line length and number of lines in input deck*/ + dynmaxline = 0; + dynnLen = 0; + for(tmp_ptr1 = cc; tmp_ptr1 != NULL; tmp_ptr1 = tmp_ptr1->li_next) { + dynmaxline++; + if (dynnLen < strlen(tmp_ptr1->li_line)) + dynnLen = strlen(tmp_ptr1->li_line); + } #if defined(TRACE) || defined(OUTDECK) - /*debug: print into file*/ - if (tmp_ptr1) tfree(tmp_ptr1); - fdo = fopen("debug-out.txt", "w"); + /*debug: print into file*/ + fdo = fopen("debug-out.txt", "w"); for(tmp_ptr1 = cc; tmp_ptr1 != NULL; tmp_ptr1 = tmp_ptr1->li_next) fprintf(fdo, "%s\n", tmp_ptr1->li_line); ; (void) fclose(fdo); + fprintf(stdout, "lLen %d, maxline %d\n", dynnLen, dynmaxline); #endif + return; } diff --git a/src/frontend/numparam/numpaif.h b/src/frontend/numparam/numpaif.h index 31895897d..8580a27fe 100644 --- a/src/frontend/numparam/numpaif.h +++ b/src/frontend/numparam/numpaif.h @@ -22,4 +22,6 @@ extern void nupa_add_param(char *param_name, double value); extern void nupa_add_inst_param(char *param_name, double value); extern void nupa_copy_inst_dico(); +extern int dynMaxckt; /* number of lines in deck after expansion */ + #endif /* NUMPAIF_H */ diff --git a/src/frontend/numparam/numparam.h b/src/frontend/numparam/numparam.h index 062a772ad..4346a307a 100644 --- a/src/frontend/numparam/numparam.h +++ b/src/frontend/numparam/numparam.h @@ -29,7 +29,7 @@ typedef enum {Llen=40000} _nLlen; typedef char str50 [54]; typedef char str80 [84]; -typedef enum {Maxline=20000} _nMaxline; /* Size of initial unexpanded circuit code */ +typedef enum {Maxline=70000} _nMaxline; /* Size of initial unexpanded circuit code */ typedef enum {Maxckt=40000} _nMaxckt; /* Size of expanded circuit code */ diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index 6316613b3..6a95c9f0b 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -32,6 +32,8 @@ extern void txfree (void *ptr); char *nupa_inst_name; static tdico *inst_dico; +extern long dynsubst; /* inpcom.c */ + /* Uncomment this line to allow debug tracing */ /* #define TRACE_NUMPARAMS */ @@ -216,7 +218,7 @@ stripbraces (char *s) ls = length (s); } - + dynsubst = placeholder; return n; } @@ -702,43 +704,43 @@ nupa_copy (char *s, int linenum) dico->srcline = linenum; if ((!inexpansion) && (linenum >= 0) && (linenum < Maxline)) - { - linecount++; - dico->refptr[linenum] = s; - c = transform (dico, u, incontrol, keywd); - if (c == 'C') - incontrol = 1; - else if (c == 'E') - incontrol = 0; + { + linecount++; + dico->refptr[linenum] = s; + c = transform (dico, u, incontrol, keywd); + if (c == 'C') + incontrol = 1; + else if (c == 'E') + incontrol = 0; - if (incontrol) - c = 'C'; /* force it */ + if (incontrol) + c = 'C'; /* force it */ - d = dico->category[linenum]; /* warning if already some strategic line! */ + d = dico->category[linenum]; /* warning if already some strategic line! */ - if ((d == 'P') || (d == 'S') || (d == 'X')) - fprintf (stderr, - " Numparam warning: overwriting P,S or X line (linenum == %d).\n", - linenum); + if ((d == 'P') || (d == 'S') || (d == 'X')) + fprintf (stderr, + " Numparam warning: overwriting P,S or X line (linenum == %d).\n", + linenum); - dico->category[linenum] = c; - } /* keep a local copy and mangle the string */ + dico->category[linenum] = c; + } /* keep a local copy and mangle the string */ ls = length (u); t = strdup (u); if (t == NULL) - { - fputs ("Fatal: String malloc crash in nupa_copy()\n", stderr); - exit (-1); - } + { + fputs ("Fatal: String malloc crash in nupa_copy()\n", stderr); + exit (-1); + } else + { + if (!inexpansion) { - if (!inexpansion) - { - putlogfile (dico->category[linenum], linenum, t); - }; - } + putlogfile (dico->category[linenum], linenum, t); + }; + } return t; } diff --git a/src/frontend/numparam/xpressn.c b/src/frontend/numparam/xpressn.c index ab40c10dc..4761e0950 100644 --- a/src/frontend/numparam/xpressn.c +++ b/src/frontend/numparam/xpressn.c @@ -20,6 +20,7 @@ static Str (150, keys); /* all my keywords */ static Str (150, fmath); /* all math functions */ extern char *nupa_inst_name; /* see spicenum.c */ +extern long dynsubst; /* see inpcom.c */ static double ternary_fcn (int conditional, double if_value, double else_value) @@ -1676,7 +1677,7 @@ insertnumber (tdico * dico, int i, char *s, char *u) if (found) { accu = accu - 1000000000L; /* plausibility test */ - found = (accu > 0) && (accu < 40000); + found = (accu > 0) && (accu < dynsubst + 1); /* dynsubst numbers have been allocated */ } i++; } diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index 4151724ac..8d3c1fb5d 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -300,16 +300,24 @@ inp_subcktexpand(struct line *deck) modnames = NULL; } + /* Count numbers of line in deck after expansion */ + if (ll!=NULL) { + dynMaxckt = 0; /* number of lines in deck after expansion */ + for (c = ll; c; c = c->li_next) + dynMaxckt++; + } /* Now check to see if there are still subckt instances undefined... */ - if (ll!=NULL) for (c = ll; c; c = c->li_next) - if (ciprefix(invoke, c->li_line)) { - fprintf(cp_err, "Error: unknown subckt: %s\n", c->li_line); - if ( use_numparams ) { - ok= ok && nupa_signal(NUPAEVALDONE, NULL); - } - return NULL; - } - + if (ll!=NULL) { + for (c = ll; c; c = c->li_next) { + if (ciprefix(invoke, c->li_line)) { + fprintf(cp_err, "Error: unknown subckt: %s\n", c->li_line); + if ( use_numparams ) { + ok= ok && nupa_signal(NUPAEVALDONE, NULL); + } + return NULL; + } + } + } if ( use_numparams ) { /* the NUMPARAM final line translation pass */ ok= ok && nupa_signal(NUPASUBDONE, NULL);