From: whitequark Date: Sat, 26 Oct 2019 01:52:34 +0000 (+0000) Subject: back.rtlil: fix lowering of Part() on LHS to account for stride. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5f04ef2b518242b9298c4ec4eeadb42573e3e15f;p=nmigen.git back.rtlil: fix lowering of Part() on LHS to account for stride. --- diff --git a/examples/basic/sel.py b/examples/basic/sel.py new file mode 100644 index 0000000..b4797ec --- /dev/null +++ b/examples/basic/sel.py @@ -0,0 +1,30 @@ +from types import SimpleNamespace +from nmigen import * +from nmigen.cli import main + + +class FlatGPIO(Elaboratable): + def __init__(self, pins, bus): + self.pins = pins + self.bus = bus + + def elaborate(self, platform): + bus = self.bus + + m = Module() + m.d.comb += bus.r_data.eq(self.pins.word_select(bus.addr, len(bus.r_data))) + with m.If(bus.we): + m.d.sync += self.pins.word_select(bus.addr, len(bus.w_data)).eq(bus.w_data) + return m + + +if __name__ == "__main__": + bus = Record([ + ("addr", 3), + ("r_data", 2), + ("w_data", 2), + ("we", 1), + ]) + pins = Signal(8) + gpio = FlatGPIO(pins, bus) + main(gpio, ports=[pins, bus.addr, bus.r_data, bus.w_data, bus.we]) diff --git a/nmigen/back/rtlil.py b/nmigen/back/rtlil.py index 5a847c5..bb52721 100644 --- a/nmigen/back/rtlil.py +++ b/nmigen/back/rtlil.py @@ -622,9 +622,13 @@ class _LHSValueCompiler(_ValueCompiler): def on_Part(self, value): offset = self.s.expand(value.offset) if isinstance(offset, ast.Const): - return self(ast.Slice(value.value, offset.value, offset.value + value.width)) + return self(ast.Slice(value.value, + offset.value * value.stride, + offset.value * value.stride + value.width)) else: - raise LegalizeValue(value.offset, range((1 << len(value.offset))), value.src_loc) + raise LegalizeValue(value.offset, + range((1 << len(value.offset)) // value.stride), + value.src_loc) def on_Repl(self, value): raise TypeError # :nocov: