diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-05-27 17:50:12 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-05-28 17:47:48 +0200 |
commit | 691d4875f0710e0603a7ae563600f9a6c041c6d6 (patch) | |
tree | 529071dca47189003ebc87cc6e1c6afd5e12b975 /src/vhdl | |
parent | 58756712b9465c24e1d2a198e5a03aae7ebbf774 (diff) | |
download | ghdl-691d4875f0710e0603a7ae563600f9a6c041c6d6.tar.gz ghdl-691d4875f0710e0603a7ae563600f9a6c041c6d6.tar.bz2 ghdl-691d4875f0710e0603a7ae563600f9a6c041c6d6.zip |
ortho: add a length parameter to start_array_aggr.
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/translate/trans-chap3.adb | 10 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap3.ads | 3 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap7.adb | 35 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap8.adb | 19 | ||||
-rw-r--r-- | src/vhdl/translate/trans-helpers2.adb | 8 | ||||
-rw-r--r-- | src/vhdl/translate/trans-rtis.adb | 28 |
6 files changed, 44 insertions, 59 deletions
diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index a360c26dc..88cc0d367 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -2563,7 +2563,7 @@ package body Trans.Chap3 is Elab_Type_Definition (Get_Type (Decl)); end Elab_Subtype_Declaration; - function Get_Thin_Array_Length (Atype : Iir) return O_Cnode + function Get_Static_Array_Length (Atype : Iir) return Int64 is Indexes_List : constant Iir_Flist := Get_Index_Subtype_List (Atype); Nbr_Dim : constant Natural := Get_Nbr_Elements (Indexes_List); @@ -2577,7 +2577,13 @@ package body Trans.Chap3 is Rng := Get_Range_Constraint (Index); Val := Val * Eval_Discrete_Range_Length (Rng); end loop; - return New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Val)); + return Val; + -- return New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Val)); + end Get_Static_Array_Length; + + function Get_Thin_Array_Length (Atype : Iir) return O_Cnode is + begin + return New_Index_Lit (Unsigned_64 (Get_Static_Array_Length (Atype))); end Get_Thin_Array_Length; function Bounds_To_Range (B : Mnode; Atype : Iir; Dim : Positive) diff --git a/src/vhdl/translate/trans-chap3.ads b/src/vhdl/translate/trans-chap3.ads index 4bc05de9f..7e252f521 100644 --- a/src/vhdl/translate/trans-chap3.ads +++ b/src/vhdl/translate/trans-chap3.ads @@ -164,6 +164,9 @@ package Trans.Chap3 is -- automatically stabilized if necessary. function Get_Bounds_Length (Bounds : Mnode; Atype : Iir) return O_Enode; + -- Return the number of elements for statically bounded array ATYPE. + function Get_Static_Array_Length (Atype : Iir) return Int64; + -- Get the number of elements in array ATYPE. function Get_Array_Type_Length (Atype : Iir) return O_Enode; diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb index 32c8b8537..016132a29 100644 --- a/src/vhdl/translate/trans-chap7.adb +++ b/src/vhdl/translate/trans-chap7.adb @@ -266,7 +266,9 @@ package body Trans.Chap7 is Res : O_Cnode; begin Chap3.Translate_Anonymous_Subtype_Definition (Aggr_Type, False); - Start_Array_Aggr (List, Get_Ortho_Type (Aggr_Type, Mode_Value)); + Start_Array_Aggr + (List, Get_Ortho_Type (Aggr_Type, Mode_Value), + Unsigned_32 (Chap3.Get_Static_Array_Length (Aggr_Type))); Translate_Static_Array_Aggregate_1 (List, Aggr, Aggr_Type, 1); Finish_Array_Aggr (List, Res); @@ -283,7 +285,9 @@ package body Trans.Chap7 is Res : O_Cnode; begin Chap3.Translate_Anonymous_Subtype_Definition (Aggr_Type, False); - Start_Array_Aggr (List, Get_Ortho_Type (Aggr_Type, Mode_Value)); + Start_Array_Aggr (List, + Get_Ortho_Type (Aggr_Type, Mode_Value), + Unsigned_32 (Get_Nbr_Elements (El_List))); for I in Flist_First .. Flist_Last (El_List) loop El := Get_Nth_Element (El_List, I); @@ -306,7 +310,9 @@ package body Trans.Chap7 is Chap3.Translate_Anonymous_Subtype_Definition (Lit_Type, False); Arr_Type := Get_Ortho_Type (Lit_Type, Mode_Value); - Start_Array_Aggr (List, Arr_Type); + Start_Array_Aggr + (List, Arr_Type, + Unsigned_32 (Chap3.Get_Static_Array_Length (Lit_Type))); Translate_Static_String_Literal8_Inner (List, Str, Element_Type); @@ -318,12 +324,13 @@ package body Trans.Chap7 is -- The type of the literal element is ELEMENT_TYPE, and the ortho type -- of the string (a constrained array type) is STR_TYPE. function Create_String_Literal_Var_Inner - (Str : Iir; Element_Type : Iir; Str_Type : O_Tnode) return Var_Type + (Str : Iir; Element_Type : Iir; Arr_Type : O_Tnode) return Var_Type is Val_Aggr : O_Array_Aggr_List; Res : O_Cnode; begin - Start_Array_Aggr (Val_Aggr, Str_Type); + Start_Array_Aggr + (Val_Aggr, Arr_Type, Unsigned_32 (Get_String_Length (Str))); case Get_Kind (Str) is when Iir_Kind_String_Literal8 => Translate_Static_String_Literal8_Inner @@ -334,7 +341,7 @@ package body Trans.Chap7 is Finish_Array_Aggr (Val_Aggr, Res); return Create_Global_Const - (Create_Uniq_Identifier, Str_Type, O_Storage_Private, Res); + (Create_Uniq_Identifier, Arr_Type, O_Storage_Private, Res); end Create_String_Literal_Var_Inner; -- Create a variable (constant) for string or bit string literal STR. @@ -344,11 +351,7 @@ package body Trans.Chap7 is Arr_Type : O_Tnode; begin -- Create the string value. - Arr_Type := New_Constrained_Array_Type - (Get_Info (Str_Type).B.Base_Type (Mode_Value), - New_Unsigned_Literal (Ghdl_Index_Type, - Unsigned_64 (Get_String_Length (Str)))); - + Arr_Type := Get_Info (Str_Type).B.Base_Type (Mode_Value); return Create_String_Literal_Var_Inner (Str, Get_Element_Subtype (Str_Type), Arr_Type); end Create_String_Literal_Var; @@ -445,7 +448,8 @@ package body Trans.Chap7 is begin Chap3.Translate_Anonymous_Subtype_Definition (Str_Type, False); - Start_Array_Aggr (List, Get_Ortho_Type (Str_Type, Mode_Value)); + Start_Array_Aggr + (List, Get_Ortho_Type (Str_Type, Mode_Value), Img'Length); for I in Img'Range loop Lit := Get_Nth_Element (Literal_List, Character'Pos (Img (I))); @@ -2913,9 +2917,6 @@ package body Trans.Chap7 is -- Type of the unconstrained array type. Arr_Type : O_Tnode; - -- Type of the constrained array type. - Str_Type : O_Tnode; - Cst : Var_Type; Var_I : O_Dnode; Label : O_Snode; @@ -2928,9 +2929,7 @@ package body Trans.Chap7 is Arr_Type := New_Array_Type (Get_Ortho_Type (Expr_Type, Mode_Value), Ghdl_Index_Type); New_Type_Decl (Create_Uniq_Identifier, Arr_Type); - Str_Type := New_Constrained_Array_Type - (Arr_Type, New_Index_Lit (Unsigned_64 (Len))); - Cst := Create_String_Literal_Var_Inner (Aggr, Expr_Type, Str_Type); + Cst := Create_String_Literal_Var_Inner (Aggr, Expr_Type, Arr_Type); -- Copy it. Open_Temp; diff --git a/src/vhdl/translate/trans-chap8.adb b/src/vhdl/translate/trans-chap8.adb index 2c67eebd4..1b7c756b9 100644 --- a/src/vhdl/translate/trans-chap8.adb +++ b/src/vhdl/translate/trans-chap8.adb @@ -1423,7 +1423,6 @@ package body Trans.Chap8 is -- Dichotomy table (table of choices). String_Type : O_Tnode; Table_Base_Type : O_Tnode; - Table_Type : O_Tnode; Table : O_Dnode; List : O_Array_Aggr_List; Table_Cst : O_Cnode; @@ -1433,7 +1432,6 @@ package body Trans.Chap8 is -- statement list. -- Could be replaced by jump table. Assoc_Table_Base_Type : O_Tnode; - Assoc_Table_Type : O_Tnode; Assoc_Table : O_Dnode; begin -- Fill Choices_Info array, and count number of associations. @@ -1541,14 +1539,10 @@ package body Trans.Chap8 is New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Sel_Length))); Table_Base_Type := New_Array_Type (String_Type, Ghdl_Index_Type); New_Type_Decl (Create_Uniq_Identifier, Table_Base_Type); - Table_Type := New_Constrained_Array_Type - (Table_Base_Type, - New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Nbr_Choices))); - New_Type_Decl (Create_Uniq_Identifier, Table_Type); New_Const_Decl (Table, Create_Uniq_Identifier, O_Storage_Private, - Table_Type); + Table_Base_Type); Start_Init_Value (Table); - Start_Array_Aggr (List, Table_Type); + Start_Array_Aggr (List, Table_Base_Type, Unsigned_32 (Nbr_Choices)); El := First; while El /= No_Choice_Id loop @@ -1563,14 +1557,11 @@ package body Trans.Chap8 is Assoc_Table_Base_Type := New_Array_Type (Ghdl_Index_Type, Ghdl_Index_Type); New_Type_Decl (Create_Uniq_Identifier, Assoc_Table_Base_Type); - Assoc_Table_Type := New_Constrained_Array_Type - (Assoc_Table_Base_Type, - New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Nbr_Choices))); - New_Type_Decl (Create_Uniq_Identifier, Assoc_Table_Type); New_Const_Decl (Assoc_Table, Create_Uniq_Identifier, - O_Storage_Private, Assoc_Table_Type); + O_Storage_Private, Assoc_Table_Base_Type); Start_Init_Value (Assoc_Table); - Start_Array_Aggr (List, Assoc_Table_Type); + Start_Array_Aggr + (List, Assoc_Table_Base_Type, Unsigned_32 (Nbr_Choices)); El := First; while El /= No_Choice_Id loop New_Array_Aggr_El diff --git a/src/vhdl/translate/trans-helpers2.adb b/src/vhdl/translate/trans-helpers2.adb index f05bf2477..4072fe321 100644 --- a/src/vhdl/translate/trans-helpers2.adb +++ b/src/vhdl/translate/trans-helpers2.adb @@ -51,7 +51,7 @@ package body Trans.Helpers2 is List : O_Array_Aggr_List; begin Start_Init_Value (Const); - Start_Array_Aggr (List, Const_Type); + Start_Array_Aggr (List, Const_Type, Str'Length + 1); for I in Str'Range loop New_Array_Aggr_El (List, @@ -64,12 +64,10 @@ package body Trans.Helpers2 is function Create_String (Str : String; Id : O_Ident) return O_Dnode is - Atype : O_Tnode; Const : O_Dnode; begin - Atype := Create_String_Type (Str); - New_Const_Decl (Const, Id, O_Storage_Private, Atype); - Create_String_Value (Const, Atype, Str); + New_Const_Decl (Const, Id, O_Storage_Private, Chararray_Type); + Create_String_Value (Const, Chararray_Type, Str); return Const; end Create_String; diff --git a/src/vhdl/translate/trans-rtis.adb b/src/vhdl/translate/trans-rtis.adb index 8a691fac5..5b55c69c6 100644 --- a/src/vhdl/translate/trans-rtis.adb +++ b/src/vhdl/translate/trans-rtis.adb @@ -877,20 +877,16 @@ package body Trans.Rtis is function Generate_Rti_Array (Id : O_Ident) return O_Dnode is - Arr_Type : O_Tnode; List : O_Array_Aggr_List; L : Rti_Array_List_Acc; Nbr : Integer; Val : O_Cnode; Res : O_Dnode; begin - Arr_Type := New_Constrained_Array_Type - (Ghdl_Rti_Array, - New_Unsigned_Literal (Ghdl_Index_Type, - Unsigned_64 (Cur_Block.Nbr + 1))); - New_Const_Decl (Res, Id, O_Storage_Private, Arr_Type); + New_Const_Decl (Res, Id, O_Storage_Private, Ghdl_Rti_Array); Start_Init_Value (Res); - Start_Array_Aggr (List, Arr_Type); + Start_Array_Aggr + (List, Ghdl_Rti_Array, Unsigned_32 (Cur_Block.Nbr + 1)); Nbr := Cur_Block.Nbr; -- First chunk. @@ -1098,7 +1094,6 @@ package body Trans.Rtis is type Dnode_Array is array (Natural range <>) of O_Dnode; Name_Lits : Dnode_Array (0 .. Nbr_Lit - 1); Mark : Id_Mark_Type; - Name_Arr_Type : O_Tnode; Name_Arr : O_Dnode; Arr_Aggr : O_Array_Aggr_List; @@ -1115,14 +1110,11 @@ package body Trans.Rtis is end loop; -- Generate array of names. - Name_Arr_Type := New_Constrained_Array_Type - (Char_Ptr_Array_Type, - New_Unsigned_Literal (Ghdl_Index_Type, - Unsigned_64 (Nbr_Lit))); New_Const_Decl (Name_Arr, Create_Identifier ("RTINAMES"), - O_Storage_Private, Name_Arr_Type); + O_Storage_Private, Char_Ptr_Array_Type); Start_Init_Value (Name_Arr); - Start_Array_Aggr (Arr_Aggr, Name_Arr_Type); + Start_Array_Aggr + (Arr_Aggr, Char_Ptr_Array_Type, Unsigned_32 (Nbr_Lit)); for I in Name_Lits'Range loop New_Array_Aggr_El (Arr_Aggr, New_Name_Address (Name_Lits (I))); end loop; @@ -1413,7 +1405,6 @@ package body Trans.Rtis is Index : Iir; Tmp : O_Dnode; pragma Unreferenced (Tmp); - Arr_Type : O_Tnode; Arr_Aggr : O_Array_Aggr_List; Val : O_Cnode; Mark : Id_Mark_Type; @@ -1429,14 +1420,11 @@ package body Trans.Rtis is end loop; -- Generate array of index. - Arr_Type := New_Constrained_Array_Type - (Ghdl_Rti_Array, - New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Nbr_Indexes))); New_Const_Decl (Res, Create_Identifier ("RTIINDEXES"), - Global_Storage, Arr_Type); + Global_Storage, Ghdl_Rti_Array); Start_Init_Value (Res); - Start_Array_Aggr (Arr_Aggr, Arr_Type); + Start_Array_Aggr (Arr_Aggr, Ghdl_Rti_Array, Unsigned_32 (Nbr_Indexes)); for I in 1 .. Nbr_Indexes loop Index := Get_Index_Type (List, I - 1); New_Array_Aggr_El |