mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
task return
This commit is contained in:
parent
b59a38d375
commit
b604bbbbf3
@ -1243,12 +1243,14 @@ class _ConvertFunctionVisitor(_ConvertVisitor):
|
|||||||
self.indent()
|
self.indent()
|
||||||
self.writeInputDeclarations()
|
self.writeInputDeclarations()
|
||||||
self.writeDeclarations()
|
self.writeDeclarations()
|
||||||
|
self.dedent()
|
||||||
self.writeline()
|
self.writeline()
|
||||||
self.write("begin: %s" % self.returnLabel)
|
self.write("begin: %s" % self.returnLabel)
|
||||||
|
self.indent()
|
||||||
self.visit(node.code)
|
self.visit(node.code)
|
||||||
|
self.dedent()
|
||||||
self.writeline()
|
self.writeline()
|
||||||
self.write("end")
|
self.write("end")
|
||||||
self.dedent()
|
|
||||||
self.writeline()
|
self.writeline()
|
||||||
self.write("endfunction")
|
self.write("endfunction")
|
||||||
self.writeline(2)
|
self.writeline(2)
|
||||||
@ -1268,6 +1270,7 @@ class _ConvertTaskVisitor(_ConvertVisitor):
|
|||||||
self.argnames = ast.argnames
|
self.argnames = ast.argnames
|
||||||
self.inputs = ast.inputs
|
self.inputs = ast.inputs
|
||||||
self.outputs = ast.outputs
|
self.outputs = ast.outputs
|
||||||
|
self.returnLabel = Label("RETURN")
|
||||||
|
|
||||||
|
|
||||||
def writeInterfaceDeclarations(self):
|
def writeInterfaceDeclarations(self):
|
||||||
@ -1292,12 +1295,14 @@ class _ConvertTaskVisitor(_ConvertVisitor):
|
|||||||
self.indent()
|
self.indent()
|
||||||
self.writeInterfaceDeclarations()
|
self.writeInterfaceDeclarations()
|
||||||
self.writeDeclarations()
|
self.writeDeclarations()
|
||||||
|
self.dedent()
|
||||||
self.writeline()
|
self.writeline()
|
||||||
self.write("begin")
|
self.write("begin")
|
||||||
|
self.indent()
|
||||||
self.visit(node.code)
|
self.visit(node.code)
|
||||||
|
self.dedent()
|
||||||
self.writeline()
|
self.writeline()
|
||||||
self.write("end")
|
self.write("end")
|
||||||
self.dedent()
|
|
||||||
self.writeline()
|
self.writeline()
|
||||||
self.write("endtask")
|
self.write("endtask")
|
||||||
self.writeline(2)
|
self.writeline(2)
|
||||||
|
@ -74,6 +74,34 @@ def NestedForLoop2(a, out):
|
|||||||
break
|
break
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def ReturnFromFunction(a):
|
||||||
|
for i in downrange(len(a)):
|
||||||
|
if a[i] == 1:
|
||||||
|
return i
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def FunctionCall(a, out):
|
||||||
|
while 1:
|
||||||
|
yield a
|
||||||
|
out.next = ReturnFromFunction(a)
|
||||||
|
|
||||||
|
# During the following check, I noticed that non-blocking assignments
|
||||||
|
# are not scheduled when a task is disabled in Icarus. Apparently
|
||||||
|
# this is one of the many vague areas in the Verilog standard.
|
||||||
|
def ReturnFromTask(a, out):
|
||||||
|
for i in downrange(len(a)):
|
||||||
|
if a[i] == 1:
|
||||||
|
out[:] = i
|
||||||
|
return
|
||||||
|
out[:] = 23 # to notice it
|
||||||
|
|
||||||
|
def TaskCall(a, out):
|
||||||
|
var = intbv()[8:]
|
||||||
|
while 1:
|
||||||
|
yield a
|
||||||
|
ReturnFromTask(a, var)
|
||||||
|
out.next = var
|
||||||
|
|
||||||
def WhileLoop(a, out):
|
def WhileLoop(a, out):
|
||||||
while 1:
|
while 1:
|
||||||
yield a
|
yield a
|
||||||
@ -138,7 +166,7 @@ class TestLoops(unittest.TestCase):
|
|||||||
|
|
||||||
def bench(self, LoopTest):
|
def bench(self, LoopTest):
|
||||||
|
|
||||||
a = Signal(intbv(0)[16:])
|
a = Signal(intbv(-1)[16:])
|
||||||
out_v = Signal(intbv(0)[16:])
|
out_v = Signal(intbv(0)[16:])
|
||||||
out = Signal(intbv(0)[16:])
|
out = Signal(intbv(0)[16:])
|
||||||
|
|
||||||
@ -150,50 +178,62 @@ class TestLoops(unittest.TestCase):
|
|||||||
for i in range(100):
|
for i in range(100):
|
||||||
a.next = randrange(2**min(i, 16))
|
a.next = randrange(2**min(i, 16))
|
||||||
yield delay(10)
|
yield delay(10)
|
||||||
print "%s %s" % (out, out_v)
|
# print "%s %s" % (out, out_v)
|
||||||
self.assertEqual(out, out_v)
|
self.assertEqual(out, out_v)
|
||||||
|
|
||||||
return stimulus(), looptest_inst, looptest_v_inst
|
return stimulus(), looptest_inst, looptest_v_inst
|
||||||
|
|
||||||
## def testForLoop(self):
|
def testForLoop(self):
|
||||||
## sim = self.bench(ForLoop)
|
sim = self.bench(ForLoop)
|
||||||
## Simulation(sim).run()
|
Simulation(sim).run()
|
||||||
|
|
||||||
## def testForContinueLoop(self):
|
def testForContinueLoop(self):
|
||||||
## sim = self.bench(ForContinueLoop)
|
sim = self.bench(ForContinueLoop)
|
||||||
## Simulation(sim).run()
|
Simulation(sim).run()
|
||||||
|
|
||||||
## def testForBreakLoop(self):
|
def testForBreakLoop(self):
|
||||||
## sim = self.bench(ForBreakLoop)
|
sim = self.bench(ForBreakLoop)
|
||||||
## Simulation(sim).run()
|
Simulation(sim).run()
|
||||||
|
|
||||||
## def testForBreakContinueLoop(self):
|
def testForBreakContinueLoop(self):
|
||||||
## sim = self.bench(ForBreakContinueLoop)
|
sim = self.bench(ForBreakContinueLoop)
|
||||||
## Simulation(sim).run()
|
Simulation(sim).run()
|
||||||
|
|
||||||
## def testNestedForLoop1(self):
|
def testNestedForLoop1(self):
|
||||||
## sim = self.bench(NestedForLoop1)
|
sim = self.bench(NestedForLoop1)
|
||||||
## Simulation(sim).run()
|
Simulation(sim).run()
|
||||||
|
|
||||||
def testNestedForLoop2(self):
|
def testNestedForLoop2(self):
|
||||||
sim = self.bench(NestedForLoop2)
|
sim = self.bench(NestedForLoop2)
|
||||||
Simulation(sim).run()
|
Simulation(sim).run()
|
||||||
|
|
||||||
## def testWhileLoop(self):
|
def testNestedForLoop2(self):
|
||||||
## sim = self.bench(WhileLoop)
|
sim = self.bench(NestedForLoop2)
|
||||||
## Simulation(sim).run()
|
Simulation(sim).run()
|
||||||
|
|
||||||
## def testWhileContinueLoop(self):
|
def testFunctionCall(self):
|
||||||
## sim = self.bench(WhileContinueLoop)
|
sim = self.bench(FunctionCall)
|
||||||
## Simulation(sim).run()
|
Simulation(sim).run()
|
||||||
|
|
||||||
## def testWhileBreakLoop(self):
|
|
||||||
## sim = self.bench(WhileBreakLoop)
|
|
||||||
## Simulation(sim).run()
|
|
||||||
|
|
||||||
## def testWhileBreakContinueLoop(self):
|
def testTaskCall(self):
|
||||||
## sim = self.bench(WhileBreakContinueLoop)
|
sim = self.bench(TaskCall)
|
||||||
## Simulation(sim).run()
|
Simulation(sim).run()
|
||||||
|
|
||||||
|
def testWhileLoop(self):
|
||||||
|
sim = self.bench(WhileLoop)
|
||||||
|
Simulation(sim).run()
|
||||||
|
|
||||||
|
def testWhileContinueLoop(self):
|
||||||
|
sim = self.bench(WhileContinueLoop)
|
||||||
|
Simulation(sim).run()
|
||||||
|
|
||||||
|
def testWhileBreakLoop(self):
|
||||||
|
sim = self.bench(WhileBreakLoop)
|
||||||
|
Simulation(sim).run()
|
||||||
|
|
||||||
|
def testWhileBreakContinueLoop(self):
|
||||||
|
sim = self.bench(WhileBreakContinueLoop)
|
||||||
|
Simulation(sim).run()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user