mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
embedded functions in not supported
This commit is contained in:
parent
22fb4b309b
commit
4000304246
@ -54,6 +54,11 @@ class ScopeError(Error):
|
||||
class SignalAsInoutError(Error):
|
||||
"""signal used as inout in always_comb function argument"""
|
||||
|
||||
class EmbeddedFunctionError(Error):
|
||||
"""embedded functions in always_comb function argument not supported"""
|
||||
|
||||
|
||||
|
||||
|
||||
def always_comb(func):
|
||||
f = inspect.getouterframes(inspect.currentframe())[1][0]
|
||||
@ -81,6 +86,7 @@ class _SigNameVisitor(object):
|
||||
def __init__(self, sigdict):
|
||||
self.inputs = []
|
||||
self.outputs = []
|
||||
self.toplevel = 1
|
||||
self.sigdict = sigdict
|
||||
|
||||
def visitModule(self, node):
|
||||
@ -91,7 +97,15 @@ class _SigNameVisitor(object):
|
||||
if n in outputs:
|
||||
raise SignalAsInoutError(n)
|
||||
|
||||
def visitFunction(self, node):
|
||||
if self.toplevel:
|
||||
self.toplevel = 0 # skip embedded functions
|
||||
self.visit(node.code)
|
||||
else:
|
||||
raise EmbeddedFunctionError
|
||||
|
||||
def visitName(self, node, access=INPUT):
|
||||
print node.name
|
||||
if node.name not in self.sigdict:
|
||||
return
|
||||
if access == INPUT:
|
||||
@ -127,6 +141,12 @@ class _SigNameVisitor(object):
|
||||
self.visit(node.node, INOUT)
|
||||
self.visit(node.expr, INPUT)
|
||||
|
||||
def visitClass(self, node):
|
||||
pass # skip
|
||||
|
||||
def visitExec(self, node):
|
||||
pass # skip
|
||||
|
||||
|
||||
class _AlwaysComb(object):
|
||||
|
||||
|
@ -37,7 +37,7 @@ from myhdl import Signal, Simulation, instances, processes, \
|
||||
|
||||
from myhdl._always_comb import always_comb, _AlwaysComb, \
|
||||
ScopeError, ArgumentError, NrOfArgsError, \
|
||||
SignalAsInoutError
|
||||
SignalAsInoutError, EmbeddedFunctionError
|
||||
|
||||
|
||||
QUIET=1
|
||||
@ -49,6 +49,7 @@ x = Signal(0)
|
||||
|
||||
class AlwaysCombCompilationTest(TestCase):
|
||||
|
||||
|
||||
def testArgIsFunction(self):
|
||||
h = 5
|
||||
try:
|
||||
@ -201,6 +202,22 @@ class AlwaysCombCompilationTest(TestCase):
|
||||
expected.sort()
|
||||
self.assertEqual(i.inputs, expected)
|
||||
|
||||
def testEmbeddedFunction(self):
|
||||
a, b, c, d = [Signal(0) for i in range(4)]
|
||||
u = 1
|
||||
def h():
|
||||
def g():
|
||||
e = b
|
||||
return e
|
||||
c.next = x
|
||||
g = a
|
||||
try:
|
||||
g = always_comb(h)
|
||||
except EmbeddedFunctionError:
|
||||
pass
|
||||
else:
|
||||
self.fail()
|
||||
|
||||
|
||||
class AlwaysCombSimulationTest(TestCase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user