Skip to content

Commit

Permalink
optional scoped sourcing, fix info script
Browse files Browse the repository at this point in the history
- add new global variable, ::sta_scoped_source that if set to 1, causes all sourced files to be evaluated at the scope of the calling function instead of the top level (default 0). read_sdc will always be evaluated at the top-level, however.
- add info script calls in source and read_sdc so [info script] would return the correct filename

Co-authored-by: Peter <46405338+gadfort@users.noreply.github.com>
Signed-off-by: Mohamed Gaber <donn@efabless.com>
  • Loading branch information
donn and gadfort committed Feb 4, 2025
1 parent 988514f commit accdce7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sdc/Sdc.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ proc_redirect read_sdc {
set prev_filename [info script]
try {
info script $filename
source_ $filename $echo 0
uplevel \#0 "sta::source_ $filename $echo 0"
} finally {
info script $prev_filename
}
Expand All @@ -63,6 +63,7 @@ if { ![info exists renamed_source] } {
}

set ::sta_continue_on_error 0
set ::sta_scoped_source 0

define_cmd_args "source" \
{[-echo] [-verbose] filename [> filename] [>> filename]}
Expand All @@ -79,7 +80,7 @@ proc_redirect source {
set prev_filename [info script]
try {
info script $filename
source_ $filename $echo $verbose
uplevel 1 "sta::source_ $filename $echo $verbose"
} finally {
info script $prev_filename
}
Expand Down Expand Up @@ -118,7 +119,11 @@ proc source_ { filename echo verbose } {
if { [string index $line end] != "\\" \
&& [info complete $cmd] } {
set error {}
set error_code [catch {uplevel \#0 $cmd} result]
set source_uplevel "\#0"
if { $::sta_scoped_source } {
set source_uplevel "1"
}
set error_code [catch {uplevel $source_uplevel $cmd} result]
# cmd consumed
set cmd ""
# Flush results printed outside tcl to stdout/stderr.
Expand Down
1 change: 1 addition & 0 deletions test/regression_vars.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ record_sta_tests {
report_checks_src_attr
report_json1
report_json2
scoped_source
suppress_msg
verilog_attribute
}
Expand Down
2 changes: 2 additions & 0 deletions test/scoped_source.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Test String: foo
Test String: bar
12 changes: 12 additions & 0 deletions test/scoped_source.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set test_string foo

proc source_file {} {
set test_string bar
source ./scoped_sourceable.tcl
}

source_file

set ::sta_scoped_source 1

source_file
1 change: 1 addition & 0 deletions test/scoped_sourceable.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "Test String: $test_string"

0 comments on commit accdce7

Please sign in to comment.