aboutsummaryrefslogtreecommitdiffstats
path: root/src/vhdl/python/pnodespy.py
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-10-23 18:23:05 +0200
committerTristan Gingold <tgingold@free.fr>2017-10-23 18:23:05 +0200
commit09a8b72257bc6f33fd2ee89c3418d8bcee6e05e6 (patch)
tree89d788b7f66d284860b5ff631f07b71ac520f2a4 /src/vhdl/python/pnodespy.py
parentf16c8e7239d43f466a5f79bdff59824d2b037310 (diff)
downloadghdl-09a8b72257bc6f33fd2ee89c3418d8bcee6e05e6.tar.gz
ghdl-09a8b72257bc6f33fd2ee89c3418d8bcee6e05e6.tar.bz2
ghdl-09a8b72257bc6f33fd2ee89c3418d8bcee6e05e6.zip
python: supports python3, add more interfaces.
Diffstat (limited to 'src/vhdl/python/pnodespy.py')
-rwxr-xr-xsrc/vhdl/python/pnodespy.py89
1 files changed, 54 insertions, 35 deletions
diff --git a/src/vhdl/python/pnodespy.py b/src/vhdl/python/pnodespy.py
index d0168784c..11f9fcf2f 100755
--- a/src/vhdl/python/pnodespy.py
+++ b/src/vhdl/python/pnodespy.py
@@ -2,6 +2,7 @@
"""Like pnodes but output for python"""
+from __future__ import print_function
import sys
sys.path.append("../xtools")
@@ -12,44 +13,58 @@ libname = 'libghdl'
def print_enum(name, vals):
- print
- print
- print 'class {0}:'.format(name)
+ print()
+ print()
+ print('class {0}:'.format(name))
for n, k in enumerate(vals):
if k == 'None':
k = 'PNone'
- print ' {0} = {1}'.format(k, n)
+ print(' {0} = {1}'.format(k, n))
def do_class_kinds():
print_enum(pnodes.prefix_name.rstrip('_'), pnodes.kinds)
+ print()
+ print()
+ print('class Iir_Kinds:')
+ for k, v in pnodes.kinds_ranges.items():
+ print(' {0} = ['.format(k))
+ first = True
+ for e in v:
+ if first:
+ first = False
+ else:
+ print(',')
+ print(' Iir_Kind.{}'.format(e), end='')
+ print(']')
+ print()
def do_iirs_subprg():
classname = pnodes.node_type.lower() + 's'
- print
- print 'Get_Kind = {0}.{1}__get_kind'.format(libname, classname)
- print 'Get_Location = {0}.nodes__get_location'.format(libname, classname)
+ print()
+ print('Get_Kind = {0}.{1}__get_kind'.format(libname, classname))
+ print('Get_Location = {0}.nodes__get_location'.format(libname, classname))
for k in pnodes.funcs:
- print
- print 'Get_{0} = {1}.{2}__get_{3}'.format(
- k.name, libname, classname, k.name.lower())
- print
- print 'Set_{0} = {1}.{2}__set_{3}'.format(
- k.name, libname, classname, k.name.lower(), k.pname, k.rname)
+ print()
+ print('Get_{0} = {1}.{2}__get_{3}'.format(
+ k.name, libname, classname, k.name.lower()))
+ print()
+ print('Set_{0} = {1}.{2}__set_{3}'.format(
+ k.name, libname, classname, k.name.lower(), k.pname, k.rname))
def do_libghdl_elocations():
classname = 'elocations'
- print 'from libghdl import libghdl'
- print
+ print('from libghdl import libghdl')
+ print()
for k in pnodes.funcs:
- print
- print 'Get_{0} = {1}.{2}__get_{3}'.format(
- k.name, libname, classname, k.name.lower())
- print
- print 'Set_{0} = {1}.{2}__set_{3}'.format(
- k.name, libname, classname, k.name.lower(), k.pname, k.rname)
+ print()
+ print('Get_{0} = {1}.{2}__get_{3}'.format(
+ k.name, libname, classname, k.name.lower()))
+ print()
+ print('Set_{0} = {1}.{2}__set_{3}'.format(
+ k.name, libname, classname, k.name.lower(), k.pname, k.rname))
def do_class_types():
@@ -57,19 +72,19 @@ def do_class_types():
def do_types_subprg():
- print
+ print()
for k in pnodes.get_types():
- print
- print 'Get_{0} = {1}.nodes_meta__get_{2}'.format(
- k, libname, k.lower())
+ print()
+ print('Get_{0} = {1}.nodes_meta__get_{2}'.format(
+ k, libname, k.lower()))
def do_has_subprg():
- print
+ print()
for f in pnodes.funcs:
- print
- print 'Has_{0} =\\'.format(f.name)
- print ' {0}.nodes_meta__has_{1}'.format(libname, f.name.lower())
+ print()
+ print('Has_{0} =\\'.format(f.name))
+ print(' {0}.nodes_meta__has_{1}'.format(libname, f.name.lower()))
def do_class_field_attributes():
@@ -100,17 +115,18 @@ def read_spec_enum(type_name, prefix, class_name):
def do_libghdl_iirs():
- print 'from libghdl import libghdl'
+ print('from libghdl import libghdl')
do_class_kinds()
read_spec_enum('Iir_Mode', 'Iir', 'Iir_Mode')
+ read_spec_enum('Date_State_Type', 'Date', 'Date_State')
read_spec_enum('Iir_Predefined_Functions',
'Iir_Predefined', 'Iir_Predefined')
do_iirs_subprg()
def do_libghdl_meta():
- print 'from libghdl import libghdl'
- print """
+ print('from libghdl import libghdl')
+ print("""
# From nodes_meta
@@ -122,7 +138,7 @@ get_field_by_index = libghdl.nodes_meta__get_field_by_index
get_field_type = libghdl.nodes_meta__get_field_type
-get_field_attribute = libghdl.nodes_meta__get_field_attribute"""
+get_field_attribute = libghdl.nodes_meta__get_field_attribute""")
do_class_types()
do_class_field_attributes()
do_class_fields()
@@ -168,9 +184,12 @@ def do_libghdl_names():
val_max = max(val_max, val)
dict[name_def] = val
res.append((name_def, val))
- print 'class Name:'
+ print('class Name:')
for n, v in res:
- print ' {0} = {1}'.format(n, v)
+ # Avoid clash with Python names
+ if n in ['False', 'True']:
+ n = 'N' + n
+ print(' {0} = {1}'.format(n, v))
def do_libghdl_tokens():