首次提交
This commit is contained in:
114
new_project_rtl_template/sim/func001/savewave.tcl
Normal file
114
new_project_rtl_template/sim/func001/savewave.tcl
Normal file
@@ -0,0 +1,114 @@
|
||||
# When open .wlf file, there is no CASE_NAME variable in context. We get the case name by searching in the struct window instead.
|
||||
if {true} {
|
||||
# raw script code in pre_format
|
||||
set pre_format {
|
||||
# When open .wlf file, there is no CASE_NAME variable in context. We get the case name by searching in the struct window instead.
|
||||
if {![info exists CASE_NAME]} {
|
||||
puts "++++++++++ search case name ++++++++++"
|
||||
set wave_sim_type func
|
||||
for {set wave_i 0} {$wave_i < 1000} {incr wave_i 1} {
|
||||
set wave_case_num [format "%03d" $wave_i];
|
||||
set wave_case_name ${wave_sim_type}${wave_case_num}
|
||||
if {[search structure $wave_case_name] >= 0} {
|
||||
break
|
||||
}
|
||||
}
|
||||
set unset_CASE_NAME true
|
||||
set CASE_NAME $wave_case_name
|
||||
}
|
||||
}
|
||||
}; list
|
||||
# from stackoverflow.com "how to keep commands quiet in TCL?"
|
||||
# if you want to inhibit such printouts in an interactive session(comes in handy from time to time), a simple hack to achieve that is to chain the command
|
||||
# you want to "silence" with a "silent" command(producing a value whose string representation is an empty string).
|
||||
# for instance: set a [open "giri.txt" r]; list
|
||||
|
||||
if {true} {
|
||||
# raw script code in post_format
|
||||
set post_format {
|
||||
if { [info exists unset_CASE_NAME] && [string equal -nocase true $unset_CASE_NAME] } {
|
||||
set unset_CASE_NAME false
|
||||
unset CASE_NAME
|
||||
}
|
||||
}
|
||||
}; list
|
||||
|
||||
# support save format when only open .wlf instead of run a case
|
||||
# When open .wlf file, there is no CASE_NAME variable in context. We get the case name by searching in the struct window instead.
|
||||
if {![info exists CASE_NAME]} {
|
||||
puts "++++++++++ search case name ++++++++++"
|
||||
set wave_sim_type func
|
||||
for {set wave_i 0} {$wave_i < 1000} {incr wave_i 1} {
|
||||
set wave_case_num [format "%03d" $wave_i];
|
||||
set wave_case_name ${wave_sim_type}${wave_case_num}
|
||||
if {[search structure $wave_case_name] >= 0} {
|
||||
break
|
||||
}
|
||||
}
|
||||
set unset_CASE_NAME true
|
||||
set CASE_NAME $wave_case_name
|
||||
}
|
||||
|
||||
# brace all to eliminate unnecessary output(example. "set fd_pre_savewave [open pre_savewave.tcl r]" will display returned value of set cmd)
|
||||
if {true} {
|
||||
# save current wave format to a tmp file
|
||||
catch {write format wave -window Wave intermediate_wave_format_file.tmp} res
|
||||
|
||||
if {$argc>=1} { # example: do savewave.tcl wave_name
|
||||
set wave_name $1
|
||||
if {[regexp {^([-\w\+]+\.)+[-\w\+]*$} $wave_name] >= 1} {
|
||||
# replace the last postfix(.tcl or .do or .) with null, i.e. delete the last postfix(including .)
|
||||
while {[regexp -nocase {(\.(tcl|do)*$)} $wave_name] >= 1} {
|
||||
regsub {(\.[-\w\+]*$)} $wave_name {} wave_name
|
||||
}
|
||||
} elseif {[regexp {^[-\w\+]+$} $wave_name] >= 1} {
|
||||
# nop
|
||||
} else {
|
||||
echo "Invalid file name $wave_name!"
|
||||
return
|
||||
}
|
||||
set fd_wave [open $wave_name.tcl w]
|
||||
echo "Wave format saved to $wave_name.tcl"
|
||||
} else { # example: do savewave.tcl
|
||||
set fd_wave [open wave1.tcl w]
|
||||
echo "Wave format saved to wave1.tcl"
|
||||
}
|
||||
|
||||
set fd_intermediate_wave_format_file [open intermediate_wave_format_file.tmp r]
|
||||
|
||||
# put lines in pre_format to final file(the file specified in argument $1)
|
||||
set lines [split $pre_format "\n"]
|
||||
set total_lines [llength $lines]
|
||||
for {set line_idx 0} {$line_idx < $total_lines} {incr line_idx 1} {
|
||||
set wave_format_line [lindex $lines $line_idx]
|
||||
chan puts $fd_wave $wave_format_line
|
||||
}
|
||||
|
||||
# put lines in tmp file to final file(the file specified in argument $1)
|
||||
while {[chan gets $fd_intermediate_wave_format_file wave_format_line] >= 0} {
|
||||
if {[regexp -all {\[|\]} $wave_format_line] >= 1} {
|
||||
# if [ and ] exist in line(like [10:0] or [2]), then escape them, i.e. \[ and \]
|
||||
regsub -all {\[|\]} $wave_format_line {\\&} wave_format_line
|
||||
# and then add eval in the biginning
|
||||
regsub (^) $wave_format_line {eval } wave_format_line
|
||||
}
|
||||
# make virtual signal ok
|
||||
if {[regexp -all {virtual signal} $wave_format_line] >= 1} {
|
||||
regsub -all {\{} $wave_format_line {[subst &} wave_format_line
|
||||
regsub -all {\}} $wave_format_line {&]} wave_format_line
|
||||
}
|
||||
regsub -all $CASE_NAME $wave_format_line {$CASE_NAME} wave_format_line
|
||||
chan puts $fd_wave $wave_format_line
|
||||
}
|
||||
|
||||
# put lines in post_format to final file(the file specified in argument $1)
|
||||
set lines [split $post_format "\n"]
|
||||
set total_lines [llength $lines]
|
||||
for {set line_idx 0} {$line_idx < $total_lines} {incr line_idx 1} {
|
||||
set wave_format_line [lindex $lines $line_idx]
|
||||
chan puts $fd_wave $wave_format_line
|
||||
}
|
||||
|
||||
close $fd_wave
|
||||
close $fd_intermediate_wave_format_file
|
||||
}
|
||||
Reference in New Issue
Block a user