Skip to content

Commit f6f4170

Browse files
committed
modify xs generation and fix preprocess for new chisel
1 parent ce376fc commit f6f4170

2 files changed

Lines changed: 68 additions & 3 deletions

File tree

.github/workflows/sta.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ jobs:
2727
- name: Build XiangShan
2828
run: |
2929
cd $NOOP_HOME
30-
make verilog DEBUG_ARGS="--difftest-config ESBIFDU --difftest-exclude Vec" FPGA=1 WITH_CHISELDB=0 WITH_CONSTANTIN=0 CONFIG=XSNoCDiffTopConfig -j10
30+
make verilog CHISEL_TARGET=chirrtl DEBUG_ARGS="--difftest-config ESBIFDU" FPGA=1 WITH_CHISELDB=0 WITH_CONSTANTIN=0 CONFIG=FpgaDiffDefaultConfig -j64
3131
3232
- name: Build DiffTest
3333
run: |
3434
cd $NOOP_HOME/difftest
3535
export NOOP_HOME=$(pwd)
36-
make difftest_verilog PROFILE=../build/generated-src/difftest_profile.json NUMCORES=1 CONFIG=ESBIFDU
37-
36+
make difftest_verilog PROFILE=../build/generated-src/difftest_profile.json NUM_CORES=1 CONFIG=ESBIFDU -j64
37+
3838
- name: Run STA
3939
run: |
4040
export PATH=/nfs/home/share/tools/yosys:$PATH

scripts/ieda/sv_preprocessor.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@
2020
1. string type declarations - Comment out
2121
2. automatic keyword - Remove
2222
3. Assignment pattern syntax '{...} - Convert to compatible format
23+
4. procedural logic declaration initialization - Split declaration and assignment
2324
"""
2425

2526
import re
2627
import sys
2728
import os
2829

30+
PROCEDURAL_START_RE = re.compile(r'^\s*(always(?:_\w+)?|initial|final)\b')
31+
LOGIC_INIT_DECL_RE = re.compile(
32+
r'^(\s*)logic\s+'
33+
r'((?:signed\s+)?(?:\[[^\]]+\]\s*)*)'
34+
r'([A-Za-z_][A-Za-z0-9_$]*)'
35+
r'(\s*(?:\[[^\]]+\]\s*)*)'
36+
r'\s*=\s*(.*?);\s*(//.*)?$'
37+
)
38+
2939
def preprocess_automatic_keyword(content):
3040
"""
3141
Remove automatic keyword (not supported by Yosys)
@@ -42,6 +52,58 @@ def preprocess_automatic_keyword(content):
4252

4353
return content
4454

55+
def preprocess_procedural_logic_initialization(content):
56+
"""
57+
Split initialized logic declarations inside procedural blocks.
58+
59+
Yosys accepts local declarations in procedural blocks, but rejects
60+
declaration-time initialization there.
61+
62+
Original:
63+
always_comb begin
64+
logic tmp = in_valid & in_ready;
65+
end
66+
67+
Converted:
68+
always_comb begin
69+
logic tmp;
70+
tmp = in_valid & in_ready;
71+
end
72+
"""
73+
lines = content.splitlines()
74+
result = []
75+
procedural_depth = 0
76+
77+
def count_keyword(line, keyword):
78+
code = line.split('//', 1)[0]
79+
return len(re.findall(rf'\b{keyword}\b', code))
80+
81+
for line in lines:
82+
in_procedural = procedural_depth > 0
83+
match = LOGIC_INIT_DECL_RE.match(line) if in_procedural else None
84+
85+
if match:
86+
indent, packed_dims, name, unpacked_dims, initializer, comment = match.groups()
87+
packed_dims = ' '.join(packed_dims.split())
88+
unpacked_dims = ''.join(unpacked_dims.split())
89+
dims = f' {packed_dims}' if packed_dims else ''
90+
comment = f' {comment}' if comment else ''
91+
result.append(f"{indent}logic{dims} {name}{unpacked_dims};")
92+
result.append(f"{indent}{name} = {initializer};{comment}")
93+
else:
94+
result.append(line)
95+
96+
begins = count_keyword(line, 'begin')
97+
ends = count_keyword(line, 'end')
98+
if PROCEDURAL_START_RE.match(line):
99+
procedural_depth += max(begins - ends, 1)
100+
elif procedural_depth > 0:
101+
procedural_depth += begins - ends
102+
if procedural_depth < 0:
103+
procedural_depth = 0
104+
105+
return '\n'.join(result) + ('\n' if content.endswith('\n') else '')
106+
45107
def preprocess_string_type(content):
46108
"""
47109
Comment out string type declarations (not supported by Yosys)
@@ -137,6 +199,9 @@ def preprocess_file(input_file, output_file):
137199
# Remove automatic keyword
138200
content = preprocess_automatic_keyword(content)
139201

202+
# Split initialized procedural logic declarations
203+
content = preprocess_procedural_logic_initialization(content)
204+
140205
# Comment out string type declarations
141206
content = preprocess_string_type(content)
142207

0 commit comments

Comments
 (0)