ALA: use records for tokens

This commit is contained in:
Sebastien Bourdeauducq 2012-01-06 14:32:00 +01:00
parent 1905eb3707
commit a3bf877802
1 changed files with 13 additions and 11 deletions

View File

@ -1,27 +1,29 @@
from migen.fhdl.structure import * from migen.fhdl.structure import *
from migen.flow.actor import * from migen.flow.actor import *
from migen.corelogic.record import *
from migen.corelogic import divider from migen.corelogic import divider
class Sum(Actor): class Adder(Actor):
def __init__(self, width): def __init__(self, width):
self.a = Signal(BV(width)) self.operands = Record([('a', BV(width)), ('b', BV(width))])
self.b = Signal(BV(width)) self.result = Record(['sum', BV(width+1)])
self.r = Signal(BV(width+1))
Actor.__init__(self, Actor.__init__(self,
SchedulingModel(SchedulingModel.COMBINATORIAL), SchedulingModel(SchedulingModel.COMBINATORIAL),
[Sink(self, [self.a, self.b])], [Sink(self, self.operands)],
[Source(self, self.r)]) [Source(self, self.result)])
def get_process_fragment(self): def get_process_fragment(self):
return Fragment([self.r.eq(self.a + self.b)]) return Fragment([self.result.sum.eq(self.operands.a + self.operands.b)])
class Divider(Actor): class Divider(Actor):
def __init__(self, width): def __init__(self, width):
self.div = divider.Inst(width) self.div = divider.Inst(width)
self.operands = Record([('dividend', self.div.dividend_i), ('divisor', self.div.divisor_i)])
self.result = Record([('quotient', self.div.quotient_o), ('remainder', self.div.remainder_o)])
Actor.__init__(self, Actor.__init__(self,
SchedulingModel(SchedulingModel.SEQUENTIAL, width), SchedulingModel(SchedulingModel.SEQUENTIAL, width),
[Sink(self, [self.div.dividend_i]), Sink(self, [self.div.divisor_i])], [Sink(self, [self.operands])],
[Source(self, [self.div.quotient_o]), Source(self, [self.div.remainder_o])]) [Source(self, [self.result])])
def get_process_fragment(self): def get_process_fragment(self):
return self.div.get_fragment() + Fragment([self.div.start_i.eq(self.trigger)]) return self.div.get_fragment() + Fragment([self.div.start_i.eq(self.trigger)])