has_included_subcircuit(): correctly handle bussed ports in symbol and spice .subckt file

This commit is contained in:
stefan schippers 2024-01-14 11:28:51 +01:00
parent ac04ce5c55
commit 17e24e0f5f
7 changed files with 61 additions and 34 deletions

View File

@ -647,6 +647,7 @@ void my_realloc(int id, void *ptr,size_t size)
{
void *a;
char old[100];
void *tmp;
a = *(void **)ptr;
my_snprintf(old, S(old), "%p", a);
if(size == 0) {
@ -654,10 +655,14 @@ void my_realloc(int id, void *ptr,size_t size)
dbg(3, "\nmy_free(%d,): my_realloc_freeing %p\n",id, *(void **)ptr);
*(void **)ptr=NULL;
} else {
*(void **)ptr=realloc(*(void **)ptr,size);
if(*(void **)ptr == NULL) fprintf(errfp,"my_realloc(%d,): allocation failure for %ld bytes\n", id, size);
dbg(3, "\nmy_realloc(%d,): reallocating %s --> %p to %lu bytes\n",
id, old, *(void **)ptr,(unsigned long) size);
tmp = realloc(*(void **)ptr,size);
if(tmp == NULL) {
fprintf(errfp,"my_realloc(%d,): allocation failure for %ld bytes\n", id, size);
} else {
*(void **)ptr = tmp;
dbg(3, "\nmy_realloc(%d,): reallocating %s --> %p to %lu bytes\n",
id, old, *(void **)ptr,(unsigned long) size);
}
}
}

View File

@ -1838,10 +1838,11 @@ static int has_included_subcircuit(int inst, int symbol, char **result)
tclvareval("has_included_subcircuit {", get_cell(symname, 0), "} {",
spice_sym_def, "}", NULL);
my_free(_ALLOC_ID_, &symname);
if(tclresult()[0]) {
char *pinlist = NULL;
char *pin, *save;
char *pinlist_ptr;
char *pinlist = NULL;
const char *net;
char *tmp_result = NULL;
int i, no_of_pins = (xctx->inst[inst].ptr + xctx->sym)->rects[PINLAYER], multip;
@ -1849,19 +1850,28 @@ static int has_included_subcircuit(int inst, int symbol, char **result)
int instance_pins = 0;
Int_hashentry *entry;
Int_hashtable table = {NULL, 0};
int_hash_init(&table, 37);
int done_first = -1;
int_hash_init(&table, 6247);
my_strdup2(_ALLOC_ID_, &pinlist, tclresult());
dbg(1, "included subcircuit: pinlist=%s\n", pinlist);
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");
const char *name = get_tok_value(prop, "name", 0);
if(!spice_ignore) {
int_hash_lookup(&table, name, i, XINSERT_NOREPLACE);
int mult;
char *name_expanded_ptr, *name_expanded = NULL;
my_strdup2(_ALLOC_ID_, &name_expanded, expandlabel(name, &mult));
name_expanded_ptr = name_expanded;
while((pin = my_strtok_r(name_expanded_ptr, ",", "", 0, &save))) {
int_hash_lookup(&table, pin, i, XINSERT_NOREPLACE);
name_expanded_ptr = NULL;
}
my_free(_ALLOC_ID_, &name_expanded);
}
}
my_strdup2(_ALLOC_ID_, &pinlist, tclresult());
dbg(1, "included subcircuit: pinlist=%s\n", pinlist);
pinlist_ptr = pinlist;
while( (pin = my_strtok_r(pinlist_ptr, " ", "", 0, &save)) ) {
instance_pins++;
@ -1869,8 +1879,11 @@ static int has_included_subcircuit(int inst, int symbol, char **result)
if(entry) {
i = entry->value;
symbol_pins++;
net = net_name(inst, i, &multip, 0, 1);
my_mstrcat(_ALLOC_ID_, &tmp_result, "?", my_itoa(multip), " ", net, " ", NULL);
if(done_first != i) {
net = net_name(inst, i, &multip, 0, 1);
my_mstrcat(_ALLOC_ID_, &tmp_result, "?", my_itoa(multip), " ", net, " ", NULL);
done_first = i;
}
}
pinlist_ptr = NULL;
}

View File

@ -706,7 +706,8 @@ proc has_included_subcircuit {symname spice_sym_def} {
alert_ "has_included_subcircuit: $symname: no matching .subckt found in spice_sym_def. Ignore"
}
}
return $pinlist
# puts $pinlist
return [join $pinlist]
}
# should not be called directly by user

View File

@ -1,7 +1,8 @@
* example of a subcircuit contained in a file
.subckt symbol_include Z VCC VSS
+ A B C W=10 L=1
.subckt symbol_include Z Y[5] Y[4] Y[3] Y[2]
+ VCC VSS
+ A[2] A[1] A[0] B C W=10 L=1
...
...
.ends

View File

@ -1,11 +1,14 @@
v {xschem version=3.4.5 file_version=1.2}
v {xschem version=3.4.5 file_version=1.2
}
G {}
K {}
V {}
E {}
S {}
C {ipin.sym} -120 0 0 0 {name=g0 lab=A }
E {}
C {ipin.sym} -120 0 0 0 {name=g0 lab=A[2:0]}
C {ipin.sym} -120 20 0 0 {name=g1 lab=B }
C {ipin.sym} -120 40 0 0 {name=g2 lab=C }
C {ipin.sym} -120 60 0 0 {name=g3 lab=VCC }
C {ipin.sym} -120 80 0 0 {name=g4 lab=VSS }
C {opin.sym} 120 0 0 0 {name=g5 lab=Z }
C {opin.sym} 120 40 0 0 {name=g6 lab=Y[5:2]}

View File

@ -13,8 +13,9 @@ spice_sym_def=".include symbol_include.cir"
comm="following spice_sym_def directly contains the definition of the subckt"
xxspice_sym_def="
.subckt symbol_include Z VCC VSS
+ A B C
.subckt symbol_include Z Y[5] Y[4] Y[3] Y[2]
+ VCC VSS
+ A[2] A[1] A[0] B C W=10 L=1
...
...
.ends
@ -27,26 +28,25 @@ L 4 -130 50 130 50 {}
L 4 -130 -50 -130 50 {}
L 4 130 -50 130 50 {}
L 4 -150 -40 -130 -40 {}
L 4 -150 -20 -130 -20 {}
L 4 -150 0 -130 0 {}
L 4 130 -40 150 -40 {}
L 4 -150 -20 -130 -20 {}
L 4 130 -20 150 -20 {}
L 4 -150 0 -130 0 {}
L 4 -150 20 -130 20 {}
L 4 -150 40 -130 40 {}
B 5 -152.5 -42.5 -147.5 -37.5 {name=A dir=in}
B 5 -152.5 -22.5 -147.5 -17.5 {name=B dir=in}
B 5 -152.5 -2.5 -147.5 2.5 {name=C dir=in}
B 5 -152.5 -42.5 -147.5 -37.5 {name=A[2:0] dir=in}
B 5 147.5 -42.5 152.5 -37.5 {name=Z dir=out}
B 5 -152.5 -22.5 -147.5 -17.5 {name=B dir=in}
B 5 147.5 -22.5 152.5 -17.5 {name=Y[5:2] dir=out}
B 5 -152.5 -2.5 -147.5 2.5 {name=C dir=in}
B 5 -152.5 17.5 -147.5 22.5 {name=VCC dir=in}
B 5 -152.5 37.5 -147.5 42.5 {name=VSS dir=in}
T {@symname} -81 -6 0 0 0.3 0.3 {}
T {@name} 135 -62 0 0 0.2 0.2 {}
T {A} -125 -44 0 0 0.2 0.2 {}
T {B} -125 -24 0 0 0.2 0.2 {}
T {C} -125 -4 0 0 0.2 0.2 {}
T {A[2:0]} -125 -44 0 0 0.2 0.2 {}
T {Z} 125 -44 0 1 0.2 0.2 {}
T {B} -125 -24 0 0 0.2 0.2 {}
T {Y[5:2]} 125 -24 0 1 0.2 0.2 {}
T {C} -125 -4 0 0 0.2 0.2 {}
T {VCC} -125 16 0 0 0.2 0.2 {}
T {VSS} -125 36 0 0 0.2 0.2 {}
T {This symbol has attribute "spice_sym_def"
that references a .subckt file.
The port order of the symbol instance call
will match the order in the .subckt} -190 -210 0 0 0.4 0.4 {hide=instance layer=6}

View File

@ -8,6 +8,8 @@ E {}
T {Control + left mouse button on
the symbol to see the
symbol_include.cir file} 290 -130 0 0 0.3 0.3 {}
T {Example of symbol with associated spice .subckt file.
The pin order will be taken from the spice file.} 10 -380 0 0 0.4 0.4 {}
C {symbol_include.sym} 410 -190 0 0 {name=x1
tclcommand="textwindow [xschem get current_dirname]/symbol_include.cir"
@ -15,15 +17,17 @@ comm="following instance attributes (now 'x' commented) specify an alternate
symbol reference to use in netlist"
xspice_sym_def=".include symbol_include2.cir"
xschematic="symbol_include2.sch"}
C {lab_pin.sym} 260 -230 0 0 {name=p1 lab=XA}
C {lab_pin.sym} 260 -230 0 0 {name=p1 lab=XA[9:7]}
C {lab_pin.sym} 260 -210 0 0 {name=p2 lab=XB}
C {lab_pin.sym} 260 -190 0 0 {name=p3 lab=XC}
C {lab_pin.sym} 560 -230 0 1 {name=p4 lab=XZ}
C {lab_pin.sym} 260 -170 0 0 {name=p5 lab=XVCC}
C {lab_pin.sym} 260 -150 0 0 {name=p6 lab=XVSS}
C {opin.sym} 120 -70 0 0 { name=p7 lab=XZ }
C {opin.sym} 120 -70 0 0 { name=p7 lab=XY[7:4]}
C {ipin.sym} 80 -70 0 0 { name=p8 lab=XVSS }
C {ipin.sym} 80 -90 0 0 { name=p9 lab=XVCC }
C {ipin.sym} 80 -110 0 0 { name=p10 lab=XC }
C {ipin.sym} 80 -130 0 0 { name=p11 lab=XB }
C {ipin.sym} 80 -150 0 0 { name=p12 lab=XA }
C {ipin.sym} 80 -150 0 0 { name=p12 lab=XA[9:7]}
C {lab_pin.sym} 560 -210 0 1 {name=p13 lab=XY[7:4]}
C {opin.sym} 120 -90 0 0 { name=p14 lab=XZ }