From 0f7785d5888f690c2cd79eb5cf753e3440a114fc Mon Sep 17 00:00:00 2001 From: Stefan Schippers Date: Sun, 7 Jan 2024 19:51:48 +0100 Subject: [PATCH] initial implementation of `has_included_subcircuit()` --- src/token.c | 82 ++++++++++++++++++++++++++++++-------------------- src/xschem.tcl | 9 +++++- 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/src/token.c b/src/token.c index 63283f90..75e09917 100644 --- a/src/token.c +++ b/src/token.c @@ -1812,6 +1812,21 @@ void print_tedax_subckt(FILE *fd, int symbol) } } +static int has_included_subcircuit(int symbol, char **result) +{ + + char *spice_sym_def = NULL; + int ret = 0; + + my_strdup2(_ALLOC_ID_, &spice_sym_def, get_tok_value(xctx->sym[symbol].prop_ptr, "spice_sym_def", 0)); + if(xctx->tok_size) { + tclvareval("has_included_subcircuit {", spice_sym_def, "}", NULL); + my_mstrcat(_ALLOC_ID_, result, tclresult(), NULL); + ret = 1; + } + my_free(_ALLOC_ID_, &spice_sym_def); + return ret; +} void print_spice_subckt_nodes(FILE *fd, int symbol) { @@ -1894,20 +1909,20 @@ void print_spice_subckt_nodes(FILE *fd, int symbol) break ; } else if(strcmp(token, "@pinlist")==0) { - Int_hashtable table = {NULL, 0}; - int_hash_init(&table, 37); - for(i=0;isym[symbol].rect[PINLAYER][i].prop_ptr,"spice_ignore",0), "true")) { - const char *name = get_tok_value(xctx->sym[symbol].rect[PINLAYER][i].prop_ptr,"name",0); - if(!int_hash_lookup(&table, name, 1, XINSERT_NOREPLACE)) { - str_ptr= expandlabel(name, &multip); - /* fprintf(fd, "%s ", str_ptr); */ - my_mstrcat(_ALLOC_ID_, &result, str_ptr, " ", NULL); - } - } - } - int_hash_free(&table); + Int_hashtable table = {NULL, 0}; + int_hash_init(&table, 37); + for(i=0;isym[symbol].rect[PINLAYER][i].prop_ptr,"spice_ignore",0), "true")) { + const char *name = get_tok_value(xctx->sym[symbol].rect[PINLAYER][i].prop_ptr,"name",0); + if(!int_hash_lookup(&table, name, 1, XINSERT_NOREPLACE)) { + str_ptr= expandlabel(name, &multip); + /* fprintf(fd, "%s ", str_ptr); */ + my_mstrcat(_ALLOC_ID_, &result, str_ptr, " ", NULL); + } + } + } + int_hash_free(&table); } else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */ char *prop=NULL; @@ -2192,25 +2207,27 @@ int print_spice_element(FILE *fd, int inst) else if(strcmp(token,"@pinlist")==0) /* of course pinlist must not be present in attributes */ /* print multiplicity */ { /* and node number: m1 n1 m2 n2 .... */ - Int_hashtable table = {NULL, 0}; - int_hash_init(&table, 37); - for(i=0;iinst[inst].ptr + xctx->sym)->rect[PINLAYER][i].prop_ptr; - int spice_ignore = !strboolcmp(get_tok_value(prop, "spice_ignore", 0), "true"); - const char *name = get_tok_value(prop, "name", 0); - if(!spice_ignore) { - if(!int_hash_lookup(&table, name, 1, XINSERT_NOREPLACE)) { - str_ptr = net_name(inst, i, &multip, 0, 1); - - tmp = strlen(str_ptr) +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, "?%d %s ", multip, str_ptr); + if(1 || !has_included_subcircuit(xctx->inst[inst].ptr, &result)) { + Int_hashtable table = {NULL, 0}; + int_hash_init(&table, 37); + for(i=0;iinst[inst].ptr + xctx->sym)->rect[PINLAYER][i].prop_ptr; + int spice_ignore = !strboolcmp(get_tok_value(prop, "spice_ignore", 0), "true"); + const char *name = get_tok_value(prop, "name", 0); + if(!spice_ignore) { + if(!int_hash_lookup(&table, name, 1, XINSERT_NOREPLACE)) { + str_ptr = net_name(inst, i, &multip, 0, 1); + + tmp = strlen(str_ptr) +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, "?%d %s ", multip, str_ptr); + } } } + int_hash_free(&table); } - int_hash_free(&table); } else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */ for(i=0;i=0 && n < (xctx->inst[inst].ptr + xctx->sym)->rects[PINLAYER]) { diff --git a/src/xschem.tcl b/src/xschem.tcl index 80491c23..58ab8cb5 100644 --- a/src/xschem.tcl +++ b/src/xschem.tcl @@ -653,7 +653,14 @@ proc ev0 {args} { return 0 } } - + +proc has_included_subcircuit {spice_sym_def} { + regsub -all {\n\+} $spice_sym_def { } spice_sym_def + if {[regexp -nocase {^\.include } $spice_sym_def]} { + set filename [lindex $spice_sym_def 1] + } + return "---- $filename ----" +} # should not be called directly by user # does netlist post processing, called from global_(spice|vhdl|verilog)_netlist()