Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/contrib/TclContract.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ to follow.

## Idiom

- **Strings compare with `eq` and `ne`; `==` is for numbers.** `==` tries a
numeric comparison first, so `"1e3" == "1000"` and `"0x10" == "16"` are
true. A list a command returns is tested with `[llength $x]`; a
variable from the environment is a string, tested with `ne ""`.
*Breaks:* a name or type that looks like a number compares equal to another.
- **A script never writes its own version of an idiom `util.tcl` already
has.** An optional flag is added with `append_env_var`, a command that does
real work runs through `log_cmd`, a result is written with `orfs_write_db`,
Expand Down
14 changes: 7 additions & 7 deletions flow/platforms/gf180/setRC.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ set_layer_rc -layer Metal5 -resistance 5.85545E-02 -capacitance 1.55595E-04

regexp {(\d+)} $::env(METAL_OPTION) metal

if { $metal == "6" } {
if { $metal eq "6" } {
set_wire_rc -signal -layer Metal2
set_wire_rc -clock -layer Metal5
} elseif { $metal == "5" } {
} elseif { $metal eq "5" } {
# TC matches LEF. These are the temperature adjusted values.
# The other stacks are likely similar but I haven't checked yet.
if { $::env(CORNER) == "WC" } {
if { $::env(CORNER) eq "WC" } {
set_layer_rc -via Via1 -resistance 16.845
set_layer_rc -via Via2 -resistance 16.845
set_layer_rc -via Via3 -resistance 16.845
Expand All @@ -23,7 +23,7 @@ if { $metal == "6" } {
$via setResistance 16.845
}
}
} elseif { $::env(CORNER) == "BC" } {
} elseif { $::env(CORNER) eq "BC" } {
set_layer_rc -via Via1 -resistance 4.23
set_layer_rc -via Via2 -resistance 4.23
set_layer_rc -via Via3 -resistance 4.23
Expand All @@ -39,13 +39,13 @@ if { $metal == "6" } {

set_wire_rc -signal -layer Metal2
set_wire_rc -clock -layer Metal4
} elseif { $metal == "4" } {
} elseif { $metal eq "4" } {
set_wire_rc -signal -layer Metal2
set_wire_rc -clock -layer Metal3
} elseif { $metal == "3" } {
} elseif { $metal eq "3" } {
set_wire_rc -signal -layer Metal2
set_wire_rc -clock -layer Metal2
} elseif { $metal == "2" } {
} elseif { $metal eq "2" } {
set_wire_rc -signal -layer Metal2
set_wire_rc -clock -layer Metal2
}
2 changes: 1 addition & 1 deletion flow/scripts/floorplan.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ proc report_unused_masters { } {
foreach lib $libs {
foreach master [$lib getMasters] {
# filter out non-block masters, or you can remove this conditional to detect any unused master
if { [$master getType] == "BLOCK" } {
if { [$master getType] eq "BLOCK" } {
lappend masters $master
}
}
Expand Down
6 changes: 3 additions & 3 deletions flow/scripts/load.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ proc load_stage_input { design_file } {
proc load_design_from { dir design_file } {
# Do not reload if design is already loaded
set db [ord::get_db]
if { [$db getChip] != "NULL" && [[$db getChip] getBlock] != "NULL" } {
if { [$db getChip] ne "NULL" && [[$db getChip] getBlock] ne "NULL" } {
return
}

Expand All @@ -44,7 +44,7 @@ proc load_design_from { dir design_file } {

# Read design files
set ext [file extension $design_file]
if { $ext == ".v" } {
if { $ext eq ".v" } {
read_lef $::env(TECH_LEF)
read_lef $::env(SC_LEF)
if { [env_var_exists_and_non_empty ADDITIONAL_LEFS] } {
Expand All @@ -58,7 +58,7 @@ proc load_design_from { dir design_file } {
}
read_verilog $dir/$design_file
log_cmd link_design {*}[hier_options] $::env(DESIGN_NAME)
} elseif { $ext == ".odb" } {
} elseif { $ext eq ".odb" } {
log_cmd read_db {*}[hier_options] $dir/$design_file
} else {
error "Unrecognized input file $design_file"
Expand Down
2 changes: 1 addition & 1 deletion flow/scripts/macro_place_util.tcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if { [find_macros] != "" } {
if { [find_macros] ne "" } {
if { ![env_var_exists_and_non_empty RTLMP_RPT_DIR] } {
set ::env(RTLMP_RPT_DIR) "$::env(OBJECTS_DIR)/rtlmp"
}
Expand Down
2 changes: 1 addition & 1 deletion flow/scripts/pdn.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set_placement_padding -global -left 0 -right 0
set block [ord::get_db_block]
foreach net [$block getNets] {
set type [$net getSigType]
if { $type == "POWER" || $type == "GROUND" } {
if { $type eq "POWER" || $type eq "GROUND" } {
# Temporarily disable due to CI issues
# puts "Check supply: [$net getName]"
# check_power_grid -net [$net getName]
Expand Down
6 changes: 3 additions & 3 deletions flow/scripts/report_metrics.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ proc report_metrics { stage when { include_erc true } { include_clock_skew true
report_puts "hold violation count [sta::endpoint_violation_count min]"

set critical_path [lindex [find_timing_paths -sort_by_slack] 0]
if { $critical_path != "" } {
if { $critical_path ne "" } {
set path_delay [sta::format_time [[$critical_path path] arrival] 4]
set path_slack [sta::format_time [[$critical_path path] slack] 4]
} else {
Expand All @@ -197,7 +197,7 @@ proc report_metrics { stage when { include_erc true } { include_clock_skew true

set inp_to_reg_critical_path \
[lindex [find_timing_paths -path_delay max -from [all_inputs] -to [all_registers]] 0]
if { $inp_to_reg_critical_path != "" } {
if { $inp_to_reg_critical_path ne "" } {
set target_clock_latency_max \
[sta::format_time [$inp_to_reg_critical_path target_clk_delay] 4]
} else {
Expand All @@ -207,7 +207,7 @@ proc report_metrics { stage when { include_erc true } { include_clock_skew true

set inp_to_reg_critical_path [lindex \
[find_timing_paths -path_delay min -from [all_inputs] -to [all_registers]] 0]
if { $inp_to_reg_critical_path != "" } {
if { $inp_to_reg_critical_path ne "" } {
set target_clock_latency_min \
[sta::format_time [$inp_to_reg_critical_path target_clk_delay] 4]
set source_clock_latency [sta::format_time [$inp_to_reg_critical_path source_clk_latency] 4]
Expand Down
2 changes: 1 addition & 1 deletion flow/scripts/run_step.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ proc write_failure_checkpoint { } {
return
}
set chip [[ord::get_db] getChip]
if { $chip == "NULL" || [$chip getBlock] == "NULL" } {
if { $chip eq "NULL" || [$chip getBlock] eq "NULL" } {
puts "No design loaded, no failure checkpoint written"
return
}
Expand Down
2 changes: 1 addition & 1 deletion flow/scripts/save_images.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set height [ord::dbu_to_microns $height]
set resolution [expr $height / 1000]

set markerdb [[ord::get_db_block] findMarkerCategory DRC]
if { $markerdb != "NULL" && [$markerdb getMarkerCount] > 0 } {
if { $markerdb ne "NULL" && [$markerdb getMarkerCount] > 0 } {
gui::select_marker_category $markerdb
}

Expand Down
6 changes: 3 additions & 3 deletions flow/scripts/synth_preamble.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if { [env_var_exists_and_non_empty SYNTH_NETLIST_FILES] } {

proc read_checkpoint { file } {
# We are reading a Yosys checkpoint
if { [file extension $file] == ".json" } {
if { [file extension $file] eq ".json" } {
read_json $file
} else {
read_rtlil $file
Expand Down Expand Up @@ -268,12 +268,12 @@ proc convert_liberty_areas { } {
continue
}
set area [rtlil::get_attr -string -mod $cell area]
if { $found_cell == "" || $area < $found_cell_area } {
if { $found_cell eq "" || $area < $found_cell_area } {
set found_cell $cell
set found_cell_area $area
}
}
if { $found_cell == "" } {
if { $found_cell eq "" } {
error "reference nand2 cell not found"
}

Expand Down
2 changes: 1 addition & 1 deletion flow/scripts/synth_syn.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ lappend elaborate_args {*}$::env(SYNTH_SLANG_ARGS)
# If the sources are solely .v files, enable Verilog compatibility
set has_non_v_files false
foreach fn $verilog_files {
if { [file extension [string trim $fn]] != ".v" } {
if { [file extension [string trim $fn]] ne ".v" } {
set has_non_v_files true
}
}
Expand Down
10 changes: 5 additions & 5 deletions flow/scripts/util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ proc extract_stage { input_file } {
exit 1
}
lappend number_groups $num1
if { $num2 != "" } {
if { $num2 ne "" } {
lappend number_groups $num2
} else {
lappend number_groups "0"
Expand Down Expand Up @@ -324,7 +324,7 @@ proc is_physical_only_master { master } {
proc has_signal_pins { master } {
foreach mterm [$master getMTerms] {
set sig_type [$mterm getSigType]
if { $sig_type != "POWER" && $sig_type != "GROUND" } {
if { $sig_type ne "POWER" && $sig_type ne "GROUND" } {
return 1
}
}
Expand All @@ -335,7 +335,7 @@ proc has_signal_pins { master } {
proc has_liberty_cell { master } {
set master_name [$master getName]
set lib_cells [get_lib_cells -quiet */$master_name]
if { $lib_cells == {} } {
if { [llength $lib_cells] == 0 } {
return 0
}
return 1
Expand Down Expand Up @@ -399,7 +399,7 @@ proc use_ccs_delay_calculator { } {
# design is placed, what OpenROAD estimates (global routes if there are
# any, else placement), else none.
proc orfs_load_parasitics { step } {
if { $step == "6_final" && [final_extracts_parasitics] } {
if { $step eq "6_final" && [final_extracts_parasitics] } {
log_cmd read_spef $::env(RESULTS_DIR)/6_final.spef
} elseif { [grt::design_is_placed] } {
log_cmd estimate_parasitics
Expand Down Expand Up @@ -466,7 +466,7 @@ proc copy_endpoint_slack { input_file output_file } {
}
set step [file rootname [file tail $output_file]]
set chip [[ord::get_db] getChip]
if { $chip != "NULL" && [$chip getBlock] != "NULL" } {
if { $chip ne "NULL" && [$chip getBlock] ne "NULL" } {
write_endpoint_slack $step
return
}
Expand Down
18 changes: 9 additions & 9 deletions flow/util/cell-veneer/lefdef.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ proc open { file_name } {
# tclint-disable-next-line redefined-builtin
proc close { } {
variable lefOut
if { $lefOut != "stdout" } {
if { $lefOut ne "stdout" } {
::close $lefOut
}
set lefOut stdout
Expand Down Expand Up @@ -105,7 +105,7 @@ proc read_macros { file_name } {
dict set cells $cell_name site $site
} elseif { [regexp {PIN\s*([^\s]*)} $line - pin_name] } {
set pin_pattern [regsub -all {([\[\]])} $pin_name {\\\1}]
if { [info vars antennamodel] != "" } {
if { [info vars antennamodel] ne "" } {
unset antennamodel
}
while { ![eof $ch] } {
Expand All @@ -119,7 +119,7 @@ proc read_macros { file_name } {
} elseif { [regexp {ANTENNAMODEL\s+([^\s]*)} $line - antennamodel] } {
continue
} elseif { [regexp {ANTENNAGATEAREA\s+([^\s]*)\s+LAYER\s+([^\s]*)} $line - gate_area layer] } {
if { [info vars antennamodel] == "" } {
if { [info vars antennamodel] eq "" } {
set antennamodel "default"
}
if { [dict exists $cells $cell_name pins $pin_name antenna_model $antennamodel] } {
Expand All @@ -130,7 +130,7 @@ proc read_macros { file_name } {
lappend model [list gate_area $gate_area layer $layer]
dict set cells $cell_name pins $pin_name antenna_model $antennamodel $model
} elseif { [regexp {ANTENNAGATEAREA\s+([^\s]*)} $line - gate_area] } {
if { [info vars antennamodel] == "" } {
if { [info vars antennamodel] eq "" } {
set antennamodel "default"
}
if { [dict exists $cells $cell_name pins $pin_name antenna_model $antennamodel] } {
Expand Down Expand Up @@ -214,7 +214,7 @@ proc read_macros { file_name } {
if { [regexp {^\s*$} $line] } {
continue
} elseif { [regexp {LAYER\s+([^\s]*)(\s+DESIGNRULEWIDTH\s+([0-9.]+))?} $line - layer - drw] } {
if { $drw != "" } {
if { $drw ne "" } {
dict set cells $cell_name layers $layer drw $drw
}
continue
Expand Down Expand Up @@ -473,7 +473,7 @@ proc open { file_name } {
# tclint-disable-next-line redefined-builtin
proc close { } {
variable defOut
if { $defOut != "stdout" } {
if { $defOut ne "stdout" } {
::close $defOut
}
set defOut stdout
Expand Down Expand Up @@ -676,7 +676,7 @@ proc get_line_direction { points } {
proc get_line_width { layer_name points } {
set direction [get_line_direction $points]

if { [get_layer_direction $layer_name] == $direction } {
if { [get_layer_direction $layer_name] eq $direction } {
return [get_layer_width $layer_name]
} else {
return [get_layer_non_preferred_width $layer_name]
Expand All @@ -690,13 +690,13 @@ proc get_extended_line { layer_name points } {

set direction [get_line_direction $points]

if { $direction == [get_layer_direction $layer_name] } {
if { $direction eq [get_layer_direction $layer_name] } {
set extension [expr [get_layer_non_preferred_width $layer_name] / 2]
} else {
set extension [expr [get_layer_width $layer_name] / 2]
}

if { $direction == "VERTICAL" } {
if { $direction eq "VERTICAL" } {
set x_min [lindex $points 0 0]
set x_max [lindex $points 0 0]
set y_min [expr min([lindex $points 0 1], [lindex $points 1 1]) - $extension]
Expand Down
2 changes: 1 addition & 1 deletion flow/util/cell-veneer/wrap.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if { [set idx [lsearch -exact $argv {-cfg}]] > -1 } {
wrapper critical 2 "no configuration data loaded"
}

if { [lindex $argv 0] == "-macro" } {
if { [lindex $argv 0] eq "-macro" } {
set lef_files [lrange $argv 1 end]
set cells {}
foreach file_name $lef_files {
Expand Down
16 changes: 8 additions & 8 deletions flow/util/cell-veneer/wrap_stdcells.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ proc find_cells_with_m2_pins { } {

if { [dict exists $data $cell_name] } {
dict for {layer_name obstructions} [dict get $cell obstructions] {
if { $layer_name == "M2" } {
if { $layer_name eq "M2" } {
foreach obs $obstructions {
set rect [dict get $obs rect]
set x1 [lindex $rect 0]
Expand Down Expand Up @@ -151,7 +151,7 @@ proc create_def_wrapper { cell_name new_cell_name } {
dict for {pin_name pin} [dict get $orig_cell pins] {
dict set design pins $pin_name net_name $pin_name
if { [dict exists $pin use] } {
if { [dict get $pin use] == "POWER" || [dict get $pin use] == "GROUND" } {
if { [dict get $pin use] eq "POWER" || [dict get $pin use] eq "GROUND" } {
dict set design special_nets $pin_name connections [list "PIN $pin_name" "* $pin_name"]
dict set design special_nets $pin_name use [dict get $pin use]
} else {
Expand Down Expand Up @@ -228,17 +228,17 @@ proc move_m2_pins_to_edge { cell_name cell_data } {
}
}

if { $direction == "blocked" } {
if { $direction eq "blocked" } {
break
}

set y [expr [dict get $physical_pin track] * 128]
if { $direction == "right" } {
if { $direction eq "right" } {
set x1 [dict get $physical_pin to]
set x2 [expr $cell_width + ($padding_cell_width * ($right_padding + 1))]
set x3 [expr $cell_width + ($padding_cell_width * ($right_padding + 1)) + $via_overlap]
incr right_padding
} elseif { $direction == "left" } {
} elseif { $direction eq "left" } {
set x1 [dict get $physical_pin from]
set x2 [expr 0 - ($padding_cell_width * ($left_padding + 1))]
set x3 [expr 0 - ($padding_cell_width * ($left_padding + 1)) - $via_overlap]
Expand Down Expand Up @@ -271,7 +271,7 @@ proc move_m2_pins_to_edge { cell_name cell_data } {
break
}

if { $direction == "blocked" } {
if { $direction eq "blocked" } {
break
}

Expand Down Expand Up @@ -471,7 +471,7 @@ proc wrap_macro { cell_name } {
set grid_pins {}

dict for {pin_name pin} [dict get $cell pins] {
if { [dict get $pin use] != "SIGNAL" } { continue }
if { [dict get $pin use] ne "SIGNAL" } { continue }

# CHEAT: Assume that there is only one port for each pin and one rectangle per layer
set port [lindex [dict get $pin ports] 0]
Expand Down Expand Up @@ -597,7 +597,7 @@ proc wrap_macro { cell_name } {
"$macro_x [dict get $net macro_pin_y]" \
"$target_grid_point [dict get $net macro_pin_y]" \
"$target_grid_point $y_position"]]
if { [dict get $net pin_layer] != "C4" } {
if { [dict get $net pin_layer] ne "C4" } {
lappend segments [list \
layer [dict get $net pin_layer] \
points [list \
Expand Down