litex/examples/pytholite/basic.py

43 lines
1006 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})
2013-04-10 13:12:42 -04:00
class SimNumberGen(SimActor):
def __init__(self):
self.result = Source(layout)
SimActor.__init__(self, number_gen())
2012-11-16 13:34:34 -05:00
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:")
2013-04-10 13:12:42 -04:00
ng_native = SimNumberGen()
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-04-10 13:12:42 -04:00
ng_pytholite = make_pytholite(number_gen, dataflow=[("result", Source, layout)])
2013-03-12 11:59:24 -04:00
print(verilog.convert(ng_pytholite))
2012-11-16 13:34:34 -05:00
main()