/* Ivl entry point. */ int target_design(ivl_design_t des) { design = des; output = fopen(ivl_design_flag(design, "-o"), "w"); if (output == 0) { /* perror("** ERROR: Can not opening output file \"%s\".\n\n", ivl_design_flag(design, "-o")); */ perror(ivl_design_flag(design, "-o")); return -1; } level = 0; build_hierarchy(ivl_design_root(design), 0); design = 0; fclose(output); output = 0; return 0; }
int RAPID_model::EndModel() { if (!RAPID_initialized) RAPID_initialize(); if (num_tris == 0) { return RAPID_ERR_BUILD_EMPTY_MODEL; } int myrc = build_hierarchy(); if (myrc == RAPID_OK) { // only change to processed state if successful. build_state = RAPID_BUILD_STATE_PROCESSED; return RAPID_OK; } else return myrc; }
static struct tree * build_hierarchy (struct ghw_handler *h, struct ghw_hie *hie) { struct tree *t; struct tree *t_ch; struct tree *prev; struct ghw_hie *ch; unsigned char ttype; switch (hie->kind) { case ghw_hie_design: case ghw_hie_block: case ghw_hie_instance: case ghw_hie_generate_for: case ghw_hie_generate_if: case ghw_hie_package: /* Convert kind. */ switch(hie->kind) { case ghw_hie_design: ttype = TREE_VHDL_ST_DESIGN; break; case ghw_hie_block: ttype = TREE_VHDL_ST_BLOCK; break; case ghw_hie_instance: ttype = TREE_VHDL_ST_INSTANCE; break; case ghw_hie_generate_for: ttype = TREE_VHDL_ST_GENFOR; break; case ghw_hie_generate_if: ttype = TREE_VHDL_ST_GENIF; break; case ghw_hie_package: default: ttype = TREE_VHDL_ST_PACKAGE; break; } /* For iterative generate, add the index. */ if (hie->kind == ghw_hie_generate_for) { char buf[128]; int name_len, buf_len; char *n; ghw_get_value (buf, sizeof (buf), hie->u.blk.iter_value, hie->u.blk.iter_type); name_len = strlen (hie->name); buf_len = strlen (buf); t = (struct tree *) calloc_2(1, sizeof (struct tree) + (2 + buf_len + name_len + 1)); t->kind = ttype; n = t->name; memcpy (n, hie->name, name_len); n += name_len; *n++ = '['; memcpy (n, buf, buf_len); n += buf_len; *n++ = ']'; *n = 0; } else { if(hie->name) { t = (struct tree *) calloc_2(1, sizeof (struct tree) + strlen(hie->name) + 1); t->kind = ttype; strcpy(t->name, (char *)hie->name); } else { t = (struct tree *) calloc_2(1, sizeof (struct tree) + 1); t->kind = ttype; } } t->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME; /* Recurse. */ prev = NULL; for (ch = hie->u.blk.child; ch != NULL; ch = ch->brother) { t_ch = build_hierarchy (h, ch); if (t_ch != NULL) { if (prev == NULL) t->child = t_ch; else prev->next = t_ch; prev = t_ch; } } return t; case ghw_hie_process: return NULL; case ghw_hie_signal: case ghw_hie_port_in: case ghw_hie_port_out: case ghw_hie_port_inout: case ghw_hie_port_buffer: case ghw_hie_port_linkage: { unsigned int *ptr = hie->u.sig.sigs; /* Convert kind. */ switch(hie->kind) { case ghw_hie_signal: ttype = TREE_VHDL_ST_SIGNAL; break; case ghw_hie_port_in: ttype = TREE_VHDL_ST_PORTIN; break; case ghw_hie_port_out: ttype = TREE_VHDL_ST_PORTOUT; break; case ghw_hie_port_inout: ttype = TREE_VHDL_ST_PORTINOUT; break; case ghw_hie_port_buffer: ttype = TREE_VHDL_ST_BUFFER; break; case ghw_hie_port_linkage: default: ttype = TREE_VHDL_ST_LINKAGE; break; } /* Convert type. */ t = build_hierarchy_type (h, hie->u.sig.type, hie->name, &ptr); if (*ptr != 0) abort (); if(t) { t->kind = ttype; } return t; } default: fprintf (stderr, "ghw: build_hierarchy: cannot handle hie %d\n", hie->kind); abort (); } }
TimeType ghw_main(char *fname) { struct ghw_handler handle; int i; int rc; if(!GLOBALS->hier_was_explicitly_set) /* set default hierarchy split char */ { GLOBALS->hier_delimeter='.'; } handle.flag_verbose = 0; if ((rc=ghw_open (&handle, fname)) < 0) { fprintf (stderr, "Error opening ghw file '%s', rc=%d.\n", fname, rc); return(LLDescriptor(0)); /* look at return code in caller for success status... */ } GLOBALS->time_scale = 1; GLOBALS->time_dimension = 'f'; GLOBALS->asbuf = malloc_2(4097); if (ghw_read_base (&handle) < 0) { free_2(GLOBALS->asbuf); GLOBALS->asbuf = NULL; fprintf (stderr, "Error in ghw file '%s'.\n", fname); return(LLDescriptor(0)); /* look at return code in caller for success status... */ } GLOBALS->min_time = 0; GLOBALS->max_time = 0; GLOBALS->nbr_sig_ref_ghw_c_1 = 0; GLOBALS->nxp_ghw_c_1 =(struct Node **)calloc_2(handle.nbr_sigs, sizeof(struct Node *)); for(i=0;i<handle.nbr_sigs;i++) { GLOBALS->nxp_ghw_c_1[i] = (struct Node *)calloc_2(1,sizeof(struct Node)); } GLOBALS->treeroot = build_hierarchy (&handle, handle.hie); /* GHW does not contains a 'top' name. FIXME: should use basename of the file. */ create_facs (&handle); read_traces (&handle); add_tail (&handle); set_fac_name (&handle); free_2(GLOBALS->nxp_ghw_c_1); GLOBALS->nxp_ghw_c_1 = NULL; /* fix up names on aliased nodes via cloning... */ for(i=0;i<GLOBALS->numfacs;i++) { if(strcmp(GLOBALS->facs[i]->name, GLOBALS->facs[i]->n->nname)) { struct Node *n = malloc_2(sizeof(struct Node)); memcpy(n, GLOBALS->facs[i]->n, sizeof(struct Node)); GLOBALS->facs[i]->n = n; n->nname = GLOBALS->facs[i]->name; } } /* treeroot->name = "top"; */ { const char *base_hier = "top"; struct tree *t = calloc_2(1, sizeof(struct tree) + strlen(base_hier) + 1); memcpy(t, GLOBALS->treeroot, sizeof(struct tree)); strcpy(t->name, base_hier); /* scan-build false warning here, thinks name[1] is total length */ #ifndef WAVE_TALLOC_POOL_SIZE free_2(GLOBALS->treeroot); /* if using tree alloc pool, can't deallocate this */ #endif GLOBALS->treeroot = t; } ghw_close (&handle); rechain_facs(); /* vectorize bitblasted nets */ ghw_sortfacs(); /* sort nets as ghw is unsorted ... also fix hier tree (it should really be built *after* facs are sorted!) */ #if 0 treedebug(GLOBALS->treeroot,""); facs_debug(); #endif GLOBALS->is_ghw = 1; fprintf(stderr, "["TTFormat"] start time.\n["TTFormat"] end time.\n", GLOBALS->min_time*GLOBALS->time_scale, GLOBALS->max_time*GLOBALS->time_scale); if(GLOBALS->num_glitches_ghw_c_1) fprintf(stderr, "Warning: encountered %d glitch%s across %d glitch region%s.\n", GLOBALS->num_glitches_ghw_c_1, (GLOBALS->num_glitches_ghw_c_1!=1)?"es":"", GLOBALS->num_glitch_regions_ghw_c_1, (GLOBALS->num_glitch_regions_ghw_c_1!=1)?"s":""); return GLOBALS->max_time; }