From 340b89c58d91201217b80e0a4898f24d76ccbd21 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Thu, 13 Apr 2023 22:25:36 +0200 Subject: [PATCH] add base_name field in xSymbol struct to keep track of the base symbol name the "virtual" symbol is inherited from (instance based implementation selection with schematic=... attribute) --- ...utorial_instance_based_implementation.html | 4 +- src/actions.c | 1 + src/in_memory_undo.c | 79 +------------------ src/save.c | 1 + src/spice_netlist.c | 9 +-- src/tedax_netlist.c | 7 +- src/verilog_netlist.c | 8 +- src/vhdl_netlist.c | 9 +-- src/xschem.h | 2 + 9 files changed, 19 insertions(+), 101 deletions(-) diff --git a/doc/xschem_man/tutorial_instance_based_implementation.html b/doc/xschem_man/tutorial_instance_based_implementation.html index 657d1a80..e95a7a76 100644 --- a/doc/xschem_man/tutorial_instance_based_implementation.html +++ b/doc/xschem_man/tutorial_instance_based_implementation.html @@ -75,7 +75,7 @@ p{padding: 15px 30px 10px;}

@@ -84,7 +84,7 @@ p{padding: 15px 30px 10px;}

- Note: when creating alternate alternate netlist files ensure the port order is identical to the base + Note: when creating alternate netlist files ensure the port order is identical to the base circuit. The assumption for all alternate circuits created using the methods explained above is that the alternate circuits have all the same interface as the base circuit (same input, output, inout pins, in the same order).



diff --git a/src/actions.c b/src/actions.c index 563d6adc..3caf4481 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1235,6 +1235,7 @@ void get_additional_symbols(int what) dbg(1, "get_additional_symbols(): adding symbol %s\n", sym); check_symbol_storage(); copy_symbol(&xctx->sym[j], xctx->inst[i].ptr + xctx->sym); + xctx->sym[j].base_name = (xctx->inst[i].ptr + xctx->sym)->name; my_strdup(_ALLOC_ID_, &xctx->sym[j].name, sym); if(spice_sym_def) diff --git a/src/in_memory_undo.c b/src/in_memory_undo.c index 145ad036..51fa881f 100644 --- a/src/in_memory_undo.c +++ b/src/in_memory_undo.c @@ -256,6 +256,7 @@ void copy_symbol(xSymbol *dest_sym, xSymbol *src_sym) int c, j; *dest_sym = *src_sym; dest_sym->name = NULL; + dest_sym->base_name = NULL; dest_sym->prop_ptr = NULL; dest_sym->type = NULL; dest_sym->templ = NULL; @@ -456,8 +457,6 @@ void mem_push_undo(void) void mem_pop_undo(int redo, int set_modify_status) { int slot, i, c; - xSymbol *sym; - int j; if(xctx->no_undo)return; if(redo == 1) { @@ -581,81 +580,7 @@ void mem_pop_undo(int redo, int set_modify_status) xctx->sym = my_calloc(_ALLOC_ID_, xctx->symbols, sizeof(xSymbol)); for(i = 0;isymbols; ++i) { - sym = &xctx->uslot[slot].symptr[i]; - xctx->sym[i] = *sym; - xctx->sym[i].name = NULL; - xctx->sym[i].prop_ptr = NULL; - xctx->sym[i].type = NULL; - xctx->sym[i].templ = NULL; - my_strdup2(_ALLOC_ID_, &xctx->sym[i].name, sym->name); - my_strdup2(_ALLOC_ID_, &xctx->sym[i].type, sym->type); - my_strdup2(_ALLOC_ID_, &xctx->sym[i].templ, sym->templ); - my_strdup2(_ALLOC_ID_, &xctx->sym[i].prop_ptr, sym->prop_ptr); - - xctx->sym[i].line = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xLine *)); - xctx->sym[i].poly = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xPoly *)); - xctx->sym[i].arc = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xArc *)); - xctx->sym[i].rect = my_calloc(_ALLOC_ID_, cadlayers, sizeof(xRect *)); - xctx->sym[i].lines = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int)); - xctx->sym[i].rects = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int)); - xctx->sym[i].arcs = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int)); - xctx->sym[i].polygons = my_calloc(_ALLOC_ID_, cadlayers, sizeof(int)); - xctx->sym[i].text = my_calloc(_ALLOC_ID_, xctx->sym[i].texts, sizeof(xText)); - - memcpy(xctx->sym[i].lines, sym->lines, sizeof(sym->lines[0]) * cadlayers); - memcpy(xctx->sym[i].rects, sym->rects, sizeof(sym->rects[0]) * cadlayers); - memcpy(xctx->sym[i].arcs, sym->arcs, sizeof(sym->arcs[0]) * cadlayers); - memcpy(xctx->sym[i].polygons, sym->polygons, sizeof(sym->polygons[0]) * cadlayers); - - for(c = 0;csym[i].line[c] = my_calloc(_ALLOC_ID_, sym->lines[c], sizeof(xLine)); - for(j = 0; j < xctx->sym[i].lines[c]; ++j) { - xctx->sym[i].line[c][j] = sym->line[c][j]; - xctx->sym[i].line[c][j].prop_ptr = NULL; - my_strdup(_ALLOC_ID_, & xctx->sym[i].line[c][j].prop_ptr, sym->line[c][j].prop_ptr); - } - /* symbol rects */ - xctx->sym[i].rect[c] = my_calloc(_ALLOC_ID_, sym->rects[c], sizeof(xRect)); - for(j = 0; j < xctx->sym[i].rects[c]; ++j) { - xctx->sym[i].rect[c][j] = sym->rect[c][j]; - xctx->sym[i].rect[c][j].prop_ptr = NULL; - xctx->sym[i].rect[c][j].extraptr = NULL; - my_strdup(_ALLOC_ID_, & xctx->sym[i].rect[c][j].prop_ptr, sym->rect[c][j].prop_ptr); - } - /* symbol arcs */ - xctx->sym[i].arc[c] = my_calloc(_ALLOC_ID_, sym->arcs[c], sizeof(xArc)); - for(j = 0; j < xctx->sym[i].arcs[c]; ++j) { - xctx->sym[i].arc[c][j] = sym->arc[c][j]; - xctx->sym[i].arc[c][j].prop_ptr = NULL; - my_strdup(_ALLOC_ID_, & xctx->sym[i].arc[c][j].prop_ptr, sym->arc[c][j].prop_ptr); - } - /* symbol polygons */ - xctx->sym[i].poly[c] = my_calloc(_ALLOC_ID_, sym->polygons[c], sizeof(xPoly)); - for(j = 0; j < xctx->sym[i].polygons[c]; ++j) { - int points = sym->poly[c][j].points; - xctx->sym[i].poly[c][j] = sym->poly[c][j]; - xctx->sym[i].poly[c][j].prop_ptr = NULL; - xctx->sym[i].poly[c][j].x = my_malloc(_ALLOC_ID_, points * sizeof(double)); - xctx->sym[i].poly[c][j].y = my_malloc(_ALLOC_ID_, points * sizeof(double)); - xctx->sym[i].poly[c][j].selected_point = my_malloc(_ALLOC_ID_, points * sizeof(unsigned short)); - memcpy(xctx->sym[i].poly[c][j].x, sym->poly[c][j].x, points * sizeof(double)); - memcpy(xctx->sym[i].poly[c][j].y, sym->poly[c][j].y, points * sizeof(double)); - memcpy(xctx->sym[i].poly[c][j].selected_point, sym->poly[c][j].selected_point, - points * sizeof(unsigned short)); - my_strdup(_ALLOC_ID_, & xctx->sym[i].poly[c][j].prop_ptr, sym->poly[c][j].prop_ptr); - } - } - /* symbol texts */ - for(j = 0; j < xctx->sym[i].texts; ++j) { - xctx->sym[i].text[j] = sym->text[j]; - xctx->sym[i].text[j].prop_ptr = NULL; - xctx->sym[i].text[j].txt_ptr = NULL; - xctx->sym[i].text[j].font = NULL; - my_strdup(_ALLOC_ID_, &xctx->sym[i].text[j].prop_ptr, sym->text[j].prop_ptr); - my_strdup(_ALLOC_ID_, &xctx->sym[i].text[j].txt_ptr, sym->text[j].txt_ptr); - my_strdup(_ALLOC_ID_, &xctx->sym[i].text[j].font, sym->text[j].font); - } + copy_symbol(&xctx->sym[i], &xctx->uslot[slot].symptr[i]); } /* texts */ diff --git a/src/save.c b/src/save.c index 9a9ac009..718ce3ee 100644 --- a/src/save.c +++ b/src/save.c @@ -3179,6 +3179,7 @@ int load_sym_def(const char *name, FILE *embed_fd) symbol[symbols].prop_ptr = NULL; symbol[symbols].type = NULL; symbol[symbols].templ = NULL; + symbol[symbols].base_name=NULL; symbol[symbols].name=NULL; my_strdup2(_ALLOC_ID_, &symbol[symbols].name,name); /* read symbol from file */ diff --git a/src/spice_netlist.c b/src/spice_netlist.c index 6856d01c..1e023322 100644 --- a/src/spice_netlist.c +++ b/src/spice_netlist.c @@ -531,8 +531,7 @@ int spice_block_netlist(FILE *fd, int i) /* int multip; */ char *extra=NULL; int split_f; - const char *sym_def, *sympath; - struct stat buf; + const char *sym_def; split_f = tclgetboolvar("split_files"); @@ -551,10 +550,8 @@ int spice_block_netlist(FILE *fd, int i) } fprintf(fd, "\n* expanding symbol: %s # of pins=%d\n", xctx->sym[i].name,xctx->sym[i].rects[PINLAYER] ); - sympath = abs_sym_path(xctx->sym[i].name, ""); - if(!stat(sympath, &buf)) fprintf(fd, "** sym_path: %s\n", abs_sym_path(xctx->sym[i].name, "")); - else fprintf(fd, "** sym_path: %s\n", xctx->sym[i].name); - + if(xctx->sym[i].base_name) fprintf(fd, "** sym_path: %s\n", abs_sym_path(xctx->sym[i].base_name, "")); + else fprintf(fd, "** sym_path: %s\n", abs_sym_path(xctx->sym[i].name, "")); sym_def = get_tok_value(xctx->sym[i].prop_ptr,"spice_sym_def",0); if(sym_def[0]) { fprintf(fd, "%s\n", sym_def); diff --git a/src/tedax_netlist.c b/src/tedax_netlist.c index f1ea9671..96e9d99d 100644 --- a/src/tedax_netlist.c +++ b/src/tedax_netlist.c @@ -81,8 +81,6 @@ static int tedax_block_netlist(FILE *fd, int i) int tedax_stop=0; char filename[PATH_MAX]; char *extra=NULL; - const char *sympath; - struct stat buf; if(!strcmp( get_tok_value(xctx->sym[i].prop_ptr,"tedax_stop",0),"true") ) tedax_stop=1; @@ -92,9 +90,8 @@ static int tedax_block_netlist(FILE *fd, int i) fprintf(fd, "\n# expanding symbol: %s # of pins=%d\n", xctx->sym[i].name,xctx->sym[i].rects[PINLAYER] ); - sympath = abs_sym_path(xctx->sym[i].name, ""); - if(!stat(sympath, &buf)) fprintf(fd, "## sym_path: %s\n", abs_sym_path(xctx->sym[i].name, "")); - else fprintf(fd, "## sym_path: %s\n", xctx->sym[i].name); + if(xctx->sym[i].base_name) fprintf(fd, "## sym_path: %s\n", abs_sym_path(xctx->sym[i].base_name, "")); + else fprintf(fd, "## sym_path: %s\n", abs_sym_path(xctx->sym[i].name, "")); fprintf(fd, "## sch_path: %s\n", filename); fprintf(fd, "begin netlist v1 %s\n",skip_dir(xctx->sym[i].name)); diff --git a/src/verilog_netlist.c b/src/verilog_netlist.c index 343a2e0f..8b29e623 100644 --- a/src/verilog_netlist.c +++ b/src/verilog_netlist.c @@ -432,8 +432,7 @@ int verilog_block_netlist(FILE *fd, int i) char cellname[PATH_MAX]; const char *str_tmp, *fmt_attr = NULL; int split_f; - const char *sym_def, *sympath; - struct stat buf; + const char *sym_def; char *extra_ptr, *saveptr1, *extra_token, *extra = NULL, *extra2=NULL; @@ -455,9 +454,8 @@ int verilog_block_netlist(FILE *fd, int i) dbg(1, "verilog_block_netlist(): expanding %s\n", xctx->sym[i].name); fprintf(fd, "\n// expanding symbol: %s # of pins=%d\n", xctx->sym[i].name,xctx->sym[i].rects[PINLAYER] ); - sympath = abs_sym_path(xctx->sym[i].name, ""); - if(!stat(sympath, &buf)) fprintf(fd, "// sym_path: %s\n", abs_sym_path(xctx->sym[i].name, "")); - else fprintf(fd, "// sym_path: %s\n", xctx->sym[i].name); + if(xctx->sym[i].base_name) fprintf(fd, "// sym_path: %s\n", abs_sym_path(xctx->sym[i].base_name, "")); + else fprintf(fd, "// sym_path: %s\n", abs_sym_path(xctx->sym[i].name, "")); sym_def = get_tok_value(xctx->sym[i].prop_ptr,"verilog_sym_def",0); if(sym_def[0]) { fprintf(fd, "%s\n", sym_def); diff --git a/src/vhdl_netlist.c b/src/vhdl_netlist.c index 9c01f219..30a822f5 100644 --- a/src/vhdl_netlist.c +++ b/src/vhdl_netlist.c @@ -529,8 +529,7 @@ int vhdl_block_netlist(FILE *fd, int i) char *abs_path = NULL; const char *str_tmp; int split_f; - const char *sym_def, *sympath; - struct stat buf; + const char *sym_def; split_f = tclgetboolvar("split_files"); if(!strcmp( get_tok_value(xctx->sym[i].prop_ptr,"vhdl_stop",0),"true") ) @@ -550,10 +549,8 @@ int vhdl_block_netlist(FILE *fd, int i) dbg(1, "vhdl_block_netlist(): expanding %s\n", xctx->sym[i].name); fprintf(fd, "\n-- expanding symbol: %s # of pins=%d\n", xctx->sym[i].name,xctx->sym[i].rects[PINLAYER] ); - sympath = abs_sym_path(xctx->sym[i].name, ""); - if(!stat(sympath, &buf)) fprintf(fd, "-- sym_path: %s\n", abs_sym_path(xctx->sym[i].name, "")); - else fprintf(fd, "-- sym_path: %s\n", xctx->sym[i].name); - + if(xctx->sym[i].base_name) fprintf(fd, "-- sym_path: %s\n", abs_sym_path(xctx->sym[i].base_name, "")); + else fprintf(fd, "-- sym_path: %s\n", abs_sym_path(xctx->sym[i].name, "")); sym_def = get_tok_value(xctx->sym[i].prop_ptr,"vhdl_sym_def",0); if(sym_def[0]) { fprintf(fd, "%s\n", sym_def); diff --git a/src/xschem.h b/src/xschem.h index be9d3135..c7c64798 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -495,6 +495,8 @@ typedef struct typedef struct { char *name; + const char *base_name; /* points to the base symbol name this symbol is inherited from + * (schematic attribute set on instances, create "virtual" symbol) */ double minx; double maxx; double miny;