Skip to content

Commit

Permalink
Merge 5405592 into f1f516d
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed May 20, 2019
2 parents f1f516d + 5405592 commit d3904ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
22 changes: 12 additions & 10 deletions fault/verilator_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ def __init__(self, circuit, directory="build/",
# works
self.verilator_version = float(verilator_version.split()[1])

def process_signed_values(self, port, value):
if isinstance(value, (int, BitVector)) and value < 0:
# Handle sign extension for verilator since it expects and unsigned
# c type
if isinstance(port, SelectPath):
port = port[-1]
port_len = len(port)
value = BitVector(value, port_len).as_uint()
return value

def make_poke(self, i, action):
if self.verilator_version > 3.874:
prefix = f"{self.circuit_name}"
Expand Down Expand Up @@ -169,11 +179,7 @@ def make_poke(self, i, action):
value = action.value
if isinstance(value, actions.FileRead):
value = f"*{value.file.name_without_ext}_in"
if isinstance(action.port, m.SIntType) and value < 0:
# Handle sign extension for verilator since it expects and
# unsigned c type
port_len = len(action.port)
value = BitVector(value, port_len).as_uint()
value = self.process_signed_values(action.port, value)
result = [f"top->{name} = {value};"]
# Hack to support verilator's semantics, need to set the register
# mux values for expected behavior
Expand Down Expand Up @@ -238,11 +244,7 @@ def make_expect(self, i, action):
circuit_name = type(item.instance).name
self.debug_includes.add(f"{circuit_name}")
value = f"top->{prefix}->" + value.select_path.verilator_path
elif isinstance(action.port, m.SIntType) and value < 0:
# Handle sign extension for verilator since it expects and
# unsigned c type
port_len = len(action.port)
value = BitVector(value, port_len).as_uint()
value = self.process_signed_values(action.port, value)

return [f"my_assert(top->{name}, {value}, "
f"{i}, \"{debug_name}\");"]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_verilog_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def test_target_clock(capfd, target, simulator):
assert lines[-5] == "0", out
assert lines[-4] == "1", out
elif simulator == "vcs":
assert lines[-10] == "0", out
assert lines[-9] == "0", out
assert lines[-8] == "0", out
assert lines[-7] == "1", out
assert lines[-8] == "1", out
else:
raise NotImplementedError(f"Unsupported simulator: {simulator}")

Expand All @@ -148,7 +148,7 @@ def test_print_nested_arrays(capfd, target, simulator):
if simulator == "ncsim":
actual = "\n".join(out.splitlines()[-9 - 3: -3])
elif simulator == "vcs":
actual = "\n".join(out.splitlines()[-9 - 6: -6])
actual = "\n".join(out.splitlines()[-9 - 7: -7])
else:
raise NotImplementedError(f"Unsupported simulator: {simulator}")
assert actual == """\
Expand Down Expand Up @@ -186,7 +186,7 @@ def test_print_double_nested_arrays(capfd, target, simulator):
if simulator == "ncsim":
actual = "\n".join(out.splitlines()[-18 - 3: -3])
elif simulator == "vcs":
actual = "\n".join(out.splitlines()[-18 - 6: -6])
actual = "\n".join(out.splitlines()[-18 - 7: -7])
else:
raise NotImplementedError(f"Unsupported simulator: {simulator}")
assert actual == """\
Expand Down

0 comments on commit d3904ce

Please sign in to comment.