2012-01-08 07:56:11 -05:00
|
|
|
from migen.flow.actor import *
|
|
|
|
from migen.flow.ala import *
|
|
|
|
from migen.flow.plumbing import *
|
|
|
|
from migen.flow.network import *
|
|
|
|
|
2012-06-15 11:52:19 -04:00
|
|
|
def _create(a, b, actor_class):
|
2012-01-08 07:56:11 -05:00
|
|
|
assert id(a.dfg) == id(b.dfg)
|
2012-06-15 11:52:19 -04:00
|
|
|
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)
|
2012-01-08 07:56:11 -05:00
|
|
|
|
2012-06-15 11:52:19 -04:00
|
|
|
class ComposableSource:
|
|
|
|
def __init__(self, dfg, actor_node):
|
2012-01-08 07:56:11 -05:00
|
|
|
self.dfg = dfg
|
2012-06-15 11:52:19 -04:00
|
|
|
if not isinstance(actor_node, ActorNode):
|
|
|
|
actor_node = ActorNode(actor_node)
|
|
|
|
self.actor_node = actor_node
|
2012-01-08 07:56:11 -05:00
|
|
|
|
|
|
|
def __add__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, Add)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __radd__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(other, self, Add)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __sub__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, Sub)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __rsub__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(other, self, Sub)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __mul__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, Mul)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __rmul__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(other, self, Mul)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __and__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, And)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __rand__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(other, self, And)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __xor__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, Xor)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __rxor__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(other, self, Xor)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __or__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, Or)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __ror__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(other, self, Or)
|
2012-01-08 07:56:11 -05:00
|
|
|
|
|
|
|
def __lt__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, LT)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __le__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, LE)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __eq__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, EQ)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __ne__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(self, other, NE)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __gt__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(other, self, LT)
|
2012-01-08 07:56:11 -05:00
|
|
|
def __ge__(self, other):
|
2012-06-15 11:52:19 -04:00
|
|
|
return _create(other, self, LE)
|