mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
support for optional represention of integer literals has hex numbers
This commit is contained in:
parent
c61634f759
commit
69b9225e67
@ -75,13 +75,14 @@ def _flatten(*args):
|
|||||||
|
|
||||||
class _ToVerilogConvertor(object):
|
class _ToVerilogConvertor(object):
|
||||||
|
|
||||||
__slots__ = ("name", "timescale", "standard", "prefer_blocking_assignments")
|
__slots__ = ("name", "timescale", "standard", "prefer_blocking_assignments", "radix")
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.name = None
|
self.name = None
|
||||||
self.timescale = "1ns/10ps"
|
self.timescale = "1ns/10ps"
|
||||||
self.standard = '2001'
|
self.standard = '2001'
|
||||||
self.prefer_blocking_assignments = False
|
self.prefer_blocking_assignments = False
|
||||||
|
self.radix = ''
|
||||||
|
|
||||||
def __call__(self, func, *args, **kwargs):
|
def __call__(self, func, *args, **kwargs):
|
||||||
global _converting
|
global _converting
|
||||||
@ -146,6 +147,7 @@ class _ToVerilogConvertor(object):
|
|||||||
self.name = None
|
self.name = None
|
||||||
self.standard = '2001'
|
self.standard = '2001'
|
||||||
self.prefer_blocking_assignments = False
|
self.prefer_blocking_assignments = False
|
||||||
|
self.radix = ''
|
||||||
|
|
||||||
return h.top
|
return h.top
|
||||||
|
|
||||||
@ -387,12 +389,21 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
def dedent(self):
|
def dedent(self):
|
||||||
self.ind = self.ind[:-4]
|
self.ind = self.ind[:-4]
|
||||||
|
|
||||||
def writeIntSize(self, n):
|
def IntRepr(self, n):
|
||||||
# write size for large integers (beyond 32 bits signed)
|
# write size for large integers (beyond 32 bits signed)
|
||||||
# with some safety margin
|
# with some safety margin
|
||||||
|
# XXX signed indication 's' ???
|
||||||
|
size = ''
|
||||||
|
radix = ''
|
||||||
|
num = str(n)
|
||||||
|
if toVerilog.radix == "hex":
|
||||||
|
radix = "'h"
|
||||||
|
num = hex(n)[2:]
|
||||||
if n >= 2**30:
|
if n >= 2**30:
|
||||||
size = int(math.ceil(math.log(n+1,2))) + 1 # sign bit!
|
size = int(math.ceil(math.log(n+1,2))) + 1 # sign bit!
|
||||||
self.write("%s'sd" % size)
|
if not radix:
|
||||||
|
radix = "'d"
|
||||||
|
return "%s%s%s" % (size, radix, num)
|
||||||
|
|
||||||
def writeDeclaration(self, obj, name, dir):
|
def writeDeclaration(self, obj, name, dir):
|
||||||
if dir: dir = dir + ' '
|
if dir: dir = dir + ' '
|
||||||
@ -746,8 +757,8 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
self.isSigAss = False
|
self.isSigAss = False
|
||||||
else:
|
else:
|
||||||
self.write(' = ')
|
self.write(' = ')
|
||||||
self.writeIntSize(n)
|
s = self.IntRepr(n)
|
||||||
self.write("%s;" % n)
|
self.write("%s;" %s)
|
||||||
self.dedent()
|
self.dedent()
|
||||||
self.writeline()
|
self.writeline()
|
||||||
self.write("endcase")
|
self.write("endcase")
|
||||||
@ -1337,8 +1348,7 @@ class _ConvertVisitor(ast.NodeVisitor, _ConversionMixin):
|
|||||||
if isinstance(obj, bool):
|
if isinstance(obj, bool):
|
||||||
s = "%s" % int(obj)
|
s = "%s" % int(obj)
|
||||||
elif isinstance(obj, (int, long)):
|
elif isinstance(obj, (int, long)):
|
||||||
self.writeIntSize(obj)
|
s = self.IntRepr(obj)
|
||||||
s = str(obj)
|
|
||||||
elif isinstance(obj, _Signal):
|
elif isinstance(obj, _Signal):
|
||||||
addSignBit = isMixedExpr
|
addSignBit = isMixedExpr
|
||||||
s = str(obj)
|
s = str(obj)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user