aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2021-06-16 21:16:50 +0200
committerTristan Gingold <tgingold@free.fr>2021-06-16 21:16:50 +0200
commit17ddaa0d211903e9e07cf26b0c7d23dee47fae99 (patch)
treec3f4fb71cec7b942ad9525ecc1cfdf5b8da53eb1
parent4c0f9967e541b914a207bd4419d62d00d3e1745c (diff)
downloadghdl-17ddaa0d211903e9e07cf26b0c7d23dee47fae99.tar.gz
ghdl-17ddaa0d211903e9e07cf26b0c7d23dee47fae99.tar.bz2
ghdl-17ddaa0d211903e9e07cf26b0c7d23dee47fae99.zip
pyGHDL: add Get_Character to name_table.py
-rw-r--r--pyGHDL/libghdl/name_table.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/pyGHDL/libghdl/name_table.py b/pyGHDL/libghdl/name_table.py
index 7dd5165a8..2e912d741 100644
--- a/pyGHDL/libghdl/name_table.py
+++ b/pyGHDL/libghdl/name_table.py
@@ -32,7 +32,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================
-from ctypes import c_char_p
+from ctypes import c_char_p, c_char
from pydecor import export
@@ -58,7 +58,7 @@ def Get_Name_Length(Id: NameId) -> int:
@export
def Get_Name_Ptr(Id: NameId) -> str:
"""
- Get the address of the first character of 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).
@@ -72,6 +72,19 @@ def Get_Name_Ptr(Id: NameId) -> str:
@export
+def Get_Character(Id: NameId) -> str:
+ """
+ Get the string corresponding to character identifier ID.
+
+ :param Id: NameId for the identifier to query.
+ :return:
+ """
+ func = libghdl.name_table__get_character
+ func.restype = c_char
+
+ return func(Id).decode("utf-8")
+
+@export
def Get_Identifier(string: str) -> NameId:
"""
Get or create an entry in the name table.