diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-05-15 19:05:31 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-05-15 19:05:31 +0200 |
commit | 659dc5995a93794ca27949667edf90cc9f04468b (patch) | |
tree | 9deae1681e8de862711c3ec6f9faee9842b6c783 /src | |
parent | 1d5db1f18f4d6f61433f4b91961378df24e5949b (diff) | |
download | ghdl-659dc5995a93794ca27949667edf90cc9f04468b.tar.gz ghdl-659dc5995a93794ca27949667edf90cc9f04468b.tar.bz2 ghdl-659dc5995a93794ca27949667edf90cc9f04468b.zip |
vhdl-utils: factorize Get_File_Signature.
Diffstat (limited to 'src')
-rw-r--r-- | src/vhdl/translate/trans-chap3.adb | 68 | ||||
-rw-r--r-- | src/vhdl/vhdl-annotations.adb | 66 | ||||
-rw-r--r-- | src/vhdl/vhdl-utils.adb | 101 | ||||
-rw-r--r-- | src/vhdl/vhdl-utils.ads | 12 |
4 files changed, 113 insertions, 134 deletions
diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index b1d2406d0..d52a95726 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -430,74 +430,6 @@ package body Trans.Chap3 is Info.B.Align := Align_32; end Translate_File_Type; - function Get_File_Signature_Length (Def : Iir) return Natural is - begin - case Get_Kind (Def) is - when Iir_Kinds_Scalar_Type_And_Subtype_Definition => - return 1; - when Iir_Kind_Array_Type_Definition - | Iir_Kind_Array_Subtype_Definition => - return 2 - + Get_File_Signature_Length (Get_Element_Subtype (Def)); - when Iir_Kind_Record_Type_Definition - | Iir_Kind_Record_Subtype_Definition => - declare - List : constant Iir_Flist := - Get_Elements_Declaration_List (Get_Base_Type (Def)); - El : Iir; - Res : Natural; - begin - Res := 2; - for I in Flist_First .. Flist_Last (List) loop - El := Get_Nth_Element (List, I); - Res := Res + Get_File_Signature_Length (Get_Type (El)); - end loop; - return Res; - end; - when others => - Error_Kind ("get_file_signature_length", Def); - end case; - end Get_File_Signature_Length; - - procedure Get_File_Signature (Def : Iir; - Res : in out String; - Off : in out Natural) - is - Scalar_Map : constant array (Type_Mode_Scalar) of Character - := "beEiIpPF"; - begin - case Get_Kind (Def) is - when Iir_Kinds_Scalar_Type_And_Subtype_Definition => - Res (Off) := Scalar_Map (Get_Info (Def).Type_Mode); - Off := Off + 1; - when Iir_Kind_Array_Type_Definition - | Iir_Kind_Array_Subtype_Definition => - Res (Off) := '['; - Off := Off + 1; - Get_File_Signature (Get_Element_Subtype (Def), Res, Off); - Res (Off) := ']'; - Off := Off + 1; - when Iir_Kind_Record_Type_Definition - | Iir_Kind_Record_Subtype_Definition => - declare - List : constant Iir_Flist := - Get_Elements_Declaration_List (Get_Base_Type (Def)); - El : Iir; - begin - Res (Off) := '<'; - Off := Off + 1; - for I in Flist_First .. Flist_Last (List) loop - El := Get_Nth_Element (List, I); - Get_File_Signature (Get_Type (El), Res, Off); - end loop; - Res (Off) := '>'; - Off := Off + 1; - end; - when others => - Error_Kind ("get_file_signature", Def); - end case; - end Get_File_Signature; - procedure Create_File_Type_Var (Def : Iir_File_Type_Definition) is Type_Name : constant Iir := Get_Type (Get_File_Type_Mark (Def)); diff --git a/src/vhdl/vhdl-annotations.adb b/src/vhdl/vhdl-annotations.adb index 48ec93fc3..e215b934e 100644 --- a/src/vhdl/vhdl-annotations.adb +++ b/src/vhdl/vhdl-annotations.adb @@ -144,72 +144,6 @@ package body Vhdl.Annotations is end if; end Annotate_Anonymous_Type_Definition; - function Get_File_Signature_Length (Def : Iir) return Natural is - begin - case Get_Kind (Def) is - when Iir_Kinds_Scalar_Type_And_Subtype_Definition => - return 1; - when Iir_Kind_Array_Type_Definition - | Iir_Kind_Array_Subtype_Definition => - return 2 - + Get_File_Signature_Length (Get_Element_Subtype (Def)); - when Iir_Kind_Record_Type_Definition - | Iir_Kind_Record_Subtype_Definition => - declare - List : constant Iir_Flist := - Get_Elements_Declaration_List (Get_Base_Type (Def)); - El : Iir; - Res : Natural; - begin - Res := 2; - for I in Flist_First .. Flist_Last (List) loop - El := Get_Nth_Element (List, I); - Res := Res + Get_File_Signature_Length (Get_Type (El)); - end loop; - return Res; - end; - when others => - Error_Kind ("get_file_signature_length", Def); - end case; - end Get_File_Signature_Length; - - procedure Get_File_Signature (Def : Iir; - Res : in out String; - Off : in out Natural) - is - Scalar_Map : constant array (Kind_Scalar_Types) of Character := "beeEIF"; - begin - case Get_Kind (Def) is - when Iir_Kinds_Scalar_Type_And_Subtype_Definition => - Res (Off) := Scalar_Map (Get_Info (Get_Base_Type (Def)).Kind); - Off := Off + 1; - when Iir_Kind_Array_Type_Definition - | Iir_Kind_Array_Subtype_Definition => - Res (Off) := '['; - Off := Off + 1; - Get_File_Signature (Get_Element_Subtype (Def), Res, Off); - Res (Off) := ']'; - Off := Off + 1; - when Iir_Kind_Record_Type_Definition - | Iir_Kind_Record_Subtype_Definition => - declare - List : constant Iir_Flist := - Get_Elements_Declaration_List (Get_Base_Type (Def)); - El : Iir; - begin - Res (Off) := '<'; - Off := Off + 1; - for I in Flist_First .. Flist_Last (List) loop - El := Get_Nth_Element (List, I); - Get_File_Signature (Get_Type (El), Res, Off); - end loop; - Res (Off) := '>'; - Off := Off + 1; - end; - when others => - Error_Kind ("get_file_signature", Def); - end case; - end Get_File_Signature; procedure Annotate_Protected_Type_Declaration (Block_Info : Sim_Info_Acc; Prot: Iir) diff --git a/src/vhdl/vhdl-utils.adb b/src/vhdl/vhdl-utils.adb index 8728d1b51..261be0f4e 100644 --- a/src/vhdl/vhdl-utils.adb +++ b/src/vhdl/vhdl-utils.adb @@ -1774,6 +1774,107 @@ package body Vhdl.Utils is end case; end Get_Attribute_Parameter; + function Get_File_Signature_Length (Def : Iir) return Natural is + begin + case Get_Kind (Def) is + when Iir_Kinds_Scalar_Type_And_Subtype_Definition => + return 1; + when Iir_Kind_Array_Type_Definition + | Iir_Kind_Array_Subtype_Definition => + return 2 + + Get_File_Signature_Length (Get_Element_Subtype (Def)); + when Iir_Kind_Record_Type_Definition + | Iir_Kind_Record_Subtype_Definition => + declare + List : constant Iir_Flist := + Get_Elements_Declaration_List (Get_Base_Type (Def)); + El : Iir; + Res : Natural; + begin + Res := 2; + for I in Flist_First .. Flist_Last (List) loop + El := Get_Nth_Element (List, I); + Res := Res + Get_File_Signature_Length (Get_Type (El)); + end loop; + return Res; + end; + when others => + Error_Kind ("get_file_signature_length", Def); + end case; + end Get_File_Signature_Length; + + procedure Get_File_Signature (Def : Iir; + Res : in out String; + Off : in out Natural) + is + Base_Type : constant Iir := Get_Base_Type (Def); + begin + case Get_Kind (Base_Type) is + when Iir_Kind_Integer_Type_Definition => + case Get_Scalar_Size (Base_Type) is + when Scalar_32 => + Res (Off) := 'i'; + when Scalar_64 => + Res (Off) := 'I'; + when others => + raise Internal_Error; + end case; + Off := Off + 1; + when Iir_Kind_Physical_Type_Definition => + case Get_Scalar_Size (Base_Type) is + when Scalar_32 => + Res (Off) := 'p'; + when Scalar_64 => + Res (Off) := 'P'; + when others => + raise Internal_Error; + end case; + Off := Off + 1; + when Iir_Kind_Floating_Type_Definition => + Res (Off) := 'F'; + Off := Off + 1; + when Iir_Kind_Enumeration_Type_Definition => + if Base_Type = Std_Package.Boolean_Type_Definition then + Res (Off) := 'b'; + else + case Get_Scalar_Size (Base_Type) is + when Scalar_8 => + Res (Off) := 'e'; + when Scalar_32 => + Res (Off) := 'E'; + when others => + raise Internal_Error; + end case; + end if; + Off := Off + 1; + when Iir_Kind_Array_Type_Definition + | Iir_Kind_Array_Subtype_Definition => + Res (Off) := '['; + Off := Off + 1; + Get_File_Signature (Get_Element_Subtype (Def), Res, Off); + Res (Off) := ']'; + Off := Off + 1; + when Iir_Kind_Record_Type_Definition + | Iir_Kind_Record_Subtype_Definition => + declare + List : constant Iir_Flist := + Get_Elements_Declaration_List (Get_Base_Type (Def)); + El : Iir; + begin + Res (Off) := '<'; + Off := Off + 1; + for I in Flist_First .. Flist_Last (List) loop + El := Get_Nth_Element (List, I); + Get_File_Signature (Get_Type (El), Res, Off); + end loop; + Res (Off) := '>'; + Off := Off + 1; + end; + when others => + Error_Kind ("get_file_signature", Def); + end case; + end Get_File_Signature; + function Get_HDL_Node (N : PSL_Node) return Iir is begin return Iir (PSL.Nodes.Get_HDL_Node (N)); diff --git a/src/vhdl/vhdl-utils.ads b/src/vhdl/vhdl-utils.ads index 49ba24e57..0f99595ab 100644 --- a/src/vhdl/vhdl-utils.ads +++ b/src/vhdl/vhdl-utils.ads @@ -400,6 +400,18 @@ package Vhdl.Utils is function Get_Attribute_Parameter (Attr : Iir; N : Parameter_Index) return Iir; + -- Return the expected signature length that will be used by + -- Get_File_Signature. + function Get_File_Signature_Length (Def : Iir) return Natural; + + -- Store in RES the file signature for type DEF. + -- Set the length of the buffer to OFF. + -- Parameters are 'in out' as they are updated, so you should call this + -- procedure with OFF = RES'First. + procedure Get_File_Signature (Def : Iir; + Res : in out String; + Off : in out Natural); + -- IIR wrapper around Get_HDL_Node/Set_HDL_Node. function Get_HDL_Node (N : PSL_Node) return Iir; procedure Set_HDL_Node (N : PSL_Node; Expr : Iir); |