hdl,back,sim: accept .as_signed() and .as_unsigned() on LHS.

These operators are ignored when they are encountered on LHS, as
the signedness of the assignment target does not matter in Amaranth.
.as_signed() appears on LHS of assigns to signed aggregate fields.
This commit is contained in:
Catherine 2022-04-06 04:15:48 +00:00
parent 90fcbfc357
commit da26f1c915
4 changed files with 20 additions and 0 deletions

View file

@ -652,6 +652,11 @@ class _LHSValueCompiler(_ValueCompiler):
raise TypeError # :nocov:
def on_Operator(self, value):
if value.operator in ("u", "s"):
# These operators are transparent on the LHS.
arg, = value.operands
return self(arg)
raise TypeError # :nocov:
def match_shape(self, value, new_bits, new_sign):

View file

@ -734,6 +734,11 @@ class Operator(Value):
raise NotImplementedError("Operator {}/{} not implemented"
.format(self.operator, len(op_shapes))) # :nocov:
def _lhs_signals(self):
if self.operator in ("u", "s"):
return union(op._lhs_signals() for op in self.operands)
return super()._lhs_signals()
def _rhs_signals(self):
return union(op._rhs_signals() for op in self.operands)

View file

@ -279,6 +279,8 @@ class _LHSValueCompiler(_ValueCompiler):
return gen
def on_Operator(self, value):
if value.operator in ("u", "s"):
return self(value.operands[0])
raise TypeError # :nocov:
def on_Slice(self, value):