Skip to content

Commit f1cc48f

Browse files
oharboeclaude
andcommitted
dump stage variables as .md table at start of each stage
Adds dump_stage_variables to log all set stage variables (name, value, description) as a GitHub-flavored markdown table at the beginning of each stage. Descriptions are sourced from variables.yaml via stage_variables.py and truncated to fit 80 char lines. Helps humans and AI debug build issues by making the effective configuration visible in the log. Once per stage is enough, balance between information and spammyness. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent a6f355a commit f1cc48f

10 files changed

Lines changed: 106 additions & 0 deletions

‎flow/scripts/cts.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ utl::set_metrics_stage "cts__{}"
22
source $::env(SCRIPTS_DIR)/load.tcl
33
source $::env(SCRIPTS_DIR)/lec_check.tcl
44
erase_non_stage_variables cts
5+
dump_stage_variables cts
56
load_design 3_place.odb 3_place.sdc
67
source_step_tcl PRE CTS
78

‎flow/scripts/density_fill.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
source $::env(SCRIPTS_DIR)/load.tcl
22
erase_non_stage_variables final
3+
dump_stage_variables final
34
load_design 5_route.odb 5_route.sdc
45
source_step_tcl PRE DENSITY_FILL
56

‎flow/scripts/detail_route.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if { $::env(SKIP_DETAILED_ROUTE) } {
1313
}
1414

1515
erase_non_stage_variables route
16+
dump_stage_variables route
1617
set_propagated_clock [all_clocks]
1718

1819
set additional_args ""

‎flow/scripts/floorplan.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
utl::set_metrics_stage "floorplan__{}"
22
source $::env(SCRIPTS_DIR)/load.tcl
33
erase_non_stage_variables floorplan
4+
dump_stage_variables floorplan
45
load_design 1_synth.odb 1_synth.sdc
56
source_step_tcl PRE FLOORPLAN
67

‎flow/scripts/generate_abstract.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
source $::env(SCRIPTS_DIR)/load.tcl
22
erase_non_stage_variables generate_abstract
3+
dump_stage_variables generate_abstract
34

45
set stem [expr {
56
[env_var_exists_and_non_empty ABSTRACT_SOURCE] ?

‎flow/scripts/global_place_skip_io.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
source $::env(SCRIPTS_DIR)/load.tcl
22
erase_non_stage_variables place
3+
dump_stage_variables place
34
load_design 2_floorplan.odb 2_floorplan.sdc
45
source_step_tcl PRE GLOBAL_PLACE_SKIP_IO
56

‎flow/scripts/global_route.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
utl::set_metrics_stage "globalroute__{}"
22
source $::env(SCRIPTS_DIR)/load.tcl
33
erase_non_stage_variables grt
4+
dump_stage_variables grt
45
load_design 4_cts.odb 4_cts.sdc
56

67
# This proc is here to allow us to use 'return' to return early from this

‎flow/scripts/stage_variables.py‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Print a .md table of stage variables that are set in the environment.
4+
# Sorted alphabetically, description truncated to fit 80 char lines.
5+
# No external dependencies: parses variables.yaml line by line.
6+
#
7+
import os
8+
import re
9+
import sys
10+
11+
12+
def parse_variables(yaml_path):
13+
"""Parse variables.yaml into {name: {description, stages}}."""
14+
variables = {}
15+
current_var = None
16+
current_field = None
17+
18+
with open(yaml_path) as f:
19+
for line in f:
20+
# Top-level variable: "VAR_NAME:"
21+
m = re.match(r"^(\w+):\s*$", line)
22+
if m:
23+
current_var = m.group(1)
24+
variables[current_var] = {"description": "", "stages": []}
25+
current_field = None
26+
continue
27+
28+
if current_var is None:
29+
continue
30+
31+
# Field: " description: >" or " stages:"
32+
m = re.match(r"^ (\w+):", line)
33+
if m:
34+
current_field = m.group(1)
35+
continue
36+
37+
# List item under stages: " - name"
38+
m = re.match(r"^ - (\S+)", line)
39+
if m and current_field == "stages":
40+
variables[current_var]["stages"].append(m.group(1))
41+
continue
42+
43+
# Continuation of description
44+
if current_field == "description":
45+
variables[current_var]["description"] += " " + line.strip()
46+
47+
return variables
48+
49+
50+
def main():
51+
stage = sys.argv[1]
52+
dir_path = os.path.dirname(os.path.realpath(__file__))
53+
yaml_path = os.path.join(dir_path, "variables.yaml")
54+
variables = parse_variables(yaml_path)
55+
56+
rows = []
57+
for key in sorted(variables):
58+
v = variables[key]
59+
stages = v["stages"]
60+
if not stages:
61+
continue
62+
if "All stages" not in stages and stage not in stages:
63+
continue
64+
if key not in os.environ:
65+
continue
66+
desc = v["description"].strip()
67+
rows.append((key, os.environ[key], desc))
68+
69+
if rows:
70+
w0 = max(len(r[0]) for r in rows)
71+
w1 = max(len(r[1]) for r in rows)
72+
w0 = max(w0, len("Variable"))
73+
w1 = max(w1, len("Value"))
74+
75+
def fmt(c0, c1, c2):
76+
prefix = f"| {c0:<{w0}} | {c1:<{w1}} |"
77+
remaining = 80 - len(prefix) - 1
78+
if remaining >= 4:
79+
max_desc = remaining - 3
80+
if len(c2) > max_desc:
81+
c2 = c2[: max_desc - 3] + "..."
82+
return f"{prefix} {c2:<{max_desc}} |"
83+
return f"{prefix} |"
84+
85+
header = fmt("Variable", "Value", "Description")
86+
print(header)
87+
print(re.sub(r"[^|]", "-", header))
88+
for var, val, desc in rows:
89+
print(fmt(var, val, desc))
90+
91+
92+
if __name__ == "__main__":
93+
main()

‎flow/scripts/synth_odb.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
utl::set_metrics_stage "floorplan__{}"
22
source $::env(SCRIPTS_DIR)/load.tcl
33
erase_non_stage_variables synth
4+
dump_stage_variables synth
45
load_design 1_2_yosys.v 1_2_yosys.sdc
56
source_step_tcl PRE SYNTH
67

‎flow/scripts/util.tcl‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ proc erase_non_stage_variables { stage_name } {
167167
}
168168
}
169169

170+
# Log stage variables to help humans and bots debug build issues.
171+
proc dump_stage_variables { stage_name } {
172+
puts [exec $::env(SCRIPTS_DIR)/stage_variables.py $stage_name]
173+
}
174+
170175
set global_route_congestion_report $::env(REPORTS_DIR)/congestion.rpt
171176

172177
proc place_density_with_lb_addon { } {

0 commit comments

Comments
 (0)