mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
fhdl: support nested statement lists
This commit is contained in:
parent
47f5fc70e4
commit
badba89686
3 changed files with 13 additions and 4 deletions
|
@ -2,6 +2,14 @@ from migen.fhdl.structure import *
|
|||
from migen.fhdl.structure import _Operator, _Slice, _Assign, _ArrayProxy
|
||||
from migen.fhdl.visit import NodeVisitor, NodeTransformer
|
||||
|
||||
def flat_iteration(l):
|
||||
for element in l:
|
||||
if isinstance(element, (list, tuple)):
|
||||
for element2 in flat_iteration(element):
|
||||
yield element2
|
||||
else:
|
||||
yield element
|
||||
|
||||
class _SignalLister(NodeVisitor):
|
||||
def __init__(self):
|
||||
self.output_list = set()
|
||||
|
@ -35,7 +43,7 @@ def list_targets(node):
|
|||
|
||||
def group_by_targets(sl):
|
||||
groups = []
|
||||
for statement in sl:
|
||||
for statement in flat_iteration(sl):
|
||||
targets = list_targets(statement)
|
||||
processed = False
|
||||
for g in groups:
|
||||
|
|
|
@ -97,7 +97,7 @@ def _printnode(ns, at, level, node):
|
|||
else:
|
||||
assignment = " <= "
|
||||
return "\t"*level + _printexpr(ns, node.l)[0] + assignment + _printexpr(ns, node.r)[0] + ";\n"
|
||||
elif isinstance(node, list):
|
||||
elif isinstance(node, (list, tuple)):
|
||||
return "".join(list(map(partial(_printnode, ns, at, level), node)))
|
||||
elif isinstance(node, If):
|
||||
r = "\t"*level + "if (" + _printexpr(ns, node.cond)[0] + ") begin\n"
|
||||
|
|
|
@ -25,7 +25,7 @@ class NodeVisitor:
|
|||
self.visit_Case(node)
|
||||
elif isinstance(node, Fragment):
|
||||
self.visit_Fragment(node)
|
||||
elif isinstance(node, list):
|
||||
elif isinstance(node, (list, tuple)):
|
||||
self.visit_statements(node)
|
||||
elif isinstance(node, dict):
|
||||
self.visit_clock_domains(node)
|
||||
|
@ -115,7 +115,7 @@ class NodeTransformer:
|
|||
return self.visit_Case(node)
|
||||
elif isinstance(node, Fragment):
|
||||
return self.visit_Fragment(node)
|
||||
elif isinstance(node, list):
|
||||
elif isinstance(node, (list, tuple)):
|
||||
return self.visit_statements(node)
|
||||
elif isinstance(node, dict):
|
||||
return self.visit_clock_domains(node)
|
||||
|
@ -164,6 +164,7 @@ class NodeTransformer:
|
|||
r.sync = self.visit(node.sync)
|
||||
return r
|
||||
|
||||
# NOTE: this will always return a list, even if node is a tuple
|
||||
def visit_statements(self, node):
|
||||
return [self.visit(statement) for statement in node]
|
||||
|
||||
|
|
Loading…
Reference in a new issue