std::pair<bool, NumID> MemoryStorage::find(const std::string &s, NumID &counter) { NumID id = 0; bool inserted = false; JError_t err; memset(&err, 0, sizeof(err)); PPvoid_t rv = JudySLGet(data, reinterpret_cast<const uint8_t*>(s.c_str()), &err); THROW_EXC_IF_FAILED(JU_ERRNO(&err) == 0 && rv != PPJERR, "Memory operaton failed, error code: %i", JU_ERRNO(&err)); if (rv != NULL) { id = *reinterpret_cast<NumID*>(rv); } else { memset(&err, 0, sizeof(err)); rv = JudySLIns(&data, reinterpret_cast<const uint8_t*>(s.c_str()), &err); THROW_EXC_IF_FAILED(JU_ERRNO(&err) == 0 && rv != NULL && rv != PPJERR, "Memory allocation failed, error code: %i", JU_ERRNO(&err)); value = reinterpret_cast<PWord_t>(rv); id = counter++; *value = id; inserted = true; } return std::make_pair(inserted, id); }
void MemoryStorage::insert(const std::string &s, NumID id) { JError_t err; memset(&err, 0, sizeof(err)); PPvoid_t rv = JudySLGet(data, reinterpret_cast<const uint8_t*>(s.c_str()), &err); THROW_EXC_IF_FAILED(JU_ERRNO(&err) == 0 && rv != PPJERR, "Memory operaton failed, error code: %i", JU_ERRNO(&err)); if (rv == NULL) { memset(&err, 0, sizeof(err)); rv = JudySLIns(&data, reinterpret_cast<const uint8_t*>(s.c_str()), &err); THROW_EXC_IF_FAILED(JU_ERRNO(&err) == 0 && rv != NULL && rv != PPJERR, "Memory allocation failed, error code: %i", JU_ERRNO(&err)); } value = reinterpret_cast<PWord_t>(rv); *value = id; }
void build_tree_from_name(const char *s, int which) { struct tree *t, *nt; struct tree *tchain = NULL, *tchain_iter; struct tree *prevt; #ifdef _WAVE_HAVE_JUDY PPvoid_t PPValue = NULL; char str[2048]; #endif if(s==NULL || !s[0]) return; t = GLOBALS->treeroot; if(t) { prevt = NULL; while(s) { rs: s=get_module_name(s); if(t && !strcmp(t->name, GLOBALS->module_tree_c_1)) { prevt = t; t = t->child; continue; } #ifdef _WAVE_HAVE_JUDY rescan: if(prevt && prevt->children_in_gui) { /* find with judy */ int len = gen_hier_string(str, prevt); strcpy(str+len, GLOBALS->module_tree_c_1); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); if(*PPValue) { t = *PPValue; prevt = t; t = t->child; continue; } goto construct; } #endif tchain = tchain_iter = t; if(s && t) { #ifdef _WAVE_HAVE_JUDY int dep = 0; #endif nt = t->next; while(nt) { if(nt && !strcmp(nt->name, GLOBALS->module_tree_c_1)) { /* move to front to speed up next compare if in same hier during build */ if(prevt) { tchain_iter->next = nt->next; nt->next = tchain; prevt->child = nt; } prevt = nt; t = nt->child; goto rs; } tchain_iter = nt; nt = nt->next; #ifdef _WAVE_HAVE_JUDY dep++; #endif } #ifdef _WAVE_HAVE_JUDY if(prevt && (dep >= FST_TREE_SEARCH_NEXT_LIMIT)) { int len = gen_hier_string(str, prevt); prevt->children_in_gui = 1; /* "borrowed" for tree build */ t = prevt->child; Judy1Set ((Pvoid_t)&GLOBALS->sym_tree_addresses, (Word_t)prevt, PJE0); /* assemble judy based on scopename + prevt pnt */ while(t) { strcpy(str+len, t->name); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); *PPValue = t; t = t->next; } goto rescan; /* this level of hier is built, now do insert */ } #endif } #ifdef _WAVE_HAVE_JUDY construct: #endif nt=(struct tree *)talloc_2(sizeof(struct tree)+GLOBALS->module_len_tree_c_1); memcpy(nt->name, GLOBALS->module_tree_c_1, GLOBALS->module_len_tree_c_1); if(s) { nt->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME; #ifdef _WAVE_HAVE_JUDY if(prevt && prevt->children_in_gui) { *PPValue = nt; } #endif if(prevt) /* make first in chain */ { nt->next = prevt->child; prevt->child = nt; } else /* make second in chain as it's toplevel */ { nt->next = tchain->next; tchain->next = nt; } } else { nt->child = prevt; /* parent */ nt->t_which = which; nt->next = GLOBALS->terminals_tchain_tree_c_1; GLOBALS->terminals_tchain_tree_c_1 = nt; return; } /* blindly clone fac from next part of hier on down */ t = nt; while(s) { s=get_module_name(s); nt=(struct tree *)talloc_2(sizeof(struct tree)+GLOBALS->module_len_tree_c_1); memcpy(nt->name, GLOBALS->module_tree_c_1, GLOBALS->module_len_tree_c_1); if(s) { nt->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME; t->child = nt; t = nt; } else { nt->child = t; /* parent */ nt->t_which = which; nt->next = GLOBALS->terminals_tchain_tree_c_1; GLOBALS->terminals_tchain_tree_c_1 = nt; } } } } else { /* blindly create first fac in the tree (only ever called once) */ while(s) { s=get_module_name(s); nt=(struct tree *)talloc_2(sizeof(struct tree)+GLOBALS->module_len_tree_c_1); memcpy(nt->name, GLOBALS->module_tree_c_1, GLOBALS->module_len_tree_c_1); if(!s) nt->t_which=which; else nt->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME; if((GLOBALS->treeroot)&&(t)) /* scan-build : && t should be unnecessary to avoid null pointer deref, but add defensively */ { t->child = nt; t = nt; } else { GLOBALS->treeroot = t = nt; } } } }
/* * decorated module add */ void allocate_and_decorate_module_tree_node(unsigned char ttype, const char *scopename, const char *compname, uint32_t scopename_len, uint32_t compname_len, uint32_t t_stem, uint32_t t_istem) { struct tree *t; int mtyp = WAVE_T_WHICH_UNDEFINED_COMPNAME; #ifdef _WAVE_HAVE_JUDY char str[2048]; #endif if(compname && compname[0] && strcmp(scopename, compname)) { int ix = add_to_comp_name_table(compname, compname_len); if(ix) { ix--; mtyp = WAVE_T_WHICH_COMPNAME_START - ix; } } if(GLOBALS->treeroot) { if(GLOBALS->mod_tree_parent) { #ifdef _WAVE_HAVE_JUDY if(GLOBALS->mod_tree_parent->children_in_gui) { PPvoid_t PPValue; /* find with judy */ int len = gen_hier_string(str, GLOBALS->mod_tree_parent); strcpy(str+len, scopename); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); if(*PPValue) { GLOBALS->mod_tree_parent = *PPValue; return; } t = talloc_2(sizeof(struct tree) + scopename_len); *PPValue = t; goto t_allocated; } else { int dep = 0; #endif t = GLOBALS->mod_tree_parent->child; while(t) { if(!strcmp(t->name, scopename)) { GLOBALS->mod_tree_parent = t; return; } t = t->next; #ifdef _WAVE_HAVE_JUDY dep++; #endif } #ifdef _WAVE_HAVE_JUDY if(dep >= FST_TREE_SEARCH_NEXT_LIMIT) { PPvoid_t PPValue; int len = gen_hier_string(str, GLOBALS->mod_tree_parent); GLOBALS->mod_tree_parent->children_in_gui = 1; /* "borrowed" for tree build */ t = GLOBALS->mod_tree_parent->child; Judy1Set ((Pvoid_t)&GLOBALS->sym_tree_addresses, (Word_t)GLOBALS->mod_tree_parent, PJE0); /* assemble judy based on scopename + GLOBALS->mod_tree_parent pnt */ while(t) { strcpy(str+len, t->name); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); *PPValue = t; t = t->next; } strcpy(str+len, scopename); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); t = talloc_2(sizeof(struct tree) + scopename_len); *PPValue = t; goto t_allocated; } } #endif t = talloc_2(sizeof(struct tree) + scopename_len); #ifdef _WAVE_HAVE_JUDY t_allocated: #endif strcpy(t->name, scopename); t->kind = ttype; t->t_which = mtyp; t->t_stem = t_stem; t->t_istem = t_istem; if(GLOBALS->mod_tree_parent->child) { t->next = GLOBALS->mod_tree_parent->child; } GLOBALS->mod_tree_parent->child = t; GLOBALS->mod_tree_parent = t; } else { t = GLOBALS->treeroot; while(t) { if(!strcmp(t->name, scopename)) { GLOBALS->mod_tree_parent = t; return; } t = t->next; } t = talloc_2(sizeof(struct tree) + scopename_len); strcpy(t->name, scopename); t->kind = ttype; t->t_which = mtyp; t->t_stem = t_stem; t->t_istem = t_istem; t->next = GLOBALS->treeroot; GLOBALS->mod_tree_parent = GLOBALS->treeroot = t; } } else { t = talloc_2(sizeof(struct tree) + scopename_len); strcpy(t->name, scopename); t->kind = ttype; t->t_which = mtyp; t->t_stem = t_stem; t->t_istem = t_istem; GLOBALS->mod_tree_parent = GLOBALS->treeroot = t; } }
static char *get_scopename(void *xc, FILE *extload) { static char sbuff[65537]; char * rc; #ifdef _WAVE_HAVE_JUDY PPvoid_t PPValue; #else JRB str; Jval jv; #endif for(;;) { rc = fgets(sbuff, 65536, extload); if(rc) { if(isspace(rc[0])) { char sbuff2[65537]; sbuff2[0] = 0; if(strstr(rc+1, "Struct Name:")) { sscanf(rc+14,"%s", sbuff2); if(sbuff2[0]) { sprintf(rc, "Scope: vcd_struct %s NULL\n", sbuff2); } } else if(strstr(rc+1, "Struct End")) { sprintf(rc, "Upscope:\n"); } } } else { return(NULL); } if(rc[0] == 'V') { if(!strncmp("Var: ", rc, 5)) { char *pnt = rc + 5; char *pntd = strrchr(pnt, ':'); if(pntd) { unsigned char vd = FST_VD_IMPLICIT; pntd = strchr(pntd, ' '); if(pntd) { pntd++; if(*pntd == 'o') { vd = FST_VD_OUTPUT; } else if(!strncmp(pntd, "in", 2)) { vd = (pntd[2] == 'p') ? FST_VD_INPUT : FST_VD_INOUT; } } var_direction[var_direction_idx++] = vd; } } } else if(rc[0] == 'S') { if(!strncmp(rc, "Scope:", 6)) { char vht[2048]; char cname[2048]; char ctype[2048]; int mtype = FST_ST_VCD_MODULE; cname[0] = ctype[1] = 0; sscanf(rc+6, "%s %s %s", vht, cname, ctype+1); if(!strncmp("vcd_", vht, 4)) { switch(vht[4]) { case 'g': mtype = FST_ST_VCD_GENERATE; break; /* other code looks for non-modules to replace type with */ case 's': mtype = FST_ST_VCD_STRUCT; break; /* other code looks for non-modules to replace type with */ default: break; } } else if(!strncmp("sv_", vht, 3)) { switch(vht[3]) { case 'i': mtype = FST_ST_VCD_INTERFACE; break; /* other code looks for non-modules to replace type with */ default: break; } } else if(!strncmp(vht, "vhdl_", 5)) { switch(vht[5]) { case 'a': mtype = FST_ST_VHDL_ARCHITECTURE; break; case 'r': mtype = FST_ST_VHDL_RECORD; break; case 'b': mtype = FST_ST_VHDL_BLOCK; break; case 'g': mtype = FST_ST_VHDL_GENERATE; break; case 'i': mtype = FST_ST_VHDL_IF_GENERATE; break; case 'f': mtype = (vht[6] == 'u') ? FST_ST_VHDL_FUNCTION : FST_ST_VHDL_FOR_GENERATE; break; case 'p': mtype = (!strncmp(vht+6, "roces", 5)) ? FST_ST_VHDL_PROCESS: FST_ST_VHDL_PROCEDURE; break; default: break; } } ctype[0] = mtype + 1; /* bias for zero terminated string */ fst_scope_name = fstReaderPushScope(xc, cname, NULL); /* process fst_scope_name + cname vs ctype here */ if((strcmp(ctype+1, "NULL") && strcmp(cname, ctype+1)) || (mtype != FST_ST_VCD_MODULE)) { #ifdef _WAVE_HAVE_JUDY PPValue = JudySLIns(&PJArray, (uint8_t *)fst_scope_name, PJE0); if(!*((char **)PPValue)) { *((char **)PPValue) = strdup(ctype); } #else char cstring[65537]; strcpy(cstring, fst_scope_name); str = jrb_find_str(comp_name_jrb, cstring); if(!str) { jv.s = strdup(ctype); jrb_insert_str(comp_name_jrb, strdup(cstring), jv); } #endif } } } else if(rc[0] == 'U') { fst_scope_name = fstReaderPopScope(xc); } } return(rc); }