Skip to content

Commit

Permalink
pyGHDL: add Get_Character to name_table.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tgingold committed Jun 16, 2021
1 parent 4c0f996 commit 17ddaa0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pyGHDL/libghdl/name_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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).
Expand All @@ -71,6 +71,19 @@ def Get_Name_Ptr(Id: NameId) -> str:
return func(Id).decode("utf-8")


@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:
"""
Expand Down

0 comments on commit 17ddaa0

Please sign in to comment.