mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
docstrings in Verilog output
This commit is contained in:
parent
1ab5fccce8
commit
96ad4abbcd
@ -71,7 +71,17 @@ def _flatten(*args):
|
|||||||
else:
|
else:
|
||||||
arglist.append(arg)
|
arglist.append(arg)
|
||||||
return arglist
|
return arglist
|
||||||
|
|
||||||
|
def _makeDoc(doc, indent=''):
|
||||||
|
if doc is None:
|
||||||
|
return ''
|
||||||
|
pre = indent + '// '
|
||||||
|
doc = pre + doc
|
||||||
|
pre = '\n' + pre
|
||||||
|
doc = doc.replace('\n', pre)
|
||||||
|
doc = doc + '\n'
|
||||||
|
return doc
|
||||||
|
|
||||||
|
|
||||||
class _ToVerilogConvertor(object):
|
class _ToVerilogConvertor(object):
|
||||||
|
|
||||||
@ -127,9 +137,10 @@ class _ToVerilogConvertor(object):
|
|||||||
genlist = _analyzeGens(arglist, h.absnames)
|
genlist = _analyzeGens(arglist, h.absnames)
|
||||||
intf = _analyzeTopFunc(func, *args, **kwargs)
|
intf = _analyzeTopFunc(func, *args, **kwargs)
|
||||||
intf.name = name
|
intf.name = name
|
||||||
|
doc = _makeDoc(inspect.getdoc(func))
|
||||||
|
|
||||||
_writeFileHeader(vfile, vpath, self.timescale)
|
_writeFileHeader(vfile, vpath, self.timescale)
|
||||||
_writeModuleHeader(vfile, intf)
|
_writeModuleHeader(vfile, intf, doc)
|
||||||
_writeSigDecls(vfile, intf, siglist, memlist)
|
_writeSigDecls(vfile, intf, siglist, memlist)
|
||||||
_convertGens(genlist, vfile)
|
_convertGens(genlist, vfile)
|
||||||
_writeModuleFooter(vfile)
|
_writeModuleFooter(vfile)
|
||||||
@ -182,7 +193,7 @@ def _writeFileHeader(f, fn, ts):
|
|||||||
print >> f
|
print >> f
|
||||||
|
|
||||||
|
|
||||||
def _writeModuleHeader(f, intf):
|
def _writeModuleHeader(f, intf, doc):
|
||||||
print >> f, "module %s (" % intf.name
|
print >> f, "module %s (" % intf.name
|
||||||
b = StringIO()
|
b = StringIO()
|
||||||
for portname in intf.argnames:
|
for portname in intf.argnames:
|
||||||
@ -190,6 +201,7 @@ def _writeModuleHeader(f, intf):
|
|||||||
print >> f, b.getvalue()[:-2]
|
print >> f, b.getvalue()[:-2]
|
||||||
b.close()
|
b.close()
|
||||||
print >> f, ");"
|
print >> f, ");"
|
||||||
|
print >> f, doc
|
||||||
print >> f
|
print >> f
|
||||||
for portname in intf.argnames:
|
for portname in intf.argnames:
|
||||||
s = intf.argdict[portname]
|
s = intf.argdict[portname]
|
||||||
@ -402,6 +414,11 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
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 writeDoc(self, node):
|
||||||
|
doc = ast.get_docstring(node)
|
||||||
|
doc = _makeDoc(doc)
|
||||||
|
self.write(doc)
|
||||||
|
|
||||||
def indent(self):
|
def indent(self):
|
||||||
self.ind += ' ' * 4
|
self.ind += ' ' * 4
|
||||||
|
|
||||||
@ -1827,6 +1844,7 @@ class _ConvertAlwaysCombVisitor(_ConvertVisitor):
|
|||||||
|
|
||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
|
self.writeDoc(node)
|
||||||
self.writeAlwaysHeader()
|
self.writeAlwaysHeader()
|
||||||
self.writeDeclarations()
|
self.writeDeclarations()
|
||||||
self.visit_stmt(node.body)
|
self.visit_stmt(node.body)
|
||||||
@ -1860,6 +1878,7 @@ class _ConvertSimpleAlwaysCombVisitor(_ConvertVisitor):
|
|||||||
# self.writeline(2)
|
# self.writeline(2)
|
||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
|
self.writeDoc(node)
|
||||||
self.visit_stmt(node.body)
|
self.visit_stmt(node.body)
|
||||||
self.writeline(2)
|
self.writeline(2)
|
||||||
|
|
||||||
@ -1884,6 +1903,7 @@ class _ConvertAlwaysDecoVisitor(_ConvertVisitor):
|
|||||||
# self.writeline(2)
|
# self.writeline(2)
|
||||||
|
|
||||||
def visit_FunctionDef(self, node):
|
def visit_FunctionDef(self, node):
|
||||||
|
self.writeDoc(node)
|
||||||
self.writeAlwaysHeader()
|
self.writeAlwaysHeader()
|
||||||
self.writeDeclarations()
|
self.writeDeclarations()
|
||||||
self.visit_stmt(node.body)
|
self.visit_stmt(node.body)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user