From 400030424618996d4cfb1dc3c793d9472b7ca905 Mon Sep 17 00:00:00 2001 From: jand Date: Thu, 31 Jul 2003 20:32:50 +0000 Subject: [PATCH] embedded functions in not supported --- myhdl/_always_comb.py | 20 ++++++++++++++++++++ myhdl/test_always_comb.py | 35 ++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/myhdl/_always_comb.py b/myhdl/_always_comb.py index 478cca17..9e977380 100644 --- a/myhdl/_always_comb.py +++ b/myhdl/_always_comb.py @@ -53,6 +53,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): @@ -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): diff --git a/myhdl/test_always_comb.py b/myhdl/test_always_comb.py index dc40aa0b..c30e2338 100644 --- a/myhdl/test_always_comb.py +++ b/myhdl/test_always_comb.py @@ -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 @@ -48,6 +48,7 @@ def g(): x = Signal(0) class AlwaysCombCompilationTest(TestCase): + def testArgIsFunction(self): h = 5 @@ -93,7 +94,7 @@ class AlwaysCombCompilationTest(TestCase): c.next = a v = u g = always_comb(h) - i= g.gi_frame.f_locals['self'] + i = g.gi_frame.f_locals['self'] expected = ['a'] self.assertEqual(i.inputs, expected) @@ -104,7 +105,7 @@ class AlwaysCombCompilationTest(TestCase): c.next = x g = a g = always_comb(h) - i= g.gi_frame.f_locals['self'] + i = g.gi_frame.f_locals['self'] expected = ['a', 'x'] expected.sort() self.assertEqual(i.inputs, expected) @@ -117,7 +118,7 @@ class AlwaysCombCompilationTest(TestCase): c.next = a + x + u a = 1 g = always_comb(h) - i= g.gi_frame.f_locals['self'] + i = g.gi_frame.f_locals['self'] expected = ['x'] self.assertEqual(i.inputs, expected) @@ -128,7 +129,7 @@ class AlwaysCombCompilationTest(TestCase): c.next = a + x + u x = 1 g = always_comb(h) - i= g.gi_frame.f_locals['self'] + i = g.gi_frame.f_locals['self'] expected = ['a'] self.assertEqual(i.inputs, expected) @@ -162,7 +163,7 @@ class AlwaysCombCompilationTest(TestCase): def h(): c.next[a:0] = x[b:0] g = always_comb(h) - i= g.gi_frame.f_locals['self'] + i = g.gi_frame.f_locals['self'] expected = ['a', 'b', 'x'] expected.sort() self.assertEqual(i.inputs, expected) @@ -174,7 +175,7 @@ class AlwaysCombCompilationTest(TestCase): v = 2 c.next[8:1+a+v] = x[4:b*3+u] g = always_comb(h) - i= g.gi_frame.f_locals['self'] + i = g.gi_frame.f_locals['self'] expected = ['a', 'b', 'x'] expected.sort() self.assertEqual(i.inputs, expected) @@ -184,7 +185,7 @@ class AlwaysCombCompilationTest(TestCase): def h(): c.next[a-1] = x[b-1] g = always_comb(h) - i= g.gi_frame.f_locals['self'] + i = g.gi_frame.f_locals['self'] expected = ['a', 'b', 'x'] expected.sort() self.assertEqual(i.inputs, expected) @@ -196,11 +197,27 @@ class AlwaysCombCompilationTest(TestCase): def h(): c.next = f(a, 2*b, d*x) g = always_comb(h) - i= g.gi_frame.f_locals['self'] + i = g.gi_frame.f_locals['self'] expected = ['a', 'b', 'd', 'x'] 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):