From b52f313eda78ff0edb29d9898e48e9e032d4b9b5 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 20 Dec 2022 06:58:09 +0100 Subject: libghdl: add Get_Source_Identifier_Str --- pyGHDL/libghdl/vhdl/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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") -- cgit v1.2.3