Skip to content

Commit d7ffb7f

Browse files
committed
Simplify Yosys script
1 parent 3bb27f4 commit d7ffb7f

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

pyrtl/importexport.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def input_from_verilog(verilog, clock_name='clk', toplevel=None, leave_in_dir=No
446446
447447
Note: This function is essentially a wrapper for `input_from_blif()`, with the added convenience
448448
of turning the Verilog into BLIF for import for you. This function passes a set of commands to
449-
Yosys as a script that is normally produces BLIF files that can be successuflly imported into
449+
Yosys as a script that normally produces BLIF files that can be successuflly imported into
450450
PyRTL via `input_from_blif()`. If the Yosys conversion fails here, we recommend you create your
451451
own custom Yosys script to try and produce BLIF yourself. Then you can import BLIF directly via
452452
`input_from_blif()`.
@@ -469,15 +469,6 @@ def input_from_verilog(verilog, clock_name='clk', toplevel=None, leave_in_dir=No
469469
else:
470470
raise PyrtlError('input_from_verilog expecting either open file or string')
471471

472-
if toplevel is None:
473-
module_lines = [line
474-
for line in verilog_string.split('\n')
475-
if ('module ' in line) and ('endmodule' not in line)]
476-
if module_lines:
477-
toplevel = re.match(r'\s*module\s+([^;(]*)', module_lines[0]).group(1).strip()
478-
if toplevel is None:
479-
raise PyrtlError('No module found in verilog file')
480-
481472
block = working_block(block)
482473

483474
# Create a temporary Verilog file
@@ -493,15 +484,15 @@ def input_from_verilog(verilog, clock_name='clk', toplevel=None, leave_in_dir=No
493484
yosys_arg_template = (
494485
"-p "
495486
"read_verilog %s; "
496-
"hierarchy -check -top %s; "
497-
"proc; opt; memory; opt; fsm; opt; "
498-
"techmap; opt; "
487+
"synth %s; "
499488
"setundef -zero -undriven; "
500489
"opt; "
501490
"write_blif %s; "
502491
)
503492

504-
yosys_arg = yosys_arg_template % (tmp_verilog_path, toplevel, tmp_blif_path)
493+
yosys_arg = yosys_arg_template % (tmp_verilog_path,
494+
('-top ' + toplevel) if toplevel is not None else '-auto-top',
495+
tmp_blif_path)
505496

506497
try:
507498
os.close(temp_vd)

tests/test_importexport.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,23 +1668,19 @@ def test_import_counter_with_reset(self):
16681668
sim.step_multiple({'rst': '1000'})
16691669
self.assertEqual(sim.tracer.trace['o'], [0, 2, 3, 4])
16701670

1671-
def test_import_multi_module_top_most_module(self):
1671+
def test_import_multi_module_specified_module(self):
16721672
# Import foo module because occurs first in file
1673-
pyrtl.input_from_verilog(verilog_input_multi_module)
1673+
pyrtl.input_from_verilog(verilog_input_multi_module, toplevel="foo")
16741674
sim = pyrtl.Simulation()
16751675
sim.step_multiple({'a': '0011', 'b': '0101'})
16761676
self.assertEqual(sim.tracer.trace['o'], [0, 1, 1, 2])
16771677

1678-
def test_import_multi_module_specified_module(self):
1679-
pyrtl.input_from_verilog(verilog_input_multi_module, toplevel='top')
1678+
def test_import_multi_module_auto_select_top_module(self):
1679+
pyrtl.input_from_verilog(verilog_input_multi_module)
16801680
sim = pyrtl.Simulation()
16811681
sim.step_multiple(nsteps=5)
16821682
self.assertEqual(sim.tracer.trace['o'], [0, 2, 0, 2, 0])
16831683

1684-
def test_error_import_no_module(self):
1685-
with self.assertRaisesRegex(pyrtl.PyrtlError, "No module found in verilog file"):
1686-
pyrtl.input_from_verilog("")
1687-
16881684
def test_error_import_bad_file(self):
16891685
with self.assertRaisesRegex(pyrtl.PyrtlError,
16901686
"input_from_verilog expecting either open file or string"):

0 commit comments

Comments
 (0)