fhdl/tools: add input lister
authorSebastien Bourdeauducq <sb@m-labs.hk>
Fri, 11 Sep 2015 03:33:10 +0000 (20:33 -0700)
committerSebastien Bourdeauducq <sb@m-labs.hk>
Fri, 11 Sep 2015 03:33:10 +0000 (20:33 -0700)
migen/fhdl/tools.py

index 8be41e476691b0cfe1f09926609d6ab5ec436755..8ae03ced49aacc50ca398cd13ad433ff846bb654 100644 (file)
@@ -32,6 +32,17 @@ class _TargetLister(NodeVisitor):
             self.visit(choice)
 
 
+class _InputLister(NodeVisitor):
+    def __init__(self):
+        self.output_list = set()
+
+    def visit_Signal(self, node):
+        self.output_list.add(node)
+
+    def visit_Assign(self, node):
+        self.visit(node.r)
+
+
 def list_signals(node):
     lister = _SignalLister()
     lister.visit(node)
@@ -44,6 +55,12 @@ def list_targets(node):
     return lister.output_list
 
 
+def list_inputs(node):
+    lister = _InputLister()
+    lister.visit(node)
+    return lister.output_list
+
+
 def _resort_statements(ol):
     return [statement for i, statement in
             sorted(ol, key=lambda x: x[0])]