Skip to content

Commit ad76a84

Browse files
committed
build: patch bazel-orfs synth_partition kept_modules.json parse
The sed-based parser used greedy '.*\\[' / '\\].*' regexes. Slang elaborates parameterized instances into names that contain '[' and ']' (e.g. 'tcdm_adapter\$mempool_group.gen_tiles[0].i_tile.gen_banks[0]'), so the greedy match strips most of the JSON and leaves a single nonsense module name like '0'. nangate45/mempool_group hit this and its partition action would print 'synthesizing 1 modules: 0' before failing with 'Module \`0' not found'. Module names cannot contain '"', so 'grep -oE "\\"[^\"]+\\""' followed by 'tail -n +2' (skip the "modules" key) is a safe parse without greedy backtracking. Verified with 'bazelisk build //flow/designs/nangate45/mempool_group:mempool_group_synth', which now completes. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 2039457 commit ad76a84

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎MODULE.bazel‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ git_override(
3939
patches = [
4040
"//bazel/bazel-orfs-patches:0001-stages-register-bazel-injected-vars-in-validator.patch",
4141
"//bazel/bazel-orfs-patches:0002-synth_partition-fix-SYNTH_SKIP_KEEP-truthy-check.patch",
42+
"//bazel/bazel-orfs-patches:0003-synth_partition-parse-kept_modules-json-without-greedy-sed.patch",
4243
],
4344
remote = BAZEL_ORFS_REMOTE,
4445
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
diff --git a/synth_partition.sh b/synth_partition.sh
2+
index 5fa420b..f37ca48 100755
3+
--- a/synth_partition.sh
4+
+++ b/synth_partition.sh
5+
@@ -17,9 +17,12 @@ NUM_PARTITIONS=${SYNTH_NUM_PARTITIONS:?}
6+
KEPT_JSON="$RESULTS_DIR/kept_modules.json"
7+
OUTPUT="$RESULTS_DIR/partition_${PARTITION_ID}.v"
8+
9+
-# Parse module list from JSON using sed (avoids python wrapper issues)
10+
-# JSON format: {"modules": ["mod1", "mod2", ...]}
11+
-ALL_MODULES=$(sed 's/.*\[//;s/\].*//;s/"//g;s/,/\n/g;s/ //g' "$KEPT_JSON")
12+
+# Parse module list from JSON. Module names can contain '[' and ']'
13+
+# (slang elaborates parameterized instances to names like
14+
+# 'foo$bar.gen_tiles[0].i_tile.gen_banks[3]'), so a greedy sed regex is
15+
+# unsafe. Module names cannot contain '"', so extracting all quoted
16+
+# strings and skipping the first ("modules" key) is correct.
17+
+ALL_MODULES=$(grep -oE '"[^"]+"' "$KEPT_JSON" | tail -n +2 | sed 's/"//g')
18+
19+
# When SYNTH_SKIP_KEEP=1, the keep-hierarchy discovery was skipped.
20+
# Partitions read from canonical RTLIL and run full synthesis (coarse+fine).

0 commit comments

Comments
 (0)