mirror of
https://github.com/myhdl/myhdl.git
synced 2024-12-14 07:44:38 +08:00
This commit is contained in:
parent
6ce526f179
commit
90dab3f2dd
@ -1117,7 +1117,6 @@ class _ConvertVisitor(_ConversionMixin):
|
|||||||
## self.handlePrint(node)
|
## self.handlePrint(node)
|
||||||
|
|
||||||
def visitPrintnl(self, node, *args):
|
def visitPrintnl(self, node, *args):
|
||||||
print node.format
|
|
||||||
## self.handlePrint(node)
|
## self.handlePrint(node)
|
||||||
argnr = 0
|
argnr = 0
|
||||||
for s in node.format:
|
for s in node.format:
|
||||||
@ -1126,7 +1125,6 @@ class _ConvertVisitor(_ConversionMixin):
|
|||||||
else:
|
else:
|
||||||
a = node.args[argnr]
|
a = node.args[argnr]
|
||||||
argnr += 1
|
argnr += 1
|
||||||
print s.conv
|
|
||||||
if s.conv is int:
|
if s.conv is int:
|
||||||
a.vhd = vhd_int()
|
a.vhd = vhd_int()
|
||||||
else:
|
else:
|
||||||
@ -1267,6 +1265,7 @@ class _ConvertVisitor(_ConversionMixin):
|
|||||||
self.raiseError(node, "base type error in sensitivity list")
|
self.raiseError(node, "base type error in sensitivity list")
|
||||||
if len(senslist) >= 2 and bt == _WaiterList:
|
if len(senslist) >= 2 and bt == _WaiterList:
|
||||||
# ifnode = node.code.nodes[0]
|
# ifnode = node.code.nodes[0]
|
||||||
|
# print ifnode
|
||||||
assert isinstance(ifnode, astNode.If)
|
assert isinstance(ifnode, astNode.If)
|
||||||
asyncEdges = []
|
asyncEdges = []
|
||||||
for test, suite in ifnode.tests:
|
for test, suite in ifnode.tests:
|
||||||
@ -1411,7 +1410,7 @@ class _ConvertAlwaysDecoVisitor(_ConvertVisitor):
|
|||||||
def visitFunction(self, node, *args):
|
def visitFunction(self, node, *args):
|
||||||
assert self.ast.senslist
|
assert self.ast.senslist
|
||||||
senslist = self.ast.senslist
|
senslist = self.ast.senslist
|
||||||
senslist = self.manageEdges(node.code.nodes[0], senslist)
|
senslist = self.manageEdges(node.code.nodes[-1], senslist)
|
||||||
singleEdge = (len(senslist) == 1) and isinstance(senslist[0], _WaiterList)
|
singleEdge = (len(senslist) == 1) and isinstance(senslist[0], _WaiterList)
|
||||||
self.write("%s: process (" % self.ast.name)
|
self.write("%s: process (" % self.ast.name)
|
||||||
if singleEdge:
|
if singleEdge:
|
||||||
@ -1421,10 +1420,10 @@ class _ConvertAlwaysDecoVisitor(_ConvertVisitor):
|
|||||||
self.write(e)
|
self.write(e)
|
||||||
self.write(', ')
|
self.write(', ')
|
||||||
self.write(senslist[-1])
|
self.write(senslist[-1])
|
||||||
|
self.write(") is")
|
||||||
self.indent()
|
self.indent()
|
||||||
self.writeDeclarations()
|
self.writeDeclarations()
|
||||||
self.dedent()
|
self.dedent()
|
||||||
self.write(") is")
|
|
||||||
self.writeline()
|
self.writeline()
|
||||||
self.write("begin")
|
self.write("begin")
|
||||||
self.indent()
|
self.indent()
|
||||||
|
@ -545,6 +545,9 @@ class _ConvertVisitor(_ConversionMixin):
|
|||||||
self.write(f.__name__)
|
self.write(f.__name__)
|
||||||
elif f is concat:
|
elif f is concat:
|
||||||
opening, closing = '{', '}'
|
opening, closing = '{', '}'
|
||||||
|
elif f is delay:
|
||||||
|
self.visit(node.args[0])
|
||||||
|
return
|
||||||
elif hasattr(node, 'ast'):
|
elif hasattr(node, 'ast'):
|
||||||
self.write(node.ast.name)
|
self.write(node.ast.name)
|
||||||
else:
|
else:
|
||||||
@ -793,26 +796,60 @@ class _ConvertVisitor(_ConversionMixin):
|
|||||||
def visitPass(self, node, *args):
|
def visitPass(self, node, *args):
|
||||||
self.write("// pass")
|
self.write("// pass")
|
||||||
|
|
||||||
def handlePrint(self, node):
|
## def handlePrint(self, node):
|
||||||
self.write('$display(')
|
## self.write('$display(')
|
||||||
s = node.nodes[0]
|
## s = node.nodes[0]
|
||||||
self.visit(s, _context.PRINT)
|
## self.visit(s, _context.PRINT)
|
||||||
for s in node.nodes[1:]:
|
## for s in node.nodes[1:]:
|
||||||
self.write(', , ')
|
## self.write(', , ')
|
||||||
self.visit(s, _context.PRINT)
|
## self.visit(s, _context.PRINT)
|
||||||
self.write(');')
|
## self.write(');')
|
||||||
|
|
||||||
def visitPrint(self, node, *args):
|
## def visitPrint(self, node, *args):
|
||||||
self.handlePrint(node)
|
## self.handlePrint(node)
|
||||||
|
|
||||||
def visitPrintnl(self, node, *args):
|
def visitPrintnl(self, node, *args):
|
||||||
self.handlePrint(node)
|
argnr = 0
|
||||||
|
for s in node.format:
|
||||||
|
if isinstance(s, str):
|
||||||
|
self.write('write(L, string\'("%s"));' % s)
|
||||||
|
else:
|
||||||
|
a = node.args[argnr]
|
||||||
|
argnr += 1
|
||||||
|
obj = a.obj
|
||||||
|
if (s.conv is str) and isinstance(obj, bool):
|
||||||
|
w = 5
|
||||||
|
else:
|
||||||
|
w = len(obj)
|
||||||
|
if s.width > w:
|
||||||
|
self.write('$write(" ";' % (s.width-w))
|
||||||
|
self.writeline()
|
||||||
|
fs = "%d"
|
||||||
|
else:
|
||||||
|
fs = "%0d"
|
||||||
|
if (s.conv is str) and isinstance(obj, bool):
|
||||||
|
self.write('if (')
|
||||||
|
self.visit(a, _context.PRINT)
|
||||||
|
self.write(')')
|
||||||
|
self.writeline()
|
||||||
|
self.write(' $write(" True");')
|
||||||
|
self.writeline()
|
||||||
|
self.write('else')
|
||||||
|
self.writeline()
|
||||||
|
self.write(' $write("False");')
|
||||||
|
else:
|
||||||
|
self.write('$write("%s", ' % fs)
|
||||||
|
self.visit(a, _context.PRINT)
|
||||||
|
self.write(');')
|
||||||
|
self.writeline()
|
||||||
|
self.write('$write("\\n");')
|
||||||
|
|
||||||
|
|
||||||
def visitRaise(self, node, *args):
|
def visitRaise(self, node, *args):
|
||||||
self.write('$display("')
|
## self.write('$display("')
|
||||||
self.visit(node.expr1)
|
## self.visit(node.expr1)
|
||||||
self.write('");')
|
## self.write('");')
|
||||||
self.writeline()
|
## self.writeline()
|
||||||
self.write("$finish;")
|
self.write("$finish;")
|
||||||
|
|
||||||
def visitReturn(self, node, *args):
|
def visitReturn(self, node, *args):
|
||||||
@ -901,8 +938,15 @@ class _ConvertVisitor(_ConversionMixin):
|
|||||||
self.labelStack.pop()
|
self.labelStack.pop()
|
||||||
|
|
||||||
def visitYield(self, node, *args):
|
def visitYield(self, node, *args):
|
||||||
|
yieldObj = self.getObj(node.value)
|
||||||
|
if isinstance(yieldObj, delay):
|
||||||
|
self.write("# ")
|
||||||
|
else:
|
||||||
self.write("@ (")
|
self.write("@ (")
|
||||||
self.visit(node.value, _context.YIELD)
|
self.visit(node.value, _context.YIELD)
|
||||||
|
if isinstance(yieldObj, delay):
|
||||||
|
self.write(";")
|
||||||
|
else:
|
||||||
self.write(");")
|
self.write(");")
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,16 +11,17 @@ from myhdl.conversion._toVerilog import toVerilog
|
|||||||
|
|
||||||
_version = myhdl.__version__.replace('.','')
|
_version = myhdl.__version__.replace('.','')
|
||||||
_simulators = []
|
_simulators = []
|
||||||
_conversionCommands = {}
|
_hdlMap = {}
|
||||||
_analyzeCommands = {}
|
_analyzeCommands = {}
|
||||||
_elaborateCommands = {}
|
_elaborateCommands = {}
|
||||||
_simulateCommands = {}
|
_simulateCommands = {}
|
||||||
|
_offsets = {}
|
||||||
|
|
||||||
def registerSimulator(name=None, convert=None, analyze=None, elaborate=None, simulate=None):
|
def registerSimulator(name=None, hdl=None, analyze=None, elaborate=None, simulate=None, offset=0):
|
||||||
if not isinstance(name, str) or (name.strip() == ""):
|
if not isinstance(name, str) or (name.strip() == ""):
|
||||||
raise ValueError("Invalid simulator name")
|
raise ValueError("Invalid simulator name")
|
||||||
if convert not in (toVHDL, toVerilog):
|
if hdl not in ("VHDL", "Verilog"):
|
||||||
raise ValueError("Invalid convert command")
|
raise ValueError("Invalid hdl %s" % hdl)
|
||||||
if not isinstance(analyze, str) or (analyze.strip() == ""):
|
if not isinstance(analyze, str) or (analyze.strip() == ""):
|
||||||
raise ValueError("Invalid analyzer command")
|
raise ValueError("Invalid analyzer command")
|
||||||
# elaborate command is optional
|
# elaborate command is optional
|
||||||
@ -30,22 +31,29 @@ def registerSimulator(name=None, convert=None, analyze=None, elaborate=None, sim
|
|||||||
if not isinstance(simulate, str) or (simulate.strip() == ""):
|
if not isinstance(simulate, str) or (simulate.strip() == ""):
|
||||||
raise ValueError("Invalid simulator command")
|
raise ValueError("Invalid simulator command")
|
||||||
_simulators.append(name)
|
_simulators.append(name)
|
||||||
_conversionCommands[name] = convert
|
_hdlMap[name] = hdl
|
||||||
_analyzeCommands[name] = analyze
|
_analyzeCommands[name] = analyze
|
||||||
_elaborateCommands[name] = elaborate
|
_elaborateCommands[name] = elaborate
|
||||||
_simulateCommands[name] = simulate
|
_simulateCommands[name] = simulate
|
||||||
|
_offsets[name] = offset
|
||||||
|
|
||||||
registerSimulator(name="GHDL",
|
registerSimulator(name="GHDL",
|
||||||
convert=toVHDL,
|
hdl="VHDL",
|
||||||
analyze="ghdl -a --workdir=work pck_myhdl_%(version)s.vhd %(topname)s.vhd",
|
analyze="ghdl -a --workdir=work pck_myhdl_%(version)s.vhd %(topname)s.vhd",
|
||||||
elaborate="ghdl -e --workdir=work %(topname)s",
|
elaborate="ghdl -e --workdir=work %(topname)s",
|
||||||
simulate="ghdl -r %(topname)s")
|
simulate="ghdl -r %(topname)s")
|
||||||
|
|
||||||
registerSimulator(name="icarus",
|
registerSimulator(name="icarus",
|
||||||
convert=toVerilog,
|
hdl="Verilog",
|
||||||
analyze="iverilog -o %(topname)s.o %(topname)s.v",
|
analyze="iverilog -o %(topname)s.o %(topname)s.v",
|
||||||
simulate="vvp %(topname)s.o")
|
simulate="vvp %(topname)s.o")
|
||||||
|
|
||||||
|
registerSimulator(name="cver",
|
||||||
|
hdl="Verilog",
|
||||||
|
analyze="cver -c -q %(topname)s.v",
|
||||||
|
simulate="cver -q %(topname)s.v",
|
||||||
|
offset=3)
|
||||||
|
|
||||||
|
|
||||||
class _VerificationClass(object):
|
class _VerificationClass(object):
|
||||||
|
|
||||||
@ -62,21 +70,25 @@ class _VerificationClass(object):
|
|||||||
vals['topname'] = func.func_name
|
vals['topname'] = func.func_name
|
||||||
vals['version'] = _version
|
vals['version'] = _version
|
||||||
|
|
||||||
hdl = self.simulator
|
hdlsim = self.simulator
|
||||||
if not hdl:
|
if not hdlsim:
|
||||||
raise ValueError("No simulator specified")
|
raise ValueError("No simulator specified")
|
||||||
if not hdl in _simulators:
|
if not hdlsim in _simulators:
|
||||||
raise ValueError("Simulator %s is not registered" % hdl)
|
raise ValueError("Simulator %s is not registered" % hdlsim)
|
||||||
convert = _conversionCommands[hdl]
|
hdl = _hdlMap[hdlsim]
|
||||||
analyze = _analyzeCommands[hdl] % vals
|
analyze = _analyzeCommands[hdlsim] % vals
|
||||||
elaborate = _elaborateCommands[hdl]
|
elaborate = _elaborateCommands[hdlsim]
|
||||||
if elaborate is not None:
|
if elaborate is not None:
|
||||||
elaborate = elaborate % vals
|
elaborate = elaborate % vals
|
||||||
simulate = _simulateCommands[hdl] % vals
|
simulate = _simulateCommands[hdlsim] % vals
|
||||||
|
offset = _offsets[hdlsim]
|
||||||
|
|
||||||
inst = convert(func, *args, **kwargs)
|
if hdl == "VHDL":
|
||||||
|
inst = toVHDL(func, *args, **kwargs)
|
||||||
|
else:
|
||||||
|
inst = toVerilog(func, *args, **kwargs)
|
||||||
|
|
||||||
if convert is toVHDL:
|
if hdl == "VHDL":
|
||||||
if not os.path.exists("work"):
|
if not os.path.exists("work"):
|
||||||
os.mkdir("work")
|
os.mkdir("work")
|
||||||
ret = subprocess.call(analyze, shell=True)
|
ret = subprocess.call(analyze, shell=True)
|
||||||
@ -117,13 +129,13 @@ class _VerificationClass(object):
|
|||||||
g.flush()
|
g.flush()
|
||||||
g.seek(0)
|
g.seek(0)
|
||||||
|
|
||||||
glines = g.readlines()
|
glines = g.readlines()[offset:]
|
||||||
flinesNorm = [line.lower() for line in flines]
|
flinesNorm = [line.lower() for line in flines]
|
||||||
glinesNorm = [line.lower() for line in glines]
|
glinesNorm = [line.lower() for line in glines]
|
||||||
g = difflib.unified_diff(flinesNorm, glinesNorm, fromfile=hdl, tofile="VHDL")
|
g = difflib.unified_diff(flinesNorm, glinesNorm, fromfile=hdlsim, tofile=hdl)
|
||||||
|
|
||||||
MyHDLLog = "MyHDL.log"
|
MyHDLLog = "MyHDL.log"
|
||||||
HDLLog = hdl + ".log"
|
HDLLog = hdlsim + ".log"
|
||||||
try:
|
try:
|
||||||
os.remove(MyHDLLog)
|
os.remove(MyHDLLog)
|
||||||
os.remove(HDLLog)
|
os.remove(HDLLog)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user