aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyGHDL/libghdl/errorout_console.py3
-rw-r--r--pyGHDL/libghdl/errorout_memory.py42
-rw-r--r--pyGHDL/libghdl/files_map.py5
-rw-r--r--pyGHDL/libghdl/files_map_editor.py70
-rw-r--r--pyGHDL/libghdl/flags.py11
-rw-r--r--pyGHDL/libghdl/libraries.py96
-rw-r--r--pyGHDL/libghdl/vhdl/canon.py10
-rw-r--r--pyGHDL/libghdl/vhdl/flists.py50
-rw-r--r--pyGHDL/libghdl/vhdl/formatters.py69
-rw-r--r--pyGHDL/libghdl/vhdl/lists.py128
-rw-r--r--pyGHDL/libghdl/vhdl/nodes_utils.py75
-rw-r--r--pyGHDL/libghdl/vhdl/parse.py23
-rw-r--r--pyGHDL/libghdl/vhdl/scanner.py96
-rw-r--r--pyGHDL/libghdl/vhdl/sem.py19
-rw-r--r--pyGHDL/libghdl/vhdl/sem_lib.py39
-rw-r--r--pyGHDL/libghdl/vhdl/std_package.py23
16 files changed, 650 insertions, 109 deletions
diff --git a/pyGHDL/libghdl/errorout_console.py b/pyGHDL/libghdl/errorout_console.py
index a553e70b9..4edf3da7b 100644
--- a/pyGHDL/libghdl/errorout_console.py
+++ b/pyGHDL/libghdl/errorout_console.py
@@ -9,7 +9,7 @@
# Authors: Tristan Gingold
# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
@@ -40,4 +40,5 @@ from pyGHDL.libghdl import libghdl
@export
def Install_Handler() -> None:
+ """Install the handlers for reporting errors."""
libghdl.errorout__console__install_handler()
diff --git a/pyGHDL/libghdl/errorout_memory.py b/pyGHDL/libghdl/errorout_memory.py
index 444c53e80..97873a1d3 100644
--- a/pyGHDL/libghdl/errorout_memory.py
+++ b/pyGHDL/libghdl/errorout_memory.py
@@ -43,6 +43,26 @@ from pyGHDL.libghdl._types import ErrorIndex
@export
class Error_Message(Structure):
+ """
+ Id : Msgid_Type
+ Message error/warning id
+
+ Group : Group_Type;
+ Whether this is an single message or a related one.
+
+ File : Source_File_Entry;
+ Error soure file.
+
+ Line : Natural;
+ The first line is line 1, 0 can be used when line number is not relevant.
+
+ Offset : Natural;
+ Offset in the line. The first character is at offset 0.
+
+ Length : Natural;
+ Length of the location (for a range). It is assumed to be on the same line;
+ use 0 when unknown.
+ """
_fields_ = [
("id", c_int8),
("group", c_int8),
@@ -62,24 +82,43 @@ Msg_Last = 3
@export
def Install_Handler() -> None:
+ """Install the handlers for reporting errors."""
libghdl.errorout__memory__install_handler()
@export
def Get_Nbr_Messages() -> ErrorIndex:
+ """
+ Get number of error messages available.
+
+ :return: Number of messages available.
+ """
return libghdl.errorout__memory__get_nbr_messages()
@export
-def Get_Error_Record(Idx: ErrorIndex): # FIXME: returns Error_Message
+def Get_Error_Record(Idx: ErrorIndex) -> Error_Message:
+ """
+ Get error messages by index :obj:`Idy` as structure :class:`Error_Message`.
+
+ :param Idx: Index from 1 to ``Nbr_Messages`` See :func:`Get_Nbr_Messages`.
+ :return: Type: ``Error_Message``
+ """
func = libghdl.errorout__memory__get_error_record
func.argstypes = [c_int32]
func.restype = Error_Message
+
return func(Idx)
@export
def Get_Error_Message(Idx: ErrorIndex) -> str:
+ """
+ Get error messages by index :obj:`Idy` as string.
+
+ :param Idx: Index from 1 to ``Nbr_Messages`` See :func:`Get_Nbr_Messages`.
+ :return: Type: ``Error_Message``
+ """
func = libghdl.errorout__memory__get_error_message_addr
func.argstype = [c_int32]
func.restype = c_char_p
@@ -89,4 +128,5 @@ def Get_Error_Message(Idx: ErrorIndex) -> str:
@export
def Clear_Errors() -> None:
+ """Remove all error messages."""
libghdl.errorout__memory__clear_errors()
diff --git a/pyGHDL/libghdl/files_map.py b/pyGHDL/libghdl/files_map.py
index 195b1d70e..b850a0a20 100644
--- a/pyGHDL/libghdl/files_map.py
+++ b/pyGHDL/libghdl/files_map.py
@@ -40,6 +40,11 @@ from pydecor import export
from pyGHDL.libghdl import libghdl
from pyGHDL.libghdl._types import NameId, SourceFileEntry
+__all__ = [
+ 'EOT',
+ 'No_Source_File_Entry',
+ 'No_Location',
+]
EOT = b"\x04"
diff --git a/pyGHDL/libghdl/files_map_editor.py b/pyGHDL/libghdl/files_map_editor.py
index ebd6c6724..410fdb1e4 100644
--- a/pyGHDL/libghdl/files_map_editor.py
+++ b/pyGHDL/libghdl/files_map_editor.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -34,15 +35,68 @@
#
from ctypes import c_int32, c_char_p, c_bool
+from pydecor import export
+
from pyGHDL.libghdl import libghdl
+from pyGHDL.libghdl._types import SourceFileEntry
+
+
+@export
+def Replace_Text(File: SourceFileEntry, Start_Line: int, Start_Offset: int, End_Line: int, End_Offset: int, Text_Pointer, Text_Length: int) -> bool:
+ """ Replace [START; END) by TEXT.
+
+ .. todo:: Replace ``Text_Pointer`` and ``Text_Length`` with Python string
+
+ :param File: File where to replace a text section.
+ :param Start_Line:
+ :param Start_Offset:
+ :param End_Line:
+ :param End_Offset:
+ :param Text_Pointer: Type: ``File_Buffer_Ptr``
+ :param Text_Length: Type: ``Source_Ptr``
+ :return: Return True in case of success, False in case of failure (the gap is too small).
+ """
+ func = libghdl.files_map__editor__replace_text_ptr
+ func.argstype = [c_int32, c_int32, c_int32, c_int32, c_char_p, c_int32]
+ func.restype = c_bool
+
+ return func(File, Start_Line, Start_Offset, End_Line, End_Offset, Text_Pointer, Text_Length)
+
+
+@export
+def Fill_Text(File: SourceFileEntry, Text_Pointer, Text_Length: int) -> None:
+ """Replace the content of :obj:`File` with TEXT.
+
+ .. todo:: Replace ``Text_Pointer`` and ``Text_Length`` with Python string
+
+ :param File: File where to replace the content.
+ :param Text_Pointer: Type: ``File_Buffer_Ptr``
+ :param Text_Length: Type: ``Source_Ptr``
+ """
+ libghdl.files_map__editor__fill_text_ptr(File, Text_Pointer, Text_Length)
+
+
+@export
+def Check_Buffer_Content(File: SourceFileEntry, String_Pointer, String_Length: int) -> None:
+ """
+ Check that content of :obj:`File` is STR[1 .. STR_LEN].
+
+ .. todo:: Replace ``String_Pointer`` and ``String_Length`` with Python string
+ :param File: File to check the content.
+ :param String_Pointer: Type: ``File_Buffer_Ptr``
+ :param String_Length: Type: ``Source_Ptr``
+ """
+ libghdl.files_map__editor__check_buffer_content(File, String_Pointer, String_Length)
-Replace_Text = libghdl.files_map__editor__replace_text_ptr
-Replace_Text.argstype = [c_int32, c_int32, c_int32, c_int32, c_char_p, c_int32]
-Replace_Text.restype = c_bool
-Fill_Text = libghdl.files_map__editor__fill_text_ptr
+@export
+def Copy_Source_File(Dest: SourceFileEntry, Src: SourceFileEntry) -> None:
+ """
+ Copy content of :obj:`Src` to :obj:`Dest`.
-Check_Buffer_Content = libghdl.files_map__editor__check_buffer_content
+ .. warning:: The size of :obj:`Dest` must be large enough.
-Copy_Source_File = libghdl.files_map__editor__copy_source_file
+ Clear lines table of :obj:`Dest`.
+ """
+ return libghdl.files_map__editor__copy_source_file(Dest, Src)
diff --git a/pyGHDL/libghdl/flags.py b/pyGHDL/libghdl/flags.py
index 907b736a3..d87f108c6 100644
--- a/pyGHDL/libghdl/flags.py
+++ b/pyGHDL/libghdl/flags.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -36,6 +37,12 @@ from ctypes import c_bool, sizeof
from pyGHDL.libghdl import libghdl
+__all__ = [
+ 'Flag_Elocations',
+ 'Verbose',
+ 'Flag_Elaborate_With_Outdated',
+ 'Flag_Force_Analysis'
+]
assert sizeof(c_bool) == 1
diff --git a/pyGHDL/libghdl/libraries.py b/pyGHDL/libghdl/libraries.py
index 4fc91f062..895194458 100644
--- a/pyGHDL/libghdl/libraries.py
+++ b/pyGHDL/libghdl/libraries.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -34,23 +35,94 @@
#
from ctypes import c_int32
+from pydecor import export
+
from pyGHDL.libghdl import libghdl
+__all__ = [
+ 'Library_Location',
+ 'Work_Library'
+]
+
+from pyGHDL.libghdl._types import NameId
+
+
+Library_Location = c_int32.in_dll(libghdl, "libraries__library_location") #: A location for library declarations (such as library WORK). Type ``Location_Type``. Use ``.value`` to access this variable inside libghdl
+Work_Library = c_int32.in_dll(libghdl, "libraries__work_library") #: Library declaration for the work library. Note: the identifier of the work_library is ``work_library_name``, which may be different from 'WORK'. Type: ``Iir_Library_Declaration``. Use ``.value`` to access this variable inside libghdl
+
+
+@export
+def Get_Libraries_Chain():
+ """
+ Get the chain of libraries. Can be used only to read (it mustn't be modified).
+
+ :return: Type ``Iir_Library_Declaration``
+ """
+ return libghdl.libraries__get_libraries_chain()
+
+
+@export
+def Add_Design_Unit_Into_Library(Unit, Keep_Obsolete: bool = False) -> None:
+ """
+ Add or replace an design unit in the work library. DECL must not have a chain
+ (because it may be modified).
+
+ If the design_file of UNIT is not already in the library, a new one is created.
+
+ Units are always appended to the design_file. Therefore, the order is kept.
+
+ :param Unit: Type: ``Iir_Design_Unit``
+ :param Keep_Obsolete: If :obj:`Keep_Obsolete` is True, obsoleted units are
+ kept in the library.
+
+ This is used when a whole design file has to be added
+ in the library and then processed (without that feature,
+ redefined units would disappear).
+ """
+ libghdl.libraries__add_design_unit_into_library(Unit, Keep_Obsolete)
+
+
+@export
+def Purge_Design_File(Design_File) -> None:
+ """
+ Remove the same file as DESIGN_FILE from work library and all of its units.
+
+ :param Design_File: Type: ``Iir_Design_File``
+ """
+ libghdl.libraries__purge_design_file(Design_File)
+
-Get_Libraries_Chain = libghdl.libraries__get_libraries_chain
+@export
+def Find_Entity_For_Component(Name: NameId):
+ """
+ Find an entity whose name is :obj:`Name` in any library. |br|
+ If there is no such entity, return :attr:`~pyGHDL.libghdl.vhdl.nodes.Null_Iir`. |br|
+ If there are several entities, return :attr:`~pyGHDL.libghdl.vhdl.nodes.Null_Iir`;
-Add_Design_Unit_Into_Library = libghdl.libraries__add_design_unit_into_library
+ :param Name: Entity name to search for.
+ :return: Type: ``Iir_Design_Unit``
+ """
+ return libghdl.libraries__find_entity_for_component(Name)
-# Use .value
-Library_Location = c_int32.in_dll(libghdl, "libraries__library_location")
-# Use .value
-Work_Library = c_int32.in_dll(libghdl, "libraries__work_library")
+@export
+def Get_Library_No_Create(Ident: NameId):
+ """
+ Get the library named :obj:`Ident`.
-Purge_Design_File = libghdl.libraries__purge_design_file
+ :param Ident: Libryr to look for.
+ :return: Return :attr:`~pyGHDL.libghdl.vhdl.nodes.Null_Iir` if it doesn't exist. Type ``Iir_Library_Declaration``
+ """
+ return libghdl.libraries__get_library_no_create(Ident)
-Find_Entity_For_Component = libghdl.libraries__find_entity_for_component
-Get_Library_No_Create = libghdl.libraries__get_library_no_create
+@export
+def Find_Primary_Unit(Library, Name: NameId):
+ """
+ Just return the design_unit for :obj:`Name`, or ``NULL`` if not found.
-Find_Primary_Unit = libghdl.libraries__find_primary_unit
+ :param Library: Library to look in. Type: ``Iir_Library_Declaration``
+ :param Name: Primary unit to search for.
+ :return: Type: ``Iir_Design_Unit``
+ """
+ return libghdl.libraries__find_primary_unit(Library, Name)
diff --git a/pyGHDL/libghdl/vhdl/canon.py b/pyGHDL/libghdl/vhdl/canon.py
index e54bb06e1..d4e5eb4e3 100644
--- a/pyGHDL/libghdl/vhdl/canon.py
+++ b/pyGHDL/libghdl/vhdl/canon.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -36,6 +37,11 @@ from ctypes import c_bool
from pyGHDL.libghdl import libghdl
+__all__ = [
+ 'Flag_Concurrent_Stmts',
+ 'Flag_Configurations',
+ 'Flag_Associations'
+]
Flag_Concurrent_Stmts = c_bool.in_dll(
libghdl, "vhdl__canon__canon_flag_concurrent_stmts"
diff --git a/pyGHDL/libghdl/vhdl/flists.py b/pyGHDL/libghdl/vhdl/flists.py
index df7f87cc5..2c123cb20 100644
--- a/pyGHDL/libghdl/vhdl/flists.py
+++ b/pyGHDL/libghdl/vhdl/flists.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -34,14 +35,51 @@
#
from ctypes import c_int32
+from pydecor import export
+
from pyGHDL.libghdl import libghdl
+__all__ = [
+ 'Flist_Type',
+ 'Ffirst'
+]
-Flist_Type = c_int32
+Flist_Type = c_int32 #: First index of a ``FList``.
Ffirst = 0
-Flast = libghdl.vhdl__flists__flast
-Length = libghdl.vhdl__flists__length
+@export
+def Flast(FList) -> int:
+ """
+ Last index of :obj:`FList`.
+
+ .. hint:: Could be used to iterate.
+
+ :param FList: List to query.
+ :return: Index of the last element in the list.
+ """
+ return libghdl.vhdl__flists__flast(FList)
+
+
+@export
+def Length(FList) -> int:
+ """
+ Get the length of :obj:`FList`.
+
+ :param FList: List to query.
+ :return: Number of elements in the list.
+ """
+ return libghdl.vhdl__flists__length(FList)
+
+
+@export
+def Get_Nth_Element(FList, N: int):
+ """
+ Get the N-th element of :obj:`FList`.
+
+ First element has index 0.
-Get_Nth_Element = libghdl.vhdl__flists__get_nth_element
+ :param FList: List to query.
+ :return: Type: ``El_Type``
+ """
+ return libghdl.vhdl__flists__get_nth_element(FList, N)
diff --git a/pyGHDL/libghdl/vhdl/formatters.py b/pyGHDL/libghdl/vhdl/formatters.py
index 3c15c724c..fe9098297 100644
--- a/pyGHDL/libghdl/vhdl/formatters.py
+++ b/pyGHDL/libghdl/vhdl/formatters.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -34,17 +35,67 @@
#
from ctypes import c_int32, c_char_p
+from pydecor import export
+
from pyGHDL.libghdl import libghdl
-Indent_String = libghdl.vhdl__formatters__indent_string
+@export
+def Indent_String(File, Handle, FirstLine: int, LastLine: int) -> None:
+ """
+ Reindent all lines of F between [First_Line; Last_Line] to :obj:`Handle`.
+
+ :param File: File to indent lines within. Type: ``Iir_Design_File``
+ :param Handle: undocumented. Type: ``Vstring_Acc``
+ :param FirstLine: undocumented.
+ :param LastLine: undocumented.
+ """
+ libghdl.vhdl__formatters__indent_string(File, Handle, FirstLine, LastLine)
+
+
+@export
+def Allocate_Handle():
+ """
+ .. todo:: Undocumented in Ada code.
+
+ :return: undocumented. Type: ``Vstring_Acc``
+ """
+ return libghdl.vhdl__formatters__allocate_handle()
+
+
+@export
+def Get_Length(Handle) -> int:
+ """
+ .. todo:: Undocumented in Ada code.
+
+ :param Handle: undocumented. Type: ``Vstring_Acc``
+ :return: undocumented.
+ """
+ func = libghdl.vhdl__formatters__get_length
+ func.restype = c_int32
+
+ return func(Handle)
+
+
+@export
+def Get_C_String(Handle):
+ """
+ .. todo:: Undocumented in Ada code.
+
+ :param Handle: undocumented. Type: ``Vstring_Acc``
+ :return: Type: ``Grt.Types.Ghdl_C_String``
+ """
+ func = libghdl.vhdl__formatters__get_c_string
+ func.restype = c_char_p
-Allocate_Handle = libghdl.vhdl__formatters__allocate_handle
+ return func(Handle)
-Get_Length = libghdl.vhdl__formatters__get_length
-Get_Length.restype = c_int32
-Get_C_String = libghdl.vhdl__formatters__get_c_string
-Get_C_String.restype = c_char_p
+@export
+def Free_Handle(Handle) -> None:
+ """
+ .. todo:: Undocumented in Ada code.
-Free_Handle = libghdl.vhdl__formatters__free_handle
+ :param Handle: undocumented. Type: ``Vstring_Acc``
+ """
+ libghdl.vhdl__formatters__free_handle(Handle)
diff --git a/pyGHDL/libghdl/vhdl/lists.py b/pyGHDL/libghdl/vhdl/lists.py
index efb5b4ea9..dc4391ebf 100644
--- a/pyGHDL/libghdl/vhdl/lists.py
+++ b/pyGHDL/libghdl/vhdl/lists.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -39,34 +40,117 @@ from pydecor import export
from pyGHDL.libghdl import libghdl
-List_Type = c_int32
+@export
+class Iterator(Structure):
+ _fields_ = [
+ ("chunk", c_int32),
+ ("chunk_idx", c_int32),
+ ("remain", c_int32)
+ ]
@export
-class Iterator(Structure):
- _fields_ = [("chunk", c_int32), ("chunk_idx", c_int32), ("remain", c_int32)]
+def Iterate(List) -> Iterator:
+ """
+ Create an iterator for a given list.
+
+ The idiomatic way to iterate is:
+ .. code-block:: Python
-Iterate = libghdl.vhdl__lists__iterate
-Iterate.argstype = [List_Type]
-Iterate.restype = Iterator
+ It = Iterate(List)
+ while Is_Valid(It):
+ El = Get_Element(It)
+ # ...
+ Next(It)
-Is_Valid = libghdl.vhdl__lists__is_valid
-Is_Valid.argstype = [POINTER(Iterator)]
-Is_Valid.restype = c_bool
+ :param List: List to create an iterator from.
+ :return: Iterator structure.
+ """
+ func = libghdl.vhdl__lists__iterate
+ func.argstype = [(c_int32)]
+ func.restype = Iterator
+
+ return func(List)
+
+
+@export
+def Is_Valid(Iterator) -> bool:
+ """
+ Check if iterator reached the end.
-Next = libghdl.vhdl__lists__next
-Next.argstype = [POINTER(Iterator)]
-Next.restype = None
+ :param Iterator: Iterator to check.
+ :return: False, if iterator has reached the end.
+ """
+ func = libghdl.vhdl__lists__is_valid
+ func.argstype = [POINTER(Iterator)]
+ func.restype = c_bool
-Get_Element = libghdl.vhdl__lists__get_element
-Get_Element.argstype = [POINTER(Iterator)]
-Get_Element.restype = c_int32
+ return func(Iterator)
-Get_Nbr_Elements = libghdl.vhdl__lists__get_nbr_elements
-Get_Nbr_Elements.argtype = [List_Type]
-Get_Nbr_Elements.restype = c_int32
-Create_Iir_List = libghdl.vhdl__lists__create_list
+@export
+def Next(Iterator):
+ """
+ Move iterator to the next element.
+
+ :param Iterator: Iterator to increment.
+ :return: False, if iterator has reached the end.
+ """
+ func = libghdl.vhdl__lists__next
+ func.argstype = [POINTER(Iterator)]
+ func.restype = None
+
+ func(Iterator)
+
+
+@export
+def Get_Element(Iterator) -> int:
+ """
+ Get the current element from iterator.
+
+ :param Iterator: Iterator the get the element from.
+ :return: The current element the iterator points to. Type: ``El_Type``
+ """
+ func = libghdl.vhdl__lists__get_element
+ func.argstype = [POINTER(Iterator)]
+ func.restype = c_int32
+
+ return func(Iterator)
+
+
+@export
+def Get_Nbr_Elements(List) -> int:
+ """
+ Return the number of elements in the list.
+
+ .. hint:: This is also 1 + the position of the last element.
+
+ :param List: The list to use.
+ :return: Number of list elements.
+ """
+ func = libghdl.vhdl__lists__get_nbr_elements
+ func.argtype = [(c_int32)]
+ func.restype = c_int32
+
+ return func(List)
+
+
+@export
+def Create_Iir_List():
+ """
+ Create a list.
+
+ :return: Type: ``List_Type``
+ """
+ return libghdl.vhdl__lists__create_list()
+
+
+@export
+def Destroy_Iir_List(List) -> None:
+ """
+ Destroy a list.
-Destroy_Iir_List = libghdl.vhdl__lists__destroy_list
+ :param List: List to destroy.
+ """
+ libghdl.vhdl__lists__destroy_list(List)
diff --git a/pyGHDL/libghdl/vhdl/nodes_utils.py b/pyGHDL/libghdl/vhdl/nodes_utils.py
index 650bc9f54..b2cbef56f 100644
--- a/pyGHDL/libghdl/vhdl/nodes_utils.py
+++ b/pyGHDL/libghdl/vhdl/nodes_utils.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -32,17 +33,71 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
#
-from pyGHDL.libghdl import libghdl
+from pydecor import export
+from pyGHDL.libghdl import libghdl, Iir
-Strip_Denoting_Name = libghdl.vhdl__utils__strip_denoting_name
-Get_Entity = libghdl.vhdl__utils__get_entity
+@export
+def Strip_Denoting_Name(Name: Iir) -> Iir:
+ """
+ If :obj:`Name` is a simple or an expanded name, return the denoted declaration.
+ Otherwise, return :obj:`Name`.
-Is_Second_Subprogram_Specification = (
- libghdl.vhdl__utils__is_second_subprogram_specification
-)
+ :param Name: Simple or an expanded name.
+ :return: Denoted declaration.
+ """
+ return libghdl.vhdl__utils__strip_denoting_name(Name)
-Get_Entity_From_Entity_Aspect = libghdl.vhdl__utils__get_entity_from_entity_aspect
-Get_Interface_Of_Formal = libghdl.vhdl__utils__get_interface_of_formal
+@export
+def Get_Entity(Decl: Iir) -> Iir:
+ """
+ This is a wrapper around ``Get_Entity_Name`` to return the entity declaration
+ of the entity name of :obj:`Decl`, or ``Null_Iir`` in case of error.
+
+ :param Decl: Declaration
+ :return: Entity
+ """
+ return libghdl.vhdl__utils__get_entity(Decl)
+
+
+@export
+def Is_Second_Subprogram_Specification(Spec: Iir) -> bool:
+ """
+ Check if :obj:`Spec` is the subprogram specification of a subprogram body
+ which was previously declared. In that case, the only use of :obj:`Spec`
+ is to match the body with its declaration.
+
+ :param Spec: Specification
+ :return: ``True`` if subprogram specification and previously declared subprogram body match
+ """
+ return libghdl.vhdl__utils__is_second_subprogram_specification(Spec)
+
+
+@export
+def Get_Entity_From_Entity_Aspect(Aspect: Iir) -> Iir:
+ """
+ Extract the entity from :obj:`Aspect`.
+
+ .. note::
+
+ If :obj:`Aspect` is a component declaration, return :obj:`Aspect`. |br|
+ If :obj:`Aspect` is open, return ``Null_Iir``
+
+ :param Aspect: Aspect
+ :return: Entity
+ """
+ return libghdl.vhdl__utils__get_entity_from_entity_aspect(Aspect)
+
+
+@export
+def Get_Interface_Of_Formal(Formal: Iir) -> Iir:
+ """
+ Get the interface corresponding to the formal name :obj:`Formal`. This is
+ always an interface, even if the formal is a name.
+
+ :param Formal: The formal.
+ :return: The corresponding interface.
+ """
+ return libghdl.vhdl__utils__get_interface_of_formal(Formal)
diff --git a/pyGHDL/libghdl/vhdl/parse.py b/pyGHDL/libghdl/vhdl/parse.py
index ecb84736f..69083c469 100644
--- a/pyGHDL/libghdl/vhdl/parse.py
+++ b/pyGHDL/libghdl/vhdl/parse.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -34,9 +35,25 @@
#
from ctypes import c_bool
+from pydecor import export
+
from pyGHDL.libghdl import libghdl
+__all__ = [
+ 'Flag_Parse_Parenthesis'
+]
-Parse_Design_File = libghdl.vhdl__parse__parse_design_file
Flag_Parse_Parenthesis = c_bool.in_dll(libghdl, "vhdl__parse__flag_parse_parenthesis")
+
+
+@export
+def Parse_Design_File():
+ """
+ Parse a file.
+
+ ..note:: The scanner must have been initialized as for parse_design_unit.
+
+ :return: Return :obj:`~pyGHDL.libghdl.vhdl.nodes.Null_Iir` in case of error. Type: ``Iir_Design_File``
+ """
+ return libghdl.vhdl__parse__parse_design_file()
diff --git a/pyGHDL/libghdl/vhdl/scanner.py b/pyGHDL/libghdl/vhdl/scanner.py
index 1debe9dde..1215c97a2 100644
--- a/pyGHDL/libghdl/vhdl/scanner.py
+++ b/pyGHDL/libghdl/vhdl/scanner.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -34,26 +35,95 @@
#
from ctypes import c_int, c_bool
-from pyGHDL.libghdl import libghdl
-
+from pydecor import export
-Set_File = libghdl.vhdl__scanner__set_file
+from pyGHDL.libghdl import libghdl
+from pyGHDL.libghdl._types import SourceFileEntry, NameId
-Close_File = libghdl.vhdl__scanner__close_file
-Scan = libghdl.vhdl__scanner__scan
+__all__ = [
+ 'Current_Token',
+ 'Flag_Comment'
+]
# This is a c_int, so you want to use its .value
Current_Token = c_int.in_dll(libghdl, "vhdl__scanner__current_token")
-
Flag_Comment = c_bool.in_dll(libghdl, "vhdl__scanner__flag_comment")
-Get_Current_Line = libghdl.vhdl__scanner__get_current_line
-Get_Token_Offset = libghdl.vhdl__scanner__get_token_offset
+@export
+def Set_File(SourceFile: SourceFileEntry) -> None:
+ """
+ Initialize the scanner with file :obj:`SourceFile`.
+
+ :param SourceFile: File to scan.
+ """
+ libghdl.vhdl__scanner__set_file(SourceFile)
+
+
+@export
+def Close_File() -> None:
+ """Finalize the scanner."""
+ libghdl.vhdl__scanner__close_file()
+
+
+@export
+def Scan() -> None:
+ """Get a new token."""
+ libghdl.vhdl__scanner__scan()
+
+
+@export
+def Get_Current_Line() -> int:
+ """
+ Get the current token's line.
+
+ :return: Current token's line.
+ """
+ """ -- Get the current location, or the location of the current token.
+ -- Since a token cannot spread over lines, file and line of the current
+ -- token are the same as those of the current position.
+ -- The offset is the offset in the current line."""
+ return libghdl.vhdl__scanner__get_current_line()
+
+
+@export
+def Get_Token_Offset() -> int:
+ """
+ Get the current token's offset in the current line.
+
+ :return: Current token's offset.
+ """
+ return libghdl.vhdl__scanner__get_token_offset()
+
+
+@export
+def Get_Token_Position():
+ """
+ Get the current token's position.
+
+ :return: Current token's position. Type: ``Source_Ptr``
+ """
+ return libghdl.vhdl__scanner__get_token_position()
+
+
+@export
+def Get_Position():
+ """
+ Get the current position.
+
+ :return: Current position. Type: ``Source_Ptr``
+ """
+ return libghdl.vhdl__scanner__get_position()
-Get_Token_Position = libghdl.vhdl__scanner__get_token_position
-Get_Position = libghdl.vhdl__scanner__get_position
+@export
+def Current_Identifier() -> NameId:
+ """
+ When :attr:`~pyGHDL.libghdl.vhdl.scanner.Current_Token` is an
+ ``tok_identifier``, ``tok_char`` or ``tok_string``, its name_id can be
+ retrieved via this function.
-Current_Identifier = libghdl.vhdl__scanner__current_identifier
+ :return: NameId of the current token.
+ """
+ return libghdl.vhdl__scanner__current_identifier()
diff --git a/pyGHDL/libghdl/vhdl/sem.py b/pyGHDL/libghdl/vhdl/sem.py
index 751611cbe..24a9b44c3 100644
--- a/pyGHDL/libghdl/vhdl/sem.py
+++ b/pyGHDL/libghdl/vhdl/sem.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -32,7 +33,19 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
#
+from pydecor import export
+
from pyGHDL.libghdl import libghdl
-Semantic = libghdl.vhdl__sem__semantic
+@export
+def Semantic(DesignUnit) -> None:
+ """
+ Do the semantic analysis of design unit :obj:`DesignUnit`.
+
+ Also add a few node or change some nodes, when for exemple an identifier is
+ changed into an access to the type.
+
+ :param DesignUnit: Design unit to semantically analyze. Type: ``Iir_Design_Unit``
+ """
+ libghdl.vhdl__sem__semantic(DesignUnit)
diff --git a/pyGHDL/libghdl/vhdl/sem_lib.py b/pyGHDL/libghdl/vhdl/sem_lib.py
index d2a807656..9fcc7ac79 100644
--- a/pyGHDL/libghdl/vhdl/sem_lib.py
+++ b/pyGHDL/libghdl/vhdl/sem_lib.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -32,11 +33,39 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
#
+from pydecor import export
+
from pyGHDL.libghdl import libghdl
+from pyGHDL.libghdl._types import SourceFileEntry
+
+
+@export
+def Load_File(File: SourceFileEntry):
+ """
+ Start to analyse a file (i.e. load and parse it).
+
+ :param File: File to analyse.
+ :return: Return :attr:`~pyGHDL.libghdl.vhdl.nodes.Null_Iir` in case of parse error. Type: ``Iir_Design_File``
+ """
+ return libghdl.vhdl__sem_lib__load_file(File)
+
+
+@export
+def Finish_Compilation(Unit, Main: bool = False) -> None:
+ """
+ Analyze :obj:`Unit`.
+ :param Unit: Design unit to analyze.
+ :param Main: Is main unit.
+ """
+ libghdl.vhdl__sem_lib__finish_compilation(Unit, Main)
-Load_File = libghdl.vhdl__sem_lib__load_file
-Finish_Compilation = libghdl.vhdl__sem_lib__finish_compilation
+@export
+def Free_Dependence_List(Design) -> None:
+ """
+ Free the dependence list of :obj:`Design`.
-Free_Dependence_List = libghdl.vhdl__sem_lib__free_dependence_list
+ :param Design: Design unit to free dependencies for.
+ """
+ libghdl.vhdl__sem_lib__free_dependence_list(Design)
diff --git a/pyGHDL/libghdl/vhdl/std_package.py b/pyGHDL/libghdl/vhdl/std_package.py
index fa5d5e2b7..bf347efba 100644
--- a/pyGHDL/libghdl/vhdl/std_package.py
+++ b/pyGHDL/libghdl/vhdl/std_package.py
@@ -7,12 +7,13 @@
# |_| |___/ |___/
# =============================================================================
# Authors: Tristan Gingold
+# Patrick Lehmann
#
-# Package package: Python binding and low-level API for shared library 'libghdl'.
+# Package module: Python binding and low-level API for shared library 'libghdl'.
#
# License:
# ============================================================================
-# Copyright (C) 2019-2020 Tristan Gingold
+# Copyright (C) 2019-2021 Tristan Gingold
#
# GHDL is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
@@ -36,14 +37,12 @@ from ctypes import c_int32
from pyGHDL.libghdl import libghdl
+__all__ = [
+ 'Std_Location',
+ 'Standard_Package',
+ 'Character_Type_Definition'
+]
-# Use .value
-Std_Location = c_int32.in_dll(libghdl, "vhdl__std_package__std_location")
-
-# Use .value
-Standard_Package = c_int32.in_dll(libghdl, "vhdl__std_package__standard_package")
-
-# Use .value
-Character_Type_Definition = c_int32.in_dll(
- libghdl, "vhdl__std_package__character_type_definition"
-)
+Std_Location = c_int32.in_dll(libghdl, "vhdl__std_package__std_location") #: Virtual location for the ``std.standard`` package. Type ``Location_Type``. Use ``.value`` to access this variable inside libghdl.
+Standard_Package = c_int32.in_dll(libghdl, "vhdl__std_package__standard_package") #: Virtual package ``std.package``. Type ``Iir_Package_Declaration``. Use ``.value`` to access this variable inside libghdl.
+Character_Type_Definition = c_int32.in_dll(libghdl, "vhdl__std_package__character_type_definition") #: Predefined character. Type ``Iir_Enumeration_Type_Definition``. Use ``.value`` to access this variable inside libghdl.