litex/examples/pytholite/basic.py

38 lines
918 B
Python
Raw Normal View History

2012-11-16 13:34:34 -05:00
from migen.flow.network import *
from migen.actorlib.sim import *
from migen.pytholite.compiler import make_pytholite
from migen.sim.generic import Simulator
from migen.sim.icarus import Runner
from migen.fhdl import verilog
2012-11-16 13:34:34 -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-11-16 13:34:34 -05:00
g.add_connection(ActorNode(ng), ActorNode(d))
c = CompositeActor(g)
fragment = c.get_fragment()
sim = Simulator(fragment, Runner())
sim.run(30)
del sim
def main():
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)
print("Converting Pytholite to Verilog:")
print(verilog.convert(ng_pytholite.get_fragment()))
2012-11-16 13:34:34 -05:00
main()