litex/examples/dataflow/arithmetic.py

40 lines
838 B
Python
Raw Normal View History

2012-01-09 08:21:54 -05:00
import sys
2012-01-06 18:33:28 -05:00
2012-06-15 11:52:19 -04:00
import matplotlib.pyplot as plt
import networkx as nx
from migen.fhdl import verilog
2011-12-22 18:36:07 -05:00
from migen.flow.ala import *
2012-01-06 18:33:28 -05:00
from migen.flow.network import *
2012-01-08 07:56:11 -05:00
from migen.flow.composer import *
2012-01-06 11:24:05 -05:00
2012-06-15 11:52:19 -04:00
draw = len(sys.argv) > 1 and sys.argv[1] == "draw"
# Create graph
2012-06-08 16:49:49 -04:00
g = DataFlowGraph()
2012-06-15 11:52:19 -04:00
a1 = ComposableSource(g, Add(BV(16)))
a2 = ComposableSource(g, Add(BV(16)))
a3 = ComposableSource(g, Add(BV(16)))
2012-01-08 07:56:11 -05:00
c3 = (a1 + a2)*a3
2012-01-06 18:33:28 -05:00
2012-06-15 11:52:19 -04:00
a1.actor_node.name = "in1"
a2.actor_node.name = "in2"
a3.actor_node.name = "in3"
c3.actor_node.name = "result"
2012-01-09 08:21:54 -05:00
2012-06-15 11:52:19 -04:00
# Elaborate
print("is_abstract before elaboration: " + str(g.is_abstract()))
if draw:
2012-01-09 08:21:54 -05:00
nx.draw(g)
plt.show()
2012-06-15 11:52:19 -04:00
g.elaborate()
print("is_abstract after elaboration : " + str(g.is_abstract()))
if draw:
nx.draw(g)
plt.show()
# Convert
#c = CompositeActor(g)
#frag = c.get_fragment()
#print(verilog.convert(frag))