From 8a66f99cd6b58313a4e9f08ce2c9dd1355d9aa7d Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 31 Oct 2016 09:08:30 +0100 Subject: ghdlxml: display image of string_literal8 Fix #176 --- src/ghdldrv/ghdlxml.adb | 5 +---- src/vhdl/disp_tree.adb | 28 ++++++++++++++++++++++++++++ src/vhdl/disp_tree.ads | 1 + src/vhdl/iirs.ads | 2 ++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/ghdldrv/ghdlxml.adb b/src/ghdldrv/ghdlxml.adb index 6641202a0..eb6eceec9 100644 --- a/src/ghdldrv/ghdlxml.adb +++ b/src/ghdldrv/ghdlxml.adb @@ -20,7 +20,6 @@ with GNAT.OS_Lib; use GNAT.OS_Lib; with Types; use Types; with Name_Table; use Name_Table; with Nodes_Meta; use Nodes_Meta; -with Str_Table; with Files_Map; with Disp_Tree; use Disp_Tree; with Ghdlprint; use Ghdlprint; @@ -429,9 +428,7 @@ package body Ghdlxml is begin Put_Stag (Get_Field_Image (F)); Put_Attribute ("length", Strip (Int32'Image (Len))); - Put_Attribute ("content", - To_XML (Str_Table.String_String8 - (Get_String8_Id (N), Len))); + Put_Attribute ("content", To_XML (Image_String8 (N))); Put_Empty_Stag_End; end; when others => diff --git a/src/vhdl/disp_tree.adb b/src/vhdl/disp_tree.adb index e254bb883..9aed6c3f9 100644 --- a/src/vhdl/disp_tree.adb +++ b/src/vhdl/disp_tree.adb @@ -20,6 +20,7 @@ with Ada.Text_IO; use Ada.Text_IO; with Name_Table; +with Str_Table; with Files_Map; with PSL.Dump_Tree; with Nodes_Meta; @@ -315,6 +316,33 @@ package body Disp_Tree is function Image_Token_Type (Tok : Tokens.Token_Type) return String renames Tokens.Image; + function Image_String8 (N : Iir) return String + is + use Str_Table; + T : constant Iir := Get_Type (N); + Str : constant String8_Id := Get_String8_Id (N); + Len : constant Int32 := Get_String_Length (N); + begin + if Is_Null (T) then + -- Not yet analyzed, the string is the ASCII image. + return Str_Table.String_String8 (Str, Len); + else + declare + El : constant Iir := Get_Base_Type (Get_Element_Subtype (T)); + Lits : constant Iir_List := Get_Enumeration_Literal_List (El); + Res : String (1 .. Natural (Len)); + C : Natural; + begin + for I in 1 .. Len loop + C := Natural (Element_String8 (Str, I)); + Res (Natural (I)) := Name_Table.Get_Character + (Get_Identifier (Get_Nth_Element (Lits, C))); + end loop; + return Res; + end; + end if; + end Image_String8; + procedure Header (Str : String; Indent : Natural) is begin Put_Indent (Indent); diff --git a/src/vhdl/disp_tree.ads b/src/vhdl/disp_tree.ads index 0ea056a6a..e6a10fcea 100644 --- a/src/vhdl/disp_tree.ads +++ b/src/vhdl/disp_tree.ads @@ -47,4 +47,5 @@ package Disp_Tree is function Image_Location_Type (Loc : Location_Type) return String; function Image_Iir_Direction (Dir : Iir_Direction) return String; function Image_Token_Type (Tok : Tokens.Token_Type) return String; + function Image_String8 (N : Iir) return String; end Disp_Tree; diff --git a/src/vhdl/iirs.ads b/src/vhdl/iirs.ads index 79356b3cd..3c33aeecc 100644 --- a/src/vhdl/iirs.ads +++ b/src/vhdl/iirs.ads @@ -310,6 +310,8 @@ package Iirs is -- Number of literals in the expanded string. -- Get/Set_String_Length (Field4) -- + -- Before analysis, this is the ASCII code of each character in the string. + -- After analysis, this is the position of each literal. -- Get/Set_String8_Id (Field5) -- -- Base of the bit_string (corresponds to letters 'b', 'o', 'd' or 'x' in -- cgit v1.2.3