diff --git a/src/actions.c b/src/actions.c index 73e78c9c..6fb538cc 100644 --- a/src/actions.c +++ b/src/actions.c @@ -705,8 +705,8 @@ void attach_labels_to_inst() /* offloaded from callback.c 20171005 */ piny0 += y0; get_square(pinx0, piny0, &sqx, &sqy); - iptr=xctx->instpintable[sqx][sqy]; - wptr=xctx->wiretable[sqx][sqy]; + iptr=xctx->instpin_spatial_table[sqx][sqy]; + wptr=xctx->wire_spatial_table[sqx][sqy]; skip=0; while(iptr) { @@ -1284,7 +1284,7 @@ void calc_drawing_bbox(xRect *boundbox, int selected) if(selected == 2) { const char *str; str = get_tok_value(xctx->wire[i].prop_ptr, "lab",0); - if(!str[0] || !bus_hilight_lookup(str, 0,XLOOKUP)) continue; + if(!str[0] || !bus_hilight_hash_lookup(str, 0,XLOOKUP)) continue; } if(xctx->wire[i].bus){ ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE; @@ -1333,7 +1333,7 @@ void calc_drawing_bbox(xRect *boundbox, int selected) type = (xctx->inst[i].ptr+ xctx->sym)->type; found = 0; if( type && IS_LABEL_OR_PIN(type)) { - entry=bus_hilight_lookup(xctx->inst[i].lab, 0, XLOOKUP ); + entry=bus_hilight_hash_lookup(xctx->inst[i].lab, 0, XLOOKUP ); if(entry) found = 1; } else if( xctx->inst[i].color != -10000 ) { diff --git a/src/check.c b/src/check.c index 2cc69ccd..c82b6195 100644 --- a/src/check.c +++ b/src/check.c @@ -53,7 +53,7 @@ void update_conn_cues(int draw_cues, int dr_win) xWire * const wire = xctx->wire; struct iterator_ctx ctx; - hash_wires(); /* must be done also if wires==0 to clear wiretable */ + hash_wires(); /* must be done also if wires==0 to clear wire_spatial_table */ if(!xctx->wires) return; if(!xctx->draw_dots) return; if(cadhalfdotsize*xctx->mooz<0.7) return; @@ -78,7 +78,7 @@ void update_conn_cues(int draw_cues, int dr_win) y0 = wire[k].y2; } get_square(x0, y0, &sqx, &sqy); - for(wptr = xctx->wiretable[sqx][sqy] ; wptr ; wptr = wptr->next) { + for(wptr = xctx->wire_spatial_table[sqx][sqy] ; wptr ; wptr = wptr->next) { i = wptr->n; if(i == k) { continue; /* no check wire against itself */ @@ -160,13 +160,13 @@ void trim_wires(void) y0 = xctx->wire[i].y1; get_square(x0, y0, &sqx, &sqy); k=1; - for(wptr = xctx->wiretable[sqx][sqy] ; ; wptr = wptr->next) { + for(wptr = xctx->wire_spatial_table[sqx][sqy] ; ; wptr = wptr->next) { if(!wptr) { if(k == 1) { x0 = xctx->wire[i].x2; y0 = xctx->wire[i].y2; get_square(x0, y0, &sqx, &sqy); - wptr = xctx->wiretable[sqx][sqy]; + wptr = xctx->wire_spatial_table[sqx][sqy]; k = 2; if(!wptr) break; } else break; @@ -220,13 +220,13 @@ void trim_wires(void) y0 = xctx->wire[i].y1; get_square(x0, y0, &sqx, &sqy); k=1; - for(wptr = xctx->wiretable[sqx][sqy] ; ; wptr = wptr->next) { + for(wptr = xctx->wire_spatial_table[sqx][sqy] ; ; wptr = wptr->next) { if(!wptr) { if(k == 1) { x0 = xctx->wire[i].x2; y0 = xctx->wire[i].y2; get_square(x0, y0, &sqx, &sqy); - wptr = xctx->wiretable[sqx][sqy]; + wptr = xctx->wire_spatial_table[sqx][sqy]; k = 2; if(!wptr) break; } else break; @@ -284,13 +284,13 @@ void trim_wires(void) xctx->wire[i].end1 = xctx->wire[i].end2 = 0; get_square(x0, y0, &sqx, &sqy); k=1; - for(wptr = xctx->wiretable[sqx][sqy] ; ; wptr = wptr->next) { + for(wptr = xctx->wire_spatial_table[sqx][sqy] ; ; wptr = wptr->next) { if(!wptr) { if(k == 1) { x0 = xctx->wire[i].x2; y0 = xctx->wire[i].y2; get_square(x0, y0, &sqx, &sqy); - wptr = xctx->wiretable[sqx][sqy]; + wptr = xctx->wire_spatial_table[sqx][sqy]; k = 2; if(!wptr) break; } else break; @@ -322,7 +322,7 @@ void trim_wires(void) x0 = xctx->wire[i].x2; y0 = xctx->wire[i].y2; get_square(x0, y0, &sqx, &sqy); - for(wptr = xctx->wiretable[sqx][sqy] ; wptr ; wptr = wptr->next) { + for(wptr = xctx->wire_spatial_table[sqx][sqy] ; wptr ; wptr = wptr->next) { j = wptr->n; if(i == j || wireflag[j]) continue; if( touch(xctx->wire[j].x1, xctx->wire[j].y1, xctx->wire[j].x2, xctx->wire[j].y2, x0,y0) && @@ -407,7 +407,7 @@ void break_wires_at_pins(void) x0=xctx->inst[k].x0+rx1; y0=xctx->inst[k].y0+ry1; get_square(x0, y0, &sqx, &sqy); - for(wptr=xctx->wiretable[sqx][sqy]; wptr; wptr=wptr->next) { + for(wptr=xctx->wire_spatial_table[sqx][sqy]; wptr; wptr=wptr->next) { i = wptr->n; if( touch(xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2, x0,y0) ) @@ -458,7 +458,7 @@ void break_wires_at_pins(void) } get_square(x0, y0, &sqx, &sqy); /* printf(" k=%d, x0=%g, y0=%g\n", k, x0, y0); */ - for(wptr=xctx->wiretable[sqx][sqy] ; wptr ; wptr = wptr->next) { + for(wptr=xctx->wire_spatial_table[sqx][sqy] ; wptr ; wptr = wptr->next) { i = wptr->n; /* printf("check wire %d to wire %d\n", k, i); */ if(i==k) { diff --git a/src/draw.c b/src/draw.c index bb25c934..3b07591e 100644 --- a/src/draw.c +++ b/src/draw.c @@ -390,7 +390,7 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot, ( ( /* ... and inst is hilighted ... */ IS_LABEL_SH_OR_PIN(type) && xctx->inst[n].node && xctx->inst[n].node[0] && - bus_hilight_lookup(xctx->inst[n].node[0], 0, XLOOKUP ) + bus_hilight_hash_lookup(xctx->inst[n].node[0], 0, XLOOKUP ) ) || ( !IS_LABEL_SH_OR_PIN(type) && (xctx->inst[n].color != -10000)) )) { xctx->inst[n].flags|=1; /* ... then SKIP instance now and for following layers */ return; diff --git a/src/hash_iterator.c b/src/hash_iterator.c index 85c05597..c851dc8d 100644 --- a/src/hash_iterator.c +++ b/src/hash_iterator.c @@ -39,7 +39,7 @@ void init_inst_iterator(struct iterator_ctx *ctx, double x1, double y1, double x ctx->tmpi = ctx->i % NBOXES; if(ctx->tmpi<0) ctx->tmpi+=NBOXES; ctx->tmpj = ctx->j % NBOXES; if(ctx->tmpj<0) ctx->tmpj+=NBOXES; ctx->counti=0; - ctx->instanceptr=xctx->insttable[ctx->tmpi][ctx->tmpj]; + ctx->instanceptr=xctx->inst_spatial_table[ctx->tmpi][ctx->tmpj]; ctx->countj=0; } @@ -60,14 +60,14 @@ struct instentry *inst_iterator_next(struct iterator_ctx *ctx) if(ctx->j < ctx->y2a && ctx->countj++ < NBOXES) { ctx->j++; ctx->tmpj = ctx->j % NBOXES; if(ctx->tmpj < 0) ctx->tmpj+=NBOXES; - ctx->instanceptr = xctx->insttable[ctx->tmpi][ctx->tmpj]; + ctx->instanceptr = xctx->inst_spatial_table[ctx->tmpi][ctx->tmpj]; } else if(ctx->i < ctx->x2a && ctx->counti++ < NBOXES) { ctx->i++; ctx->j = ctx->y1a; ctx->countj = 0; ctx->tmpi = ctx->i % NBOXES; if(ctx->tmpi < 0) ctx->tmpi += NBOXES; ctx->tmpj = ctx->j % NBOXES; if(ctx->tmpj < 0) ctx->tmpj += NBOXES; - ctx->instanceptr = xctx->insttable[ctx->tmpi][ctx->tmpj]; + ctx->instanceptr = xctx->inst_spatial_table[ctx->tmpi][ctx->tmpj]; } else { my_free(753, &ctx->instflag); return NULL; @@ -92,7 +92,7 @@ void init_wire_iterator(struct iterator_ctx *ctx, double x1, double y1, double x ctx->tmpi=ctx->i % NBOXES; if(ctx->tmpi < 0) ctx->tmpi += NBOXES; ctx->tmpj=ctx->j % NBOXES; if(ctx->tmpj < 0) ctx->tmpj += NBOXES; ctx->counti=0; - ctx->wireptr = xctx->wiretable[ctx->tmpi][ctx->tmpj]; + ctx->wireptr = xctx->wire_spatial_table[ctx->tmpi][ctx->tmpj]; ctx->countj = 0; } @@ -113,14 +113,14 @@ struct wireentry *wire_iterator_next(struct iterator_ctx *ctx) if(ctx->j < ctx->y2a && ctx->countj++ < NBOXES) { ctx->j++; ctx->tmpj = ctx->j % NBOXES; if(ctx->tmpj < 0) ctx->tmpj += NBOXES; - ctx->wireptr = xctx->wiretable[ctx->tmpi][ctx->tmpj]; + ctx->wireptr = xctx->wire_spatial_table[ctx->tmpi][ctx->tmpj]; } else if(ctx->i < ctx->x2a && ctx->counti++ < NBOXES) { ctx->i++; ctx->j = ctx->y1a; ctx->countj = 0; ctx->tmpi = ctx->i % NBOXES; if(ctx->tmpi < 0) ctx->tmpi += NBOXES; ctx->tmpj = ctx->j % NBOXES; if(ctx->tmpj < 0) ctx->tmpj += NBOXES; - ctx->wireptr = xctx->wiretable[ctx->tmpi][ctx->tmpj]; + ctx->wireptr = xctx->wire_spatial_table[ctx->tmpi][ctx->tmpj]; } else { my_free(754, &ctx->wireflag); return NULL; diff --git a/src/hilight.c b/src/hilight.c index fac418fe..14b349db 100644 --- a/src/hilight.c +++ b/src/hilight.c @@ -41,7 +41,7 @@ static unsigned int hi_hash(const char *tok) return hash; } -static struct hilight_hashentry *free_hilight_entry(struct hilight_hashentry *entry) +static struct hilight_hashentry *hilight_hash_free_entry(struct hilight_hashentry *entry) { struct hilight_hashentry *tmp; while(entry) { @@ -54,6 +54,119 @@ static struct hilight_hashentry *free_hilight_entry(struct hilight_hashentry *en return NULL; } +static void hilight_hash_free(void) /* remove the whole hash table */ +{ + int i; + + dbg(2, "hilight_hash_free(): removing hash table\n"); + for(i=0;ihilight_table[i] = hilight_hash_free_entry( xctx->hilight_table[i] ); + } +} + +static struct hilight_hashentry *hilight_hash_lookup(const char *token, int value, int what) +/* token what ... what ... + * -------------------------------------------------------------------------- + * "whatever" XINSERT insert in hash table if not in and return NULL. If already present update + * value if not NULL, retun new value, return NULL otherwise + * "whatever" XINSERT_NOREPLACE same as XINSERT but do not replace existing value, return NULL if not found. + * "whatever" XDELETE delete entry if found, return NULL + * "whatever" XLOOKUP only look up element, dont insert, return NULL if not found. + */ +{ + unsigned int hashcode, index; + struct hilight_hashentry *entry, *saveptr, **preventry; + char *ptr; + int s ; + + if(token==NULL) return NULL; + hashcode=hi_hash(token); + index=hashcode % HASHSIZE; + entry=xctx->hilight_table[index]; + preventry=&xctx->hilight_table[index]; + while(1) { + if( !entry ) { /* empty slot */ + int lent = strlen(token) + 1; + int lenp = strlen(xctx->sch_path[xctx->currsch]) + 1; + if( what==XINSERT || what == XINSERT_NOREPLACE) { /* insert data */ + s=sizeof( struct hilight_hashentry ); + ptr= my_malloc(137, s ); + entry=(struct hilight_hashentry *)ptr; + entry->next = NULL; + entry->token = my_malloc(778, lent); + memcpy(entry->token, token, lent); + entry->path = my_malloc(779, lenp); + memcpy(entry->path, xctx->sch_path[xctx->currsch], lenp); + entry->oldvalue = value-1000; /* no old value, set different value anyway*/ + entry->value = value; + entry->time = xctx->hilight_time; + entry->hash = hashcode; + *preventry = entry; + xctx->hilight_nets = 1; /* some nets should be hilighted .... 07122002 */ + } + return NULL; /* whether inserted or not return NULL since it was not in */ + } + if( entry -> hash==hashcode && !strcmp(token,entry->token) && + !strcmp(xctx->sch_path[xctx->currsch], entry->path) ) { /* found matching tok */ + if(what==XDELETE) { /* remove token from the hash table ... */ + saveptr=entry->next; + my_free(1145, &entry->token); + my_free(1198, &entry->path); + my_free(764, &entry); + *preventry=saveptr; + } else if(what == XINSERT ) { + entry->oldvalue = entry->value; + entry->value = value; + entry->time=xctx->hilight_time; + } + return entry; /* found matching entry, return the address */ + } + preventry=&entry->next; /* descend into the list. */ + entry = entry->next; + } +} + +/* warning, in case of buses return only pointer to first found bus element */ +struct hilight_hashentry *bus_hilight_hash_lookup(const char *token, int value, int what) +{ + char *start, *string_ptr, c; + char *string=NULL; + struct hilight_hashentry *ptr1=NULL, *ptr2=NULL; + int mult; + + if(token==NULL) return NULL; + if( token[0] == '#' || !strpbrk(token, "*[],.:")) { + ptr1=hilight_hash_lookup(token, value, what); + return ptr1; + } + my_strdup(141, &string, expandlabel(token,&mult)); + if(string==NULL) { + return NULL; + } + string_ptr = start = string; + while(1) { + c=(*string_ptr); + if(c==','|| c=='\0') { + *string_ptr='\0'; /* set end string at comma position.... */ + /* insert one bus element at a time in hash table */ + dbg(2, "bus_hilight_hash_lookup(): inserting: %s, value:%d\n", start,value); + ptr1=hilight_hash_lookup(start, value, what); + if(ptr1 && !ptr2) { + ptr2=ptr1; /*return first non null entry */ + if(what==XLOOKUP) break; /* 20161221 no need to go any further if only looking up element */ + } + *string_ptr=c; /* ....restore original char */ + start=string_ptr+1; + } + if(c==0) break; + string_ptr++; + } + /* if something found return first pointer */ + my_free(765, &string); + return ptr2; +} + void display_hilights(char **str) { int i; @@ -87,17 +200,6 @@ static int there_are_hilights() return 0; } -void free_hilight_hash(void) /* remove the whole hash table */ -{ - int i; - - dbg(2, "free_hilight_hash(): removing hash table\n"); - for(i=0;ihilight_table[i] = free_hilight_entry( xctx->hilight_table[i] ); - } -} - /* by default: * xctx->active_layer[0] = 7 * xctx->active_layer[1] = 8 @@ -120,7 +222,6 @@ int get_color(int value) } } - void incr_hilight_color(void) { xctx->hilight_color = (xctx->hilight_color + 1) % (xctx->n_active_layers * cadlayers); @@ -178,7 +279,7 @@ void create_plot_cmd(void) entry = xctx->hilight_table[i]; while(entry) { tok = entry->token; - node_entry = bus_hash_lookup(tok, "", XLOOKUP, 0, "", "", "", ""); + node_entry = bus_node_hash_lookup(tok, "", XLOOKUP, 0, "", "", "", ""); if(tok[0] == '#') tok++; if(node_entry && !strcmp(xctx->sch_path[xctx->currsch], entry->path) && (node_entry->d.port == 0 || !strcmp(entry->path, ".") )) { @@ -284,114 +385,12 @@ void create_plot_cmd(void) } } -struct hilight_hashentry *hilight_lookup(const char *token, int value, int what) -/* token what ... what ... - * -------------------------------------------------------------------------- - * "whatever" XINSERT insert in hash table if not in and return NULL. If already present update - * value if not NULL, retun new value, return NULL otherwise - * "whatever" XINSERT_NOREPLACE same as XINSERT but do not replace existing value, return NULL if not found. - * "whatever" XDELETE delete entry if found, return NULL - * "whatever" XLOOKUP only look up element, dont insert, return NULL if not found. - */ -{ - unsigned int hashcode, index; - struct hilight_hashentry *entry, *saveptr, **preventry; - char *ptr; - int s ; - - if(token==NULL) return NULL; - hashcode=hi_hash(token); - index=hashcode % HASHSIZE; - entry=xctx->hilight_table[index]; - preventry=&xctx->hilight_table[index]; - while(1) { - if( !entry ) { /* empty slot */ - int lent = strlen(token) + 1; - int lenp = strlen(xctx->sch_path[xctx->currsch]) + 1; - if( what==XINSERT || what == XINSERT_NOREPLACE) { /* insert data */ - s=sizeof( struct hilight_hashentry ); - ptr= my_malloc(137, s ); - entry=(struct hilight_hashentry *)ptr; - entry->next = NULL; - entry->token = my_malloc(778, lent); - memcpy(entry->token, token, lent); - entry->path = my_malloc(779, lenp); - memcpy(entry->path, xctx->sch_path[xctx->currsch], lenp); - entry->oldvalue = value-1000; /* no old value, set different value anyway*/ - entry->value = value; - entry->time = xctx->hilight_time; - entry->hash = hashcode; - *preventry = entry; - xctx->hilight_nets = 1; /* some nets should be hilighted .... 07122002 */ - } - return NULL; /* whether inserted or not return NULL since it was not in */ - } - if( entry -> hash==hashcode && !strcmp(token,entry->token) && - !strcmp(xctx->sch_path[xctx->currsch], entry->path) ) { /* found matching tok */ - if(what==XDELETE) { /* remove token from the hash table ... */ - saveptr=entry->next; - my_free(1145, &entry->token); - my_free(1198, &entry->path); - my_free(764, &entry); - *preventry=saveptr; - } else if(what == XINSERT ) { - entry->oldvalue = entry->value; - entry->value = value; - entry->time=xctx->hilight_time; - } - return entry; /* found matching entry, return the address */ - } - preventry=&entry->next; /* descend into the list. */ - entry = entry->next; - } -} - -/* warning, in case of buses return only pointer to first found bus element */ -struct hilight_hashentry *bus_hilight_lookup(const char *token, int value, int what) -{ - char *start, *string_ptr, c; - char *string=NULL; - struct hilight_hashentry *ptr1=NULL, *ptr2=NULL; - int mult; - - if(token==NULL) return NULL; - if( token[0] == '#' || !strpbrk(token, "*[],.:")) { - ptr1=hilight_lookup(token, value, what); - return ptr1; - } - my_strdup(141, &string, expandlabel(token,&mult)); - if(string==NULL) { - return NULL; - } - string_ptr = start = string; - while(1) { - c=(*string_ptr); - if(c==','|| c=='\0') { - *string_ptr='\0'; /* set end string at comma position.... */ - /* insert one bus element at a time in hash table */ - dbg(2, "bus_hilight_lookup(): inserting: %s, value:%d\n", start,value); - ptr1=hilight_lookup(start, value, what); - if(ptr1 && !ptr2) { - ptr2=ptr1; /*return first non null entry */ - if(what==XLOOKUP) break; /* 20161221 no need to go any further if only looking up element */ - } - *string_ptr=c; /* ....restore original char */ - start=string_ptr+1; - } - if(c==0) break; - string_ptr++; - } - /* if something found return first pointer */ - my_free(765, &string); - return ptr2; -} - void clear_all_hilights(void) { int i; xctx->hilight_color=0; if(!xctx->hilight_nets) return; - free_hilight_hash(); + hilight_hash_free(); xctx->hilight_nets=0; for(i=0;iinstances;i++) { xctx->inst[i].color = -10000 ; @@ -431,11 +430,10 @@ void hilight_net_pin_mismatches(void) dbg(1, "hilight_net_pin_mismatches(): i=%d labname=%s explabname = %s net = %s\n", i, labname, lab, netname); if(netname && strcmp(lab, netname)) { dbg(1, "hilight_net_pin_mismatches(): hilight: %s\n", netname); - bus_hilight_lookup(netname, xctx->hilight_color, XINSERT_NOREPLACE); + bus_hilight_hash_lookup(netname, xctx->hilight_color, XINSERT_NOREPLACE); if(incr_hi) incr_hilight_color(); } } - } my_free(713, &type); my_free(714, &labname); @@ -475,16 +473,16 @@ void hilight_parent_pins(void) for(k = 1; k<=mult; k++) { xctx->currsch++; - entry = bus_hilight_lookup(find_nth(pin_node, ',', k), 0, XLOOKUP); + entry = bus_hilight_hash_lookup(find_nth(pin_node, ',', k), 0, XLOOKUP); xctx->currsch--; if(entry) { - bus_hilight_lookup(find_nth(net_node, ',', + bus_hilight_hash_lookup(find_nth(net_node, ',', ((inst_number - 1) * mult + k - 1) % net_mult + 1), entry->value, XINSERT); } else { - bus_hilight_lookup(find_nth(net_node, ',', + bus_hilight_hash_lookup(find_nth(net_node, ',', ((inst_number - 1) * mult + k - 1) % net_mult + 1), 0, XDELETE); } } @@ -524,15 +522,15 @@ void hilight_child_pins(void) dbg(1, "hilight_child_pins(): looking net:%s\n", find_nth(net_node, ',', ((inst_number - 1) * mult + k - 1) % net_mult + 1)); xctx->currsch--; - entry = bus_hilight_lookup(find_nth(net_node, ',', + entry = bus_hilight_hash_lookup(find_nth(net_node, ',', ((inst_number - 1) * mult + k - 1) % net_mult + 1), 0, XLOOKUP); xctx->currsch++; if(entry) { - bus_hilight_lookup(find_nth(pin_node, ',', k), entry->value, XINSERT_NOREPLACE); + bus_hilight_hash_lookup(find_nth(pin_node, ',', k), entry->value, XINSERT_NOREPLACE); dbg(1, "hilight_child_pins(): inserting: %s\n", find_nth(pin_node, ',', k)); } else { - bus_hilight_lookup(find_nth(pin_node, ',', k), 0, XDELETE); + bus_hilight_hash_lookup(find_nth(pin_node, ',', k), 0, XDELETE); dbg(1, "hilight_child_pins(): deleting: %s\n", find_nth(pin_node, ',', k)); } } /* for(k..) */ @@ -631,7 +629,7 @@ int search(const char *tok, const char *val, int sub, int sel) if(!sel) { type = (xctx->inst[i].ptr+ xctx->sym)->type; if( type && xctx->inst[i].node && IS_LABEL_SH_OR_PIN(type) ) { - bus_hilight_lookup(xctx->inst[i].node[0], col, XINSERT_NOREPLACE); /* sets xctx->hilight_nets=1; */ + bus_hilight_hash_lookup(xctx->inst[i].node[0], col, XINSERT_NOREPLACE); /* sets xctx->hilight_nets=1; */ } else { dbg(1, "search(): setting hilight flag on inst %d\n",i); xctx->hilight_nets=1; @@ -661,7 +659,7 @@ int search(const char *tok, const char *val, int sub, int sel) #endif { if(!sel) { - bus_hilight_lookup(xctx->wire[i].node, col, XINSERT_NOREPLACE); /* sets xctx->hilight_nets = 1 */ + bus_hilight_hash_lookup(xctx->wire[i].node, col, XINSERT_NOREPLACE); /* sets xctx->hilight_nets = 1 */ } if(sel==1) { xctx->wire[i].sel = SELECTED; @@ -782,7 +780,7 @@ void drill_hilight(int mode) ( (xctx->inst[i].flags & 4) || ((xctx->inst[i].ptr+ xctx->sym)->flags & 4) ); for(j=0; jtype && IS_LABEL_SH_OR_PIN(symbol->type))) ) { xctx->inst[i].color = entry->value; } @@ -805,7 +803,7 @@ void drill_hilight(int mode) /* get net to propagate hilight to...*/ my_strdup(144, &propagated_net, net_name(i, propagate, &mult, 1, 0)); /* add net to highlight list */ - propag_entry = bus_hilight_lookup(propagated_net, entry->value, mode); + propag_entry = bus_hilight_hash_lookup(propagated_net, entry->value, mode); if(!propag_entry) found=1; /* keep looping until no more nets are found. */ } } @@ -825,9 +823,9 @@ int hilight_netname(const char *name) prepare_netlist_structs(0); dbg(1, "hilight_netname(): entering\n"); rebuild_selected_array(); - node_entry = bus_hash_lookup(name, "", XLOOKUP, 0, "", "", "", ""); + node_entry = bus_node_hash_lookup(name, "", XLOOKUP, 0, "", "", "", ""); /* sets xctx->hilight_nets=1 */ - if(node_entry && !bus_hilight_lookup(name, xctx->hilight_color, XINSERT_NOREPLACE)) { + if(node_entry && !bus_hilight_hash_lookup(name, xctx->hilight_color, XINSERT_NOREPLACE)) { if(tclgetboolvar("incr_hilight")) incr_hilight_color(); propagate_hilights(1, 0, XINSERT_NOREPLACE); redraw_hilights(0); @@ -848,7 +846,7 @@ static void send_net_to_bespice(int simtype, const char *node) my_strncpy(rawfile, tclresult(), S(rawfile)); if(!node || !node[0]) return; tok = node; - node_entry = bus_hash_lookup(tok, "", XLOOKUP, 0, "", "", "", ""); + node_entry = bus_node_hash_lookup(tok, "", XLOOKUP, 0, "", "", "", ""); if(tok[0] == '#') tok++; if(node_entry && (node_entry->d.port == 0 || !strcmp(xctx->sch_path[xctx->currsch], ".") )) { char *t=NULL, *p=NULL; @@ -909,7 +907,7 @@ static void send_net_to_gaw(int simtype, const char *node) if(!node || !node[0]) return; tok = node; - node_entry = bus_hash_lookup(tok, "", XLOOKUP, 0, "", "", "", ""); + node_entry = bus_node_hash_lookup(tok, "", XLOOKUP, 0, "", "", "", ""); if(tok[0] == '#') tok++; if(node_entry && (node_entry->d.port == 0 || !strcmp(xctx->sch_path[xctx->currsch], ".") )) { char *t=NULL, *p=NULL; @@ -1067,7 +1065,7 @@ void propagate_hilights(int set, int clear, int mode) nohilight_pins = 1; for(j=0;jinst[i].node && xctx->inst[i].node[j]) { - entry=bus_hilight_lookup(xctx->inst[i].node[j], 0, XLOOKUP); + entry=bus_hilight_hash_lookup(xctx->inst[i].node[j], 0, XLOOKUP); if(entry) { if(set) { xctx->inst[i].color=entry->value; @@ -1083,7 +1081,7 @@ void propagate_hilights(int set, int clear, int mode) } } } else if(type && xctx->inst[i].node && IS_LABEL_SH_OR_PIN(type) ) { - entry=bus_hilight_lookup( xctx->inst[i].node[0], 0, XLOOKUP); + entry=bus_hilight_hash_lookup( xctx->inst[i].node[0], 0, XLOOKUP); if(entry && set) xctx->inst[i].color = entry->value; else if(!entry && clear) xctx->inst[i].color = -10000; } @@ -1110,7 +1108,7 @@ int get_logic_value(int inst, int n) /* fast option: dont use net_name() (no expandlabel though) */ /* THIS MUST BE DONE TO HANDLE VECTOR INSTANCES/BUSES */ /* my_strdup(xxxx, &netname, net_name(inst, n, &mult, 1, 0)); */ - entry=hilight_lookup(xctx->inst[inst].node[n], 0, XLOOKUP); + entry=hilight_hash_lookup(xctx->inst[inst].node[n], 0, XLOOKUP); if(!entry) { val = 2; /* LOGIC_X */ } else { @@ -1379,7 +1377,7 @@ void propagate_logic() clock_pin = xctx->simdata[i].pin[j].clock; if(clock_pin != -1) { /* no bus_hilight_lookup --> no bus expansion */ - entry = hilight_lookup(xctx->inst[i].node[j], 0, XLOOKUP); /* clock pin */ + entry = hilight_hash_lookup(xctx->inst[i].node[j], 0, XLOOKUP); /* clock pin */ clock_val = (!entry) ? LOGIC_X : entry->value; clock_oldval = (!entry) ? LOGIC_X : entry->oldvalue; if(entry) { @@ -1442,14 +1440,14 @@ void propagate_logic() for(i=0; iinstances; i++) { for(j=0;j < xctx->simdata[i].npin; j++) { if(xctx->simdata[i].pin[j].value != -10000) { - entry = hilight_lookup(xctx->inst[i].node[j], 0, XLOOKUP); + entry = hilight_hash_lookup(xctx->inst[i].node[j], 0, XLOOKUP); if(!entry || xctx->hilight_time != entry->time) { - hilight_lookup(xctx->inst[i].node[j], xctx->simdata[i].pin[j].value, XINSERT); + hilight_hash_lookup(xctx->inst[i].node[j], xctx->simdata[i].pin[j].value, XINSERT); dbg(1, "propagate_logic(): UPDATE1 inst %s pin %d, net %s --> value %d\n", xctx->inst[i].instname, j, xctx->inst[i].node[j], xctx->simdata[i].pin[j].value); } else if(entry->value != xctx->simdata[i].pin[j].value && xctx->simdata[i].pin[j].value != LOGIC_Z) { - hilight_lookup(xctx->inst[i].node[j], xctx->simdata[i].pin[j].value, XINSERT); + hilight_hash_lookup(xctx->inst[i].node[j], xctx->simdata[i].pin[j].value, XINSERT); dbg(1, "propagate_logic(): UPDATE2 inst %s pin %d, net %s --> value %d\n", xctx->inst[i].instname, j, xctx->inst[i].node[j], xctx->simdata[i].pin[j].value); } else { @@ -1507,12 +1505,12 @@ void logic_set(int value, int num) } if(node) { if(value == -1) { /* toggle */ - entry = bus_hilight_lookup(node, 0, XLOOKUP); + entry = bus_hilight_hash_lookup(node, 0, XLOOKUP); if(entry) newval = (entry->value == LOGIC_1) ? 0 : (entry->value == LOGIC_0) ? 1 : 2; else newval = 2; } - bus_hilight_lookup(node, map[newval], XINSERT); + bus_hilight_hash_lookup(node, map[newval], XINSERT); } } propagate_logic(); @@ -1547,7 +1545,7 @@ void hilight_net(int viewer) switch(xctx->sel_array[i].type) { case WIRE: /* sets xctx->hilight_nets=1 */ - if(!bus_hilight_lookup(xctx->wire[n].node, xctx->hilight_color, XINSERT_NOREPLACE)) { + if(!bus_hilight_hash_lookup(xctx->wire[n].node, xctx->hilight_color, XINSERT_NOREPLACE)) { if(viewer == GAW) send_net_to_gaw(sim_is_xyce, xctx->wire[n].node); if(viewer == BESPICE) send_net_to_bespice(sim_is_xyce, xctx->wire[n].node); if(incr_hi) incr_hilight_color(); @@ -1557,7 +1555,7 @@ void hilight_net(int viewer) type = (xctx->inst[n].ptr+ xctx->sym)->type; if( type && xctx->inst[n].node && IS_LABEL_SH_OR_PIN(type) ) { /* instance must have a pin! */ /* sets xctx->hilight_nets=1 */ - if(!bus_hilight_lookup(xctx->inst[n].node[0], xctx->hilight_color, XINSERT_NOREPLACE)) { + if(!bus_hilight_hash_lookup(xctx->inst[n].node[0], xctx->hilight_color, XINSERT_NOREPLACE)) { if(viewer == GAW) send_net_to_gaw(sim_is_xyce, xctx->inst[n].node[0]); if(viewer == BESPICE) send_net_to_bespice(sim_is_xyce, xctx->inst[n].node[0]); if(incr_hi) incr_hilight_color(); @@ -1597,12 +1595,12 @@ void unhilight_net(void) n = xctx->sel_array[i].n; switch(xctx->sel_array[i].type) { case WIRE: - bus_hilight_lookup(xctx->wire[n].node, xctx->hilight_color, XDELETE); + bus_hilight_hash_lookup(xctx->wire[n].node, xctx->hilight_color, XDELETE); break; case ELEMENT: type = (xctx->inst[n].ptr+ xctx->sym)->type; if( type && xctx->inst[n].node && IS_LABEL_SH_OR_PIN(type) ) { /* instance must have a pin! */ - bus_hilight_lookup(xctx->inst[n].node[0], xctx->hilight_color, XDELETE); + bus_hilight_hash_lookup(xctx->inst[n].node[0], xctx->hilight_color, XDELETE); } xctx->inst[n].color = -10000; break; @@ -1652,7 +1650,7 @@ void select_hilight_net(void) en_hi = tclgetboolvar("en_hilight_conn_inst"); prepare_netlist_structs(0); for(i=0;iwires;i++) { - if( (entry = bus_hilight_lookup(xctx->wire[i].node, 0, XLOOKUP)) ) { + if( (entry = bus_hilight_hash_lookup(xctx->wire[i].node, 0, XLOOKUP)) ) { xctx->wire[i].sel = SELECTED; } } @@ -1670,7 +1668,7 @@ void select_hilight_net(void) if( (rects = (xctx->inst[i].ptr+ xctx->sym)->rects[PINLAYER]) > 0 ) { for(j=0;jinst[i].node && xctx->inst[i].node[j]) { - entry=bus_hilight_lookup(xctx->inst[i].node[j], 0, XLOOKUP); + entry=bus_hilight_hash_lookup(xctx->inst[i].node[j], 0, XLOOKUP); if(entry) { xctx->inst[i].sel = SELECTED; break; @@ -1679,7 +1677,7 @@ void select_hilight_net(void) } } } else if( type && xctx->inst[i].node && IS_LABEL_SH_OR_PIN(type) ) { - entry=bus_hilight_lookup(xctx->inst[i].node[0], 0, XLOOKUP); + entry=bus_hilight_hash_lookup(xctx->inst[i].node[0], 0, XLOOKUP); if(entry) xctx->inst[i].sel = SELECTED; } } @@ -1726,7 +1724,7 @@ void draw_hilight_net(int on_window) i++; if(i >= xctx->wires) break; } - if( (entry = bus_hilight_lookup(xctx->wire[i].node, 0, XLOOKUP)) ) { + if( (entry = bus_hilight_hash_lookup(xctx->wire[i].node, 0, XLOOKUP)) ) { if(xctx->wire[i].bus) drawline(get_color(entry->value), THICK, xctx->wire[i].x1, xctx->wire[i].y1, xctx->wire[i].x2, xctx->wire[i].y2, 0); @@ -1817,7 +1815,7 @@ void print_hilight_net(int show) entry=xctx->hilight_table[i]; while(entry) { dbg(1, "print_hilight_net(): (hilight_hashentry *)entry->token=%s\n", entry->token); - node_entry = bus_hash_lookup(entry->token, "", XLOOKUP, 0, "", "", "", ""); + node_entry = bus_node_hash_lookup(entry->token, "", XLOOKUP, 0, "", "", "", ""); /* 20170926 test for not null node_entry, this may happen if a hilighted net name has been changed */ /* before invoking this function, in this case --> skip */ if(node_entry && !strcmp(xctx->sch_path[xctx->currsch], entry->path)) { diff --git a/src/move.c b/src/move.c index 637d07cd..b6335c8d 100644 --- a/src/move.c +++ b/src/move.c @@ -513,7 +513,7 @@ void find_inst_to_be_redrawn() } } } - free_int_hash(xctx->node_redraw_table); + int_hash_free(xctx->node_redraw_table); } void copy_objects(int what) diff --git a/src/netlist.c b/src/netlist.c index cdebe74b..740c3bae 100644 --- a/src/netlist.c +++ b/src/netlist.c @@ -26,7 +26,7 @@ static void instdelete(int n, int x, int y) { struct instentry *saveptr, **prevptr; - prevptr = &xctx->insttable[x][y]; + prevptr = &xctx->inst_spatial_table[x][y]; while( (*prevptr)->n != n) prevptr = &(*prevptr)->next; saveptr = (*prevptr)->next; my_free(821, prevptr); @@ -36,11 +36,11 @@ static void instdelete(int n, int x, int y) static void instinsert(int n, int x, int y) { struct instentry *ptr, *newptr; - ptr=xctx->insttable[x][y]; + ptr=xctx->inst_spatial_table[x][y]; newptr=my_malloc(236, sizeof(struct instentry)); newptr->next=ptr; newptr->n=n; - xctx->insttable[x][y]=newptr; + xctx->inst_spatial_table[x][y]=newptr; dbg(2, "instinsert(): inserting object %d at %d,%d\n",n,x,y); } @@ -61,7 +61,7 @@ void del_inst_table(void) for(i=0;iinsttable[i][j] = delinstentry(xctx->insttable[i][j]); + xctx->inst_spatial_table[i][j] = delinstentry(xctx->inst_spatial_table[i][j]); xctx->prep_hash_inst=0; dbg(1, "del_inst_table(): cleared object hash table\n"); } @@ -126,7 +126,7 @@ static void instpindelete(int n,int pin, int x, int y) { struct instpinentry *saveptr, **prevptr, *ptr; - prevptr = &xctx->instpintable[x][y]; + prevptr = &xctx->instpin_spatial_table[x][y]; ptr = *prevptr; while(ptr) { if(ptr->n == n && ptr->pin == pin) { @@ -145,14 +145,14 @@ static void instpininsert(int n,int pin, double x0, double y0, int x, int y) { struct instpinentry *ptr, *newptr; - ptr=xctx->instpintable[x][y]; + ptr=xctx->instpin_spatial_table[x][y]; newptr=my_malloc(237, sizeof(struct instpinentry)); newptr->next=ptr; newptr->n=n; newptr->x0=x0; newptr->y0=y0; newptr->pin=pin; - xctx->instpintable[x][y]=newptr; + xctx->instpin_spatial_table[x][y]=newptr; dbg(2, "instpininsert(): inserting inst %d at %d,%d\n",n,x,y); } @@ -175,7 +175,7 @@ static void del_inst_pin_table(void) for(i=0;iinstpintable[i][j] = delinstpinentry(xctx->instpintable[i][j]); + xctx->instpin_spatial_table[i][j] = delinstpinentry(xctx->instpin_spatial_table[i][j]); } @@ -183,7 +183,7 @@ static void wiredelete(int n, int x, int y) { struct wireentry *saveptr, **prevptr; - prevptr = &xctx->wiretable[x][y]; + prevptr = &xctx->wire_spatial_table[x][y]; while( (*prevptr)->n != n) prevptr = &(*prevptr)->next; saveptr = (*prevptr)->next; my_free(825, prevptr); @@ -194,11 +194,11 @@ static void wireinsert(int n, int x, int y) { struct wireentry *ptr, *newptr; - ptr=xctx->wiretable[x][y]; + ptr=xctx->wire_spatial_table[x][y]; newptr=my_malloc(238, sizeof(struct wireentry)); newptr->next=ptr; newptr->n=n; - xctx->wiretable[x][y]=newptr; + xctx->wire_spatial_table[x][y]=newptr; dbg(2, "wireinsert(): inserting wire %d at %d,%d\n",n,x,y); } @@ -220,7 +220,7 @@ void del_wire_table(void) for(i=0;iwiretable[i][j] = delwireentry(xctx->wiretable[i][j]); + xctx->wire_spatial_table[i][j] = delwireentry(xctx->wire_spatial_table[i][j]); xctx->prep_hash_wires=0; } @@ -241,7 +241,7 @@ void get_square(double x, double y, int *xx, int *yy) * 0, XINSERT : add to hash * 1, XDELETE : remove from hash */ -void hash_inst_pin(int what, int i, int j) +static void hash_inst_pin(int what, int i, int j) /* inst pin */ { @@ -337,7 +337,7 @@ void hash_wire(int what, int n, int incremental) else wiredelete(n, tmpi, tmpj); /* reset ends of all wires that *could* touch wire[n] */ - if(incremental) for(wptr = xctx->wiretable[tmpi][tmpj] ; wptr ; wptr = wptr->next) { + if(incremental) for(wptr = xctx->wire_spatial_table[tmpi][tmpj] ; wptr ; wptr = wptr->next) { wire[wptr->n].end1 = wire[wptr->n].end2 = -1; } } @@ -420,7 +420,7 @@ void print_wires(void) for(j=0;jwiretable[i][j]; + ptr=xctx->wire_spatial_table[i][j]; while(ptr) { dbg(1, "print_wires(): %6d\n", ptr->n); @@ -429,7 +429,7 @@ void print_wires(void) dbg(1, "print_wires(): \n"); } } - ptr=xctx->wiretable[0][1]; + ptr=xctx->wire_spatial_table[0][1]; while(ptr) { select_wire(ptr->n,SELECTED, 1); @@ -449,9 +449,9 @@ static void signal_short( char *n1, char *n2) statusmsg(str,2); tcleval("wm deiconify .infotext"); /* critical error: force ERC window showing */ if(!xctx->netlist_count) { - bus_hilight_lookup(n1, xctx->hilight_color, XINSERT); + bus_hilight_hash_lookup(n1, xctx->hilight_color, XINSERT); if(tclgetboolvar("incr_hilight")) incr_hilight_color(); - bus_hilight_lookup(n2, xctx->hilight_color, XINSERT); + bus_hilight_hash_lookup(n2, xctx->hilight_color, XINSERT); if(tclgetboolvar("incr_hilight")) incr_hilight_color(); } } @@ -493,7 +493,7 @@ void wirecheck(int k) /* recursive routine */ countj++; tmpj=j%NBOXES; if(tmpj<0) tmpj+=NBOXES; /*check if wire[k] touches wires in square [tmpi, tmpj] */ - ptr2=xctx->wiretable[tmpi][tmpj]; + ptr2=xctx->wire_spatial_table[tmpi][tmpj]; while(ptr2) { if(wire[ptr2->n].node) {ptr2=ptr2->next; continue;} /* 20171207 net already checked. Move on */ @@ -765,7 +765,7 @@ void prepare_netlist_structs(int for_netlist) } /* do not count multiple labels/pins with same name */ - bus_hash_lookup(inst[i].node[0], /* insert node in hash table */ + bus_node_hash_lookup(inst[i].node[0], /* insert node in hash table */ dir, XINSERT, port, sig_type, verilog_type, value, class); dbg(2, "prepare_netlist_structs(): pin=%s\n", @@ -783,7 +783,7 @@ void prepare_netlist_structs(int for_netlist) x0=inst[i].x0+rx1; y0=inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); - wptr=xctx->wiretable[sqx][sqy]; + wptr=xctx->wire_spatial_table[sqx][sqy]; if (inst[i].node[0]) while(wptr) { if (touch(xctx->wire[wptr->n].x1, xctx->wire[wptr->n].y1, @@ -811,14 +811,14 @@ void prepare_netlist_structs(int for_netlist) my_snprintf(tmp_str, S(tmp_str), "#net%d", get_unnamed_node(1,0,0)); /* JL avoid autonamed nets clash with user defined 'net#' names */ - while (bus_hash_lookup(&tmp_str[1], "", XLOOKUP, 0, "", "", "", "")!=NULL) + while (bus_node_hash_lookup(&tmp_str[1], "", XLOOKUP, 0, "", "", "", "")!=NULL) my_snprintf(tmp_str, S(tmp_str), "#net%d", get_unnamed_node(1, 0, 0)); my_strdup(265, &xctx->wire[i].node , tmp_str); my_strdup(266, &xctx->wire[i].prop_ptr, subst_token(xctx->wire[i].prop_ptr, "lab", xctx->wire[i].node)); /* insert unnamed wire name in hash table */ - bus_hash_lookup(xctx->wire[i].node,"", XINSERT, 0,"","","",""); + bus_node_hash_lookup(xctx->wire[i].node,"", XINSERT, 0,"","","",""); wirecheck(i); } } @@ -848,7 +848,7 @@ void prepare_netlist_structs(int for_netlist) y0=inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); - iptr=xctx->instpintable[sqx][sqy]; + iptr=xctx->instpin_spatial_table[sqx][sqy]; while (iptr) { if (iptr->n == i) @@ -870,7 +870,7 @@ void prepare_netlist_structs(int for_netlist) if (!for_netlist) { my_strdup(270, &sig_type,""); - bus_hash_lookup(inst[iptr->n].node[iptr->pin],"none", + bus_node_hash_lookup(inst[iptr->n].node[iptr->pin],"none", XINSERT, 1, sig_type,"", "",""); } else { my_strdup(271, &sig_type,get_tok_value( @@ -879,7 +879,7 @@ void prepare_netlist_structs(int for_netlist) /* insert generic label in hash table as a port so it will not */ /* be declared as a signal in the vhdl netlist. this is a workaround */ /* that should be fixed 25092001 */ - bus_hash_lookup(inst[iptr->n].node[iptr->pin], + bus_node_hash_lookup(inst[iptr->n].node[iptr->pin], get_tok_value((inst[i].ptr+ xctx->sym)->rect[GENERICLAYER][j-rects].prop_ptr, "dir",0), XINSERT, 1, sig_type,"", "",""); } @@ -918,7 +918,7 @@ void prepare_netlist_structs(int for_netlist) y0=inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); /* name instance nodes that touch named nets */ - wptr=xctx->wiretable[sqx][sqy]; + wptr=xctx->wire_spatial_table[sqx][sqy]; dbg(2, "prepare_netlist_structs(): from attached nets\n"); while (wptr) { @@ -934,7 +934,7 @@ void prepare_netlist_structs(int for_netlist) if (!touches) { my_strdup(273, &inst[i].node[j], xctx->wire[wptr->n].node ); - bus_hash_lookup(inst[i].node[j], + bus_node_hash_lookup(inst[i].node[j], get_tok_value( (inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr, "dir",0), XINSERT, 0,"","","",""); @@ -953,7 +953,7 @@ void prepare_netlist_structs(int for_netlist) dbg(2, "prepare_netlist_structs(): from other instances\n"); touches_unnamed=0; - iptr=xctx->instpintable[sqx][sqy]; + iptr=xctx->instpin_spatial_table[sqx][sqy]; while (iptr) { if (iptr->n == i) @@ -974,9 +974,9 @@ void prepare_netlist_structs(int for_netlist) { my_strdup(274, &inst[i].node[j], inst[iptr->n].node[iptr->pin] ); if (!for_netlist) { - bus_hash_lookup(inst[i].node[j],"none", XINSERT, 0,"","","",""); + bus_node_hash_lookup(inst[i].node[j],"none", XINSERT, 0,"","","",""); } else { - bus_hash_lookup(inst[i].node[j], + bus_node_hash_lookup(inst[i].node[j], get_tok_value( (inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr, "dir",0), XINSERT, 0,"","","",""); } @@ -1014,9 +1014,9 @@ void prepare_netlist_structs(int for_netlist) my_snprintf( tmp_str, S(tmp_str), "#net%d", get_unnamed_node(1, pin_mult * inst_mult, 0)); my_strdup(275, &inst[i].node[j], tmp_str ); if (!for_netlist) { - bus_hash_lookup(inst[i].node[j],"none", XINSERT, 0,"","","",""); + bus_node_hash_lookup(inst[i].node[j],"none", XINSERT, 0,"","","",""); } else { - bus_hash_lookup(inst[i].node[j], + bus_node_hash_lookup(inst[i].node[j], get_tok_value( (inst[i].ptr+ xctx->sym)->rect[PINLAYER][j].prop_ptr, "dir",0), XINSERT, 0,"","","",""); } @@ -1328,7 +1328,7 @@ void delete_netlist_structs(void) } /* erase inst and wire topological hash tables */ del_inst_pin_table(); - free_node_hash(); + node_hash_free(); dbg(1, "delete_netlist_structs(): end erasing\n"); xctx->prep_net_structs=0; xctx->prep_hi_structs=0; diff --git a/src/node_hash.c b/src/node_hash.c index 091a3fcc..883af212 100644 --- a/src/node_hash.c +++ b/src/node_hash.c @@ -21,10 +21,235 @@ */ #include "xschem.h" - -struct node_hashentry **get_node_table_ptr(void) +static struct node_hashentry *node_hash_lookup(const char *token, const char *dir,int what,int port, + char *sig_type, char *verilog_type, char *value, char *class, const char *orig_tok) +/* token dir et all what ... action ... + * -------------------------------------------------------------------------- + * "whatever" "in"/"out" 0,XINSERT insert in hash table if not in and return NULL + * if already present just return entry address + * and update in/out fields sum up port field + * return NULL otherwise + * "whatever" "in"/"out" 0,XINSERT_NOREPLACE same as XINSERT but do not replace existing value + * + * "whatever" whatever 2,XDELETE delete entry if found return NULL + * "whatever" whatever 1,XLOOKUP only look up element, dont insert */ { - return xctx->node_table; + unsigned int hashcode, index; + struct node_hashentry *entry, *saveptr, **preventry; + char *ptr; + int s ; + struct drivers d; + + if(token==NULL || token[0]==0 ) return NULL; + dbg(3, "node_hash_lookup(): called with: %s dir=%s what=%d port=%d\n", + token, dir, what, port); + d.in=d.out=d.inout=0; + if(!strcmp(dir,"in") ) d.in=1; + else if(!strcmp(dir,"out") ) d.out=1; + else if(!strcmp(dir,"inout") ) d.inout=1; + d.port=port; + hashcode=str_hash(token); + index=hashcode % HASHSIZE; + entry=xctx->node_table[index]; + preventry=&xctx->node_table[index]; + while(1) + { + if( !entry ) /* empty slot */ + { + if( what==XINSERT || what==XINSERT_NOREPLACE) /* insert data */ + { + s=sizeof( struct node_hashentry ); + ptr= my_malloc(281, s ); + entry=(struct node_hashentry *)ptr; + entry->next = NULL; + entry->token = entry->sig_type = entry->verilog_type = + entry->value = entry->class = entry->orig_tok = NULL; + my_strdup(282, &(entry->token),token); + if(sig_type &&sig_type[0]) my_strdup(283, &(entry->sig_type), sig_type); + if(verilog_type &&verilog_type[0]) my_strdup(284, &(entry->verilog_type), verilog_type); + if(class && class[0]) my_strdup(285, &(entry->class), class); + if(orig_tok && orig_tok[0]) my_strdup(286, &(entry->orig_tok), orig_tok); + if(value && value[0]) my_strdup(287, &(entry->value), value); + entry->d.port=d.port; + entry->d.in=d.in; + entry->d.out=d.out; + entry->d.inout=d.inout; + entry->hash=hashcode; + *preventry=entry; + dbg(3, "node_hash_lookup(): hashing %s : value=%s\n\n", + entry->token, entry->value? entry->value:"NULL"); + dbg(3, "node_hash_lookup(): hashing %s in=%d out=%d inout=%d port=%d\n", + token, d.in, d.out, d.inout, d.port); + } + return NULL; /* whether inserted or not return NULL since it was not in */ + } + if( entry -> hash==hashcode && strcmp(token,entry->token)==0 ) /* found matching tok */ + { + if(what==XDELETE) /* remove token from the hash table ... */ + { + saveptr=entry->next; + my_free(854, &entry->token); + my_free(855, &entry->verilog_type); + my_free(856, &entry->sig_type); + my_free(857, &entry->class); + my_free(858, &entry->orig_tok); + my_free(859, &entry->value); + my_free(860, &entry); + *preventry=saveptr; + return NULL; + } + else /* found matching entry, return the address and update in/out count */ + { + entry->d.port+=port; + entry->d.in+=d.in; + entry->d.out+=d.out; + entry->d.inout+=d.inout; + if(sig_type && sig_type[0] !='\0') + my_strdup(288, &(entry->sig_type), sig_type); + if(verilog_type && verilog_type[0] !='\0') + my_strdup(289, &(entry->verilog_type), verilog_type); + if(value && value[0] !='\0') + my_strdup(290, &(entry->value), value); + dbg(3, "node_hash_lookup(): hashing %s : value=%s\n\n", + entry->token, entry->value? entry->value:"NULL"); + return entry; + } + } + preventry=&entry->next; /* descend into the list. */ + entry = entry->next; + } +} + +/* wrapper to node_hash_lookup that handles buses */ +/* warning, in case of buses return only pointer to first bus element */ +struct node_hashentry *bus_node_hash_lookup(const char *token, const char *dir, int what, int port, + char *sig_type,char *verilog_type, char *value, char *class) +{ + char *start, *string_ptr, c; + int mult; + char *string=NULL; + struct node_hashentry *ptr1=NULL, *ptr2=NULL; + + if(token==NULL || token[0] == 0) return NULL; + if( token[0] == '#') + { + my_strdup(279, &string, token); + } + else + { + dbg(3, "bus_node_hash_lookup(): expanding node: %s\n", token); + my_strdup(280, &string, expandlabel(token,&mult)); + dbg(3, "bus_node_hash_lookup(): done expanding node: %s\n", token); + } + if(string==NULL) return NULL; + string_ptr = start = string; + while(1) + { + c=(*string_ptr); + if(c==','|| c=='\0') + { + *string_ptr='\0'; /* set end string at comma position.... */ + /* insert one bus element at a time in hash table */ + ptr1=node_hash_lookup(start, dir, what,port, sig_type, verilog_type, value, class, token); + if(!ptr2) ptr2=ptr1; + dbg(3, "bus_node_hash_lookup(): processing node: %s\n", start); + *string_ptr=c; /* ....restore original char */ + start=string_ptr+1; + } + if(c==0) break; + string_ptr++; + } + /* if something found return first pointer */ + my_free(853, &string); + return ptr2; +} + +static struct node_hashentry *node_hash_free_entry(struct node_hashentry *entry) +{ + struct node_hashentry *tmp; + + while(entry) { + tmp = entry->next; + my_free(861, &entry->token); + my_free(862, &entry->verilog_type); + my_free(863, &entry->sig_type); + my_free(864, &entry->class); + my_free(865, &entry->orig_tok); + my_free(866, &entry->value); + my_free(867, &entry); + entry = tmp; + } + return NULL; +} + +void node_hash_free(void) /* remove the whole hash table */ +{ + int i; + + dbg(2, "node_hash_free(): removing hash table\n"); + for(i=0;inode_table[i] = node_hash_free_entry( xctx->node_table[i] ); + } +} + +void traverse_node_hash() +{ + int i; + struct node_hashentry *entry; + char str[2048]; /* 20161122 overflow safe */ + int incr_hi; + + incr_hi = tclgetboolvar("incr_hilight"); + for(i=0;inode_table[i]; + while(entry) + { + if( !record_global_node(3, NULL, entry->token)) { + if(entry->d.out ==0 && entry->d.inout == 0) + { + my_snprintf(str, S(str), "undriven node: %s", entry->token); + if(!xctx->netlist_count) bus_hilight_hash_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); + if(incr_hi) incr_hilight_color(); + statusmsg(str,2); + tcleval("wm deiconify .infotext"); /* critical error: force ERC window showing */ + } + else if(entry->d.out + entry->d.inout + entry->d.in == 1) + { + my_snprintf(str, S(str), "open net: %s", entry->token); + if(!xctx->netlist_count) bus_hilight_hash_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); + if(incr_hi) incr_hilight_color(); + statusmsg(str,2); + } + else if(entry->d.out >=2 && entry->d.port>=0) /* era d.port>=2 03102001 */ + { + my_snprintf(str, S(str), "shorted output node: %s", entry->token); + if(!xctx->netlist_count) bus_hilight_hash_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); + if(incr_hi) incr_hilight_color(); + statusmsg(str,2); + } + else if(entry->d.in ==0 && entry->d.inout == 0) + { + my_snprintf(str, S(str), "node: %s goes nowhere", entry->token); + if(!xctx->netlist_count) bus_hilight_hash_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); + if(incr_hi) incr_hilight_color(); + statusmsg(str,2); + } + else if(entry->d.out >=2 && entry->d.inout == 0 && entry->d.port>=0) /* era d.port>=2 03102001 */ + { + my_snprintf(str, S(str), "shorted output node: %s", entry->token); + if(!xctx->netlist_count) bus_hilight_hash_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); + if(incr_hi) incr_hilight_color(); + statusmsg(str,2); + } + } + dbg(1, "traverse_node_hash(): node: %s in=%d out=%d inout=%d port=%d\n", + entry->token, entry->d.in, entry->d.out, entry->d.inout, entry->d.port); + + entry = entry->next; + } + } } void print_vhdl_signals(FILE *fd) @@ -141,237 +366,3 @@ void print_verilog_signals(FILE *fd) } if(found) fprintf(fd, "\n" ); } - - -/* wrapper to node_hash_lookup that handles buses */ -/* warning, in case of buses return only pointer to first bus element */ -struct node_hashentry *bus_hash_lookup(const char *token, const char *dir, int what, int port, - char *sig_type,char *verilog_type, char *value, char *class) -{ - char *start, *string_ptr, c; - int mult; - char *string=NULL; - struct node_hashentry *ptr1=NULL, *ptr2=NULL; - - if(token==NULL || token[0] == 0) return NULL; - if( token[0] == '#') - { - my_strdup(279, &string, token); - } - else - { - dbg(3, "bus_hash_lookup(): expanding node: %s\n", token); - my_strdup(280, &string, expandlabel(token,&mult)); - dbg(3, "bus_hash_lookup(): done expanding node: %s\n", token); - } - if(string==NULL) return NULL; - string_ptr = start = string; - while(1) - { - c=(*string_ptr); - if(c==','|| c=='\0') - { - *string_ptr='\0'; /* set end string at comma position.... */ - /* insert one bus element at a time in hash table */ - ptr1=node_hash_lookup(start, dir, what,port, sig_type, verilog_type, value, class, token); - if(!ptr2) ptr2=ptr1; - dbg(3, "bus_hash_lookup(): processing node: %s\n", start); - *string_ptr=c; /* ....restore original char */ - start=string_ptr+1; - } - if(c==0) break; - string_ptr++; - } - /* if something found return first pointer */ - my_free(853, &string); - return ptr2; -} - - -struct node_hashentry *node_hash_lookup(const char *token, const char *dir,int what,int port, - char *sig_type, char *verilog_type, char *value, char *class, const char *orig_tok) -/* token dir et all what ... action ... - * -------------------------------------------------------------------------- - * "whatever" "in"/"out" 0,XINSERT insert in hash table if not in and return NULL - * if already present just return entry address - * and update in/out fields sum up port field - * return NULL otherwise - * "whatever" "in"/"out" 0,XINSERT_NOREPLACE same as XINSERT but do not replace existing value - * - * "whatever" whatever 2,XDELETE delete entry if found return NULL - * "whatever" whatever 1,XLOOKUP only look up element, dont insert */ -{ - unsigned int hashcode, index; - struct node_hashentry *entry, *saveptr, **preventry; - char *ptr; - int s ; - struct drivers d; - - if(token==NULL || token[0]==0 ) return NULL; - dbg(3, "node_hash_lookup(): called with: %s dir=%s what=%d port=%d\n", - token, dir, what, port); - d.in=d.out=d.inout=0; - if(!strcmp(dir,"in") ) d.in=1; - else if(!strcmp(dir,"out") ) d.out=1; - else if(!strcmp(dir,"inout") ) d.inout=1; - d.port=port; - hashcode=str_hash(token); - index=hashcode % HASHSIZE; - entry=xctx->node_table[index]; - preventry=&xctx->node_table[index]; - while(1) - { - if( !entry ) /* empty slot */ - { - if( what==XINSERT || what==XINSERT_NOREPLACE) /* insert data */ - { - s=sizeof( struct node_hashentry ); - ptr= my_malloc(281, s ); - entry=(struct node_hashentry *)ptr; - entry->next = NULL; - entry->token = entry->sig_type = entry->verilog_type = - entry->value = entry->class = entry->orig_tok = NULL; - my_strdup(282, &(entry->token),token); - if(sig_type &&sig_type[0]) my_strdup(283, &(entry->sig_type), sig_type); - if(verilog_type &&verilog_type[0]) my_strdup(284, &(entry->verilog_type), verilog_type); - if(class && class[0]) my_strdup(285, &(entry->class), class); - if(orig_tok && orig_tok[0]) my_strdup(286, &(entry->orig_tok), orig_tok); - if(value && value[0]) my_strdup(287, &(entry->value), value); - entry->d.port=d.port; - entry->d.in=d.in; - entry->d.out=d.out; - entry->d.inout=d.inout; - entry->hash=hashcode; - *preventry=entry; - dbg(3, "node_hash_lookup(): hashing %s : value=%s\n\n", - entry->token, entry->value? entry->value:"NULL"); - dbg(3, "node_hash_lookup(): hashing %s in=%d out=%d inout=%d port=%d\n", - token, d.in, d.out, d.inout, d.port); - } - return NULL; /* whether inserted or not return NULL since it was not in */ - } - if( entry -> hash==hashcode && strcmp(token,entry->token)==0 ) /* found matching tok */ - { - if(what==XDELETE) /* remove token from the hash table ... */ - { - saveptr=entry->next; - my_free(854, &entry->token); - my_free(855, &entry->verilog_type); - my_free(856, &entry->sig_type); - my_free(857, &entry->class); - my_free(858, &entry->orig_tok); - my_free(859, &entry->value); - my_free(860, &entry); - *preventry=saveptr; - return NULL; - } - else /* found matching entry, return the address and update in/out count */ - { - entry->d.port+=port; - entry->d.in+=d.in; - entry->d.out+=d.out; - entry->d.inout+=d.inout; - if(sig_type && sig_type[0] !='\0') - my_strdup(288, &(entry->sig_type), sig_type); - if(verilog_type && verilog_type[0] !='\0') - my_strdup(289, &(entry->verilog_type), verilog_type); - if(value && value[0] !='\0') - my_strdup(290, &(entry->value), value); - dbg(3, "node_hash_lookup(): hashing %s : value=%s\n\n", - entry->token, entry->value? entry->value:"NULL"); - return entry; - } - } - preventry=&entry->next; /* descend into the list. */ - entry = entry->next; - } -} - -void traverse_node_hash() -{ - int i; - struct node_hashentry *entry; - char str[2048]; /* 20161122 overflow safe */ - int incr_hi; - - incr_hi = tclgetboolvar("incr_hilight"); - for(i=0;inode_table[i]; - while(entry) - { - if( !record_global_node(3, NULL, entry->token)) { - if(entry->d.out ==0 && entry->d.inout == 0) - { - my_snprintf(str, S(str), "undriven node: %s", entry->token); - if(!xctx->netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); - if(incr_hi) incr_hilight_color(); - statusmsg(str,2); - tcleval("wm deiconify .infotext"); /* critical error: force ERC window showing */ - } - else if(entry->d.out + entry->d.inout + entry->d.in == 1) - { - my_snprintf(str, S(str), "open net: %s", entry->token); - if(!xctx->netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); - if(incr_hi) incr_hilight_color(); - statusmsg(str,2); - } - else if(entry->d.out >=2 && entry->d.port>=0) /* era d.port>=2 03102001 */ - { - my_snprintf(str, S(str), "shorted output node: %s", entry->token); - if(!xctx->netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); - if(incr_hi) incr_hilight_color(); - statusmsg(str,2); - } - else if(entry->d.in ==0 && entry->d.inout == 0) - { - my_snprintf(str, S(str), "node: %s goes nowhere", entry->token); - if(!xctx->netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); - if(incr_hi) incr_hilight_color(); - statusmsg(str,2); - } - else if(entry->d.out >=2 && entry->d.inout == 0 && entry->d.port>=0) /* era d.port>=2 03102001 */ - { - my_snprintf(str, S(str), "shorted output node: %s", entry->token); - if(!xctx->netlist_count) bus_hilight_lookup(entry->token, xctx->hilight_color, XINSERT_NOREPLACE); - if(incr_hi) incr_hilight_color(); - statusmsg(str,2); - } - } - dbg(1, "traverse_node_hash(): node: %s in=%d out=%d inout=%d port=%d\n", - entry->token, entry->d.in, entry->d.out, entry->d.inout, entry->d.port); - - entry = entry->next; - } - } -} - -static struct node_hashentry *free_hash_entry(struct node_hashentry *entry) -{ - struct node_hashentry *tmp; - - while(entry) { - tmp = entry->next; - my_free(861, &entry->token); - my_free(862, &entry->verilog_type); - my_free(863, &entry->sig_type); - my_free(864, &entry->class); - my_free(865, &entry->orig_tok); - my_free(866, &entry->value); - my_free(867, &entry); - entry = tmp; - } - return NULL; -} - -void free_node_hash(void) /* remove the whole hash table */ -{ - int i; - - dbg(2, "free_node_hash(): removing hash table\n"); - for(i=0;inode_table[i] = free_hash_entry( xctx->node_table[i] ); - } -} - diff --git a/src/save.c b/src/save.c index 86734b59..cf15ad19 100644 --- a/src/save.c +++ b/src/save.c @@ -1474,7 +1474,7 @@ void align_sch_pins_with_sym(const char *name, int pos) xctx->sym[pos].rect[PINLAYER][i] = box[i]; } } - free_int_hash(pintable); + int_hash_free(pintable); my_free(1169, &box); } my_free(1170, &symtype); diff --git a/src/select.c b/src/select.c index 0cc3ebb3..3f219342 100644 --- a/src/select.c +++ b/src/select.c @@ -120,7 +120,7 @@ void select_connected_wires(int stop_at_junction) x0 = xctx->inst[i].x0+rx1; y0 = xctx->inst[i].y0+ry1; get_square(x0, y0, &sqx, &sqy); - wptr = xctx->wiretable[sqx][sqy]; + wptr = xctx->wire_spatial_table[sqx][sqy]; while (wptr) { dbg(1, "select_connected_wires(): x0=%g y0=%g wire[%d]=%g %g %g %g\n", x0, y0, wptr->n, xctx->wire[wptr->n].x1, xctx->wire[wptr->n].y1, diff --git a/src/spice_netlist.c b/src/spice_netlist.c index dc1d4ec1..97818118 100644 --- a/src/spice_netlist.c +++ b/src/spice_netlist.c @@ -22,9 +22,9 @@ #include "xschem.h" -static struct hashentry *model_table[HASHSIZE]; /* safe even with multiple schematics */ -static struct hashentry *model_entry; /* safe even with multiple schematics */ -static struct hashentry *subckt_table[HASHSIZE]; /* safe even with multiple schematics */ +static struct str_hashentry *model_table[HASHSIZE]; /* safe even with multiple schematics */ +static struct str_hashentry *model_entry; /* safe even with multiple schematics */ +static struct str_hashentry *subckt_table[HASHSIZE]; /* safe even with multiple schematics */ void hier_psprint(void) /* netlister driver */ { @@ -37,7 +37,7 @@ void hier_psprint(void) /* netlister driver */ if(!ps_draw(1)) return; /* prolog */ push_undo(); - free_hash(subckt_table); + str_hash_free(subckt_table); zoom_full(0, 0, 1, 0.97); ps_draw(2); /* page */ dbg(1,"--> %s\n", skip_dir( xctx->sch[xctx->currsch]) ); @@ -78,7 +78,7 @@ void hier_psprint(void) /* netlister driver */ } } my_free(1231, &abs_path); - free_hash(subckt_table); + str_hash_free(subckt_table); my_free(1229, &subckt_name); my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); xctx->currsch--; @@ -113,8 +113,8 @@ void global_spice_netlist(int global) /* netlister driver */ push_undo(); xctx->netlist_unconn_cnt=0; /* unique count of unconnected pins while netlisting */ statusmsg("",2); /* clear infowindow */ - free_hash(subckt_table); - free_hash(model_table); + str_hash_free(subckt_table); + str_hash_free(model_table); record_global_node(2, NULL, NULL); /* delete list of global nodes */ top_sub = 0; tclsetvar("spiceprefix", "1"); @@ -136,14 +136,10 @@ void global_spice_netlist(int global) /* netlister driver */ } else { my_snprintf(cellname, S(cellname), "%s.spice", skip_dir(xctx->sch[xctx->currsch])); } - if(fd==NULL) { dbg(0, "global_spice_netlist(): problems opening netlist file\n"); return; } - - - first = 0; for(i=0;iinstances;i++) /* print netlist_commands of top level cell with 'place=header' property */ { @@ -294,7 +290,7 @@ void global_spice_netlist(int global) /* netlister driver */ } my_free(1233, &abs_path); } - free_hash(subckt_table); + str_hash_free(subckt_table); my_free(944, &subckt_name); /*clear_drawing(); */ my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); @@ -356,7 +352,7 @@ void global_spice_netlist(int global) /* netlister driver */ model_entry = model_entry->next; } } - free_hash(model_table); + str_hash_free(model_table); if(first) fprintf(fd,"**** end user architecture code\n"); @@ -568,10 +564,10 @@ void spice_netlist(FILE *fd, int spice_stop ) * return NULL if not found * "whatever" "whatever" XDELETE delete entry if found,return NULL */ -struct hashentry *str_hash_lookup(struct hashentry **table, const char *token, const char *value, int what) +struct str_hashentry *str_hash_lookup(struct str_hashentry **table, const char *token, const char *value, int what) { unsigned int hashcode, idx; - struct hashentry *entry, *saveptr, **preventry; + struct str_hashentry *entry, *saveptr, **preventry; int s ; if(token==NULL) return NULL; @@ -585,8 +581,8 @@ struct hashentry *str_hash_lookup(struct hashentry **table, const char *token, c { if(what==XINSERT || what == XINSERT_NOREPLACE) /* insert data */ { - s=sizeof( struct hashentry ); - entry=(struct hashentry *)my_malloc(313, s); + s=sizeof( struct str_hashentry ); + entry=(struct str_hashentry *)my_malloc(313, s); entry->next=NULL; entry->token=NULL; entry->value=NULL; @@ -617,9 +613,9 @@ struct hashentry *str_hash_lookup(struct hashentry **table, const char *token, c } } -static struct hashentry *str_free_hash_entry(struct hashentry *entry) +static struct str_hashentry *str_hash_free_entry(struct str_hashentry *entry) { - struct hashentry *tmp; + struct str_hashentry *tmp; while( entry ) { tmp = entry -> next; my_free(956, &(entry->token)); @@ -631,13 +627,13 @@ static struct hashentry *str_free_hash_entry(struct hashentry *entry) } -void free_hash(struct hashentry **table) +void str_hash_free(struct str_hashentry **table) { int i; for(i=0;iwires;i++) { color = WIRELAYER; - if(xctx->hilight_nets && (entry=bus_hilight_lookup( xctx->wire[i].node, 0, XLOOKUP))) { + if(xctx->hilight_nets && (entry=bus_hilight_hash_lookup( xctx->wire[i].node, 0, XLOOKUP))) { color = get_color(entry->value); } svg_drawline(color, xctx->wire[i].bus, xctx->wire[i].x1, @@ -754,7 +754,7 @@ void svg_draw(void) for(init_wire_iterator(&ctx, x1, y1, x2, y2); ( wireptr = wire_iterator_next(&ctx) ) ;) { i = wireptr->n; color = WIRELAYER; - if(xctx->hilight_nets && (entry=bus_hilight_lookup( xctx->wire[i].node, 0, XLOOKUP))) { + if(xctx->hilight_nets && (entry=bus_hilight_hash_lookup( xctx->wire[i].node, 0, XLOOKUP))) { color = get_color(entry->value); } if( xctx->wire[i].end1 >1 ) { diff --git a/src/token.c b/src/token.c index cf7c8190..c7dc6d15 100644 --- a/src/token.c +++ b/src/token.c @@ -23,17 +23,6 @@ #include "xschem.h" #define SPACE(c) ( c=='\n' || c==' ' || c=='\t' || c=='\0' || c==';' ) -/* instance name (refdes) hash table, for unique name checking */ -struct inst_hashentry { - struct inst_hashentry *next; - unsigned int hash; - char *token; - int value; - }; - - -static struct inst_hashentry *table[HASHSIZE]; /* safe with multiple schematics, hash rebuilt before usage */ - enum status {TOK_BEGIN, TOK_TOKEN, TOK_SEP, TOK_VALUE, TOK_END, TOK_ENDTOK}; unsigned int str_hash(const char *tok) @@ -74,8 +63,7 @@ int name_strcmp(char *s, char *d) /* compare strings up to '\0' or'[' */ * 1,XDELETE : delete token entry, return NULL * 2,XLOOKUP : lookup only */ -static struct inst_hashentry *inst_hash_lookup(struct inst_hashentry **table, char *token, - int value, int what, size_t token_size) +static struct inst_hashentry *inst_hash_lookup(char *token, int value, int what, size_t token_size) { unsigned int hashcode; unsigned int idx; @@ -85,8 +73,8 @@ static struct inst_hashentry *inst_hash_lookup(struct inst_hashentry **table, ch if(token==NULL) return NULL; hashcode=str_hash(token); idx=hashcode % HASHSIZE; - entry=table[idx]; - preventry=&table[idx]; + entry=xctx->inst_table[idx]; + preventry=&xctx->inst_table[idx]; while(1) { if( !entry ) { /* empty slot */ if(what == XINSERT || what == XINSERT_NOREPLACE) { /* insert data */ @@ -133,24 +121,24 @@ static struct inst_hashentry *inst_free_hash_entry(struct inst_hashentry *entry) return NULL; } -static void inst_free_hash(struct inst_hashentry **table) /* remove the whole hash table */ +static void inst_hash_free(void) /* remove the whole hash table */ { int i; - dbg(1, "inst_free_hash(): removing hash table\n"); + dbg(1, "inst_hash_free(): removing hash table\n"); for(i=0;iinst_table[i] = inst_free_hash_entry( xctx->inst_table[i] ); } } void hash_all_names(int n) { int i; - inst_free_hash(table); + inst_hash_free(); for(i=0; iinstances; i++) { /* if(i == n) continue; */ - inst_hash_lookup(table, xctx->inst[i].instname, i, XINSERT, strlen(xctx->inst[i].instname)); + inst_hash_lookup(xctx->inst[i].instname, i, XINSERT, strlen(xctx->inst[i].instname)); } } @@ -174,7 +162,7 @@ const char *tcl_hook2(char **res) void clear_instance_hash() { - inst_free_hash(table); + inst_hash_free(); } void check_unique_names(int rename) @@ -204,7 +192,7 @@ void check_unique_names(int rename) draw(); if(!big) bbox(END , 0.0 , 0.0 , 0.0 , 0.0); } - inst_free_hash(table); + inst_hash_free(); first = 1; for(i=0;iinstances;i++) { if(xctx->inst[i].instname && xctx->inst[i].instname[0]) { @@ -216,7 +204,7 @@ void check_unique_names(int rename) comma_pos = strchr(start, ','); if(comma_pos) *comma_pos = '\0'; dbg(1, "check_unique_names(): checking %s\n", start); - if( (entry = inst_hash_lookup(table, start, i, XINSERT_NOREPLACE, strlen(start)) ) && entry->value != i) { + if( (entry = inst_hash_lookup(start, i, XINSERT_NOREPLACE, strlen(start)) ) && entry->value != i) { xctx->inst[i].color = -PINLAYER; xctx->hilight_nets=1; if(rename == 1) { @@ -240,7 +228,7 @@ void check_unique_names(int rename) my_strdup(511, &tmp, xctx->inst[i].prop_ptr); new_prop_string(i, tmp, newpropcnt++, !rename); my_strdup2(512, &xctx->inst[i].instname, get_tok_value(xctx->inst[i].prop_ptr, "name", 0)); - inst_hash_lookup(table, xctx->inst[i].instname, i, XINSERT, strlen(xctx->inst[i].instname)); + inst_hash_lookup(xctx->inst[i].instname, i, XINSERT, strlen(xctx->inst[i].instname)); 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(972, &tmp); @@ -695,10 +683,10 @@ void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names) } xctx->prefix=old_name[0]; /* don't change old_prop if name does not conflict. */ - if(dis_uniq_names || (entry = inst_hash_lookup(table, old_name, i, XLOOKUP, old_name_len))==NULL || + if(dis_uniq_names || (entry = inst_hash_lookup(old_name, i, XLOOKUP, old_name_len))==NULL || entry->value == i) { - inst_hash_lookup(table, old_name, i, XINSERT, old_name_len); + inst_hash_lookup(old_name, i, XINSERT, old_name_len); my_strdup(447, &xctx->inst[i].prop_ptr, old_prop); my_free(985, &old_name); return; @@ -715,7 +703,7 @@ void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names) } else { new_name_len = my_snprintf(new_name, old_name_len + 40, "%c%d%s", xctx->prefix,q, tmp); /* added new_name_len */ } - if((entry = inst_hash_lookup(table, new_name, i, XLOOKUP, new_name_len)) == NULL || entry->value == i) + if((entry = inst_hash_lookup(new_name, i, XLOOKUP, new_name_len)) == NULL || entry->value == i) { last[(int)xctx->prefix]=q+1; break; @@ -726,7 +714,7 @@ void new_prop_string(int i, const char *old_prop, int fast, int dis_uniq_names) if(strcmp(tmp2, old_prop) ) { my_strdup(449, &xctx->inst[i].prop_ptr, tmp2); } - inst_hash_lookup(table, new_name, i, XINSERT, new_name_len); /* reinsert in hash */ + inst_hash_lookup(new_name, i, XINSERT, new_name_len); /* reinsert in hash */ my_free(987, &old_name); my_free(988, &new_name); } diff --git a/src/verilog_netlist.c b/src/verilog_netlist.c index c335c22a..8cb7cbe3 100644 --- a/src/verilog_netlist.c +++ b/src/verilog_netlist.c @@ -21,7 +21,7 @@ */ #include "xschem.h" -static struct hashentry *subckt_table[HASHSIZE]; /* safe even with multiple schematics */ +static struct str_hashentry *subckt_table[HASHSIZE]; /* safe even with multiple schematics */ void global_verilog_netlist(int global) /* netlister driver */ { @@ -45,7 +45,7 @@ void global_verilog_netlist(int global) /* netlister driver */ push_undo(); xctx->netlist_unconn_cnt=0; /* unique count of unconnected pins while netlisting */ statusmsg("",2); /* clear infowindow */ - free_hash(subckt_table); + str_hash_free(subckt_table); xctx->netlist_count=0; /* top sch properties used for library use declarations and type definitions */ /* to be printed before any entity declarations */ @@ -314,7 +314,7 @@ void global_verilog_netlist(int global) /* netlister driver */ } } my_free(1235, &abs_path); - free_hash(subckt_table); + str_hash_free(subckt_table); my_free(1073, &subckt_name); my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); xctx->currsch--; diff --git a/src/vhdl_netlist.c b/src/vhdl_netlist.c index aa534df0..000486fb 100644 --- a/src/vhdl_netlist.c +++ b/src/vhdl_netlist.c @@ -22,7 +22,7 @@ #include "xschem.h" -static struct hashentry *subckt_table[HASHSIZE]; /* safe even with multiple schematics */ +static struct str_hashentry *subckt_table[HASHSIZE]; /* safe even with multiple schematics */ void global_vhdl_netlist(int global) /* netlister driver */ { @@ -50,7 +50,7 @@ void global_vhdl_netlist(int global) /* netlister driver */ /* to be printed before any entity declarations */ xctx->netlist_count=0; - free_hash(subckt_table); + str_hash_free(subckt_table); my_snprintf(netl_filename, S(netl_filename), "%s/.%s_%d", netlist_dir, skip_dir(xctx->sch[xctx->currsch]), getpid()); fd=fopen(netl_filename, "w"); @@ -293,7 +293,7 @@ void global_vhdl_netlist(int global) /* netlister driver */ } my_free(1241, &abs_path); } - free_hash(subckt_table); + str_hash_free(subckt_table); my_free(1086, &subckt_name); dbg(1, "global_vhdl_netlist(): netlisting top level\n"); @@ -373,7 +373,7 @@ void global_vhdl_netlist(int global) /* netlister driver */ } my_free(1243, &abs_path); } - free_hash(subckt_table); + str_hash_free(subckt_table); my_free(1087, &subckt_name); my_strncpy(xctx->sch[xctx->currsch] , "", S(xctx->sch[xctx->currsch])); xctx->currsch--; diff --git a/src/xinit.c b/src/xinit.c index 72abf8c5..31915879 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -448,12 +448,13 @@ void alloc_xschem_data(const char *top_path) xctx->current_dirname[0] = '\0'; for(i = 0; i < NBOXES; i++) { for(j = 0; j < NBOXES; j++) { - xctx->instpintable[i][j] = NULL; - xctx->wiretable[i][j] = NULL; - xctx->insttable[i][j] = NULL; + xctx->instpin_spatial_table[i][j] = NULL; + xctx->wire_spatial_table[i][j] = NULL; + xctx->inst_spatial_table[i][j] = NULL; } } for(i = 0 ; i < HASHSIZE; i++) { + xctx->inst_table[i] = NULL; xctx->node_table[i] = NULL; xctx->hilight_table[i] = NULL; xctx->node_redraw_table[i] = NULL; /* move.c */ diff --git a/src/xschem.h b/src/xschem.h index ac47ec92..acaf679c 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -593,9 +593,9 @@ typedef struct { int flat_netlist; char current_dirname[PATH_MAX]; int netlist_unconn_cnt; /* unique count of unconnected pins while netlisting */ - struct instpinentry *instpintable[NBOXES][NBOXES]; - struct wireentry *wiretable[NBOXES][NBOXES]; - struct instentry *insttable[NBOXES][NBOXES]; + struct instpinentry *instpin_spatial_table[NBOXES][NBOXES]; + struct wireentry *wire_spatial_table[NBOXES][NBOXES]; + struct instentry *inst_spatial_table[NBOXES][NBOXES]; Window window; Pixmap save_pixmap; XRectangle xrect[1]; @@ -616,6 +616,7 @@ typedef struct { int cur_undo_ptr; int tail_undo_ptr; int head_undo_ptr; + struct inst_hashentry *inst_table[HASHSIZE]; struct node_hashentry *node_table[HASHSIZE]; struct hilight_hashentry *hilight_table[HASHSIZE]; int hilight_nets; @@ -730,13 +731,22 @@ struct drivers { }; /* instance name (refdes) hash table, for unique name checking */ -struct hashentry { - struct hashentry *next; +struct inst_hashentry { + struct inst_hashentry *next; + unsigned int hash; + char *token; + int value; + }; + +/* generic string hash table */ +struct str_hashentry { + struct str_hashentry *next; unsigned int hash; char *token; char *value; }; +/* generic int hash table */ struct int_hashentry { struct int_hashentry *next; unsigned int hash; @@ -885,7 +895,7 @@ extern void saveas(const char *f, int type); extern const char *get_file_path(char *f); extern int save(int confirm); extern void save_ascii_string(const char *ptr, FILE *fd, int newline); -extern struct hilight_hashentry *bus_hilight_lookup(const char *token, int value, int what) ; +extern struct hilight_hashentry *bus_hilight_hash_lookup(const char *token, int value, int what) ; extern struct hilight_hashentry *hilight_lookup(const char *token, int value, int what); extern int name_strcmp(char *s, char *d) ; extern int search(const char *tok, const char *val, int sub, int sel); @@ -925,7 +935,6 @@ extern int text_bbox(const char * str,double xscale, double yscale, extern int get_color(int value); extern void incr_hilight_color(void); extern void hash_inst(int what, int n); -extern void hash_inst_pin(int what, int i, int j); extern void del_inst_table(void); extern void hash_wires(void); extern void hash_wire(int what, int n, int incremental); @@ -1104,10 +1113,12 @@ extern void check_unique_names(int rename); extern void clear_instance_hash(); extern unsigned int str_hash(const char *tok); -extern void free_hash(struct hashentry **table); -extern struct hashentry *str_hash_lookup(struct hashentry **table, const char *token, const char *value, int what); -extern void free_int_hash(struct int_hashentry **table); -extern struct int_hashentry *int_hash_lookup(struct int_hashentry **table, const char *token, const int value, int what); +extern void str_hash_free(struct str_hashentry **table); +extern struct str_hashentry *str_hash_lookup(struct str_hashentry **table, + const char *token, const char *value, int what); +extern void int_hash_free(struct int_hashentry **table); +extern struct int_hashentry *int_hash_lookup(struct int_hashentry **table, + const char *token, const int value, int what); extern const char *find_nth(const char *str, char sep, int n); extern int isonlydigit(const char *s); @@ -1171,13 +1182,10 @@ extern const char *net_name(int i, int j, int *mult, int hash_prefix_unnamed_net extern int record_global_node(int what, FILE *fp, char *node); extern int count_labels(char *s); extern int get_unnamed_node(int what, int mult, int node); -extern void free_node_hash(void); -extern struct node_hashentry - *node_hash_lookup(const char *token, const char *dir,int what, int port, char *sig_type, - char *verilog_type, char *value, char *class, const char *orig_tok); +extern void node_hash_free(void); extern void traverse_node_hash(); extern struct node_hashentry - *bus_hash_lookup(const char *token, const char *dir,int what, int port, char *sig_type, + *bus_node_hash_lookup(const char *token, const char *dir,int what, int port, char *sig_type, char *verilog_type, char *value, char *class); /* extern void insert_missing_pin(); */ extern void round_schematic_to_grid(double cadsnap);