mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
AutoCSR: refactor common gatherer code
This commit is contained in:
parent
7363f00867
commit
94a2499ce5
1 changed files with 12 additions and 26 deletions
|
@ -105,8 +105,8 @@ def memprefix(prefix, memories, done):
|
||||||
done.add(memory.huid)
|
done.add(memory.huid)
|
||||||
|
|
||||||
|
|
||||||
class AutoCSR:
|
def _make_gatherer(method, cls, prefix_cb):
|
||||||
def get_memories(self):
|
def gatherer(self):
|
||||||
try:
|
try:
|
||||||
exclude = self.autocsr_exclude
|
exclude = self.autocsr_exclude
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -118,30 +118,16 @@ class AutoCSR:
|
||||||
r = []
|
r = []
|
||||||
for k, v in xdir(self, True):
|
for k, v in xdir(self, True):
|
||||||
if k not in exclude:
|
if k not in exclude:
|
||||||
if isinstance(v, Memory):
|
if isinstance(v, cls):
|
||||||
r.append(v)
|
r.append(v)
|
||||||
elif hasattr(v, "get_memories") and callable(v.get_memories):
|
elif hasattr(v, method) and callable(getattr(v, method)):
|
||||||
memories = v.get_memories()
|
items = getattr(v, method)()
|
||||||
memprefix(k + "_", memories, prefixed)
|
prefix_cb(k + "_", items, prefixed)
|
||||||
r += memories
|
r += items
|
||||||
return sorted(r, key=lambda x: x.huid)
|
return sorted(r, key=lambda x: x.huid)
|
||||||
|
return gatherer
|
||||||
|
|
||||||
def get_csrs(self):
|
|
||||||
try:
|
class AutoCSR:
|
||||||
exclude = self.autocsr_exclude
|
get_memories = _make_gatherer("get_memories", Memory, memprefix)
|
||||||
except AttributeError:
|
get_csrs = _make_gatherer("get_csrs", _CSRBase, csrprefix)
|
||||||
exclude = {}
|
|
||||||
try:
|
|
||||||
prefixed = self.__prefixed
|
|
||||||
except AttributeError:
|
|
||||||
prefixed = self.__prefixed = set()
|
|
||||||
r = []
|
|
||||||
for k, v in xdir(self, True):
|
|
||||||
if k not in exclude:
|
|
||||||
if isinstance(v, _CSRBase):
|
|
||||||
r.append(v)
|
|
||||||
elif hasattr(v, "get_csrs") and callable(v.get_csrs):
|
|
||||||
csrs = v.get_csrs()
|
|
||||||
csrprefix(k + "_", csrs, prefixed)
|
|
||||||
r += csrs
|
|
||||||
return sorted(r, key=lambda x: x.huid)
|
|
||||||
|
|
Loading…
Reference in a new issue