From 9533b17a20bf894ee61fda97f640bb52a0136a77 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Tue, 2 May 2023 12:42:53 +0200 Subject: [PATCH] Allow to pass instance attributes (via translate() ) to symbol generators --- src/editprop.c | 9 +- src/save.c | 6 +- src/token.c | 23 ++-- xschem_library/generators/nmosgen | 127 +++++++++++++++++++ xschem_library/generators/symbolgen | 29 +++-- xschem_library/generators/test_nmosgen.sch | 27 ++++ xschem_library/generators/test_symbolgen.sch | 13 +- 7 files changed, 198 insertions(+), 36 deletions(-) create mode 100755 xschem_library/generators/nmosgen create mode 100644 xschem_library/generators/test_nmosgen.sch diff --git a/src/editprop.c b/src/editprop.c index c11e7f88..9d4ac98c 100644 --- a/src/editprop.c +++ b/src/editprop.c @@ -1329,9 +1329,8 @@ static void update_symbol(const char *result, int x) char * ss=NULL; my_strdup(_ALLOC_ID_, &ss, xctx->inst[*ii].prop_ptr); if( set_different_token(&ss, new_prop, xctx->old_prop) ) { - if(!pushed) { xctx->push_undo(); pushed=1;} + if(!pushed) { xctx->push_undo(); pushed=1; set_modify(1);} my_strdup(_ALLOC_ID_, &xctx->inst[*ii].prop_ptr, ss); - set_modify(1); } my_free(_ALLOC_ID_, &ss); } @@ -1340,14 +1339,12 @@ static void update_symbol(const char *result, int x) if(!xctx->inst[*ii].prop_ptr || strcmp(xctx->inst[*ii].prop_ptr, new_prop)) { dbg(1, "update_symbol(): changing prop: |%s| -> |%s|\n", xctx->inst[*ii].prop_ptr, new_prop); - if(!pushed) { xctx->push_undo(); pushed=1;} + if(!pushed) { xctx->push_undo(); pushed=1; set_modify(1);} my_strdup(_ALLOC_ID_, &xctx->inst[*ii].prop_ptr, new_prop); - set_modify(1); } } else { - if(!pushed) { xctx->push_undo(); pushed=1;} + if(!pushed) { xctx->push_undo(); pushed=1; set_modify(1);} my_strdup(_ALLOC_ID_, &xctx->inst[*ii].prop_ptr, ""); - set_modify(1); } } } diff --git a/src/save.c b/src/save.c index fa582be8..c881b03e 100644 --- a/src/save.c +++ b/src/save.c @@ -2393,7 +2393,7 @@ void link_symbols_to_instances(int from) 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"); - my_strdup2(_ALLOC_ID_, &name, tcl_hook2(xctx->inst[i].name)); + my_strdup2(_ALLOC_ID_, &name, tcl_hook2(translate(i, xctx->inst[i].name))); xctx->inst[i].ptr = match_symbol(name); my_free(_ALLOC_ID_, &name); } @@ -3975,7 +3975,7 @@ void descend_symbol(void) if(ret == 0) clear_all_hilights(); if(ret == -1) return; /* user cancel */ } - my_snprintf(name, S(name), "%s", xctx->inst[n].name); + my_snprintf(name, S(name), "%s", translate(n, xctx->inst[n].name)); /* dont allow descend in the default missing symbol */ if((xctx->inst[n].ptr+ xctx->sym)->type && !strcmp( (xctx->inst[n].ptr+ xctx->sym)->type,"missing")) return; @@ -4043,7 +4043,7 @@ void descend_symbol(void) "/xschem_web/", get_cell_w_ext(name, 0), NULL); load_schematic(1, sympath, 1, 1); } else { - dbg(1, "descend_symbol(): sympath=%s\n", sympath); + dbg(0, "descend_symbol(): sympath=%s\n", sympath); load_schematic(1, sympath, 1, 1); } my_free(_ALLOC_ID_, &sympath); diff --git a/src/token.c b/src/token.c index ee14378c..87dfa445 100644 --- a/src/token.c +++ b/src/token.c @@ -851,12 +851,12 @@ static void print_vhdl_primitive(FILE *fd, int inst) /* netlist primitives, 200 else if(strcmp(token,"@symname")==0) /* of course symname must not be present */ /* in hash table */ { - const char *s = sanitize(get_sym_name(inst, 0, 0)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 0))); fputs(s, fd); } else if (strcmp(token,"@symname_ext")==0) { - const char *s = sanitize(get_sym_name(inst, 0, 1)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 1))); fputs(s, fd); } else if(strcmp(token,"@schname_ext")==0) /* of course schname must not be present */ @@ -1223,9 +1223,9 @@ void print_vhdl_element(FILE *fd, int inst) /* print instance name and subckt */ dbg(2, "print_vhdl_element(): printing inst name & subcircuit name\n"); if( (lab = expandlabel(name, &tmp)) != NULL) - fprintf(fd, "%d %s : %s\n", tmp, lab, sanitize(get_sym_name(inst, 0, 0)) ); + fprintf(fd, "%d %s : %s\n", tmp, lab, sanitize(translate(inst, get_sym_name(inst, 0, 0))) ); else /* name in some strange format, probably an error */ - fprintf(fd, "1 %s : %s\n", name, sanitize(get_sym_name(inst, 0, 0)) ); + fprintf(fd, "1 %s : %s\n", name, sanitize(translate(inst, get_sym_name(inst, 0, 0))) ); dbg(2, "print_vhdl_element(): printing generics passed as properties\n"); @@ -1864,7 +1864,7 @@ int print_spice_element(FILE *fd, int inst) } else if (strcmp(token,"@symname")==0) /* of course symname must not be present in attributes */ { - const char *s = sanitize(get_sym_name(inst, 0, 0)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 0))); tmp = strlen(s) +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); @@ -1873,7 +1873,7 @@ int print_spice_element(FILE *fd, int inst) } else if (strcmp(token,"@symname_ext")==0) /* of course symname must not be present in attributes */ { - const char *s = sanitize(get_sym_name(inst, 0, 1)); + const char *s = sanitize(translate(inst, get_sym_name(inst, 0, 1))); tmp = strlen(s) +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); @@ -2094,7 +2094,8 @@ void print_tedax_element(FILE *fd, int inst) int n; Int_hashtable table={NULL, 0}; subcircuit = 1; - fprintf(fd, "__subcircuit__ %s %s\n", sanitize(get_sym_name(inst, 0, 0)), xctx->inst[inst].instname); + fprintf(fd, "__subcircuit__ %s %s\n", + sanitize(translate(inst, get_sym_name(inst, 0, 0))), xctx->inst[inst].instname); int_hash_init(&table, 37); for(i=0;i