diff options
author | Tristan Gingold <tgingold@free.fr> | 2017-11-23 18:33:02 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2017-11-23 18:33:02 +0100 |
commit | 345bcdbf2fbe012a8b4da772329d18757fef5594 (patch) | |
tree | cf0b071286121889773d35c0bd0f84e15e726853 /src | |
parent | 501366998031d73cc4286aefabffafda39921a67 (diff) | |
download | ghdl-345bcdbf2fbe012a8b4da772329d18757fef5594.tar.gz ghdl-345bcdbf2fbe012a8b4da772329d18757fef5594.tar.bz2 ghdl-345bcdbf2fbe012a8b4da772329d18757fef5594.zip |
Update python binding for flists.
Diffstat (limited to 'src')
-rw-r--r-- | src/lists.adb | 8 | ||||
-rw-r--r-- | src/lists.ads | 13 | ||||
-rw-r--r-- | src/vhdl/iirs.ads | 25 | ||||
-rw-r--r-- | src/vhdl/python/libghdl/thin.py | 55 | ||||
-rw-r--r-- | src/vhdl/python/libghdl/thinutils.py | 23 | ||||
-rwxr-xr-x | src/vhdl/python/pnodespy.py | 10 |
6 files changed, 109 insertions, 25 deletions
diff --git a/src/lists.adb b/src/lists.adb index cccfb76db..65407d943 100644 --- a/src/lists.adb +++ b/src/lists.adb @@ -173,7 +173,7 @@ package body Lists is begin return Iterator'(Chunk => L.First, Chunk_Idx => 0, - Remains => L.Nbr); + Remain => Int32 (L.Nbr)); end Iterate; function Iterate_Safe (List : List_Type) return Iterator is @@ -181,14 +181,14 @@ package body Lists is if List = Null_List then return Iterator'(Chunk => No_Chunk_Index, Chunk_Idx => 0, - Remains => 0); + Remain => 0); end if; return Iterate (List); end Iterate_Safe; function Is_Valid (It : Iterator) return Boolean is begin - return It.Remains > 0; + return It.Remain > 0; end Is_Valid; procedure Next (It : in out Iterator) is @@ -198,7 +198,7 @@ package body Lists is It.Chunk := Chunkt.Table (It.Chunk).Next; It.Chunk_Idx := 0; end if; - It.Remains := It.Remains - 1; + It.Remain := It.Remain - 1; end Next; function Get_Element (It : Iterator) return Node_Type is diff --git a/src/lists.ads b/src/lists.ads index 07e319d9f..efb7a21ea 100644 --- a/src/lists.ads +++ b/src/lists.ads @@ -103,11 +103,20 @@ package Lists is function Get_Element (It : Iterator) return Node_Type; procedure Set_Element (It : Iterator; El : Node_Type); + -- Use the C convention for all these subprograms, so that the Iterator is + -- always passed by reference. + pragma Convention (C, Is_Valid); + pragma Convention (C, Next); + pragma Convention (C, Get_Element); + pragma Convention (C, Set_Element); + -- Like Iterate, but if LIST is Null_List, it returns an iterator that is -- never valid. function Iterate_Safe (List : List_Type) return Iterator; + private type Chunk_Index_Type is new Int32; + for Chunk_Index_Type'Size use 32; No_Chunk_Index : constant Chunk_Index_Type := 0; Chunk_Len : constant := 7; @@ -123,9 +132,11 @@ private type Iterator is record Chunk : Chunk_Index_Type; Chunk_Idx : Nat32; - Remains : Natural; + Remain : Nat32; end record; + pragma Convention (C, Iterator); + pragma Inline (Iterate); pragma Inline (Is_Valid); pragma Inline (Next); pragma Inline (Get_Element); diff --git a/src/vhdl/iirs.ads b/src/vhdl/iirs.ads index 6b5de4661..08542f705 100644 --- a/src/vhdl/iirs.ads +++ b/src/vhdl/iirs.ads @@ -4826,7 +4826,13 @@ package Iirs is Iir_Predefined_Functions'Last; -- Staticness as defined by LRM93 6.1 and 7.4 - type Iir_Staticness is (Unknown, None, Globally, Locally); + type Iir_Staticness is + ( + Unknown, + None, + Globally, + Locally + ); -- Staticness as defined by LRM93 6.1 and 7.4 function Min (L,R: Iir_Staticness) return Iir_Staticness renames @@ -4870,13 +4876,20 @@ package Iirs is -- Constraint state of a type. -- See LRM08 5.1 for definition. type Iir_Constraint is - (Unconstrained, Partially_Constrained, Fully_Constrained); + ( + Unconstrained, + Partially_Constrained, + Fully_Constrained + ); -- The kind of an inteface list. - type Interface_Kind_Type is (Generic_Interface_List, - Port_Interface_List, - Procedure_Parameter_Interface_List, - Function_Parameter_Interface_List); + type Interface_Kind_Type is + ( + Generic_Interface_List, + Port_Interface_List, + Procedure_Parameter_Interface_List, + Function_Parameter_Interface_List + ); subtype Parameter_Interface_List is Interface_Kind_Type range Procedure_Parameter_Interface_List .. Function_Parameter_Interface_List; 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() |