initial implementation of `has_included_subcircuit()`

This commit is contained in:
Stefan Schippers 2024-01-07 19:51:48 +01:00
parent f0e739cf02
commit 0f7785d588
2 changed files with 57 additions and 34 deletions

View File

@ -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) void print_spice_subckt_nodes(FILE *fd, int symbol)
{ {
@ -1894,20 +1909,20 @@ void print_spice_subckt_nodes(FILE *fd, int symbol)
break ; break ;
} }
else if(strcmp(token, "@pinlist")==0) { else if(strcmp(token, "@pinlist")==0) {
Int_hashtable table = {NULL, 0}; Int_hashtable table = {NULL, 0};
int_hash_init(&table, 37); int_hash_init(&table, 37);
for(i=0;i<no_of_pins; ++i) for(i=0;i<no_of_pins; ++i)
{ {
if(strboolcmp(get_tok_value(xctx->sym[symbol].rect[PINLAYER][i].prop_ptr,"spice_ignore",0), "true")) { if(strboolcmp(get_tok_value(xctx->sym[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); 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)) { if(!int_hash_lookup(&table, name, 1, XINSERT_NOREPLACE)) {
str_ptr= expandlabel(name, &multip); str_ptr= expandlabel(name, &multip);
/* fprintf(fd, "%s ", str_ptr); */ /* fprintf(fd, "%s ", str_ptr); */
my_mstrcat(_ALLOC_ID_, &result, str_ptr, " ", NULL); my_mstrcat(_ALLOC_ID_, &result, str_ptr, " ", NULL);
} }
} }
} }
int_hash_free(&table); int_hash_free(&table);
} }
else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */ else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
char *prop=NULL; 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 */ else if(strcmp(token,"@pinlist")==0) /* of course pinlist must not be present in attributes */
/* print multiplicity */ /* print multiplicity */
{ /* and node number: m1 n1 m2 n2 .... */ { /* and node number: m1 n1 m2 n2 .... */
Int_hashtable table = {NULL, 0}; if(1 || !has_included_subcircuit(xctx->inst[inst].ptr, &result)) {
int_hash_init(&table, 37); Int_hashtable table = {NULL, 0};
for(i=0;i<no_of_pins; ++i) int_hash_init(&table, 37);
{ for(i=0;i<no_of_pins; ++i)
char *prop = (xctx->inst[inst].ptr + xctx->sym)->rect[PINLAYER][i].prop_ptr; {
int spice_ignore = !strboolcmp(get_tok_value(prop, "spice_ignore", 0), "true"); char *prop = (xctx->inst[inst].ptr + xctx->sym)->rect[PINLAYER][i].prop_ptr;
const char *name = get_tok_value(prop, "name", 0); int spice_ignore = !strboolcmp(get_tok_value(prop, "spice_ignore", 0), "true");
if(!spice_ignore) { const char *name = get_tok_value(prop, "name", 0);
if(!int_hash_lookup(&table, name, 1, XINSERT_NOREPLACE)) { if(!spice_ignore) {
str_ptr = net_name(inst, i, &multip, 0, 1); 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 tmp = strlen(str_ptr) +100 ; /* always make room for some extra chars
* so 1-char writes to result do not need reallocs */ * so 1-char writes to result do not need reallocs */
STR_ALLOC(&result, tmp + result_pos, &size); STR_ALLOC(&result, tmp + result_pos, &size);
result_pos += my_snprintf(result + result_pos, tmp, "?%d %s ", multip, str_ptr); 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 */ else if(token[0]=='@' && token[1]=='@') { /* recognize single pins 15112003 */
for(i=0;i<no_of_pins; ++i) { for(i=0;i<no_of_pins; ++i) {
@ -2273,10 +2290,9 @@ int print_spice_element(FILE *fd, int inst)
} }
my_free(_ALLOC_ID_, &tmpstr); my_free(_ALLOC_ID_, &tmpstr);
} }
tmp=strlen(value); tmp=strlen(value) + 100;
STR_ALLOC(&result, tmp + result_pos, &size); STR_ALLOC(&result, tmp + result_pos, &size);
memcpy(result+result_pos, value, tmp+1); result_pos += my_snprintf(result + result_pos, tmp, "%s", value);
result_pos+=tmp;
my_free(_ALLOC_ID_, &pin_attr_value); my_free(_ALLOC_ID_, &pin_attr_value);
} }
else if(n>=0 && n < (xctx->inst[inst].ptr + xctx->sym)->rects[PINLAYER]) { else if(n>=0 && n < (xctx->inst[inst].ptr + xctx->sym)->rects[PINLAYER]) {

View File

@ -654,6 +654,13 @@ proc ev0 {args} {
} }
} }
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 # should not be called directly by user
# does netlist post processing, called from global_(spice|vhdl|verilog)_netlist() # does netlist post processing, called from global_(spice|vhdl|verilog)_netlist()