diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-12-20 06:58:09 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-12-20 06:58:09 +0100 |
commit | b52f313eda78ff0edb29d9898e48e9e032d4b9b5 (patch) | |
tree | 967cf077fea571303136847eb5de54cd4c83695d | |
parent | 53dffcec12e6a3e8bcac73cfef39d5add83da793 (diff) | |
download | ghdl-b52f313eda78ff0edb29d9898e48e9e032d4b9b5.tar.gz ghdl-b52f313eda78ff0edb29d9898e48e9e032d4b9b5.tar.bz2 ghdl-b52f313eda78ff0edb29d9898e48e9e032d4b9b5.zip |
libghdl: add Get_Source_Identifier_Str
-rw-r--r-- | pyGHDL/libghdl/vhdl/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/pyGHDL/libghdl/vhdl/utils.py b/pyGHDL/libghdl/vhdl/utils.py index 3a82f45c0..4dd82e5ff 100644 --- a/pyGHDL/libghdl/vhdl/utils.py +++ b/pyGHDL/libghdl/vhdl/utils.py @@ -36,6 +36,8 @@ from pyTooling.Decorators import export from pyGHDL.libghdl._types import Iir, NameId from pyGHDL.libghdl._decorator import BindToLibGHDL +from pyGHDL.libghdl import name_table, files_map +from pyGHDL.libghdl.vhdl import nodes @export @@ -48,3 +50,12 @@ def Get_Source_Identifier(Decl: Iir) -> NameId: :param Decl: Iir Node. Type: ``Iir`` """ return 0 + +@export +def Get_Source_Identifier_Str(n: Iir) -> str: + loc = nodes.Get_Location(n) + l = name_table.Get_Name_Length(nodes.Get_Identifier(n)) + sfe = files_map.Location_To_File(loc) + pos = files_map.Location_File_To_Pos(loc, sfe) + buf = files_map.Get_File_Buffer(sfe) + return buf[pos:pos+l].decode("utf-8") |