Accessing signals defined inside elaborate()
without prepending with self.
in simulation
#1584
-
Is it possible to access the signal from amaranth import *
from amaranth.lib.wiring import Component, In, Out
class C(Component):
o: Out(1)
def elaborate(self, platform):
m = Module()
s = Signal() # self.s = s = Signal() would work
m.d.sync += self.o.eq(s)
return m
from amaranth.sim import Period, Simulator
dut = C()
async def bench(ctx):
for _ in range(2):
await ctx.tick()
print(ctx.get(dut.s))
sim = Simulator(dut)
sim.add_clock(Period())
sim.add_testbench(bench)
sim.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you need to introspect the object state during simulation, I will advise creating and exposing the signals you need to access in |
Beta Was this translation helpful? Give feedback.
No, that's not what I'm talking about. It should be like:
The code you wrote will break if you instantiate the component multiple times, so you shouldn't use it.