hdl.ast: deprecate Value.part, add Value.{bit,word}_select.
Fixes #148.
This commit is contained in:
parent
bcdc280a87
commit
94e13effad
6 changed files with 105 additions and 29 deletions
|
|
@ -177,11 +177,12 @@ class _RHSValueCompiler(_ValueCompiler):
|
|||
return lambda state: normalize((arg(state) >> shift) & mask, shape)
|
||||
|
||||
def on_Part(self, value):
|
||||
shape = value.shape()
|
||||
arg = self(value.value)
|
||||
shift = self(value.offset)
|
||||
mask = (1 << value.width) - 1
|
||||
return lambda state: normalize((arg(state) >> shift(state)) & mask, shape)
|
||||
shape = value.shape()
|
||||
arg = self(value.value)
|
||||
shift = self(value.offset)
|
||||
mask = (1 << value.width) - 1
|
||||
stride = value.stride
|
||||
return lambda state: normalize((arg(state) >> shift(state) * stride) & mask, shape)
|
||||
|
||||
def on_Cat(self, value):
|
||||
shape = value.shape()
|
||||
|
|
@ -260,13 +261,14 @@ class _LHSValueCompiler(_ValueCompiler):
|
|||
return eval
|
||||
|
||||
def on_Part(self, value):
|
||||
lhs_r = self.rhs_compiler(value.value)
|
||||
lhs_l = self(value.value)
|
||||
shift = self.rhs_compiler(value.offset)
|
||||
mask = (1 << value.width) - 1
|
||||
lhs_r = self.rhs_compiler(value.value)
|
||||
lhs_l = self(value.value)
|
||||
shift = self.rhs_compiler(value.offset)
|
||||
mask = (1 << value.width) - 1
|
||||
stride = value.stride
|
||||
def eval(state, rhs):
|
||||
lhs_value = lhs_r(state)
|
||||
shift_value = shift(state)
|
||||
shift_value = shift(state) * stride
|
||||
lhs_value &= ~(mask << shift_value)
|
||||
lhs_value |= (rhs & mask) << shift_value
|
||||
lhs_l(state, lhs_value)
|
||||
|
|
|
|||
|
|
@ -532,6 +532,8 @@ class _RHSValueCompiler(_ValueCompiler):
|
|||
|
||||
def on_Part(self, value):
|
||||
lhs, rhs = value.value, value.offset
|
||||
if value.stride != 1:
|
||||
rhs *= value.stride
|
||||
lhs_bits, lhs_sign = lhs.shape()
|
||||
rhs_bits, rhs_sign = rhs.shape()
|
||||
res_bits, res_sign = value.shape()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue