mirror of
https://github.com/myhdl/myhdl.git
synced 2024-12-14 07:44:38 +08:00
factored out declaration output
This commit is contained in:
parent
5df49989d6
commit
bf9b8212ac
@ -837,17 +837,21 @@ class _ConvertVisitor(_ToVerilogMixin):
|
|||||||
for i in range(nr):
|
for i in range(nr):
|
||||||
self.buf.write("\n%s" % self.ind)
|
self.buf.write("\n%s" % self.ind)
|
||||||
|
|
||||||
|
def writeDeclaration(self, obj, name, dir):
|
||||||
|
if dir: dir = dir + ' '
|
||||||
|
if type(obj) is bool:
|
||||||
|
self.write("%s%s;" % (dir, name))
|
||||||
|
elif isinstance(obj, int):
|
||||||
|
self.write("integer %s;" % name)
|
||||||
|
elif hasattr(obj, '_nrbits'):
|
||||||
|
self.write("%s[%s-1:0] %s;" % (dir, obj._nrbits, name))
|
||||||
|
else:
|
||||||
|
raise AssertionError("unexpected type")
|
||||||
|
|
||||||
def writeDeclarations(self):
|
def writeDeclarations(self):
|
||||||
for name, obj in self.ast.vardict.items():
|
for name, obj in self.ast.vardict.items():
|
||||||
self.writeline()
|
self.writeline()
|
||||||
if type(obj) is bool:
|
self.writeDeclaration(obj, name, "reg")
|
||||||
self.write("reg %s;" % name)
|
|
||||||
elif isinstance(obj, int):
|
|
||||||
self.write("integer %s;" % name)
|
|
||||||
elif hasattr(obj, '_nrbits'):
|
|
||||||
self.write("reg [%s-1:0] %s;" % (obj._nrbits, name))
|
|
||||||
else:
|
|
||||||
raise AssertionError("unexpected type")
|
|
||||||
|
|
||||||
def indent(self):
|
def indent(self):
|
||||||
self.ind += ' ' * 4
|
self.ind += ' ' * 4
|
||||||
@ -1290,32 +1294,17 @@ class _ConvertFunctionVisitor(_ConvertVisitor):
|
|||||||
|
|
||||||
def writeOutputDeclaration(self):
|
def writeOutputDeclaration(self):
|
||||||
obj = self.ast.returnObj
|
obj = self.ast.returnObj
|
||||||
if type(obj) is bool:
|
self.writeDeclaration(obj, self.ast.name, dir='')
|
||||||
pass
|
|
||||||
elif isinstance(obj, int):
|
|
||||||
self.write("integer")
|
|
||||||
elif hasattr(obj, '_nrbits'):
|
|
||||||
self.write("[%s-1:0]" % obj._nrbits)
|
|
||||||
else:
|
|
||||||
raise AssertionError("unexpected type")
|
|
||||||
|
|
||||||
def writeInputDeclarations(self):
|
def writeInputDeclarations(self):
|
||||||
for name in self.ast.argnames:
|
for name in self.ast.argnames:
|
||||||
obj = self.ast.symdict[name]
|
obj = self.ast.symdict[name]
|
||||||
self.writeline()
|
self.writeline()
|
||||||
if type(obj) is bool:
|
self.writeDeclaration(obj, name, "input")
|
||||||
self.write("input %s;" % name)
|
|
||||||
elif isinstance(obj, int):
|
|
||||||
self.write("integer %s;" % name)
|
|
||||||
elif hasattr(obj, '_nrbits'):
|
|
||||||
self.write("input [%s-1:0] %s;" % (obj._nrbits, name))
|
|
||||||
else:
|
|
||||||
raise AssertionError("unexpected type")
|
|
||||||
|
|
||||||
def visitFunction(self, node):
|
def visitFunction(self, node):
|
||||||
self.write("function ")
|
self.write("function ")
|
||||||
self.writeOutputDeclaration()
|
self.writeOutputDeclaration()
|
||||||
self.write(" %s;" % self.ast.name)
|
|
||||||
self.indent()
|
self.indent()
|
||||||
self.writeInputDeclarations()
|
self.writeInputDeclarations()
|
||||||
self.writeDeclarations()
|
self.writeDeclarations()
|
||||||
@ -1351,16 +1340,9 @@ class _ConvertTaskVisitor(_ConvertVisitor):
|
|||||||
output = name in self.ast.outputs
|
output = name in self.ast.outputs
|
||||||
input = name in self.ast.inputs
|
input = name in self.ast.inputs
|
||||||
inout = input and output
|
inout = input and output
|
||||||
dir = inout and "inout" or output and "output" or input and "input"
|
dir = (inout and "inout") or (output and "output") or (input and "input")
|
||||||
self.writeline()
|
self.writeline()
|
||||||
if type(obj) is bool:
|
self.writeDeclaration(obj, name, dir)
|
||||||
self.write("%s %s;" % (dir, name))
|
|
||||||
elif isinstance(obj, int):
|
|
||||||
self.write("integer %s;" % name)
|
|
||||||
elif hasattr(obj, '_nrbits'):
|
|
||||||
self.write("%s [%s-1:0] %s;" % (dir, obj._nrbits, name))
|
|
||||||
else:
|
|
||||||
raise AssertionError("unexpected type")
|
|
||||||
|
|
||||||
def visitFunction(self, node):
|
def visitFunction(self, node):
|
||||||
self.write("task %s;" % self.ast.name)
|
self.write("task %s;" % self.ast.name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user