Skip to content

Commit

Permalink
Cleaner interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jandecaluwe committed Jan 31, 2016
1 parent 510c532 commit 4509e56
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
12 changes: 4 additions & 8 deletions myhdl/_always_comb.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ def __init__(self, func):
v.visit(tree)
v = _SigNameVisitor(self.symdict)
v.visit(tree)
self.inputs = v.results['input']
self.outputs = v.results['output']
self.inputs = v.inputs
self.outputs = v.outputs

inouts = v.results['inout'] | self.inputs.intersection(self.outputs)
inouts = v.inouts | self.inputs.intersection(self.outputs)
if inouts:
raise AlwaysCombError(_error.SignalAsInout % inouts)

if v.results['embedded_func']:
if v.embedded_func:
raise AlwaysCombError(_error.EmbeddedFunction)

for n in self.inputs:
Expand All @@ -127,7 +127,3 @@ def genfunc(self):
while 1:
func()
yield senslist




8 changes: 4 additions & 4 deletions myhdl/_always_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ def __init__(self, func, edge, reset):
v = _SigNameVisitor(self.symdict)
v.visit(tree)

if v.results['inout']:
raise AlwaysSeqError(_error.SigAugAssign, v.results['inout'])
if v.inouts:
raise AlwaysSeqError(_error.SigAugAssign, v.inouts)

if v.results['embedded_func']:
if v.embedded_func:
raise AlwaysSeqError(_error.EmbeddedFunction)

sigregs = self.sigregs = []
varregs = self.varregs = []
for n in v.results['output']:
for n in v.outputs:
reg = self.symdict[n]
if isinstance(reg, _Signal):
sigregs.append(reg)
Expand Down
20 changes: 11 additions & 9 deletions myhdl/_visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ class _SigNameVisitor(ast.NodeVisitor):
def __init__(self, symdict):
self.toplevel = 1
self.symdict = symdict
self.results = {
'input': set(),
'output': set(),
'inout': set(),
'embedded_func': set()
}
self.inputs = set()
self.outputs = set()
self.inouts = set()
self.embedded_func = None
self.context = 'input'

def visit_Module(self, node):
Expand All @@ -26,7 +24,7 @@ def visit_FunctionDef(self, node):
for n in node.body:
self.visit(n)
else:
self.results['embedded_func'] = node.name
self.embedded_func = node.name

def visit_If(self, node):
if not node.orelse:
Expand All @@ -41,8 +39,12 @@ def visit_Name(self, node):
return
s = self.symdict[id]
if isinstance(s, (_Signal, intbv)) or _isListOfSigs(s):
if self.context in ('input', 'output', 'inout'):
self.results[self.context].add(id)
if self.context == 'input':
self.inputs.add(id)
elif self.context == 'output':
self.outputs.add(id)
elif self.context == 'inout':
self.inouts.add(id)
else:
print(self.context)
raise AssertionError("bug in always_comb")
Expand Down

0 comments on commit 4509e56

Please sign in to comment.