diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-01-09 01:10:22 +0100 |
---|---|---|
committer | tgingold <tgingold@users.noreply.github.com> | 2021-01-10 10:14:16 +0100 |
commit | 936a25178d085c7dbc651ea8889718eb302c012b (patch) | |
tree | 20788774623fb7e6c626119bc063f926b776e6a4 /pyGHDL/libghdl | |
parent | b2a98ec0674c031688ebf479664db6fd4975b428 (diff) | |
download | ghdl-936a25178d085c7dbc651ea8889718eb302c012b.tar.gz ghdl-936a25178d085c7dbc651ea8889718eb302c012b.tar.bz2 ghdl-936a25178d085c7dbc651ea8889718eb302c012b.zip |
Fixes for Python files.
Diffstat (limited to 'pyGHDL/libghdl')
-rw-r--r-- | pyGHDL/libghdl/__init__.py | 20 | ||||
-rw-r--r-- | pyGHDL/libghdl/_decorator.py | 73 | ||||
-rw-r--r-- | pyGHDL/libghdl/_types.py | 34 | ||||
-rw-r--r-- | pyGHDL/libghdl/errorout_console.py | 4 | ||||
-rw-r--r-- | pyGHDL/libghdl/errorout_memory.py | 100 | ||||
-rw-r--r-- | pyGHDL/libghdl/name_table.py | 57 | ||||
-rw-r--r-- | pyGHDL/libghdl/utils.py | 6 | ||||
-rw-r--r-- | pyGHDL/libghdl/vhdl/ieee.py | 7 | ||||
-rw-r--r-- | pyGHDL/libghdl/vhdl/nodes_utils.py | 16 | ||||
-rw-r--r-- | pyGHDL/libghdl/vhdl/scanner.py | 9 | ||||
-rw-r--r-- | pyGHDL/libghdl/vhdl/sem.py | 8 |
11 files changed, 204 insertions, 130 deletions
diff --git a/pyGHDL/libghdl/__init__.py b/pyGHDL/libghdl/__init__.py index 030c1bea2..b97e17484 100644 --- a/pyGHDL/libghdl/__init__.py +++ b/pyGHDL/libghdl/__init__.py @@ -90,38 +90,38 @@ def _get_libghdl_path(): # last path component. r = os.environ.get("GHDL_PREFIX") try: - return _check_libghdl_libdir(Path(r).parent, basename) + return _check_libghdl_libdir(Path(r).parent, basename) except (TypeError, FileNotFoundError): - pass + pass # Try VUNIT_GHDL_PATH (path of the ghdl binary when using VUnit). r = os.environ.get("VUNIT_GHDL_PATH") try: - return _check_libghdl_bindir(Path(r), basename) + return _check_libghdl_bindir(Path(r), basename) except (TypeError, FileNotFoundError): - pass + pass # Try GHDL (name/path of the ghdl binary) r = os.environ.get("GHDL", "ghdl") r = which(r) try: - return _check_libghdl_bindir(Path(r).parent, basename) + return _check_libghdl_bindir(Path(r).parent, basename) except (TypeError, FileNotFoundError): - pass + pass # Try within libghdl/ python installation r = Path(__file__) try: - return _check_libghdl_bindir(r.parent, basename) + return _check_libghdl_bindir(r.parent, basename) except (TypeError, FileNotFoundError): - pass + pass # Try when running from the build directory r = (r.parent / "../../lib").resolve() try: - return _check_libghdl_libdir(r, basename) + return _check_libghdl_libdir(r, basename) except (TypeError, FileNotFoundError): - pass + pass # Failed. raise Exception("Cannot find libghdl {}".format(basename)) diff --git a/pyGHDL/libghdl/_decorator.py b/pyGHDL/libghdl/_decorator.py index 01863381a..424b72820 100644 --- a/pyGHDL/libghdl/_decorator.py +++ b/pyGHDL/libghdl/_decorator.py @@ -1,4 +1,37 @@ -from functools import wraps +# ============================================================================= +# ____ _ _ ____ _ _ _ _ _ _ _ +# _ __ _ _ / ___| | | | _ \| | | (_) |__ __ _| |__ __| | | +# | '_ \| | | | | _| |_| | | | | | | | | '_ \ / _` | '_ \ / _` | | +# | |_) | |_| | |_| | _ | |_| | |___ _| | | |_) | (_| | | | | (_| | | +# | .__/ \__, |\____|_| |_|____/|_____(_)_|_|_.__/ \__, |_| |_|\__,_|_| +# |_| |___/ |___/ +# ============================================================================= +# Authors: Patrick Lehmann +# +# Package module: Python binding and low-level API for shared library 'libghdl'. +# +# License: +# ============================================================================ +# 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 +# Software Foundation; either version 2, or (at your option) any later +# version. +# +# GHDL is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with GHDL; see the file COPYING. If not, write to the Free +# Software Foundation, 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# SPDX-License-Identifier: GPL-2.0-or-later +# ============================================================================ +# from typing import Callable, List from pydecor import export @@ -6,28 +39,28 @@ from pydecor import export @export def EnumLookupTable(cls) -> Callable: - """ - Decorator to precalculate a enum lookup table (LUT) for enum position to - enum literal name. + """ + Decorator to precalculate a enum lookup table (LUT) for enum position to + enum literal name. - .. todo:: Make compatible to chained decorators + .. todo:: Make compatible to chained decorators - :param cls: Enumerator class for which a LUT shall be pre-calculated. - """ - def decorator(func) -> Callable: - def gen() -> List[str]: - d = [e for e in dir(cls) if e[0] != "_"] - res = [None] * len(d) - for e in d: - res[getattr(cls, e)] = e - return res + :param cls: Enumerator class for which a LUT shall be pre-calculated. + """ + def decorator(func) -> Callable: + def gen() -> List[str]: + d = [e for e in dir(cls) if e[0] != "_"] + res = [None] * len(d) + for e in d: + res[getattr(cls, e)] = e + return res - __lut = gen() + __lut = gen() - def wrapper(id: int) -> str: - # function that replaces the placeholder function - return __lut[id] + def wrapper(id: int) -> str: + # function that replaces the placeholder function + return __lut[id] - return wrapper + return wrapper - return decorator + return decorator diff --git a/pyGHDL/libghdl/_types.py b/pyGHDL/libghdl/_types.py index 2a486a15b..89db119a9 100644 --- a/pyGHDL/libghdl/_types.py +++ b/pyGHDL/libghdl/_types.py @@ -1,3 +1,37 @@ +# ============================================================================= +# ____ _ _ ____ _ _ _ _ _ _ _ +# _ __ _ _ / ___| | | | _ \| | | (_) |__ __ _| |__ __| | | +# | '_ \| | | | | _| |_| | | | | | | | | '_ \ / _` | '_ \ / _` | | +# | |_) | |_| | |_| | _ | |_| | |___ _| | | |_) | (_| | | | | (_| | | +# | .__/ \__, |\____|_| |_|____/|_____(_)_|_|_.__/ \__, |_| |_|\__,_|_| +# |_| |___/ |___/ +# ============================================================================= +# Authors: Patrick Lehmann +# +# Package module: Python binding and low-level API for shared library 'libghdl'. +# +# License: +# ============================================================================ +# 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 +# Software Foundation; either version 2, or (at your option) any later +# version. +# +# GHDL is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with GHDL; see the file COPYING. If not, write to the Free +# Software Foundation, 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# SPDX-License-Identifier: GPL-2.0-or-later +# ============================================================================ +# from typing import TypeVar __all__ = [ diff --git a/pyGHDL/libghdl/errorout_console.py b/pyGHDL/libghdl/errorout_console.py index 4edf3da7b..87508de90 100644 --- a/pyGHDL/libghdl/errorout_console.py +++ b/pyGHDL/libghdl/errorout_console.py @@ -40,5 +40,5 @@ from pyGHDL.libghdl import libghdl @export def Install_Handler() -> None: - """Install the handlers for reporting errors.""" - libghdl.errorout__console__install_handler() + """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 97873a1d3..2e53d0b4b 100644 --- a/pyGHDL/libghdl/errorout_memory.py +++ b/pyGHDL/libghdl/errorout_memory.py @@ -43,34 +43,34 @@ from pyGHDL.libghdl._types import ErrorIndex @export class Error_Message(Structure): - """ - Id : Msgid_Type - Message error/warning id + """ + Id : Msgid_Type + Message error/warning id - Group : Group_Type; - Whether this is an single message or a related one. + Group : Group_Type; + Whether this is an single message or a related one. - File : Source_File_Entry; - Error soure file. + 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. + 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. + 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), - ("file", c_int32), - ("line", c_int32), - ("offset", c_int32), - ("length", c_int32), - ] + 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), + ("file", c_int32), + ("line", c_int32), + ("offset", c_int32), + ("length", c_int32), + ] # Values for group: @@ -82,51 +82,51 @@ Msg_Last = 3 @export def Install_Handler() -> None: - """Install the handlers for reporting errors.""" - libghdl.errorout__memory__install_handler() + """Install the handlers for reporting errors.""" + libghdl.errorout__memory__install_handler() @export def Get_Nbr_Messages() -> ErrorIndex: - """ - Get number of error messages available. + """ + Get number of error messages available. - :return: Number of messages available. - """ - return libghdl.errorout__memory__get_nbr_messages() + :return: Number of messages available. + """ + return libghdl.errorout__memory__get_nbr_messages() @export def Get_Error_Record(Idx: ErrorIndex) -> Error_Message: - """ - Get error messages by index :obj:`Idy` as structure :class:`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 + :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) + return func(Idx) @export def Get_Error_Message(Idx: ErrorIndex) -> str: - """ - Get error messages by index :obj:`Idy` as string. + """ + 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 + :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 - return func(Idx).decode("utf-8") + return func(Idx).decode("utf-8") @export def Clear_Errors() -> None: - """Remove all error messages.""" - libghdl.errorout__memory__clear_errors() + """Remove all error messages.""" + libghdl.errorout__memory__clear_errors() diff --git a/pyGHDL/libghdl/name_table.py b/pyGHDL/libghdl/name_table.py index 72b6dfd8c..4e7e87283 100644 --- a/pyGHDL/libghdl/name_table.py +++ b/pyGHDL/libghdl/name_table.py @@ -40,50 +40,53 @@ from pydecor import export from pyGHDL.libghdl import libghdl from pyGHDL.libghdl._types import NameId +__all__ = [ + 'Null_Identifier' +] Null_Identifier = 0 @export def Get_Name_Length(Id: NameId) -> int: - """ - Get the length of an identifier denoted by a ``NameId``. + """ + Get the length of an identifier denoted by a ``NameId``. - :param Id: NameId for the identifier to query. - :return: Length of the identifier. - """ - return libghdl.name_table__get_name_length(Id) + :param Id: NameId for the identifier to query. + :return: Length of the identifier. + """ + return libghdl.name_table__get_name_length(Id) @export def Get_Name_Ptr(Id: NameId) -> str: - """ - Get the address of the first character of ID. The address is valid until - the next call to Get_Identifier (which may reallocate the string table). - The string is NUL-terminated (this is done by get_identifier). + """ + Get the address of the first character of ID. The address is valid until + the next call to Get_Identifier (which may reallocate the string table). + The string is NUL-terminated (this is done by get_identifier). - :param Id: NameId for the identifier to query. - :return: - """ - func = libghdl.name_table__get_name_ptr - func.restype = c_char_p + :param Id: NameId for the identifier to query. + :return: + """ + func = libghdl.name_table__get_name_ptr + func.restype = c_char_p - return func(Id).decode("utf-8") + return func(Id).decode("utf-8") @export def Get_Identifier(string: str) -> NameId: - """ - Get or create an entry in the name table. + """ + Get or create an entry in the name table. - .. note:: + .. note:: - * an identifier is represented in all lower case letter, - * an extended identifier is represented in backslashes, double internal - backslashes are simplified. + * an identifier is represented in all lower case letter, + * an extended identifier is represented in backslashes, double internal + backslashes are simplified. - :param string: String to create or lookup. - :return: Id in name table. - """ - string = string.encode("utf-8") - return libghdl.name_table__get_identifier_with_len(c_char_p(string), len(string)) + :param string: String to create or lookup. + :return: Id in name table. + """ + string = string.encode("utf-8") + return libghdl.name_table__get_identifier_with_len(c_char_p(string), len(string)) diff --git a/pyGHDL/libghdl/utils.py b/pyGHDL/libghdl/utils.py index 3b64e7698..234d16237 100644 --- a/pyGHDL/libghdl/utils.py +++ b/pyGHDL/libghdl/utils.py @@ -48,9 +48,9 @@ import pyGHDL.libghdl.vhdl.flists as flists @export -def name_image(NameId: NameId) -> str: - """Lookup a :obj:`NameId` and return its string.""" - return name_table.Get_Name_Ptr(NameId) +def name_image(Id: NameId) -> str: + """Lookup a :obj:`Id` and return its string.""" + return name_table.Get_Name_Ptr(Id) #@export # FIXME: see above diff --git a/pyGHDL/libghdl/vhdl/ieee.py b/pyGHDL/libghdl/vhdl/ieee.py index 2241188e7..953b6c64c 100644 --- a/pyGHDL/libghdl/vhdl/ieee.py +++ b/pyGHDL/libghdl/vhdl/ieee.py @@ -37,6 +37,13 @@ from ctypes import c_int from pyGHDL.libghdl import libghdl +__all__ = [ + 'Std_Logic_1164_Pkg', + 'Std_Logic_Type', + 'Std_Logic_Vector_Type' +] + + Std_Logic_1164_Pkg = c_int.in_dll( libghdl, "vhdl__ieee__std_logic_1164__std_logic_1164_pkg" ) diff --git a/pyGHDL/libghdl/vhdl/nodes_utils.py b/pyGHDL/libghdl/vhdl/nodes_utils.py index b2cbef56f..2045e50bd 100644 --- a/pyGHDL/libghdl/vhdl/nodes_utils.py +++ b/pyGHDL/libghdl/vhdl/nodes_utils.py @@ -71,7 +71,7 @@ def Is_Second_Subprogram_Specification(Spec: Iir) -> bool: :param Spec: Specification :return: ``True`` if subprogram specification and previously declared subprogram body match - """ + """ return libghdl.vhdl__utils__is_second_subprogram_specification(Spec) @@ -80,14 +80,12 @@ 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`` + If :obj:`Aspect` is a component declaration, return :obj:`Aspect`. If it's + open, return ``Null_Iir`` :param Aspect: Aspect :return: Entity - """ + """ return libghdl.vhdl__utils__get_entity_from_entity_aspect(Aspect) @@ -97,7 +95,7 @@ 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. - """ + :param Formal: The formal. + :return: The corresponding interface. + """ return libghdl.vhdl__utils__get_interface_of_formal(Formal) diff --git a/pyGHDL/libghdl/vhdl/scanner.py b/pyGHDL/libghdl/vhdl/scanner.py index 1215c97a2..24b41d7bf 100644 --- a/pyGHDL/libghdl/vhdl/scanner.py +++ b/pyGHDL/libghdl/vhdl/scanner.py @@ -76,14 +76,13 @@ def Scan() -> None: @export def Get_Current_Line() -> int: """ - Get the 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: 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() diff --git a/pyGHDL/libghdl/vhdl/sem.py b/pyGHDL/libghdl/vhdl/sem.py index 24a9b44c3..65805ce3c 100644 --- a/pyGHDL/libghdl/vhdl/sem.py +++ b/pyGHDL/libghdl/vhdl/sem.py @@ -43,9 +43,9 @@ 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. + Also add a few node or change some nodes, when for example an identifier is + changed into an access to the type. - :param DesignUnit: Design unit to semantically analyze. Type: ``Iir_Design_Unit`` - """ + :param DesignUnit: Design unit to semantically analyze. Type: ``Iir_Design_Unit`` + """ libghdl.vhdl__sem__semantic(DesignUnit) |