Skip to content

Commit d931e40

Browse files
authored
Merge pull request #373 from pllab/iscas_bench_update
Rename ISCAS bench output wires if also an input
2 parents 2d3781b + 2bf2e10 commit d931e40

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

pyrtl/importexport.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from .pyrtlexceptions import PyrtlError, PyrtlInternalError
1414
from .core import working_block, _NameSanitizer
15-
from .wire import WireVector, Input, Output, Const, Register
15+
from .wire import WireVector, Input, Output, Const, Register, next_tempvar_name
1616
from .corecircuits import concat_list
1717
from .memory import RomBlock
1818
from .passes import two_way_concat, one_bit_selects
@@ -1055,3 +1055,20 @@ def twire(name):
10551055
dst_wire <<= reg
10561056
else:
10571057
raise PyrtlError("Unexpected gate {%s}" % cmd["gate"])
1058+
1059+
# Benchmarks like c1196, b18, etc. have inputs and outputs by the
1060+
# same name, that are therefore directly connected. This pass will
1061+
# rename the outputs so that this is still okay.
1062+
for o in block.wirevector_subset(Output):
1063+
inputs = [i for i in block.wirevector_subset(Input) if i.name == o.name]
1064+
if inputs:
1065+
if len(inputs) > 1:
1066+
raise PyrtlError("More than one input found with the name %s" % inputs[0].name)
1067+
i = inputs[0]
1068+
o_internal = twire(o.name)
1069+
o_internal <<= i
1070+
o.name = next_tempvar_name()
1071+
# Ensure the input is the one mapped by the original name
1072+
block.wirevector_by_name[i.name] = i
1073+
print("Found input and output wires with the same name. "
1074+
"Output '%s' has now been renamed to '%s'." % (i.name, o.name))

tests/test_importexport.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import random
33
import io
4+
import sys
45
import six
56
import pyrtl
67
from pyrtl.importexport import _VerilogSanitizer
@@ -1875,6 +1876,17 @@ def test_textual_consistency_selects(self):
18751876
G13 = NOR(G2, G12)
18761877
"""
18771878

1879+
example_bench_with_io_same_name = """\
1880+
INPUT(G1)
1881+
INPUT(G2)
1882+
INPUT(G3)
1883+
1884+
OUTPUT(G3)
1885+
OUTPUT(G4)
1886+
1887+
G4 = OR(G1, G2)
1888+
"""
1889+
18781890

18791891
class TestInputISCASBench(unittest.TestCase):
18801892
# NOTE: number of inverters = number of original inverters + number of NORs, since
@@ -1950,6 +1962,22 @@ def test_simulation_bench(self):
19501962
trace.print_trace(output, compact=True)
19511963
self.assertEqual(output.getvalue(), correct_output)
19521964

1965+
def test_bench_with_same_io_name(self):
1966+
output = six.StringIO()
1967+
sys.stdout = output
1968+
pyrtl.input_from_iscas_bench(example_bench_with_io_same_name)
1969+
sys.stdout = sys.__stdout__
1970+
1971+
self.assertEquals(
1972+
output.getvalue(),
1973+
"Found input and output wires with the same name. "
1974+
"Output 'G3' has now been renamed to 'tmp3'.\n"
1975+
)
1976+
pyrtl.working_block().sanity_check()
1977+
1978+
self.check_io(pyrtl.Input, ['G1', 'G2', 'G3'])
1979+
self.check_io(pyrtl.Output, ['tmp3', 'G4'])
1980+
19531981

19541982
if __name__ == "__main__":
19551983
unittest.main()

0 commit comments

Comments
 (0)