Skip to content

Commit 73747f6

Browse files
committed
read_verilog: add -relativeshare for synthesis reproducibility testing
1 parent 175e024 commit 73747f6

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

frontends/verilog/verilog_frontend.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ struct VerilogFrontend : public Frontend {
229229
log(" add 'dir' to the directories which are used when searching include\n");
230230
log(" files\n");
231231
log("\n");
232+
log(" -relativeshare\n");
233+
log(" use paths relative to share directory for source locations\n");
234+
log(" where possible (experimental).\n");
235+
log("\n");
232236
log("The command 'verilog_defaults' can be used to register default options for\n");
233237
log("subsequent calls to 'read_verilog'.\n");
234238
log("\n");
@@ -273,6 +277,7 @@ struct VerilogFrontend : public Frontend {
273277
bool flag_nowb = false;
274278
bool flag_nosynthesis = false;
275279
bool flag_yydebug = false;
280+
bool flag_relative_share = false;
276281
define_map_t defines_map;
277282

278283
std::list<std::string> include_dirs;
@@ -450,6 +455,11 @@ struct VerilogFrontend : public Frontend {
450455
attributes.push_back(RTLIL::escape_id(args[++argidx]));
451456
continue;
452457
}
458+
if (arg == "-relativeshare") {
459+
flag_relative_share = true;
460+
log_experimental("read_verilog -relativeshare");
461+
continue;
462+
}
453463
if (arg == "-D" && argidx+1 < args.size()) {
454464
std::string name = args[++argidx], value;
455465
size_t equal = name.find('=');
@@ -490,6 +500,13 @@ struct VerilogFrontend : public Frontend {
490500
log("Parsing %s%s input from `%s' to AST representation.\n",
491501
parse_mode.formal ? "formal " : "", parse_mode.sv ? "SystemVerilog" : "Verilog", filename.c_str());
492502

503+
log("verilog frontend filename %s\n", filename.c_str());
504+
if (flag_relative_share) {
505+
auto share_path = proc_share_dirname();
506+
if (filename.substr(0, share_path.length()) == share_path)
507+
filename = std::string("+/") + filename.substr(share_path.length());
508+
log("new filename %s\n", filename.c_str());
509+
}
493510
AST::sv_mode_but_global_and_used_for_literally_one_condition = parse_mode.sv;
494511
std::string code_after_preproc;
495512

passes/techmap/techmap.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,10 @@ struct TechmapPass : public Pass {
10321032
log(" -dont_map <celltype>\n");
10331033
log(" leave the given cell type unmapped by ignoring any mapping rules for it\n");
10341034
log("\n");
1035+
log(" -relativeshare\n");
1036+
log(" use paths relative to share directory for source locations\n");
1037+
log(" where possible (experimental).\n");
1038+
log("\n");
10351039
log("When a module in the map file has the 'techmap_celltype' attribute set, it will\n");
10361040
log("match cells with a type that match the text value of this attribute. Otherwise\n");
10371041
log("the module name will be used to match the cell. Multiple space-separated cell\n");
@@ -1185,6 +1189,11 @@ struct TechmapPass : public Pass {
11851189
verilog_frontend += " -I " + args[++argidx];
11861190
continue;
11871191
}
1192+
if (args[argidx] == "-relativeshare") {
1193+
verilog_frontend += " -relativeshare";
1194+
log_experimental("techmap -relativeshare");
1195+
continue;
1196+
}
11881197
if (args[argidx] == "-assert") {
11891198
worker.assert_mode = true;
11901199
continue;

techlibs/common/synth.cc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,17 @@ struct SynthPass : public ScriptPass {
9898
log(" mapping library in the `techmap` step. this option can be\n");
9999
log(" repeated.\n");
100100
log("\n");
101+
log(" -relativeshare\n");
102+
log(" use paths relative to share directory for source locations\n");
103+
log(" where possible (experimental).\n");
104+
log("\n");
101105
log("The following commands are executed by this synthesis command:\n");
102106
help_script();
103107
log("\n");
104108
}
105109

106110
string top_module, fsm_opts, memory_opts, abc;
107-
bool autotop, flatten, noalumacc, nofsm, noabc, noshare, flowmap, booth, hieropt;
111+
bool autotop, flatten, noalumacc, nofsm, noabc, noshare, flowmap, booth, hieropt, relative_share;
108112
int lut;
109113
std::vector<std::string> techmap_maps;
110114

@@ -124,6 +128,7 @@ struct SynthPass : public ScriptPass {
124128
flowmap = false;
125129
booth = false;
126130
hieropt = false;
131+
relative_share = false;
127132
abc = "abc";
128133
techmap_maps.clear();
129134
}
@@ -211,6 +216,11 @@ struct SynthPass : public ScriptPass {
211216
hieropt = true;
212217
continue;
213218
}
219+
if (args[argidx] == "-relativeshare") {
220+
relative_share = true;
221+
log_experimental("synth -relativeshare");
222+
continue;
223+
}
214224
break;
215225
}
216226
extra_args(args, argidx, design);
@@ -239,6 +249,10 @@ struct SynthPass : public ScriptPass {
239249
else
240250
hieropt_flag = hieropt ? " -hier" : "";
241251

252+
std::string techmap_cmd = "techmap";
253+
if (relative_share)
254+
techmap_cmd += " -relativeshare";
255+
242256
if (check_label("begin")) {
243257
if (help_mode) {
244258
run("hierarchy -check [-top <top> | -auto-top]");
@@ -268,9 +282,9 @@ struct SynthPass : public ScriptPass {
268282
run("peepopt");
269283
run("opt_clean");
270284
if (help_mode)
271-
run("techmap -map +/cmp2lut.v -map +/cmp2lcu.v", " (if -lut)");
285+
run(techmap_cmd + " -map +/cmp2lut.v -map +/cmp2lcu.v", " (if -lut)");
272286
else if (lut)
273-
run(stringf("techmap -map +/cmp2lut.v -map +/cmp2lcu.v -D LUT_WIDTH=%d", lut));
287+
run(stringf("%s -map +/cmp2lut.v -map +/cmp2lcu.v -D LUT_WIDTH=%d", techmap_cmd, lut));
274288
if (booth || help_mode)
275289
run("booth", " (if -booth)");
276290
if (!noalumacc)
@@ -287,22 +301,22 @@ struct SynthPass : public ScriptPass {
287301
run("memory_map");
288302
run("opt -full");
289303
if (help_mode) {
290-
run("techmap", " (unless -extra-map)");
291-
run("techmap -map +/techmap.v -map <inject>", " (if -extra-map)");
304+
run(techmap_cmd, " (unless -extra-map)");
305+
run(techmap_cmd + " -map +/techmap.v -map <inject>", " (if -extra-map)");
292306
} else {
293307
std::string techmap_opts;
294308
if (!techmap_maps.empty())
295309
techmap_opts += " -map +/techmap.v";
296310
for (auto fn : techmap_maps)
297311
techmap_opts += stringf(" -map %s", fn);
298-
run("techmap" + techmap_opts);
312+
run(techmap_cmd + techmap_opts);
299313
}
300314
if (help_mode) {
301-
run("techmap -map +/gate2lut.v", "(if -noabc and -lut)");
315+
run(techmap_cmd + " -map +/gate2lut.v", "(if -noabc and -lut)");
302316
run("clean; opt_lut", " (if -noabc and -lut)");
303317
run("flowmap -maxlut K", " (if -flowmap and -lut)");
304318
} else if (noabc && lut) {
305-
run(stringf("techmap -map +/gate2lut.v -D LUT_WIDTH=%d", lut));
319+
run(stringf("%s -map +/gate2lut.v -D LUT_WIDTH=%d", techmap_cmd, lut));
306320
run("clean; opt_lut");
307321
} else if (flowmap) {
308322
run(stringf("flowmap -maxlut %d", lut));

techlibs/fabulous/synth_fabulous.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct SynthPass : public ScriptPass
6969
log(" use the specified Verilog file for extra primitives (can be specified multiple\n");
7070
log(" times).\n");
7171
log("\n");
72-
log(" -extra-map <techamp.v>\n");
72+
log(" -extra-map <techmap.v>\n");
7373
log(" use the specified Verilog file for extra techmap rules (can be specified multiple\n");
7474
log(" times).\n");
7575
log("\n");

tests/functional/test_functional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def compile_cpp(in_path, out_path, args):
2424
run(['g++', '-g', '-std=c++17'] + args + [str(in_path), '-o', str(out_path)])
2525

2626
def yosys_synth(verilog_file, rtlil_file):
27-
yosys(f"read_verilog {quote(verilog_file)} ; prep ; setundef -undriven ; write_rtlil {quote(rtlil_file)}")
27+
yosys(f"read_verilog {quote(verilog_file)} ; prep ; setundef -undriven -undef ; write_rtlil {quote(rtlil_file)}")
2828

2929
# simulate an rtlil file with yosys, comparing with a given vcd file, and writing out the yosys simulation results into a second vcd file
3030
def yosys_sim(rtlil_file, vcd_reference_file, vcd_out_file, preprocessing = ""):
@@ -91,4 +91,4 @@ def test_print_graph(tmp_path):
9191
tb_file = base_path / 'tests/functional/picorv32_tb.v'
9292
cpu_file = base_path / 'tests/functional/picorv32.v'
9393
# currently we only check that we can print the graph without getting an error, not that it prints anything sensibl
94-
yosys(f"read_verilog {quote(tb_file)} {quote(cpu_file)}; prep -top gold; setundef -undriven ; flatten; clk2fflogic; test_generic")
94+
yosys(f"read_verilog {quote(tb_file)} {quote(cpu_file)}; prep -top gold; setundef -undriven -undef ; flatten; clk2fflogic; test_generic")

0 commit comments

Comments
 (0)