mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
UNSTABLE - replace compiler by ast
All unit tests for Verilog conversion work.
This commit is contained in:
parent
e6ba8d4ec1
commit
cad761f30d
@ -448,7 +448,7 @@ class _AnalyzeVisitor(ast.NodeVisitor, _ConversionMixin):
|
||||
# self.multiLogicalOp(node, *args)
|
||||
|
||||
|
||||
def visit_Boolop(self, node):
|
||||
def visit_BoolOp(self, node):
|
||||
for n in node.values:
|
||||
self.visit(n)
|
||||
for n in node.values:
|
||||
@ -1629,7 +1629,7 @@ class _AnalyzeBlockVisitor(_AnalyzeVisitor):
|
||||
|
||||
def visit_Return(self, node):
|
||||
### value should be None
|
||||
if not node.value is None:
|
||||
if node.value is None:
|
||||
pass
|
||||
elif isinstance(node.value, ast.Name) and node.value.id == "None":
|
||||
pass
|
||||
@ -1812,7 +1812,8 @@ class _AnalyzeFuncVisitor(_AnalyzeVisitor):
|
||||
|
||||
def visit_Return(self, node):
|
||||
self.kind = _kind.DECLARATION
|
||||
self.visit(node.value)
|
||||
if node.value is not None:
|
||||
self.visit(node.value)
|
||||
self.kind = _kind.NORMAL
|
||||
if node.value is None:
|
||||
obj = None
|
||||
|
@ -83,14 +83,20 @@ _context = enum("BOOLEAN", "YIELD", "PRINT" ,"SIGNED", "UNKNOWN")
|
||||
|
||||
class _ConversionMixin(object):
|
||||
|
||||
# def getLineNo(self, node):
|
||||
# lineno = node.lineno
|
||||
# if lineno is None:
|
||||
# for n in node.getChildNodes():
|
||||
# if n.lineno is not None:
|
||||
# lineno = n.lineno
|
||||
# break
|
||||
# lineno = lineno or 0
|
||||
# return lineno
|
||||
|
||||
def getLineNo(self, node):
|
||||
lineno = node.lineno
|
||||
if lineno is None:
|
||||
for n in node.getChildNodes():
|
||||
if n.lineno is not None:
|
||||
lineno = n.lineno
|
||||
break
|
||||
lineno = lineno or 0
|
||||
lineno = 0
|
||||
if isinstance(node, (ast.stmt, ast.expr)):
|
||||
lineno = node.lineno
|
||||
return lineno
|
||||
|
||||
def getObj(self, node):
|
||||
|
@ -324,7 +324,7 @@ opmap = {
|
||||
ast.Mod : '%',
|
||||
ast.Pow : '**',
|
||||
ast.LShift : '<<',
|
||||
ast.RShift : '>>',
|
||||
ast.RShift : '>>>',
|
||||
ast.BitOr : '|',
|
||||
ast.BitAnd : '&',
|
||||
ast.BitXor : '^',
|
||||
@ -339,6 +339,8 @@ opmap = {
|
||||
ast.Lt : '<',
|
||||
ast.LtE : '<=',
|
||||
ast.NotEq : '!=',
|
||||
ast.And : '&&',
|
||||
ast.Or : '||',
|
||||
}
|
||||
|
||||
|
||||
@ -533,7 +535,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
||||
def visit_BoolOp(self, node):
|
||||
self.write("(")
|
||||
self.visit(node.values[0])
|
||||
for n in node.nodes[1:]:
|
||||
for n in node.values[1:]:
|
||||
self.write(" %s " % opmap[type(node.op)])
|
||||
self.visit(n)
|
||||
self.write(")")
|
||||
@ -1537,6 +1539,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
||||
addSignBit = isinstance(node.ctx, ast.Load) and (self.context == _context.SIGNED)
|
||||
if addSignBit:
|
||||
self.write("$signed({1'b0, ")
|
||||
self.context = None
|
||||
self.visit(node.value)
|
||||
lower, upper = node.slice.lower, node.slice.upper
|
||||
# special shortcut case for [:] slice
|
||||
@ -1563,6 +1566,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
||||
(self.context == _context.SIGNED)
|
||||
if addSignBit:
|
||||
self.write("$signed({1'b0, ")
|
||||
self.context = None
|
||||
self.visit(node.value)
|
||||
self.write("[")
|
||||
# assert len(node.subs) == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user