From 8bb6b0e3f728c8a44c954fc644a0f8882c14ed96 Mon Sep 17 00:00:00 2001 From: Stefan Schippers Date: Wed, 14 Oct 2020 21:04:45 +0200 Subject: [PATCH] pass name and symname to tcl_hook, add @symname_ext in print_spice_element --- src/editprop.c | 2 +- src/get_malloc_id.awk | 10 +++++--- src/token.c | 60 +++++++++++++++++++++++++++---------------- src/xschem.h | 2 +- src/xschem.tcl | 8 +++--- 5 files changed, 50 insertions(+), 32 deletions(-) diff --git a/src/editprop.c b/src/editprop.c index 152ec51e..8761184e 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -393,7 +393,7 @@ void set_inst_prop(int i) my_strdup(104, &ptr, (xctx.inst[i].ptr+ xctx.sym)->templ); /* my_strdup(104, &ptr, translate(i, (xctx.inst[i].ptr+ xctx.sym)->templ)); */ - /* tcl_hook(&ptr); */ + /* tcl_hook(&ptr, i); */ dbg(1, "set_inst_prop(): i=%d, name=%s, prop_ptr = %s, template=%s\n", i, xctx.inst[i].name, xctx.inst[i].prop_ptr, ptr); my_strdup(69, &xctx.inst[i].prop_ptr, ptr); diff --git a/src/get_malloc_id.awk b/src/get_malloc_id.awk index 25b02884..c944ed9e 100755 --- a/src/get_malloc_id.awk +++ b/src/get_malloc_id.awk @@ -7,10 +7,12 @@ BEGIN{ $0 ~ pattern "[0-9]+" { - a = $0 - sub("^.*" pattern,"", a) - sub(/ *,.*/,"", a) - print a "\t" FILENAME "\t" $0 + if($0 !~/^ *\/\*/) { + a = $0 + sub("^.*" pattern,"", a) + sub(/ *,.*/,"", a) + print a "\t" FILENAME "\t" $0 + } } ' \ actions.c \ diff --git a/src/token.c b/src/token.c index 23647878..205bbfb7 100644 --- a/src/token.c +++ b/src/token.c @@ -156,19 +156,16 @@ void hash_all_names(int n) } -void tcl_hook(char **res) +void tcl_hook(char **res, int inst) { char * result = *res; if(result && strstr(result, "tcleval(")== result) { - size_t s; - char *tclcmd=NULL; - s = strlen(result) + 100; - tclcmd = my_malloc(1197, s); - my_snprintf(tclcmd, s, "tclpropeval2 {%s}", result); - dbg(1, "tclpropeval2 {%s}", result); - tcleval(tclcmd); + dbg(1, "tcl_hook(): %s %s %s\n", result, xctx.inst[inst].instname, + get_cell((xctx.inst[inst].ptr + xctx.sym)->name, 0)); + Tcl_VarEval(interp, + "tclpropeval2 {", result, "} {", xctx.inst[inst].instname, "} {", + get_cell((xctx.inst[inst].ptr + xctx.sym)->name, 0), "}", NULL); my_strdup2(1198, res, tclresult()); - my_free(1199, &tclcmd); } } @@ -1429,7 +1426,7 @@ void print_spice_element(FILE *fd, int inst) my_strdup(483, &template, (xctx.inst[inst].ptr+ xctx.sym)->templ); /* my_strdup(483, &template, translate(inst, (xctx.inst[inst].ptr+ xctx.sym)->templ) ); */ - /* tcl_hook(&template); */ + /* tcl_hook(&template, inst); */ my_strdup(484, &name,xctx.inst[inst].instname); if (!name) my_strdup(43, &name, get_tok_value(template, "name", 0)); @@ -1452,16 +1449,17 @@ void print_spice_element(FILE *fd, int inst) while(1) { /* always make room for some characters so the single char writes to result do not need reallocs */ - str_alloc(&result, 0, result_pos, &size); + str_alloc(&result, 100, result_pos, &size); c=*s++; if(c=='\\') { escape=1; c=*s++; } else escape=0; + if (c=='\n' && escape) c=*s++; /* 20171030 eat escaped newlines */ space=SPACE(c); - if (state==XBEGIN && (c=='@'|| c=='$') && !escape) state=XTOKEN; + if ( state==XBEGIN && (c=='@'|| c=='$') && !escape ) state=XTOKEN; else if(state==XTOKEN && token_pos > 1 && ( ( (space || c == '$' || c == '@') && !escape ) || @@ -1530,6 +1528,16 @@ void print_spice_element(FILE *fd, int inst) result_pos += my_snprintf(result + result_pos, tmp, "%s", s); /* fputs(s,fd); */ } + else if (strcmp(token,"@symname_ext")==0) /* of course symname must not be present */ + /* in hash table */ + { + const char *s = get_cell_w_ext(xctx.inst[inst].name, 0); + tmp = strlen(s) +100 ; /* always make room for some extra chars + * so 1-char writes to result do not need reallocs */ + str_alloc(&result, tmp, result_pos, &size); + result_pos += my_snprintf(result + result_pos, tmp, "%s", s); + /* fputs(s,fd); */ + } else if(strcmp(token,"@schname")==0) /* of course schname must not be present */ /* in hash table */ { @@ -1553,7 +1561,6 @@ void print_spice_element(FILE *fd, int inst) * so 1-char writes to result do not need reallocs */ str_alloc(&result, tmp, result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "@%d %s ", mult, str_ptr); - /* fprintf(fd, "@%d %s ", mult, str_ptr); */ } } } @@ -1568,7 +1575,6 @@ void print_spice_element(FILE *fd, int inst) * so 1-char writes to result do not need reallocs */ str_alloc(&result, tmp, result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "@%d %s ", mult, str_ptr); - /* fprintf(fd, "@%d %s ", mult, str_ptr); */ } break; } @@ -1588,7 +1594,6 @@ void print_spice_element(FILE *fd, int inst) * so 1-char writes to result do not need reallocs */ str_alloc(&result, tmp, result_pos, &size); result_pos += my_snprintf(result + result_pos, tmp, "@%d %s ", mult, str_ptr); - /* fprintf(fd, "@%d %s ", mult, str_ptr); */ } } } @@ -1634,7 +1639,9 @@ void print_spice_element(FILE *fd, int inst) /* if result is like: 'tcleval(some_string)' pass it thru tcl evaluation so expressions * can be calculated */ - tcl_hook(&result); + + /* do one level of substitutions to resolve @params and equations*/ + /* my_strdup(22, &result, translate(inst, result)); */ fprintf(fd, "%s", result); my_free(1019, &template); @@ -1794,6 +1801,10 @@ void print_tedax_element(FILE *fd, int inst) { fputs(skip_dir(xctx.inst[inst].name),fd); } + else if (strcmp(token,"@symname_ext")==0) + { + fputs(get_cell_w_ext(xctx.inst[inst].name, 0), fd); + } else if(strcmp(token,"@schname")==0) /* of course schname must not be present */ /* in hash table */ { @@ -2202,6 +2213,10 @@ void print_vhdl_primitive(FILE *fd, int inst) /* netlist primitives, 20071217 * { fprintf( fd, "%s",skip_dir(xctx.inst[inst].name) ); } + else if (strcmp(token,"@symname_ext")==0) + { + fputs(get_cell_w_ext(xctx.inst[inst].name, 0), fd); + } else if(strcmp(token,"@schname")==0) /* of course schname must not be present */ /* in hash table */ { @@ -2369,7 +2384,11 @@ void print_verilog_primitive(FILE *fd, int inst) /* netlist switch level primiti else if(strcmp(token,"@symname")==0) /* of course symname must not be present */ /* in hash table */ { - fprintf( fd, "%s",skip_dir(xctx.inst[inst].name) ); + fprintf( fd, "%s",skip_dir(xctx.inst[inst]. name) ); + } + else if (strcmp(token,"@symname_ext")==0) + { + fputs(get_cell_w_ext(xctx.inst[inst].name, 0), fd); } else if(strcmp(token,"@schname")==0) /* of course schname must not be present */ /* in hash table */ @@ -2514,7 +2533,7 @@ const char *translate(int inst, const char* s) my_realloc(527, &result,size); result[0]='\0'; - dbg(2, "translate(): substituting props in <%s>, instance <%s>\n", + dbg(1, "translate(): substituting props in <%s>, instance <%s>\n", s?s:"NULL",xctx.inst[inst].instname?xctx.inst[inst].instname:"NULL"); while(1) @@ -2750,7 +2769,7 @@ const char *translate(int inst, const char* s) /* if result is like: 'tcleval(some_string)' pass it thru tcl evaluation so expressions * can be calculated */ - tcl_hook(&result); + tcl_hook(&result, inst); return result; } @@ -2857,9 +2876,6 @@ const char *translate2(struct Lcc *lcc, int level, char* s) break; } } - /* if result is like: 'tcleval(some_string)' pass it thru tcl evaluation so expressions - * can be calculated */ - tcl_hook(&result); my_free(1070, &token); my_free(1071, &value1); my_free(1072, &value2); diff --git a/src/xschem.h b/src/xschem.h index 1ad0d281..c7703cd4 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -902,7 +902,7 @@ extern const char *tcleval(const char str[]); extern const char *tclresult(void); extern const char *tclgetvar(const char *s); extern void tclsetvar(const char *s, const char *value); -extern void tcl_hook(char **res); +extern void tcl_hook(char **res, int inst); extern void statusmsg(char str[],int n); extern void place_text(int draw_text, double mx, double my); extern void init_inst_iterator(double x1, double y1, double x2, double y2); diff --git a/src/xschem.tcl b/src/xschem.tcl index e0d93860..763bd15d 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -1854,20 +1854,20 @@ proc property_search {} { # attributes. # proc tclpropeval {s instname symname} { - # puts ">>>> $s $instname $symname" + # puts "tclpropeval: $s $instname $symname" regsub {^@tcleval\(} $s {} s regsub {\)$} $s {} s return [eval $s] } # this hook is called in translate() if whole string is contained in a tcleval(...) construct -proc tclpropeval2 {s} { - # puts ">>>> $s $instname $symname" +proc tclpropeval2 {s instname symname} { + # puts "tclpropeval2: $s $instname $symname" regsub {^tcleval\(} $s {} s regsub {\)([ \n\t]*)$} $s {\1} s if { [catch {subst $s} res] } { puts "tclpropeval2: $res" - set res {} + set res $s } return $res }