/************************************************* lxt2_init - Open lxt file and enable collection ************************************************/ static void lxt2_init() { char* filename; if( lxt.inited ) { tf_error( "recording has alreay begun" ); tf_dofinish(); return; } if( lxt.filename ) { filename = lxt.filename; } else if( lxt.design ) { filename = (char*)malloc( strlen(lxt.design)+4+1 ); if( !filename ) { tf_error( "could not allocate memory" ); tf_dofinish(); return; } sprintf( filename, "%s.lxt", lxt.design ); lxt.filename = filename; } else { char* top = acc_fetch_name( acc_next_topmod(null) ); filename = (char*)malloc( strlen(top)+3+1 ); sprintf( filename, "%s.lxt", top ); lxt.filename = filename; } lxt.t = lxt2_wr_init( filename ); #if DEBUG io_printf( "lxt2_init: %p\n", lxt.t ); #endif if( !lxt.t ) { tf_error( "could not create file '%s'", filename ); tf_dofinish(); return; } lxt2_wr_set_timescale( lxt.t, acc_fetch_precision() ); if( lxt.compress ) { lxt2_wr_set_compression_depth(lxt.t, 9); lxt2_wr_set_partial_off(lxt.t); } else { lxt2_wr_set_compression_depth(lxt.t, 4); lxt2_wr_set_partial_on(lxt.t, 1); } lxt2_wr_set_break_size(lxt.t, lxt.incSize); lxt.inited = 1; lxt.enabled = 1; lxt.updateList = 0; lxt.eventList = 0; lxt.hunk = 0; lxt2_wr_set_initial_value( lxt.t, 'x' ); lxt2_wr_symbol_bracket_stripping( lxt.t, 1 ); lxt2_timemarker(); }
static PLI_INT32 sys_dumpvars_calltf(ICARUS_VPI_CONST PLI_BYTE8*name) { vpiHandle callh = vpi_handle(vpiSysTfCall, 0); vpiHandle argv = vpi_iterate(vpiArgument, callh); vpiHandle item; s_vpi_value value; unsigned depth = 0; (void)name; /* Parameter is not used. */ if (dump_file == 0) { open_dumpfile(callh); if (dump_file == 0) { if (argv) vpi_free_object(argv); return 0; } } if (install_dumpvars_callback()) { if (argv) vpi_free_object(argv); return 0; } /* Get the depth if it exists. */ if (argv) { value.format = vpiIntVal; vpi_get_value(vpi_scan(argv), &value); depth = value.value.integer; } if (!depth) depth = 10000; /* This dumps all the modules in the design if none are given. */ if (!argv || !(item = vpi_scan(argv))) { argv = vpi_iterate(vpiModule, 0x0); assert(argv); /* There must be at least one top level module. */ item = vpi_scan(argv); } for ( ; item; item = vpi_scan(argv)) { int dep = draw_scope(item); scan_item(depth, item, 0); while (dep--) pop_scope(); } /* Most effective compression. */ if (lxm_optimum_mode == LXM_SPACE) { lxt2_wr_set_compression_depth(dump_file, 9); lxt2_wr_set_partial_off(dump_file); } return 0; }
static void open_dumpfile(vpiHandle callh) { off_t use_file_size_limit = lxt2_file_size_limit; if (dump_path == 0) dump_path = strdup("dump.lx2"); dump_file = lxt2_wr_init(dump_path); if (getenv("LXT_FILE_SIZE_LIMIT")) { const char*limit_string = getenv("LXT_FILE_SIZE_LIMIT"); char*ep; use_file_size_limit = strtoul(limit_string,&ep,0); if (use_file_size_limit == 0 || ep[0] != 0) { vpi_printf("LXT2 Warning: %s:%d: LXT_FILE_SIZE_LIMIT is invalid: %s\n", vpi_get_str(vpiFile, callh), (int)vpi_get(vpiLineNo, callh), limit_string); use_file_size_limit = lxt2_file_size_limit; } } if (dump_file == 0) { vpi_printf("LXT2 Error: %s:%d: ", vpi_get_str(vpiFile, callh), (int)vpi_get(vpiLineNo, callh)); vpi_printf("Unable to open %s for output.\n", dump_path); vpi_control(vpiFinish, 1); free(dump_path); dump_path = 0; return; } else { int prec = vpi_get(vpiTimePrecision, 0); vpi_printf("LXT2 info: dumpfile %s opened for output.\n", dump_path); assert(prec >= -15); lxt2_wr_set_timescale(dump_file, prec); lxt2_wr_set_initial_value(dump_file, 'x'); lxt2_wr_set_compression_depth(dump_file, 4); lxt2_wr_set_partial_on(dump_file, 1); lxt2_wr_set_break_size(dump_file, use_file_size_limit); vcd_work_start(lxt2_thread, 0); atexit((void(*)(void))close_dumpfile); } }
TimeType vcd_main(char *fname, char *lxname) { #ifdef ONLY_NEEDED_FOR_VALGRIND_CLEAN_TEST struct vcdsymbol *v, *v2; #endif vcd_hier_delimeter[0]=hier_delimeter; errno=0; /* reset in case it's set for some reason */ yytext=(char *)malloc_2(T_MAX_STR+1); if((strlen(fname)>2)&&(!strcmp(fname+strlen(fname)-3,".gz"))) { char *str; int dlen; dlen=strlen(WAVE_DECOMPRESSOR); str=(char *)wave_alloca(strlen(fname)+dlen+1); strcpy(str,WAVE_DECOMPRESSOR); strcpy(str+dlen,fname); vcd_handle=popen(str,"r"); vcd_is_compressed=~0; } else { if(strcmp("-",fname)) { vcd_handle=fopen(fname,"rb"); } else { vcd_handle=stdin; } vcd_is_compressed=0; } if(!vcd_handle) { fprintf(stderr, "Error opening %s .vcd file '%s'.\n", vcd_is_compressed?"compressed":"", fname); exit(1); } lt=lxt2_wr_init(lxname); if(!lt) { fprintf(stderr, "Problem opening output file '%s'\n", lxname); perror("Why"); exit(255); } if(opt_partial_mode>=0) { lxt2_wr_set_partial_on(lt, opt_partial_mode); } if((opt_checkpoint_disable)&&(!opt_break_size)) { lxt2_wr_set_checkpoint_off(lt); } lxt2_wr_set_compression_depth(lt, opt_depth); lxt2_wr_set_break_size(lt, (off_t)opt_break_size); lxt2_wr_set_maxgranule(lt, opt_maxgranule); lxt2_wr_symbol_bracket_stripping(lt, 1); /* this is intentional */ sym=(struct symbol **)calloc_2(SYMPRIME,sizeof(struct symbol *)); printf("\nConverting VCD File '%s' to LXT2 file '%s'...\n\n",(vcd_handle!=stdin)?fname:"from stdin", lxname); build_slisthier(); vcd_parse(); if(varsplit) { free_2(varsplit); varsplit=NULL; } add_tail_histents(); printf("["TTFormat"] start time.\n["TTFormat"] end time.\n\n", start_time, end_time); lxt2_wr_close(lt); lt=NULL; min_time=start_time*time_scale; max_time=end_time*time_scale; if((min_time==max_time)||(max_time==0)) { fprintf(stderr, "VCD times range is equal to zero. Exiting.\n"); exit(1); } if(vcd_handle!=stdin) { fclose(vcd_handle); vcd_handle=NULL; } free(yytext); yytext=NULL; if(indexed) { free(indexed); indexed=NULL; } if(sorted) { free(sorted); sorted=NULL; } #ifdef ONLY_NEEDED_FOR_VALGRIND_CLEAN_TEST v=vcdsymroot; while(v) { if(v->name) { free(v->name); v->name=NULL; } if(v->id) { free(v->id); v->id=NULL; } if(v->value) { free(v->value); v->value=NULL; } if(v->narray) { int i; for(i=0;i<v->size;i++) { struct HistEnt *h1, *h2; if((h1 = v->narray[i]->head.next)) { h1 = v->narray[i]->head.next; while(h1) { h2 = h1->next; free(h1); h1 = h2; } } free(v->narray[i]); v->narray[i]=NULL; } free(v->narray); v->narray=NULL; } v2=v->next; free(v); v=v2; } vcdsymroot=vcdsymcurr=NULL; #endif free(sym); sym=NULL; if(slisthier) { free(slisthier); slisthier=NULL; } return(max_time); }