from migen.fhdl import verilog
from migen.corelogic.misc import optree
from migen.fhdl import autofragment
-from migen.sim.generic import Simulator
+from migen.sim.generic import Simulator, PureSimulable
from migen.sim.icarus import Runner
# A synthesizable FIR filter.
# A test bench for our FIR filter.
# Generates a sine wave at the input and records the output.
-class TB:
+class TB(PureSimulable):
def __init__(self, fir, frequency):
self.fir = fir
self.frequency = frequency
s.wr(self.fir.i, int(f*v))
self.inputs.append(v)
self.outputs.append(s.rd(self.fir.o)/f)
-
- def get_fragment(self):
- return Fragment(sim=[self.do_simulation])
def main():
# Compute filter coefficients with SciPy.
from migen.fhdl.structure import *
from migen.flow.actor import *
+from migen.sim.generic import PureSimulable
class Token:
def __init__(self, endpoint, value=None):
#
# NB: the possibility to push several tokens at once is important to interact
# with actors that only accept a group of tokens when all of them are available.
-class SimActor(Actor):
+class SimActor(Actor, PureSimulable):
def __init__(self, generator, *endpoint_descriptions, **misc):
self.generator = generator
self.active = set()
self._process_transactions(s)
else:
self._next_transactions()
-
- def get_fragment(self):
- return Fragment(sim=[self.do_simulation])
from migen.fhdl.structure import *
from migen.corelogic.misc import optree
from migen.bus.transactions import *
-from migen.sim.generic import Proxy
+from migen.sim.generic import Proxy, PureSimulable
class FinalizeError(Exception):
pass
]
return ports + Fragment(comb)
-class Tap:
+class Tap(PureSimulable):
def __init__(self, hub, handler=print):
self.hub = hub
self.handler = handler
transaction = self.tag_to_transaction[hub.tag_call]
transaction.latency = s.cycle_counter - transaction.latency + 1
self.transaction = transaction
-
- def get_fragment(self):
- return Fragment(sim=[self.do_simulation])
-class Initiator:
+class Initiator(PureSimulable):
def __init__(self, port, generator):
self.port = port
self.generator = generator
next(self._exe)
except StopIteration:
self.done = True
-
- def get_fragment(self):
- return Fragment(sim=[self.do_simulation])
class TargetModel:
def __init__(self):
self.last_slot += 1
return self.last_slot
-class Target:
+class Target(PureSimulable):
def __init__(self, hub, model):
self.hub = hub
self.model = model
else:
s.wr(self.hub.call, 0)
self._calling_tag = -1
-
- def get_fragment(self):
- return Fragment(sim=[self.do_simulation])
from migen.corelogic.misc import multimux, optree
from migen.bus.simple import *
from migen.bus.transactions import *
-from migen.sim.generic import Proxy
+from migen.sim.generic import Proxy, PureSimulable
_desc = Description(
(M_TO_S, "adr", 30),
def get_fragment(self):
return self._arbiter.get_fragment() + self._decoder.get_fragment()
-class Tap:
+class Tap(PureSimulable):
def __init__(self, bus, handler=print):
self.bus = bus
self.handler = handler
transaction = TRead(s.rd(self.bus.adr),
s.rd(self.bus.dat_r))
self.handler(transaction)
-
- def get_fragment(self):
- return Fragment(sim=[self.do_simulation])
-class Initiator:
+class Initiator(PureSimulable):
def __init__(self, generator):
self.generator = generator
self.bus = Interface()
else:
s.wr(self.bus.cyc, 0)
s.wr(self.bus.stb, 0)
-
- def get_fragment(self):
- return Fragment(sim=[self.do_simulation])
class TargetModel:
def read(self, address):
def can_ack(self, bus):
return True
-class Target:
+class Target(PureSimulable):
def __init__(self, model):
self.bus = Interface()
self.model = model
bus.ack = 1
else:
bus.ack = 0
-
- def get_fragment(self):
- return Fragment(sim=[self.do_simulation])
item = getattr(self._obj, name)
assert(isinstance(item, Signal))
self._sim.wr(item, value)
+
+class PureSimulable:
+ def do_simulation(self, s):
+ raise NotImplementedError("Need to overload do_simulation")
+
+ def get_fragment(self):
+ return Fragment(sim=[self.do_simulation])