Hi,
unlike mentioned by josyb here MyHDL’s converters do not seem to support nested functions. Example code:
from __future__ import print_function
from myhdl import *
def State_add(x, y):
return x + y
def State_update(inState, inValue):
# # Boring: works as expected
# return inState + inValue
# FIXME: MyHDL: AttributeError: '_ConvertFunctionVisitor' object has no attribute 'funcBuf'
return State_add(inState, inValue)
@block
def Funcs(ioState, inValue, reset):
@instance
def logic():
while True:
yield ioState, inValue, reset
if reset != 1:
ioState.next = modbv(0x00)[32:]
else:
ioState.next = State_update(ioState, inValue)
return logic
inst = Funcs(
ioState = Signal(intbv(0)[32:]),
inValue = Signal(intbv(0)[32:]),
reset = Signal(bool(1))
)
inst.convert(hdl='VHDL', path='work')
inst.convert(hdl='Verilog', path='work', no_testbench=True)
The commented-out version in State_update()
works but not if I call another function State_add()
. Exception:
/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py:360: ToVHDLWarning: Output port is read internally: ioState
category=ToVHDLWarning
Traceback (most recent call last):
File "./Funcs.py", line 37, in <module>
inst.convert(hdl='VHDL', path='work')
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/_block.py", line 276, in convert
return converter(self)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 244, in __call__
_convertGens(genlist, siglist, memlist, vfile)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 543, in _convertGens
v.visit(tree)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1339, in visit_Module
self.visit(stmt)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1650, in visit_FunctionDef
self.visit(stmt)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1263, in visit_If
self.mapToIf(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1329, in mapToIf
self.visit_stmt(node.else_)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1532, in visit_stmt
self.visit(stmt)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 981, in visit_Assign
self.visit(rhs)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1113, in visit_Call
v.visit(node.tree)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1339, in visit_Module
self.visit(stmt)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1909, in visit_FunctionDef
self.visit_stmt(node.body)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1532, in visit_stmt
self.visit(stmt)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1918, in visit_Return
self.visit(node.value)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 241, in visit
return visitor(node)
File "/Volumes/Data/Work/FastCloud/src/__bug/myhdl/conversion/_toVHDL.py", line 1112, in visit_Call
v = Visitor(node.tree, self.funcBuf)
AttributeError: '_ConvertFunctionVisitor' object has no attribute 'funcBuf'
That feature might be really useful in more complex designs allowing to reuse (python-)code. Can that be implemented? I’d offer to have a look at it. How difficult would it be? I have no experience with the MyHDL internals so far…
ciao,
Mario