rename top_subckt to lvs_netlist (more appropriate), better tcp interface (redirect stdout to socket in addition to command return value)

This commit is contained in:
stefan schippers 2023-02-09 11:30:27 +01:00
parent 44ee2b593f
commit e5227d6a31
7 changed files with 112 additions and 28 deletions

View File

@ -399,11 +399,11 @@ void netlist_options(int i)
}
/* fprintf(errfp, "netlist_options(): bus_char=%s\n", str); */
str = get_tok_value(xctx->inst[i].prop_ptr, "top_subckt", 0);
str = get_tok_value(xctx->inst[i].prop_ptr, "lvs_netlist", 0);
if(str[0]) {
/* fprintf(errfp, "netlist_options(): prop_ptr=%s\n", xctx->inst[i].prop_ptr); */
if(!strcmp(str, "true")) tclsetintvar("top_subckt", 1);
else tclsetintvar("top_subckt", 0);
if(!strcmp(str, "true")) tclsetintvar("lvs_netlist", 1);
else tclsetintvar("lvs_netlist", 0);
}
str = get_tok_value(xctx->inst[i].prop_ptr, "spiceprefix", 0);
if(str[0]) {

View File

@ -734,6 +734,71 @@ int raw_read(const char *f, const char *type)
}
/* Read data organized as a table
* First line is the header line. First column is sweep variable
* empty lines start a new dataset
* lines beginning with '#' are comments
*/
int table_read(const char *f)
{
int res = 0;
FILE *fd;
char *line = NULL, *line_ptr, *line_save;
const char *line_tok;
int_hash_init(&xctx->graph_raw_table, HASHSIZE);
if(xctx->graph_values || xctx->graph_npoints || xctx->graph_nvars || xctx->graph_datasets) {
dbg(0, "raw_read(): must clear current data file before loading new\n");
return res;
}
fd = fopen(f, fopen_read_mode);
if(fd) {
int nline = 0;
int field;
res = 0;
/* read data */
while((line = my_fgets(fd))) {
if(line[0] == '#') continue;
line_ptr = line;
field = 0;
while( (line_tok = my_strtok_r(line_ptr, " \t\n", "", &line_save)) ) {
line_ptr = NULL;
dbg(0,"%s ", line_tok);
if(nline == 0) {
my_realloc(_ALLOC_ID_, &xctx->graph_names, field + 1);
xctx->graph_names[field] = NULL;
my_strcat(_ALLOC_ID_, &xctx->graph_names[field], line_tok);
int_hash_lookup(&xctx->graph_raw_table, xctx->graph_names[field], field, XINSERT_NOREPLACE);
}
field++;
}
dbg(0, "\n");
nline++;
}
if(res == 1) {
int i;
my_strdup2(_ALLOC_ID_, &xctx->graph_raw_schname, xctx->sch[xctx->currsch]);
xctx->graph_raw_level = xctx->currsch;
tclsetintvar("graph_raw_level", xctx->currsch);
xctx->graph_allpoints = 0;
for(i = 0; i < xctx->graph_datasets; i++) {
xctx->graph_allpoints += xctx->graph_npoints[i];
}
dbg(0, "Raw file data read: %s\n", f);
dbg(0, "points=%d, vars=%d, datasets=%d\n",
xctx->graph_allpoints, xctx->graph_nvars, xctx->graph_datasets);
} else {
dbg(0, "raw_read(): no useful data found\n");
}
fclose(fd);
my_free(_ALLOC_ID_, &line);
return res;
}
dbg(0, "raw_read(): failed to open file %s for reading\n", f);
return 0;
}
/* given a node XXyy try XXyy , xxyy, XXYY, v(XXyy), v(xxyy), V(XXYY) */
int get_raw_index(const char *node)
{

View File

@ -2925,7 +2925,15 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
else { cmd_found = 0;}
break;
case 't': /*----------------------------------------------*/
if(!strcmp(argv[1], "test"))
if(!strcmp(argv[1], "table_read"))
{
if(argc > 2) {
table_read(argv[2]);
Tcl_ResetResult(interp);
}
}
else if(!strcmp(argv[1], "test"))
{
Ptr_hashtable table = {NULL, 0};
Ptr_hashentry *entry;

View File

@ -143,7 +143,7 @@ static void spice_netlist(FILE *fd, int spice_stop )
char *type=NULL;
int top_sub;
top_sub = tclgetboolvar("top_subckt");
top_sub = tclgetboolvar("lvs_netlist");
if(!spice_stop) {
dbg(1, "spice_netlist(): invoke prepare_netlist_structs for %s\n", xctx->current_name);
xctx->prep_net_structs = 0;
@ -232,7 +232,7 @@ void global_spice_netlist(int global) /* netlister driver */
Str_hashentry *model_entry;
split_f = tclgetboolvar("split_files");
top_sub = tclgetboolvar("top_subckt");
top_sub = tclgetboolvar("lvs_netlist");
dbg(1, "global_spice_netlist(): invoking push_undo()\n");
xctx->push_undo();
xctx->netlist_unconn_cnt=0; /* unique count of unconnected pins while netlisting */
@ -294,7 +294,7 @@ void global_spice_netlist(int global) /* netlister driver */
netlist_options(i);
}
}
top_sub = tclgetboolvar("top_subckt");
top_sub = tclgetboolvar("lvs_netlist");
if(!top_sub) fprintf(fd,"**");
fprintf(fd,".subckt %s", skip_dir( xctx->sch[xctx->currsch]) );

View File

@ -1100,6 +1100,7 @@ extern unsigned char *ascii85_encode(const unsigned char *data, const size_t inp
extern int get_raw_index(const char *node);
extern void free_rawfile(int dr);
extern int raw_read(const char *f, const char *type);
extern int table_read(const char *f);
extern double get_raw_value(int dataset, int idx, int point);
extern int plot_raw_custom_data(int sweep_idx, int first, int last, const char *ntok);
extern int calc_custom_data_yrange(int sweep_idx, const char *express, Graph_ctx *gr);

View File

@ -1229,7 +1229,7 @@ proc bespice_getdata {sock} {
}
proc xschem_getdata {sock} {
global xschem_server_getdata
global xschem_server_getdata tclcmd_puts
if {[eof $sock] || [catch {gets $sock xschem_server_getdata(line,$sock)}]} {
close $sock
puts "Close $xschem_server_getdata(addr,$sock)"
@ -1237,10 +1237,19 @@ proc xschem_getdata {sock} {
unset xschem_server_getdata(line,$sock)
unset xschem_server_getdata(res,$sock)
} else {
puts "tcp--> $xschem_server_getdata(line,$sock)"
puts "tcp<-- $xschem_server_getdata(line,$sock)"
# xschem command must be executed at global scope...
uplevel #0 [list catch $xschem_server_getdata(line,$sock) xschem_server_getdata(res,$sock)]
puts $sock "$xschem_server_getdata(res,$sock)"
redef_puts
uplevel #0 [list catch $xschem_server_getdata(line,$sock) tclcmd_puts]
rename puts {}
rename ::tcl::puts puts
puts "tcp--> $tclcmd_puts"
if {![regexp {\n$} $tclcmd_puts]} {
set xschem_server_getdata(res,$sock) "$tclcmd_puts\n"
} else {
set xschem_server_getdata(res,$sock) "$tclcmd_puts"
}
puts -nonewline $sock "$xschem_server_getdata(res,$sock)"
}
}
@ -3262,9 +3271,9 @@ proc enter_text {textlabel {preserve_disabled disabled}} {
return $retval
}
# will redefine puts to output into a text widget 'w'
proc redef_puts w {
set ::putsw $w
# will redefine puts to output into tclcmd_puts
proc redef_puts {} {
global tclcmd_puts
if ![llength [info command ::tcl::puts]] {
rename puts ::tcl::puts
proc puts args {
@ -3283,14 +3292,14 @@ proc redef_puts w {
foreach {channel s} $args break
#set s [join $s] ;# (1) prevent braces at leading/tailing spaces
if {$channel=="stdout" || $channel=="stderr"} {
$::putsw insert end $s$nl
append tclcmd_puts $s$nl
} else {
set cmd ::tcl::puts
if {$nl==""} {lappend cmd -nonewline}
lappend cmd $channel $s
eval $cmd
}
}
};# puts
}
}
@ -3303,17 +3312,17 @@ proc return_release {window} {
proc tclcmd_ok_button {} {
global tclcmd_txt
global tclcmd_txt tclcmd_puts
set tclcmd_txt [.tclcmd.t get 1.0 end]
redef_puts .tclcmd.r.r
catch {uplevel #0 $tclcmd_txt} res
redef_puts
catch {uplevel #0 $tclcmd_txt} tclcmd_puts
rename puts {}
rename ::tcl::puts puts
if {$res != {} && [string index $res end] != "\n"} {
append res "\n"
if {$tclcmd_puts != {} && [string index $tclcmd_puts end] != "\n"} {
append tclcmd_puts "\n"
}
.tclcmd.r.r insert end $res
.tclcmd.r.r insert end $tclcmd_puts
.tclcmd.r.r yview moveto 1
}
@ -5304,7 +5313,8 @@ set tctx::global_list {
graph_logy graph_rainbow graph_raw_level graph_schname graph_sel_color graph_sel_wave
graph_selected graph_sort graph_unlocked hide_empty_graphs hide_symbols hsize
incr_hilight infowindow_text input_line_cmd input_line_data launcher_default_program
light_colors line_width live_cursor2_backannotate local_netlist_dir measure_text netlist_show
light_colors line_width live_cursor2_backannotate local_netlist_dir
lvs_netlist measure_text netlist_show
netlist_type no_change_attrs nolist_libs noprint_libs old_selected_tok only_probes path pathlist
persistent_command preserve_unchanged_attrs prev_symbol ps_colors rainbow_colors
rawfile_loaded rcode recentfile
@ -5313,7 +5323,7 @@ set tctx::global_list {
simconf_default_geometry simconf_vpos simulate_bg spiceprefix split_files svg_colors
svg_font_name sym_txt symbol symbol_width tclcmd_txt tclstop text_line_default_geometry
textwindow_fileid textwindow_filename textwindow_w tmp_bus_char toolbar_horiz toolbar_list
toolbar_visible top_subckt transparent_svg undo_type use_lab_wire use_label_prefix
toolbar_visible transparent_svg undo_type use_lab_wire use_label_prefix
user_wants_copy_cell verilog_2001 verilog_bitblast viewdata_fileid viewdata_filename viewdata_w
vsize xschem_libs xschem_listen_port add_all_windows_drives
}
@ -6040,8 +6050,8 @@ tclcommand=\"xschem raw_read \$netlist_dir/[file tail [file rootname [xschem get
-command {set show_hidden_texts 1; xschem annotate_op}
$topwin.menubar.simulation.menu add separator
$topwin.menubar.simulation.menu add checkbutton -label "LVS netlist: Top level is a .subckt" \
-variable top_subckt -command {
if {$top_subckt == 1} {
-variable lvs_netlist -command {
if {$lvs_netlist == 1} {
xschem set format lvs_format
} else {
xschem set format {}
@ -6349,7 +6359,7 @@ set_ne netlist_dir "$USER_CONF_DIR/simulations"
set_ne netlist_type spice
set_ne local_netlist_dir 0 ;# if set use <sch_dir>/simulation for netlist and sims
set_ne bus_replacement_char {} ;# use {<>} to replace [] with <> in bussed signals
set_ne top_subckt 0
set_ne lvs_netlist 0
set_ne hide_empty_graphs 0 ;# if set to 1 waveform boxes will be hidden if no raw file loaded
set_ne spiceprefix 1
set_ne verilog_2001 1

View File

@ -3,7 +3,7 @@ G {}
K {type=netlist_options
template="
bus_replacement_char="[]"
top_subckt=false
lvs_netlist=false
spiceprefix=true
hiersep=.
"