pytholite/reg: use source id in dictionary

This commit is contained in:
Sebastien Bourdeauducq 2012-11-29 00:09:35 +01:00
parent fee22a4631
commit 070652cc39
1 changed files with 6 additions and 4 deletions

View File

@ -14,7 +14,7 @@ class AbstractLoad:
def lower(self): def lower(self):
if not self.target.finalized: if not self.target.finalized:
raise FinalizeError raise FinalizeError
return self.target.sel.eq(self.target.source_encoding[self.source]) return self.target.sel.eq(self.target.source_encoding[id(self.source)])
class LowerAbstractLoad(fhdl.NodeTransformer): class LowerAbstractLoad(fhdl.NodeTransformer):
def visit_unknown(self, node): def visit_unknown(self, node):
@ -28,11 +28,13 @@ class ImplRegister:
self.name = name self.name = name
self.storage = Signal(BV(nbits), name=self.name) self.storage = Signal(BV(nbits), name=self.name)
self.source_encoding = {} self.source_encoding = {}
self.id_to_source = {}
self.finalized = False self.finalized = False
def load(self, source): def load(self, source):
if source not in self.source_encoding: if id(source) not in self.source_encoding:
self.source_encoding[source] = len(self.source_encoding) + 1 self.source_encoding[id(source)] = len(self.source_encoding) + 1
self.id_to_source[id(source)] = source
return AbstractLoad(self, source) return AbstractLoad(self, source)
def finalize(self): def finalize(self):
@ -46,6 +48,6 @@ class ImplRegister:
raise FinalizeError raise FinalizeError
# do nothing when sel == 0 # do nothing when sel == 0
items = sorted(self.source_encoding.items(), key=itemgetter(1)) items = sorted(self.source_encoding.items(), key=itemgetter(1))
cases = [(v, self.storage.eq(k)) for k, v in items] cases = [(v, self.storage.eq(self.id_to_source[k])) for k, v in items]
sync = [Case(self.sel, *cases)] sync = [Case(self.sel, *cases)]
return Fragment(sync=sync) return Fragment(sync=sync)