litex/examples/pytholite/basic.py

37 lines
837 B
Python
Raw Normal View History

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
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-12-12 16:20:48 -05:00
g.add_connection(ng, d)
2012-11-16 13:34:34 -05:00
c = CompositeActor(g)
2013-03-12 11:59:24 -04:00
sim = Simulator(c)
2012-11-16 13:34:34 -05:00
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:")
2013-03-12 11:59:24 -04:00
print(verilog.convert(ng_pytholite))
2012-11-16 13:34:34 -05:00
main()