aboutsummaryrefslogtreecommitdiffstats
path: root/src/vhdl/python
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-11-23 18:33:02 +0100
committerTristan Gingold <tgingold@free.fr>2017-11-23 18:33:02 +0100
commit345bcdbf2fbe012a8b4da772329d18757fef5594 (patch)
treecf0b071286121889773d35c0bd0f84e15e726853 /src/vhdl/python
parent501366998031d73cc4286aefabffafda39921a67 (diff)
downloadghdl-345bcdbf2fbe012a8b4da772329d18757fef5594.tar.gz
ghdl-345bcdbf2fbe012a8b4da772329d18757fef5594.tar.bz2
ghdl-345bcdbf2fbe012a8b4da772329d18757fef5594.zip
Update python binding for flists.
Diffstat (limited to 'src/vhdl/python')
-rw-r--r--src/vhdl/python/libghdl/thin.py55
-rw-r--r--src/vhdl/python/libghdl/thinutils.py23
-rwxr-xr-xsrc/vhdl/python/pnodespy.py10
3 files changed, 74 insertions, 14 deletions
diff --git a/src/vhdl/python/libghdl/thin.py b/src/vhdl/python/libghdl/thin.py
index 0a0178aa3..d16475cc6 100644
--- a/src/vhdl/python/libghdl/thin.py
+++ b/src/vhdl/python/libghdl/thin.py
@@ -1,5 +1,6 @@
from libghdl import libghdl
-from ctypes import (c_char_p, c_int32, c_int, c_bool, sizeof, c_void_p)
+from ctypes import (c_char_p, c_int32, c_int, c_bool, sizeof, c_void_p,
+ POINTER, Structure)
import libghdl.iirs as iirs
import libghdl.nodes_meta as nodes_meta
from libghdl.nodes_meta import (Attr, types)
@@ -27,13 +28,50 @@ def analyze_file(filename):
# Lists
-Get_Nbr_Elements = libghdl.lists__get_nbr_elements
-Get_Nth_Element = libghdl.lists__get_nth_element
+class Lists:
+ List_Type = c_int32
-Create_Iir_List = libghdl.lists__create_list
+ class Iterator(Structure):
+ _fields_ = [("chunk", c_int32),
+ ("chunk_idx", c_int32),
+ ("remain", c_int32)]
+
+ Iterate = libghdl.lists__iterate
+ Iterate.argstype = [List_Type]
+ Iterate.restype = Iterator
+
+ Is_Valid = libghdl.lists__is_valid
+ Is_Valid.argstype = [POINTER(Iterator)]
+ Is_Valid.restype = c_bool
+
+ Next = libghdl.lists__next
+ Next.argstype = [POINTER(Iterator)]
+ Next.restype = None
+
+ Get_Element = libghdl.lists__get_element
+ Get_Element.argstype = [POINTER(Iterator)]
+ Get_Element.restype = c_int32
+
+ Get_Nbr_Elements = libghdl.lists__get_nbr_elements
+ Get_Nbr_Elements.argtype = [List_Type]
+ Get_Nbr_Elements.restype = c_int32
+
+ Create_Iir_List = libghdl.lists__create_list
+
+ Destroy_Iir_List = libghdl.lists__destroy_list
+
+
+class Flists:
+ Flist_Type = c_int32
+
+ Ffirst = 0
+ Flast = libghdl.flists__flast
+
+ Length = libghdl.flists__length
+
+ Get_Nth_Element = libghdl.flists__get_nth_element
-Destroy_Iir_List = libghdl.lists__destroy_list
# Files
@@ -189,5 +227,8 @@ class Iirs_Utils:
Null_Iir = 0
Null_Iir_List = 0
-Iir_List_Others = 1
-Iir_List_All = 2
+Iir_List_All = 1
+
+Null_Iir_Flist = 0
+Iir_Flist_Others = 1
+Iir_Flist_All = 2
diff --git a/src/vhdl/python/libghdl/thinutils.py b/src/vhdl/python/libghdl/thinutils.py
index df69aef02..93f00b8ba 100644
--- a/src/vhdl/python/libghdl/thinutils.py
+++ b/src/vhdl/python/libghdl/thinutils.py
@@ -1,5 +1,5 @@
from libghdl import libghdl
-from ctypes import (c_char_p, c_int32, c_int, c_bool, sizeof, c_void_p)
+from ctypes import (c_char_p, c_int32, c_int, c_bool, sizeof, c_void_p, byref)
import libghdl.iirs as iirs
import libghdl.thin as thin
import libghdl.nodes_meta as nodes_meta
@@ -105,14 +105,31 @@ def nodes_iter(n):
for n1 in list_iter(nodes_meta.Get_Iir_List(n, f)):
for n2 in nodes_iter(n1):
yield n2
+ elif typ == types.Iir_Flist:
+ attr = nodes_meta.get_field_attribute(f)
+ if attr == Attr.ANone:
+ for n1 in flist_iter(nodes_meta.Get_Iir_Flist(n, f)):
+ for n2 in nodes_iter(n1):
+ yield n2
def list_iter(lst):
"""Iterate of all element of Iir_List lst."""
if lst <= thin.Iir_List_All:
return
- for i in range(thin.Get_Nbr_Elements(lst)):
- yield thin.Get_Nth_Element(lst, i)
+ iter = thin.Lists.Iterate(lst)
+ while thin.Lists.Is_Valid(byref(iter)):
+ yield thin.Lists.Get_Element(byref(iter))
+ thin.Lists.Next(byref(iter))
+
+
+def flist_iter(lst):
+ """Iterate of all element of Iir_List lst."""
+ if lst <= thin.Iir_Flist_All:
+ return
+ for i in range(thin.Flists.Flast(lst) + 1):
+ yield thin.Flists.Get_Nth_Element(lst, i)
+
def declarations_iter(n):
"""Iterator on all declarations in n."""
diff --git a/src/vhdl/python/pnodespy.py b/src/vhdl/python/pnodespy.py
index 11f9fcf2f..3f3dfb4ee 100755
--- a/src/vhdl/python/pnodespy.py
+++ b/src/vhdl/python/pnodespy.py
@@ -99,7 +99,7 @@ def do_class_fields():
def read_spec_enum(type_name, prefix, class_name):
"""Read an enumeration declaration from iirs.ads"""
pat_decl = re.compile(r' type {0} is$'.format(type_name))
- pat_enum = re.compile(r' {0}_(\w+),?(-- .*)?$'.format(prefix))
+ pat_enum = re.compile(r' {0}(\w+),?(-- .*)?$'.format(prefix))
lr = pnodes.linereader(pnodes.kind_file)
while not pat_decl.match(lr.get()):
pass
@@ -117,10 +117,12 @@ def read_spec_enum(type_name, prefix, class_name):
def do_libghdl_iirs():
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_Mode', 'Iir_', 'Iir_Mode')
+ read_spec_enum('Iir_Staticness', '', 'Iir_Staticness')
+ read_spec_enum('Iir_Constraint', '', 'Iir_Constraint')
+ read_spec_enum('Date_State_Type', 'Date_', 'Date_State')
read_spec_enum('Iir_Predefined_Functions',
- 'Iir_Predefined', 'Iir_Predefined')
+ 'Iir_Predefined_', 'Iir_Predefined')
do_iirs_subprg()