2012-11-16 13:34:34 -05:00
|
|
|
from migen.flow.network import *
|
2012-12-14 09:55:38 -05:00
|
|
|
from migen.flow.transactions import *
|
2012-11-16 13:34:34 -05:00
|
|
|
from migen.actorlib.sim import *
|
|
|
|
from migen.pytholite.compiler import make_pytholite
|
|
|
|
from migen.sim.generic import Simulator
|
2012-11-16 13:38:57 -05:00
|
|
|
from migen.fhdl import verilog
|
2012-11-16 13:34:34 -05:00
|
|
|
|
2012-11-29 15:22:38 -05:00
|
|
|
layout = [("r", 32)]
|
2012-11-16 13:34:34 -05:00
|
|
|
|
|
|
|
def number_gen():
|
|
|
|
for i in range(10):
|
|
|
|
yield Token("result", {"r": i})
|
|
|
|
|
|
|
|
def run_sim(ng):
|
|
|
|
g = DataFlowGraph()
|
2012-11-23 18:00:07 -05:00
|
|
|
d = Dumper(layout)
|
2012-12-12 16:20:48 -05:00
|
|
|
g.add_connection(ng, d)
|
2012-11-16 13:34:34 -05:00
|
|
|
|
|
|
|
c = CompositeActor(g)
|
|
|
|
fragment = c.get_fragment()
|
2013-02-09 11:04:53 -05:00
|
|
|
sim = Simulator(fragment)
|
2012-11-16 13:34:34 -05:00
|
|
|
sim.run(30)
|
|
|
|
del sim
|
|
|
|
|
|
|
|
def main():
|
2012-11-16 13:38:57 -05:00
|
|
|
print("Simulating native Python:")
|
|
|
|
ng_native = SimActor(number_gen(), ("result", Source, layout))
|
|
|
|
run_sim(ng_native)
|
|
|
|
|
2012-11-16 13:34:34 -05:00
|
|
|
print("Simulating Pytholite:")
|
|
|
|
ng_pytholite = make_pytholite(number_gen, dataflow=[("result", Source, layout)])
|
|
|
|
run_sim(ng_pytholite)
|
|
|
|
|
2012-11-16 13:38:57 -05:00
|
|
|
print("Converting Pytholite to Verilog:")
|
|
|
|
print(verilog.convert(ng_pytholite.get_fragment()))
|
2012-11-16 13:34:34 -05:00
|
|
|
|
|
|
|
main()
|