fix error in link_symbols_to_instances(): potential call of symbol_bbox() -> translate() -> prepare_netlist_structs() before completing xctx->inst[i].lab assignments

This commit is contained in:
Stefan Frederik 2020-12-22 16:10:27 +01:00
parent 9b262299ba
commit 0783ff7002
7 changed files with 163 additions and 153 deletions

View File

@ -751,9 +751,7 @@ void prepare_netlist_structs(int for_netlist)
my_strdup(260, &value,get_tok_value(inst[i].prop_ptr,"value",0));
my_strdup(261, &class,get_tok_value(inst[i].prop_ptr,"class",0));
}
my_strdup(262, &inst[i].node[0], inst[i].lab);
if (!(inst[i].node[0])) {
my_strdup(65, &inst[i].node[0], get_tok_value((inst[i].ptr+ xctx->sym)->templ, "lab",0));
dbg(1, "prepare_netlist_structs(): no lab attr on instance, pick from symbol: %s\n", inst[i].node[0]);

View File

@ -958,8 +958,7 @@ void link_symbols_to_instances(int from) /* from > 0 : linking symbols from past
char *type=NULL;
int cond;
for(i = from; i < xctx->instances; i++)
{
for(i = from; i < xctx->instances; i++) {
dbg(2, "link_symbols_to_instances(): inst=%d\n", i);
dbg(2, "link_symbols_to_instances(): matching inst %d name=%s \n",i, xctx->inst[i].name);
dbg(2, "link_symbols_to_instances(): -------\n");
@ -967,7 +966,6 @@ void link_symbols_to_instances(int from) /* from > 0 : linking symbols from past
}
for(i = from; i < xctx->instances; i++) {
if(from) select_element(i,SELECTED,1, 0); /* leave elements selected if a paste/copy from windows is done */
symbol_bbox(i, &xctx->inst[i].x1, &xctx->inst[i].y1, &xctx->inst[i].x2, &xctx->inst[i].y2);
type=xctx->sym[xctx->inst[i].ptr].type;
cond= !type || !IS_LABEL_SH_OR_PIN(type);
if(cond) xctx->inst[i].flags|=2; /* ordinary symbol */
@ -976,6 +974,11 @@ void link_symbols_to_instances(int from) /* from > 0 : linking symbols from past
my_strdup(1216, &xctx->inst[i].lab, get_tok_value(xctx->inst[i].prop_ptr,"lab",0));
}
}
/* symbol_bbox() might call translate() that might call prepare_netlist_structs() that
* needs .lab field set above, so this must be done last */
for(i = from; i < xctx->instances; i++) {
symbol_bbox(i, &xctx->inst[i].x1, &xctx->inst[i].y1, &xctx->inst[i].x2, &xctx->inst[i].y2);
}
}
/* ALWAYS use absolute pathname for filename!!! */

View File

@ -899,6 +899,10 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
printf("color_ps=%d\n", color_ps);
printf("hilight_nets=%d\n", xctx->hilight_nets);
printf("semaphore=%d\n", xctx->semaphore);
printf("prep_net_structs=%d\n", xctx->prep_net_structs);
printf("prep_hi_structs=%d\n", xctx->prep_hi_structs);
printf("prep_hash_inst=%d\n", xctx->prep_hash_inst);
printf("prep_hash_wires=%d\n", xctx->prep_hash_wires);
printf("need_reb_sel_arr=%d\n", xctx->need_reb_sel_arr);
printf("******* end global variables:*******\n");
}

View File

@ -38,8 +38,6 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2)
double text_x0, text_y0;
short sym_rot, sym_flip;
double xx1,yy1,xx2,yy2;
#if HAS_CAIRO==1
int customfont;
#endif
@ -59,20 +57,16 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2)
xctx->inst[i].yy1 = *y1; /* for easier select */
xctx->inst[i].xx2 = *x2;
xctx->inst[i].yy2 = *y2;
dbg(2, "symbol_bbox(): instance=%d %.16g %.16g %.16g %.16g\n",i,*x1, *y1, *x2, *y2);
dbg(2, "symbol_bbox(): instance=%d %.16g %.16g %.16g %.16g\n",i,*x1, *y1, *x2, *y2);
/* strings bbox */
for(j=0;j< (xctx->inst[i].ptr+ xctx->sym)->texts;j++)
{
sym_flip = flip;
sym_rot = rot;
text = (xctx->inst[i].ptr+ xctx->sym)->text[j];
dbg(2, "symbol_bbox(): instance %d text n: %d text str=%s\n",
i,j, text.txt_ptr? text.txt_ptr:"NULL");
sym_flip = flip;
sym_rot = rot;
text = (xctx->inst[i].ptr+ xctx->sym)->text[j];
dbg(2, "symbol_bbox(): instance %d text n: %d text str=%s\n", i,j, text.txt_ptr? text.txt_ptr:"NULL");
tmp_txt = translate(i, text.txt_ptr);
dbg(2, "symbol_bbox(): translated text: %s\n", tmp_txt);
dbg(2, "symbol_bbox(): translated text: %s\n", tmp_txt);
ROTATION(rot, flip, 0.0,0.0,text.x0, text.y0,text_x0,text_y0);
#if HAS_CAIRO==1
customfont=set_text_custom_font(&text);
@ -89,7 +83,6 @@ void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2)
if(xx2>*x2) *x2=xx2;
if(yy2>*y2) *y2=yy2;
dbg(2, "symbol_bbox(): instance=%d text=%d %.16g %.16g %.16g %.16g\n",i,j, *x1, *y1, *x2, *y2);
}
}

View File

@ -391,144 +391,137 @@ static void svg_draw_symbol(int n,int layer,short tmp_flip, short rot,
double xoffset, double yoffset)
/* draws current layer only, should be called within */
{ /* a "for(i=0;i<cadlayers;i++)" loop */
int j;
double x0,y0,x1,y1,x2,y2;
short flip;
int textlayer;
xLine line;
xRect box;
xText text;
xArc arc;
xPoly polygon;
xSymbol *symptr;
char *textfont;
int j;
double x0,y0,x1,y1,x2,y2;
short flip;
int textlayer;
xLine line;
xRect box;
xText text;
xArc arc;
xPoly polygon;
xSymbol *symptr;
char *textfont;
if(xctx->inst[n].ptr == -1) return;
if( (layer != PINLAYER && !enable_layer[layer]) ) return;
if(layer==0)
{
x1=X_TO_SVG(xctx->inst[n].x1);
x2=X_TO_SVG(xctx->inst[n].x2);
y1=Y_TO_SVG(xctx->inst[n].y1);
y2=Y_TO_SVG(xctx->inst[n].y2);
if(OUTSIDE(x1,y1,x2,y2,xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2))
{
xctx->inst[n].flags|=1;
return;
}
else xctx->inst[n].flags&=~1;
/* following code handles different text color for labels/pins 06112002 */
x1=X_TO_SVG(xctx->inst[n].x1);
x2=X_TO_SVG(xctx->inst[n].x2);
y1=Y_TO_SVG(xctx->inst[n].y1);
y2=Y_TO_SVG(xctx->inst[n].y2);
if(OUTSIDE(x1,y1,x2,y2,xctx->areax1,xctx->areay1,xctx->areax2,xctx->areay2))
{
xctx->inst[n].flags|=1;
return;
}
else xctx->inst[n].flags&=~1;
}
else if(xctx->inst[n].flags&1)
{
dbg(1, "draw_symbol(): skippinginst %d\n", n);
return;
dbg(1, "draw_symbol(): skipping inst %d\n", n);
return;
}
flip = xctx->inst[n].flip;
if(tmp_flip) flip = !flip;
rot = (xctx->inst[n].rot + rot ) & 0x3;
x0=xctx->inst[n].x0 + xoffset;
y0=xctx->inst[n].y0 + yoffset;
symptr = (xctx->inst[n].ptr+ xctx->sym);
for(j=0;j< symptr->lines[layer];j++)
{
for(j=0;j< symptr->lines[layer];j++)
{
line = (symptr->line[layer])[j];
ROTATION(rot, flip, 0.0,0.0,line.x1,line.y1,x1,y1);
ROTATION(rot, flip, 0.0,0.0,line.x2,line.y2,x2,y2);
ORDER(x1,y1,x2,y2);
svg_drawline(layer, line.bus, x0+x1, y0+y1, x0+x2, y0+y2, line.dash);
}
}
for(j=0;j< symptr->polygons[layer];j++)
{
polygon = (symptr->poly[layer])[j];
{ /* scope block so we declare some auxiliary arrays for coord transforms. 20171115 */
int k;
double *x = my_malloc(417, sizeof(double) * polygon.points);
double *y = my_malloc(418, sizeof(double) * polygon.points);
for(k=0;k<polygon.points;k++) {
ROTATION(rot, flip, 0.0,0.0,polygon.x[k],polygon.y[k],x[k],y[k]);
x[k]+= x0;
y[k] += y0;
}
svg_drawpolygon(layer, NOW, x, y, polygon.points, polygon.fill, polygon.dash);
my_free(961, &x);
my_free(962, &y);
}
}
for(j=0;j< symptr->arcs[layer];j++)
{
double angle;
arc = (symptr->arc[layer])[j];
if(flip) {
angle = 270.*rot+180.-arc.b-arc.a;
} else {
angle = arc.a+rot*270.;
}
angle = fmod(angle, 360.);
if(angle<0.) angle+=360.;
ROTATION(rot, flip, 0.0,0.0,arc.x,arc.y,x1,y1);
svg_drawarc(layer, arc.fill, x0+x1, y0+y1, arc.r, angle, arc.b, arc.dash);
}
for(j=0;j< symptr->polygons[layer];j++)
{
polygon = (symptr->poly[layer])[j];
{ /* scope block so we declare some auxiliary arrays for coord transforms. 20171115 */
int k;
double *x = my_malloc(417, sizeof(double) * polygon.points);
double *y = my_malloc(418, sizeof(double) * polygon.points);
for(k=0;k<polygon.points;k++) {
ROTATION(rot, flip, 0.0,0.0,polygon.x[k],polygon.y[k],x[k],y[k]);
x[k]+= x0;
y[k] += y0;
}
svg_drawpolygon(layer, NOW, x, y, polygon.points, polygon.fill, polygon.dash);
my_free(961, &x);
my_free(962, &y);
}
}
for(j=0;j< symptr->arcs[layer];j++)
{
double angle;
arc = (symptr->arc[layer])[j];
if(flip) {
angle = 270.*rot+180.-arc.b-arc.a;
} else {
angle = arc.a+rot*270.;
}
angle = fmod(angle, 360.);
if(angle<0.) angle+=360.;
ROTATION(rot, flip, 0.0,0.0,arc.x,arc.y,x1,y1);
svg_drawarc(layer, arc.fill, x0+x1, y0+y1, arc.r, angle, arc.b, arc.dash);
}
if( (layer != PINLAYER || enable_layer[layer]) ) for(j=0;j< symptr->rects[layer];j++)
{
if( (layer != PINLAYER || enable_layer[layer]) ) for(j=0;j< symptr->rects[layer];j++)
{
box = (symptr->rect[layer])[j];
ROTATION(rot, flip, 0.0,0.0,box.x1,box.y1,x1,y1);
ROTATION(rot, flip, 0.0,0.0,box.x2,box.y2,x2,y2);
RECTORDER(x1,y1,x2,y2);
svg_filledrect(layer, x0+x1, y0+y1, x0+x2, y0+y2, box.dash);
}
if( (layer==TEXTWIRELAYER && !(xctx->inst[n].flags&2) ) ||
(sym_txt && (layer==TEXTLAYER) && (xctx->inst[n].flags&2) ) )
{
}
if( (layer==TEXTWIRELAYER && !(xctx->inst[n].flags&2) ) ||
(sym_txt && (layer==TEXTLAYER) && (xctx->inst[n].flags&2) ) )
{
const char *txtptr;
for(j=0;j< symptr->texts;j++)
{
text = symptr->text[j];
/* if(text.xscale*FONTWIDTH* xctx->mooz<1) continue; */
txtptr= translate(n, text.txt_ptr);
ROTATION(rot, flip, 0.0,0.0,text.x0,text.y0,x1,y1);
textlayer = layer;
if( !(layer == PINLAYER && (xctx->inst[n].color))) {
textlayer = symptr->text[j].layer;
if(textlayer < 0 || textlayer >= cadlayers) textlayer = layer;
}
my_snprintf(svg_font_family, S(svg_font_family), svg_font_name);
my_snprintf(svg_font_style, S(svg_font_style), "normal");
my_snprintf(svg_font_weight, S(svg_font_weight), "normal");
textfont = symptr->text[j].font;
if( (textfont && textfont[0])) {
my_snprintf(svg_font_family, S(svg_font_family), textfont);
}
if( symptr->text[j].flags & TEXT_BOLD)
my_snprintf(svg_font_weight, S(svg_font_weight), "bold");
if( symptr->text[j].flags & TEXT_ITALIC)
my_snprintf(svg_font_style, S(svg_font_style), "italic");
if( symptr->text[j].flags & TEXT_OBLIQUE)
my_snprintf(svg_font_style, S(svg_font_style), "oblique");
if((layer == PINLAYER && xctx->inst[n].color) || enable_layer[textlayer]) {
if(text_svg)
svg_draw_string(textlayer, txtptr,
(text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3,
flip^text.flip, text.hcenter, text.vcenter,
x0+x1, y0+y1, text.xscale, text.yscale);
else
old_svg_draw_string(textlayer, txtptr,
(text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3,
flip^text.flip, text.hcenter, text.vcenter,
x0+x1, y0+y1, text.xscale, text.yscale);
}
text = symptr->text[j];
/* if(text.xscale*FONTWIDTH* xctx->mooz<1) continue; */
txtptr= translate(n, text.txt_ptr);
ROTATION(rot, flip, 0.0,0.0,text.x0,text.y0,x1,y1);
textlayer = layer;
if( !(layer == PINLAYER && (xctx->inst[n].color))) {
textlayer = symptr->text[j].layer;
if(textlayer < 0 || textlayer >= cadlayers) textlayer = layer;
}
my_snprintf(svg_font_family, S(svg_font_family), svg_font_name);
my_snprintf(svg_font_style, S(svg_font_style), "normal");
my_snprintf(svg_font_weight, S(svg_font_weight), "normal");
textfont = symptr->text[j].font;
if( (textfont && textfont[0])) {
my_snprintf(svg_font_family, S(svg_font_family), textfont);
}
if( symptr->text[j].flags & TEXT_BOLD)
my_snprintf(svg_font_weight, S(svg_font_weight), "bold");
if( symptr->text[j].flags & TEXT_ITALIC)
my_snprintf(svg_font_style, S(svg_font_style), "italic");
if( symptr->text[j].flags & TEXT_OBLIQUE)
my_snprintf(svg_font_style, S(svg_font_style), "oblique");
if((layer == PINLAYER && xctx->inst[n].color) || enable_layer[textlayer]) {
if(text_svg)
svg_draw_string(textlayer, txtptr,
(text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3,
flip^text.flip, text.hcenter, text.vcenter,
x0+x1, y0+y1, text.xscale, text.yscale);
else
old_svg_draw_string(textlayer, txtptr,
(text.rot + ( (flip && (text.rot & 1) ) ? rot+2 : rot) ) & 0x3,
flip^text.flip, text.hcenter, text.vcenter,
x0+x1, y0+y1, text.xscale, text.yscale);
}
}
}
Tcl_SetResult(interp,"",TCL_STATIC);
}
Tcl_SetResult(interp,"",TCL_STATIC);
}
@ -573,6 +566,7 @@ void svg_draw(void)
char *tmpstring=NULL;
const char *r, *textfont;
int *used_layer;
xSymbol *symptr;
if(!plotfile[0]) {
my_strdup(61, &tmpstring, "tk_getSaveFile -title {Select destination file} -initialdir [pwd]");
@ -602,27 +596,45 @@ void svg_draw(void)
else fd=fopen("plot.svg", "w");
my_strncpy(plotfile,"", S(plotfile));
/* ================================================================================ */
used_layer = my_calloc(0, cadlayers, sizeof(int));
used_layer = my_calloc(873, cadlayers, sizeof(int));
for(i=0;i<xctx->texts;i++)
{
textlayer = xctx->text[i].layer;
if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER;
used_layer[textlayer] = 1;
}
for(c=0;c<cadlayers;c++)
{
if(xctx->lines[c] || xctx->rects[c] || xctx->arcs[c] || xctx->polygons[c]) used_layer[c] = 1;
for(i=0;i<xctx->instances;i++) {
/* ..... */
#if 0
/* ================================================================================ */
for(i=0;i<xctx->texts;i++)
{
textlayer = xctx->text[i].layer;
if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER;
used_layer[textlayer] = 1;
}
for(c=0;c<cadlayers;c++)
{
if(xctx->lines[c] || xctx->rects[c] || xctx->arcs[c] || xctx->polygons[c]) used_layer[c] = 1;
for(i=0;i<xctx->instances;i++) {
symptr = (xctx->inst[i].ptr+ xctx->sym);
if( (c == PINLAYER || enable_layer[c]) && symptr->lines[c] ) used_layer[c] = 1;
if( (c == PINLAYER || enable_layer[c]) && symptr->polygons[c] ) used_layer[c] = 1;
if( (c == PINLAYER || enable_layer[c]) && symptr->arcs[c] ) used_layer[c] = 1;
if( (c != PINLAYER || enable_layer[c]) && symptr->rects[c] ) used_layer[c] = 1;
if( (c==TEXTWIRELAYER && !(xctx->inst[i].flags&2) ) ||
(sym_txt && (c==TEXTLAYER) && (xctx->inst[i].flags&2) ) )
{
for(j=0;j< symptr->texts;j++)
{
text = symptr->text[j];
/* if(text.xscale*FONTWIDTH* xctx->mooz<1) continue; */
textlayer = c;
if( !(c == PINLAYER && (xctx->inst[i].color))) {
textlayer = symptr->text[j].c;
if(textlayer < 0 || textlayer >= cadlayers) textlayer = c;
}
used_layer[textlayer] = 1;
}
}
}
if(xctx->wires) used_layer[WIRELAYER] = 1;
my_free(0, &used_layer);
}
/* ================================================================================ */
#endif
my_free(1217, &used_layer);
fprintf(fd, "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"%g\" height=\"%g\" version=\"1.1\">\n", dx, dy);

View File

@ -1,4 +1,4 @@
v {xschem version=2.9.8 file_version=1.2 }
v {xschem version=2.9.9 file_version=1.2 }
G {}
K {}
V {}
@ -48,7 +48,7 @@ N 870 -300 990 -300 {lab=#net1}
N 910 -340 910 -250 {lab=#net2}
N 910 -270 970 -270 {lab=#net2}
N 930 -310 960 -300 {lab=#net1}
N 380 -530 700 -530 {lab=BUS[4:0]}
N 380 -530 700 -530 {lab=xxx}
N 510 -640 510 -540 {lab=BUS[1]}
N 410 -600 410 -540 {lab=BUS[2]}
C {poweramp.sym} 160 -440 0 0 {name=x1

View File

@ -13,7 +13,7 @@ N 260 -470 340 -470 {lab=E9}
N 340 -500 340 -470 {lab=E9}
N 1110 -700 1110 -670 {lab=SA}
N 840 -1020 840 -980 {lab=E4}
N 1110 -590 1110 -570 {lab=OUTI}
N 1110 -590 1110 -570 {lab=xxx}
N 1110 -510 1110 -470 {lab=#net1}
N 180 -1020 180 -980 {lab=E1}
N 390 -790 520 -790 {lab=C2}
@ -49,9 +49,9 @@ N 260 -180 260 -130 {lab=E3}
N 150 -150 150 -70 {lab=VSS}
N 50 -150 50 -70 {lab=VSS}
N 50 -70 150 -70 {lab=VSS}
N 690 -600 1110 -600 {lab=OUTI}
N 690 -600 1110 -600 {lab=xxx}
N 180 -470 260 -470 {lab=E9}
N 1110 -610 1110 -600 {lab=OUTI}
N 1110 -610 1110 -600 {lab=xxx}
N 860 -380 1110 -380 {lab=SB}
N 860 -700 1110 -700 {lab=SA}
N 1240 -1120 1240 -960 {lab=VBOOST}
@ -64,8 +64,8 @@ N 220 -630 340 -630 {lab=C9}
N 180 -600 180 -560 {lab=C5}
N 1110 -320 1110 -280 {lab=VNN}
N 1330 -590 1390 -590 {lab=OUT}
N 1110 -590 1240 -590 {lab=OUTI}
N 1110 -600 1110 -590 {lab=OUTI}
N 1110 -590 1240 -590 {lab=xxx}
N 1110 -600 1110 -590 {lab=xxx}
N 340 -860 340 -820 {lab=#net4}
N 560 -860 560 -820 {lab=#net5}
N 560 -1020 560 -920 {lab=E6}
@ -73,16 +73,16 @@ N 340 -1020 340 -920 {lab=E2}
N 260 -280 260 -240 {lab=C3}
N 730 -440 770 -440 {lab=#net6}
N 560 -440 670 -440 {lab=C8}
N 690 -650 690 -600 {lab=OUTI}
N 690 -650 690 -600 {lab=xxx}
N 690 -730 690 -710 {lab=#net7}
N 180 -840 180 -660 {lab=C7}
N 840 -860 840 -840 {lab=E11}
N 1240 -810 1240 -590 {lab=OUTI}
N 1240 -810 1240 -590 {lab=xxx}
N 860 -760 860 -750 {lab=GA}
N 860 -710 860 -700 {lab=SA}
N 860 -440 860 -430 {lab=GB}
N 860 -390 860 -380 {lab=SB}
N 1240 -590 1270 -590 {lab=OUTI}
N 1240 -590 1270 -590 {lab=xxx}
N 830 -440 860 -440 {lab=GB}
N 840 -760 860 -760 {lab=GA}
N 340 -1180 340 -1080 { lab=VPP}