diff --git a/examples/dataflow/arithmetic.py b/examples/dataflow/arithmetic.py index 63f97b167..bd3e037b4 100644 --- a/examples/dataflow/arithmetic.py +++ b/examples/dataflow/arithmetic.py @@ -4,7 +4,7 @@ import matplotlib.pyplot as plt import networkx as nx from migen.flow.network import * -from migen.flow.composer import * +from migen.actorlib.ala import * from migen.actorlib.sim import * from migen.sim.generic import Simulator from migen.sim.icarus import Runner @@ -30,23 +30,23 @@ class Dumper(SimActor): def draw(g): if len(sys.argv) > 1 and sys.argv[1] == "draw": - nx.draw(g) + nx.draw_spectral(g) plt.show() def main(): # Create graph g = DataFlowGraph() - gen1 = ComposableSource(g, NumberGen()) - gen2 = ComposableSource(g, NumberGen()) + gen1 = ComposableNode(g, NumberGen()) + gen2 = ComposableNode(g, NumberGen()) ps = gen1 + gen2 result = ps*gen1 + ps*gen2 - g.add_connection(result.actor_node, ActorNode(Dumper())) + g.add_connection(result, ActorNode(Dumper())) - gen1.actor_node.actor.name = "gen1" - gen2.actor_node.actor.name = "gen2" - result.actor_node.name = "result" + gen1.actor.name = "gen1" + gen2.actor.name = "gen2" + result.name = "result" # Elaborate print("is_abstract before elaboration: " + str(g.is_abstract())) diff --git a/migen/actorlib/ala.py b/migen/actorlib/ala.py index 992141826..fe92c8843 100644 --- a/migen/actorlib/ala.py +++ b/migen/actorlib/ala.py @@ -1,6 +1,7 @@ from migen.fhdl.structure import * from migen.fhdl.structure import _Operator from migen.flow.actor import * +from migen.flow.network import * from migen.corelogic.record import * from migen.corelogic import divider @@ -79,3 +80,64 @@ class DivMod(SequentialActor): def get_process_fragment(self): return self.div.get_fragment() + Fragment([self.div.start_i.eq(self.trigger)]) + +def _create(a, b, actor_class): + assert id(a.dfg) == id(b.dfg) + dfg = a.dfg + + bva = a.get_dict()["bv_r"] + bvb = b.get_dict()["bv_r"] + bv_op = BV(max(bva.width, bvb.width), bva.signed and bvb.signed) + bv_r = actor_class.get_result_bv(bv_op) + + new_actor = ComposableNode(dfg, actor_class, {"bv_op": bv_op, "bv_r": bv_r}) + dfg.add_connection(a, new_actor, "result", "operands", sink_subr=["a"]) + dfg.add_connection(b, new_actor, "result", "operands", sink_subr=["b"]) + + return new_actor + +class ComposableNode(ActorNode): + def __init__(self, dfg, actor_class, parameters=dict()): + self.dfg = dfg + super().__init__(actor_class, parameters) + + def __hash__(self): + return id(self) + + def __add__(self, other): + return _create(self, other, Add) + def __radd__(self, other): + return _create(other, self, Add) + def __sub__(self, other): + return _create(self, other, Sub) + def __rsub__(self, other): + return _create(other, self, Sub) + def __mul__(self, other): + return _create(self, other, Mul) + def __rmul__(self, other): + return _create(other, self, Mul) + def __and__(self, other): + return _create(self, other, And) + def __rand__(self, other): + return _create(other, self, And) + def __xor__(self, other): + return _create(self, other, Xor) + def __rxor__(self, other): + return _create(other, self, Xor) + def __or__(self, other): + return _create(self, other, Or) + def __ror__(self, other): + return _create(other, self, Or) + + def __lt__(self, other): + return _create(self, other, LT) + def __le__(self, other): + return _create(self, other, LE) + def __eq__(self, other): + return _create(self, other, EQ) + def __ne__(self, other): + return _create(self, other, NE) + def __gt__(self, other): + return _create(other, self, LT) + def __ge__(self, other): + return _create(other, self, LE) diff --git a/migen/actorlib/composer.py b/migen/actorlib/composer.py deleted file mode 100644 index d8d86ce02..000000000 --- a/migen/actorlib/composer.py +++ /dev/null @@ -1,66 +0,0 @@ -# TODO: merge this into ala + derive ComposableSource from ActorNode - -from migen.flow.actor import * -from migen.flow.plumbing import * -from migen.flow.network import * -from migen.actorlib.ala import * - -def _create(a, b, actor_class): - assert id(a.dfg) == id(b.dfg) - dfg = a.dfg - - bva = a.actor_node.get_dict()["bv_r"] - bvb = b.actor_node.get_dict()["bv_r"] - bv_op = BV(max(bva.width, bvb.width), bva.signed and bvb.signed) - bv_r = actor_class.get_result_bv(bv_op) - - new_actor = ActorNode(actor_class, {"bv_op": bv_op, "bv_r": bv_r}) - dfg.add_connection(a.actor_node, new_actor, "result", "operands", sink_subr=["a"]) - dfg.add_connection(b.actor_node, new_actor, "result", "operands", sink_subr=["b"]) - - return ComposableSource(dfg, new_actor) - -class ComposableSource: - def __init__(self, dfg, actor_node): - self.dfg = dfg - if not isinstance(actor_node, ActorNode): - actor_node = ActorNode(actor_node) - self.actor_node = actor_node - - def __add__(self, other): - return _create(self, other, Add) - def __radd__(self, other): - return _create(other, self, Add) - def __sub__(self, other): - return _create(self, other, Sub) - def __rsub__(self, other): - return _create(other, self, Sub) - def __mul__(self, other): - return _create(self, other, Mul) - def __rmul__(self, other): - return _create(other, self, Mul) - def __and__(self, other): - return _create(self, other, And) - def __rand__(self, other): - return _create(other, self, And) - def __xor__(self, other): - return _create(self, other, Xor) - def __rxor__(self, other): - return _create(other, self, Xor) - def __or__(self, other): - return _create(self, other, Or) - def __ror__(self, other): - return _create(other, self, Or) - - def __lt__(self, other): - return _create(self, other, LT) - def __le__(self, other): - return _create(self, other, LE) - def __eq__(self, other): - return _create(self, other, EQ) - def __ne__(self, other): - return _create(self, other, NE) - def __gt__(self, other): - return _create(other, self, LT) - def __ge__(self, other): - return _create(other, self, LE)