Skip to content

Commit

Permalink
Merge 204ead2 into 00d3ee0
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardt committed May 15, 2019
2 parents 00d3ee0 + 204ead2 commit 246bf69
Showing 1 changed file with 12 additions and 10 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

0 comments on commit 246bf69

Please sign in to comment.