from migen.fhdl.structure import (_Value, _Statement,
_Operator, _Slice, _ArrayProxy,
_Assign, _Fragment)
+from migen.fhdl.bitcontainer import value_bits_sign
from migen.fhdl.tools import list_signals, list_targets, insert_resets
from migen.fhdl.simplify import MemoryToArray
from migen.fhdl.specials import _MemoryLocation
}
+def _truncate(value, nbits, signed):
+ value = value & (2**nbits - 1)
+ if signed and (value & 2**(nbits - 1)):
+ value -= 2**nbits
+ return value
+
+
class Evaluator:
def __init__(self, clock_domains, replaced_memories):
self.clock_domains = clock_domains
def assign(self, node, value):
if isinstance(node, Signal):
assert not node.variable
- value = value & (2**node.nbits - 1)
- if node.signed and (value & 2**(node.nbits - 1)):
- value -= 2**node.nbits
- self.modifications[node] = value
+ self.modifications[node] = _truncate(value,
+ node.nbits, node.signed)
elif isinstance(node, Cat):
for element in node.l:
nbits = len(element)
else:
self.execute(s.f)
elif isinstance(s, Case):
- test = self.eval(s.test)
+ nbits, signed = value_bits_sign(s.test)
+ test = _truncate(self.eval(s.test), nbits, signed)
for k, v in s.cases.items():
if isinstance(k, Constant) and k.value == test:
self.execute(v)