simplify place_symbol(), hash newly placed component name, so successive placements will not clash instance name. hash_all_names() renamed to hash_names()

This commit is contained in:
stefan schippers 2023-09-28 13:28:16 +02:00
parent 5df9347533
commit e13922e94f
8 changed files with 27 additions and 35 deletions

View File

@ -512,6 +512,7 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
<li><kbd> abort_operation</kbd></li><pre>
@ -780,13 +781,13 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
'inst' can be an instance name or number </pre>
<li><kbd> hilight_netname net</kbd></li><pre>
Highlight net name 'net' </pre>
<li><kbd> instance sym_name x y rot flip [prop] [first_call]</kbd></li><pre>
<li><kbd> instance sym_name x y rot flip [prop] [n]</kbd></li><pre>
Place a new instance of symbol 'sym_name' at position x,y,
rotation and flip set to 'rot', 'flip'
if 'prop' is given it is the new instance attribute
string (default: symbol template string)
if 'first_call' is given it must be 1 on first call
and zero on following calls
if 'n' is given it must be 0 on first call
and non zero on following calls
It is used only for efficiency reasons if placing multiple instances </pre>
<li><kbd> instance_bbox inst</kbd></li><pre>
return instance and symbol bounding boxes
@ -1332,7 +1333,6 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
</ul>

View File

@ -1381,9 +1381,7 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
int i,j,n;
char name[PATH_MAX];
char name1[PATH_MAX];
char *type;
char tclev = 0;
int cond;
if(symbol_name==NULL) {
tcleval("load_file_dialog {Choose symbol} *.sym INITIALINSTDIR");
my_strncpy(name1, tclresult(), S(name1));
@ -1391,7 +1389,7 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
my_strncpy(name1, symbol_name, S(name1));
}
dbg(1, "place_symbol(): 1: name1=%s\n",name1);
dbg(0, "place_symbol(): 1: name1=%s first_call=%d\n",name1, first_call);
/* remove tcleval( given in file selector, if any ... */
if(strstr(name1, "tcleval(")) {
tclev = 1;
@ -1452,7 +1450,7 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
xctx->inst[n].prop_ptr=NULL;
xctx->inst[n].instname=NULL;
dbg(1, "place_symbol() :all inst_ptr members set\n"); /* 03-02-2000 */
if(first_call) hash_all_names(-1, XINSERT);
if(first_call) hash_names(-1, XINSERT);
if(inst_props) {
new_prop_string(n, inst_props,!first_call, tclgetboolvar("disable_unique_names")); /* 20171214 first_call */
}
@ -1461,20 +1459,14 @@ int place_symbol(int pos, const char *symbol_name, double x, double y, short rot
}
dbg(1, "place_symbol(): done set_inst_prop()\n"); /* 03-02-2000 */
set_inst_flags(&xctx->inst[n]);
/* After having assigned prop_ptr to new instance translate symbol reference
* to resolve @params --> res.tcl(@value\) --> res.tcl(100) */
my_strncpy(name, translate(n, name), S(name));
i = match_symbol(name);
xctx->inst[n].ptr = i;
type = xctx->sym[xctx->inst[n].ptr].type;
cond= type && IS_LABEL_SH_OR_PIN(type);
if(cond) {
xctx->inst[n].flags |= PIN_OR_LABEL;
my_strdup2(_ALLOC_ID_, &xctx->inst[n].lab, get_tok_value(xctx->inst[n].prop_ptr,"lab",0));
}
set_inst_flags(&xctx->inst[n]);
hash_names(n, XINSERT);
if(first_call && (draw_sym & 3) ) bbox(START, 0.0 , 0.0 , 0.0 , 0.0);
xctx->instances++; /* must be updated before calling symbol_bbox() */
/* force these vars to 0 to trigger a prepare_netlist_structs(0) needed by symbol_bbox->translate

View File

@ -631,7 +631,7 @@ char *strtoupper(char* s) {
return s;
}
/* caller should do hash_all_names() (once) before (repeatedly) using this function */
/* caller should do hash_names() (once) before (repeatedly) using this function */
void set_inst_prop(int i)
{
char *ptr;
@ -1430,7 +1430,7 @@ static int update_symbol(const char *result, int x, int first_sel)
}
/* set unique name of current inst */
if(!pushed) { xctx->push_undo(); pushed=1;}
if(!k) hash_all_names(-1, XINSERT);
if(!k) hash_names(-1, XINSERT);
new_prop_string(*ii, ptr, k, tclgetboolvar("disable_unique_names")); /* set new prop_ptr */
}

View File

@ -1043,7 +1043,7 @@ void copy_objects(int what)
xctx->inst[xctx->instances].flip = (xctx->move_flip? !xctx->inst[n].flip:xctx->inst[n].flip);
/* the newpropcnt argument is zero for the 1st call and used in */
/* new_prop_string() for cleaning some internal caches. */
if(!newpropcnt) hash_all_names(-1, XINSERT);
if(!newpropcnt) hash_names(-1, XINSERT);
new_prop_string(xctx->instances, xctx->inst[n].prop_ptr,newpropcnt++,
tclgetboolvar("disable_unique_names"));
my_strdup(_ALLOC_ID_, &xctx->inst[xctx->instances].instname,

View File

@ -275,7 +275,7 @@ static void merge_inst(int k,FILE *fd)
load_ascii_string(&prop_ptr,fd);
my_strdup(_ALLOC_ID_, &xctx->inst[i].prop_ptr, prop_ptr);
set_inst_flags(&xctx->inst[i]);
if(!k) hash_all_names(-1, XINSERT);
if(!k) hash_names(-1, XINSERT);
new_prop_string(i, prop_ptr, k, tclgetboolvar("disable_unique_names")); /* will also assign .instname */
/* the final tmp argument is zero for the 1st call and used in */
/* new_prop_string() for cleaning some internal caches. */

View File

@ -1712,13 +1712,13 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
else { cmd_found = 0;}
break;
case 'i': /*----------------------------------------------*/
/* instance sym_name x y rot flip [prop] [first_call]
/* instance sym_name x y rot flip [prop] [n]
* Place a new instance of symbol 'sym_name' at position x,y,
* rotation and flip set to 'rot', 'flip'
* if 'prop' is given it is the new instance attribute
* string (default: symbol template string)
* if 'first_call' is given it must be 1 on first call
* and zero on following calls
* if 'n' is given it must be 0 on first call
* and non zero on following calls
* It is used only for efficiency reasons if placing multiple instances */
if(!strcmp(argv[1], "instance"))
{
@ -3269,7 +3269,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
/* 20110325 only modify prefix if prefix not NUL */
if(prefix) name[0]=(char)prefix; /* change prefix if changing symbol type; */
my_strdup(_ALLOC_ID_, &ptr,subst_token(xctx->inst[inst].prop_ptr, "name", name) );
if(!fast) hash_all_names(-1, XINSERT);
if(!fast) hash_names(-1, XINSERT);
new_prop_string(inst, ptr, fast, tclgetboolvar("disable_unique_names")); /* set new prop_ptr */
my_strdup(_ALLOC_ID_, &xctx->inst[inst].instname, get_tok_value(xctx->inst[inst].prop_ptr, "name", 0));
@ -3952,7 +3952,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
xctx->prep_hash_inst=0;
xctx->prep_net_structs=0;
xctx->prep_hi_structs=0;
if(!strcmp(argv[4], "name")) hash_all_names(-1, XINSERT);
if(!strcmp(argv[4], "name")) hash_names(-1, XINSERT);
if(argc > 5) {
my_strdup2(_ALLOC_ID_, &subst, subst_token(xctx->inst[inst].prop_ptr, argv[4], argv[5]));
} else {/* assume argc == 5 , delete attribute */

View File

@ -56,7 +56,7 @@ void floater_hash_all_names(void)
/* if inst == -1 hash all instance names, else do only given instance
* action can be XINSERT or XDELETE to insert or remove items */
void hash_all_names(int inst, int action)
void hash_names(int inst, int action)
{
int i, mult, start, stop;
char *upinst = NULL;
@ -72,7 +72,7 @@ void hash_all_names(int inst, int action)
start = inst;
stop = inst + 1;
}
if(inst != -1) dbg(1, "hash_all_names(): start=%d, stop=%d, instname=%s\n",
if(inst != -1) dbg(1, "hash_names(): start=%d, stop=%d, instname=%s\n",
start, stop, xctx->inst[inst].instname? xctx->inst[inst].instname : "NULL");
for(i = start; i < stop; ++i) {
if(xctx->inst[i].instname && xctx->inst[i].instname[0]) {
@ -82,9 +82,9 @@ void hash_all_names(int inst, int action)
upinst_ptr = upinst;
while( (single_name = my_strtok_r(upinst_ptr, ",", "", &upinst_state)) ) {
upinst_ptr = NULL;
dbg(1, "hash_all_names(): inst %d, name %s --> %d\n", i, single_name, action);
dbg(1, "hash_names(): inst %d, name %s --> %d\n", i, single_name, action);
int_hash_lookup(&xctx->inst_name_table, single_name, i, action);
dbg(1, "hash_all_names(): hashing %s from %s\n", single_name, xctx->inst[i].instname);
dbg(1, "hash_names(): hashing %s from %s\n", single_name, xctx->inst[i].instname);
}
}
}
@ -161,7 +161,7 @@ void check_unique_names(int rename)
if(xctx->inst[i].ptr == -1) continue;
if(!(xctx->inst[i].ptr+ xctx->sym)->type) continue;
used = name_is_used(xctx->inst[i].instname);
hash_all_names(i, XINSERT_NOREPLACE);
hash_names(i, XINSERT_NOREPLACE);
if( used != -1 && used != i) {
dbg(0, "check_unique_names(): found duplicate: i=%d name=%s\n", i, xctx->inst[i].instname);
xctx->inst[i].color = -PINLAYER;
@ -188,7 +188,7 @@ void check_unique_names(int rename)
my_strdup(_ALLOC_ID_, &tmp, xctx->inst[i].prop_ptr);
new_prop_string(i, tmp, newpropcnt++, 0);
my_strdup(_ALLOC_ID_, &xctx->inst[i].instname, get_tok_value(xctx->inst[i].prop_ptr, "name", 0));
hash_all_names(i, XINSERT);
hash_names(i, XINSERT);
symbol_bbox(i, &xctx->inst[i].x1, &xctx->inst[i].y1, &xctx->inst[i].x2, &xctx->inst[i].y2);
bbox(ADD, xctx->inst[i].x1, xctx->inst[i].y1, xctx->inst[i].x2, xctx->inst[i].y2);
my_free(_ALLOC_ID_, &tmp);
@ -791,11 +791,11 @@ void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names)
return;
}
/* don't change old_prop if name does not conflict. */
/* if no hash_all_names() is done and inst_table uninitialized --> use old_prop */
/* if no hash_names() is done and inst_table uninitialized --> use old_prop */
is_used = name_is_used(old_name);
if(dis_uniq_names || is_used == -1 || is_used == i) {
my_strdup(_ALLOC_ID_, &xctx->inst[i].prop_ptr, old_prop);
hash_all_names(i, XINSERT); /* add instance 'i' to xctx->inst_name_table */
hash_names(i, XINSERT); /* add instance 'i' to xctx->inst_name_table */
my_free(_ALLOC_ID_, &old_name);
return;
}
@ -823,7 +823,7 @@ void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names)
if(strcmp(new_prop, old_prop) ) {
my_strdup(_ALLOC_ID_, &xctx->inst[i].prop_ptr, new_prop);
my_strdup2(_ALLOC_ID_, &xctx->inst[i].instname, new_name);
hash_all_names(i, XINSERT);
hash_names(i, XINSERT);
}
my_free(_ALLOC_ID_, &old_name);
my_free(_ALLOC_ID_, &new_name);

View File

@ -1510,7 +1510,7 @@ extern float my_atof(const char *p);
extern const char *subst_token(const char *s, const char *tok, const char *new_val);
extern void new_prop_string(int i, const char *old_prop,int fast, int dis_uniq_names);
extern void hash_name(char *token, int remove);
extern void hash_all_names(int inst, int action); /* if i == -1 hash all instances, else do only inst */
extern void hash_names(int inst, int action); /* if i == -1 hash all instances, else do only inst */
extern int name_is_used(char *name);
extern void floater_hash_all_names(void);
extern void symbol_bbox(int i, double *x1,double *y1, double *x2, double *y2);