mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
remove use of adhoc input,output,inout enum
This commit is contained in:
parent
61047c189c
commit
c4ca71f40f
@ -110,8 +110,8 @@ class _AlwaysComb(_Instantiator):
|
|||||||
v.visit(tree)
|
v.visit(tree)
|
||||||
v = _SigNameVisitor(self.symdict)
|
v = _SigNameVisitor(self.symdict)
|
||||||
v.visit(tree)
|
v.visit(tree)
|
||||||
self.inputs = v.inputs
|
self.inputs = v.results['input']
|
||||||
self.outputs = v.outputs
|
self.outputs = v.results['output']
|
||||||
senslist = []
|
senslist = []
|
||||||
for n in self.inputs:
|
for n in self.inputs:
|
||||||
s = self.symdict[n]
|
s = self.symdict[n]
|
||||||
|
@ -3,6 +3,7 @@ import ast
|
|||||||
from myhdl import AlwaysCombError
|
from myhdl import AlwaysCombError
|
||||||
from myhdl._Signal import _Signal, _isListOfSigs
|
from myhdl._Signal import _Signal, _isListOfSigs
|
||||||
|
|
||||||
|
|
||||||
class _error:
|
class _error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -13,21 +14,20 @@ _error.SignalAsInout = "signal (%s) used as inout in always_comb function argume
|
|||||||
_error.EmbeddedFunction = "embedded functions in always_comb function argument not supported"
|
_error.EmbeddedFunction = "embedded functions in always_comb function argument not supported"
|
||||||
_error.EmptySensitivityList= "sensitivity list is empty"
|
_error.EmptySensitivityList= "sensitivity list is empty"
|
||||||
|
|
||||||
INPUT, OUTPUT, INOUT = range(3)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _SigNameVisitor(ast.NodeVisitor):
|
class _SigNameVisitor(ast.NodeVisitor):
|
||||||
def __init__(self, symdict):
|
def __init__(self, symdict):
|
||||||
self.inputs = set()
|
|
||||||
self.outputs = set()
|
|
||||||
self.toplevel = 1
|
self.toplevel = 1
|
||||||
self.symdict = symdict
|
self.symdict = symdict
|
||||||
self.context = INPUT
|
self.results = {
|
||||||
|
'input': set(),
|
||||||
|
'output': set()
|
||||||
|
}
|
||||||
|
self.context = 'input'
|
||||||
|
|
||||||
def visit_Module(self, node):
|
def visit_Module(self, node):
|
||||||
inputs = self.inputs
|
inputs = self.results['input']
|
||||||
outputs = self.outputs
|
outputs = self.results['output']
|
||||||
for n in node.body:
|
for n in node.body:
|
||||||
self.visit(n)
|
self.visit(n)
|
||||||
for n in inputs:
|
for n in inputs:
|
||||||
@ -36,7 +36,7 @@ class _SigNameVisitor(ast.NodeVisitor):
|
|||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
if self.toplevel:
|
if self.toplevel:
|
||||||
self.toplevel = 0 # skip embedded functions
|
self.toplevel = 0 # skip embedded functions
|
||||||
for n in node.body:
|
for n in node.body:
|
||||||
self.visit(n)
|
self.visit(n)
|
||||||
else:
|
else:
|
||||||
@ -46,7 +46,7 @@ class _SigNameVisitor(ast.NodeVisitor):
|
|||||||
if not node.orelse:
|
if not node.orelse:
|
||||||
if isinstance(node.test, ast.Name) and \
|
if isinstance(node.test, ast.Name) and \
|
||||||
node.test.id == '__debug__':
|
node.test.id == '__debug__':
|
||||||
return # skip
|
return # skip
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
|
|
||||||
def visit_Name(self, node):
|
def visit_Name(self, node):
|
||||||
@ -55,20 +55,19 @@ class _SigNameVisitor(ast.NodeVisitor):
|
|||||||
return
|
return
|
||||||
s = self.symdict[id]
|
s = self.symdict[id]
|
||||||
if isinstance(s, _Signal) or _isListOfSigs(s):
|
if isinstance(s, _Signal) or _isListOfSigs(s):
|
||||||
if self.context == INPUT:
|
if self.context in ('input', 'output'):
|
||||||
self.inputs.add(id)
|
self.results[self.context].add(id)
|
||||||
elif self.context == OUTPUT:
|
elif self.context == 'inout':
|
||||||
self.outputs.add(id)
|
|
||||||
elif self.context == INOUT:
|
|
||||||
raise AlwaysCombError(_error.SignalAsInout % id)
|
raise AlwaysCombError(_error.SignalAsInout % id)
|
||||||
else:
|
else:
|
||||||
|
print(self.context)
|
||||||
raise AssertionError("bug in always_comb")
|
raise AssertionError("bug in always_comb")
|
||||||
|
|
||||||
def visit_Assign(self, node):
|
def visit_Assign(self, node):
|
||||||
self.context = OUTPUT
|
self.context = 'output'
|
||||||
for n in node.targets:
|
for n in node.targets:
|
||||||
self.visit(n)
|
self.visit(n)
|
||||||
self.context = INPUT
|
self.context = 'input'
|
||||||
self.visit(node.value)
|
self.visit(node.value)
|
||||||
|
|
||||||
def visit_Attribute(self, node):
|
def visit_Attribute(self, node):
|
||||||
@ -82,17 +81,16 @@ class _SigNameVisitor(ast.NodeVisitor):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
|
|
||||||
|
|
||||||
def visit_Subscript(self, node, access=INPUT):
|
def visit_Subscript(self, node, access='input'):
|
||||||
self.visit(node.value)
|
self.visit(node.value)
|
||||||
self.context = INPUT
|
self.context = 'input'
|
||||||
self.visit(node.slice)
|
self.visit(node.slice)
|
||||||
|
|
||||||
def visit_AugAssign(self, node, access=INPUT):
|
def visit_AugAssign(self, node, access='input'):
|
||||||
self.context = INOUT
|
self.context = 'inout'
|
||||||
self.visit(node.target)
|
self.visit(node.target)
|
||||||
self.context = INPUT
|
self.context = 'input'
|
||||||
self.visit(node.value)
|
self.visit(node.value)
|
||||||
|
|
||||||
def visit_ClassDef(self, node):
|
def visit_ClassDef(self, node):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user