aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/libghdl/name_table.py
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-17 13:49:20 +0200
committerUnai Martinez-Corral <38422348+umarcor@users.noreply.github.com>2021-06-17 22:53:27 +0100
commitf65fff4d5e3a33e83c633eb20fd367e349f3dc92 (patch)
tree66e3fb6afc69738b28bcaaf908a09c13143615e7 /pyGHDL/libghdl/name_table.py
parent56f8ca47465a7cc052e80c0ed4bab6fc55eeacba (diff)
downloadghdl-f65fff4d5e3a33e83c633eb20fd367e349f3dc92.tar.gz
ghdl-f65fff4d5e3a33e83c633eb20fd367e349f3dc92.tar.bz2
ghdl-f65fff4d5e3a33e83c633eb20fd367e349f3dc92.zip
Using a decorator to bind libghdl to Python.
Diffstat (limited to 'pyGHDL/libghdl/name_table.py')
-rw-r--r--pyGHDL/libghdl/name_table.py54
1 files changed, 36 insertions, 18 deletions
diff --git a/pyGHDL/libghdl/name_table.py b/pyGHDL/libghdl/name_table.py
index 0039aff20..ddb5ba491 100644
--- a/pyGHDL/libghdl/name_table.py
+++ b/pyGHDL/libghdl/name_table.py
@@ -6,9 +6,9 @@
# | .__/ \__, |\____|_| |_|____/|_____(_)_|_|_.__/ \__, |_| |_|\__,_|_|
# |_| |___/ |___/
# =============================================================================
-# Authors:
-# Tristan Gingold
-# Patrick Lehmann
+# Authors:
+# Tristan Gingold
+# Patrick Lehmann
#
# Package package: Python binding and low-level API for shared library 'libghdl'.
#
@@ -31,20 +31,23 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
-
-from ctypes import c_char_p, c_char
+#
+from ctypes import c_char, c_char_p
from pydecor import export
-from pyGHDL.libghdl import libghdl
from pyGHDL.libghdl._types import NameId
+from pyGHDL.libghdl._decorator import BindToLibGHDL
-__all__ = ["Null_Identifier"]
+__all__ = [
+ "Null_Identifier"
+]
Null_Identifier = 0
@export
+@BindToLibGHDL("name_table__get_name_length")
def Get_Name_Length(Id: NameId) -> int:
"""
Get the length of an identifier denoted by a ``NameId``.
@@ -52,23 +55,31 @@ def Get_Name_Length(Id: NameId) -> int:
:param Id: NameId for the identifier to query.
:return: Length of the identifier.
"""
- return libghdl.name_table__get_name_length(Id)
+
+
+#@export
+@BindToLibGHDL("name_table__get_name_ptr")
+def _Get_Name_Ptr(Id: NameId) -> c_char_p:
+ """"""
@export
def Get_Name_Ptr(Id: NameId) -> str:
"""
- Get the string corresponding to identifier ID. The address is valid until
+ Get the string corresponding to identifier 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:
+ :return: Identifier as string.
"""
- func = libghdl.name_table__get_name_ptr
- func.restype = c_char_p
+ return _Get_Name_Ptr(Id).decode("utf-8")
+
- return func(Id).decode("utf-8")
+#@export
+@BindToLibGHDL("name_table__get_character")
+def _Get_Character(Id: NameId) -> c_char:
+ """"""
@export
@@ -76,13 +87,20 @@ def Get_Character(Id: NameId) -> str:
"""
Get the string corresponding to character identifier ID.
+ .. note::
+
+ This is used for character literals and enumeration literals.
+
:param Id: NameId for the identifier to query.
- :return:
+ :return: Get the character of the identifier.
"""
- func = libghdl.name_table__get_character
- func.restype = c_char
+ return _Get_Character(Id).decode("utf-8")
+
- return func(Id).decode("utf-8")
+#@export
+@BindToLibGHDL("name_table__get_identifier_with_len")
+def _Get_Identifier(string: c_char_p, length: int) -> NameId:
+ """"""
@export
@@ -100,4 +118,4 @@ def Get_Identifier(string: str) -> NameId:
:return: Id in name table.
"""
string = string.encode("utf-8")
- return libghdl.name_table__get_identifier_with_len(c_char_p(string), len(string))
+ return _Get_Identifier(c_char_p(string), len(string))