diff options
author | Tristan Gingold <tgingold@free.fr> | 2020-07-24 18:31:11 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2020-07-25 11:28:49 +0200 |
commit | 04cd83fb46bee1e7a7b37be95bee73449af9c8b8 (patch) | |
tree | 3fe35d0bc6d4b1be8d81ad44df685057c221d2dc /src/vhdl | |
parent | 4033dd795927a4953879bdc92d395788893a5468 (diff) | |
download | ghdl-04cd83fb46bee1e7a7b37be95bee73449af9c8b8.tar.gz ghdl-04cd83fb46bee1e7a7b37be95bee73449af9c8b8.tar.bz2 ghdl-04cd83fb46bee1e7a7b37be95bee73449af9c8b8.zip |
ortho: add unbounded records, rework array subtypes.
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/translate/trans-chap12.adb | 5 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap3.adb | 5 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap7.adb | 9 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap8.adb | 36 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap9.adb | 6 | ||||
-rw-r--r-- | src/vhdl/translate/trans-helpers2.adb | 12 | ||||
-rw-r--r-- | src/vhdl/translate/trans-rtis.adb | 36 | ||||
-rw-r--r-- | src/vhdl/translate/translation.adb | 10 |
8 files changed, 77 insertions, 42 deletions
diff --git a/src/vhdl/translate/trans-chap12.adb b/src/vhdl/translate/trans-chap12.adb index 230a2cc58..05485a2cd 100644 --- a/src/vhdl/translate/trans-chap12.adb +++ b/src/vhdl/translate/trans-chap12.adb @@ -59,9 +59,10 @@ package body Trans.Chap12 is -- Create the array of RTIs for packages (as a variable, initialized -- during elaboration). - Arr_Type := New_Constrained_Array_Type + Arr_Type := New_Array_Subtype (Rtis.Ghdl_Rti_Array, - New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Elab_Nbr_Pkgs))); + Rtis.Ghdl_Rti_Access, + Helpers.New_Index_Lit (Unsigned_64 (Elab_Nbr_Pkgs))); New_Var_Decl (Pkgs_Arr, Get_Identifier ("__ghdl_top_RTIARRAY"), O_Storage_Private, Arr_Type); diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index 8e5cb9f33..bc3078460 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -1022,8 +1022,9 @@ package body Trans.Chap3 is when Mode_Signal => Id := Create_Identifier ("SIG"); end case; - Info.Ortho_Type (I) := New_Constrained_Array_Type - (Base (I), New_Index_Lit (Unsigned_64 (Len))); + Info.Ortho_Type (I) := New_Array_Subtype + (Base (I), Get_Ortho_Type (El_Type, I), + New_Index_Lit (Unsigned_64 (Len))); New_Type_Decl (Id, Info.Ortho_Type (I)); end loop; end if; diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb index f7ea2cdf7..cd21d4755 100644 --- a/src/vhdl/translate/trans-chap7.adb +++ b/src/vhdl/translate/trans-chap7.adb @@ -348,12 +348,17 @@ package body Trans.Chap7 is function Create_String_Literal_Var (Str : Iir) return Var_Type is Str_Type : constant Iir := Get_Type (Str); + El_Type : constant Iir := Get_Element_Subtype (Str_Type); Arr_Type : O_Tnode; + Arr_St : O_Tnode; begin -- Create the string value. 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); + Arr_St := New_Array_Subtype + (Arr_Type, + Get_Ortho_Type (El_Type, Mode_Value), + New_Index_Lit (Unsigned_64 (Get_String_Length (Str)))); + return Create_String_Literal_Var_Inner (Str, El_Type, Arr_St); end Create_String_Literal_Var; -- Some strings literal have an unconstrained array type, diff --git a/src/vhdl/translate/trans-chap8.adb b/src/vhdl/translate/trans-chap8.adb index 0b9dbce3b..65b559963 100644 --- a/src/vhdl/translate/trans-chap8.adb +++ b/src/vhdl/translate/trans-chap8.adb @@ -1368,13 +1368,13 @@ package body Trans.Chap8 is (Stmt : Iir_Case_Statement; Choices : Iir; Len_Type : out Iir; - Tinfo : out Type_Info_Acc; + Base_Type : out Iir; Expr_Node : out O_Dnode; C_Node : out O_Dnode) is Expr : constant Iir := Get_Expression (Stmt); Expr_Type : Iir; - Base_Type : Iir; + Tinfo : Type_Info_Acc; Sel_Length : Int64; Cond : O_Enode; begin @@ -1446,7 +1446,8 @@ package body Trans.Chap8 is Handler : in out Case_Handler'Class) is First, Last : Choice_Id; - El : Choice_Id; + El : Choice_Id; + Base_Type : Iir; -- Selector. Tinfo : Type_Info_Acc; @@ -1468,6 +1469,7 @@ 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; @@ -1477,6 +1479,7 @@ 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. @@ -1573,21 +1576,27 @@ package body Trans.Chap8 is Open_Temp; Translate_String_Case_Statement_Common - (Stmt, Choices_Chain, Len_Type, Tinfo, Expr_Node, C_Node); + (Stmt, Choices_Chain, Len_Type, Base_Type, Expr_Node, C_Node); + + Tinfo := Get_Info (Base_Type); -- Generate the sorted array of choices. Sel_Length := Eval_Discrete_Type_Length (Get_String_Type_Bound_Type (Len_Type)); - String_Type := New_Constrained_Array_Type + String_Type := New_Array_Subtype (Tinfo.B.Base_Type (Mode_Value), - New_Unsigned_Literal (Ghdl_Index_Type, Unsigned_64 (Sel_Length))); + Get_Ortho_Type (Get_Element_Subtype (Base_Type), Mode_Value), + New_Index_Lit (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_Array_Subtype + (Table_Base_Type, + String_Type, New_Index_Lit (Unsigned_64 (Nbr_Choices))); New_Const_Decl (Table, Create_Uniq_Identifier, O_Storage_Private, - Table_Base_Type); + Table_Type); Start_Init_Value (Table); - Start_Array_Aggr (List, Table_Base_Type, Unsigned_32 (Nbr_Choices)); + Start_Array_Aggr (List, Table_Type, Unsigned_32 (Nbr_Choices)); El := First; while El /= No_Choice_Id loop @@ -1602,11 +1611,14 @@ 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_Array_Subtype + (Assoc_Table_Base_Type, + Ghdl_Index_Type, New_Index_Lit (Unsigned_64 (Nbr_Choices))); New_Const_Decl (Assoc_Table, Create_Uniq_Identifier, - O_Storage_Private, Assoc_Table_Base_Type); + O_Storage_Private, Assoc_Table_Type); Start_Init_Value (Assoc_Table); Start_Array_Aggr - (List, Assoc_Table_Base_Type, Unsigned_32 (Nbr_Choices)); + (List, Assoc_Table_Type, Unsigned_32 (Nbr_Choices)); El := First; while El /= No_Choice_Id loop New_Array_Aggr_El @@ -1824,6 +1836,7 @@ package body Trans.Chap8 is Expr_Node : O_Dnode; -- Node containing the current choice. Val_Node : O_Dnode; + Base_Type : Iir; Tinfo : Type_Info_Acc; Cond_Var : O_Dnode; @@ -1887,7 +1900,8 @@ package body Trans.Chap8 is begin Open_Temp; Translate_String_Case_Statement_Common - (Stmt, Choices, Len_Type, Tinfo, Expr_Node, Val_Node); + (Stmt, Choices, Len_Type, Base_Type, Expr_Node, Val_Node); + Tinfo := Get_Info (Base_Type); Func := Chap7.Find_Predefined_Function (Get_Base_Type (Len_Type), Iir_Predefined_Array_Equality); diff --git a/src/vhdl/translate/trans-chap9.adb b/src/vhdl/translate/trans-chap9.adb index 2c7fd68cc..d1bd829cb 100644 --- a/src/vhdl/translate/trans-chap9.adb +++ b/src/vhdl/translate/trans-chap9.adb @@ -338,10 +338,10 @@ package body Trans.Chap9 is Push_Instance_Factory (Info.Psl_Scope'Access); -- Create the state vector type. - Info.Psl_Vect_Type := New_Constrained_Array_Type + Info.Psl_Vect_Type := New_Array_Subtype (Std_Boolean_Array_Type, - New_Unsigned_Literal (Ghdl_Index_Type, - Unsigned_64 (Get_PSL_Nbr_States (Stmt)))); + Std_Boolean_Type_Node, + New_Index_Lit (Unsigned_64 (Get_PSL_Nbr_States (Stmt)))); New_Type_Decl (Create_Identifier ("VECTTYPE"), Info.Psl_Vect_Type); -- Create the variables. diff --git a/src/vhdl/translate/trans-helpers2.adb b/src/vhdl/translate/trans-helpers2.adb index 4072fe321..22ea225d3 100644 --- a/src/vhdl/translate/trans-helpers2.adb +++ b/src/vhdl/translate/trans-helpers2.adb @@ -38,10 +38,10 @@ package body Trans.Helpers2 is -- Append a NUL terminator (to make interfaces with C easier). function Create_String_Type (Str : String) return O_Tnode is begin - return New_Constrained_Array_Type + return New_Array_Subtype (Chararray_Type, - New_Unsigned_Literal (Ghdl_Index_Type, - Unsigned_64 (Str'Length + 1))); + Char_Type_Node, + New_Index_Lit (Str'Length + 1)); end Create_String_Type; procedure Create_String_Value @@ -65,9 +65,11 @@ package body Trans.Helpers2 is function Create_String (Str : String; Id : O_Ident) return O_Dnode is Const : O_Dnode; + Stype : O_Tnode; begin - New_Const_Decl (Const, Id, O_Storage_Private, Chararray_Type); - Create_String_Value (Const, Chararray_Type, Str); + Stype := Create_String_Type (Str); + New_Const_Decl (Const, Id, O_Storage_Private, Stype); + Create_String_Value (Const, Stype, Str); return Const; end Create_String; diff --git a/src/vhdl/translate/trans-rtis.adb b/src/vhdl/translate/trans-rtis.adb index 5b55c69c6..d52a025db 100644 --- a/src/vhdl/translate/trans-rtis.adb +++ b/src/vhdl/translate/trans-rtis.adb @@ -877,16 +877,19 @@ package body Trans.Rtis is function Generate_Rti_Array (Id : O_Ident) return O_Dnode is - List : O_Array_Aggr_List; - L : Rti_Array_List_Acc; - Nbr : Integer; - Val : O_Cnode; - Res : O_Dnode; + List : O_Array_Aggr_List; + L : Rti_Array_List_Acc; + Nbr : Integer; + Val : O_Cnode; + Res : O_Dnode; + Stype : O_Tnode; begin - New_Const_Decl (Res, Id, O_Storage_Private, Ghdl_Rti_Array); + Stype := New_Array_Subtype + (Ghdl_Rti_Array, Ghdl_Rti_Access, + New_Index_Lit (Unsigned_64 (Cur_Block.Nbr + 1))); + New_Const_Decl (Res, Id, O_Storage_Private, Stype); Start_Init_Value (Res); - Start_Array_Aggr - (List, Ghdl_Rti_Array, Unsigned_32 (Cur_Block.Nbr + 1)); + Start_Array_Aggr (List, Stype, Unsigned_32 (Cur_Block.Nbr + 1)); Nbr := Cur_Block.Nbr; -- First chunk. @@ -1094,6 +1097,7 @@ 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_St : O_Tnode; Name_Arr : O_Dnode; Arr_Aggr : O_Array_Aggr_List; @@ -1110,11 +1114,14 @@ package body Trans.Rtis is end loop; -- Generate array of names. + Name_Arr_St := New_Array_Subtype + (Char_Ptr_Array_Type, + Char_Ptr_Type, + New_Index_Lit (Unsigned_64 (Nbr_Lit))); New_Const_Decl (Name_Arr, Create_Identifier ("RTINAMES"), - O_Storage_Private, Char_Ptr_Array_Type); + O_Storage_Private, Name_Arr_St); Start_Init_Value (Name_Arr); - Start_Array_Aggr - (Arr_Aggr, Char_Ptr_Array_Type, Unsigned_32 (Nbr_Lit)); + Start_Array_Aggr (Arr_Aggr, Name_Arr_St, 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; @@ -1405,6 +1412,7 @@ package body Trans.Rtis is Index : Iir; Tmp : O_Dnode; pragma Unreferenced (Tmp); + Stype : O_Tnode; Arr_Aggr : O_Array_Aggr_List; Val : O_Cnode; Mark : Id_Mark_Type; @@ -1420,11 +1428,13 @@ package body Trans.Rtis is end loop; -- Generate array of index. + Stype := New_Array_Subtype (Ghdl_Rti_Array, Ghdl_Rti_Access, + New_Index_Lit (Unsigned_64 (Nbr_Indexes))); New_Const_Decl (Res, Create_Identifier ("RTIINDEXES"), - Global_Storage, Ghdl_Rti_Array); + Global_Storage, Stype); Start_Init_Value (Res); - Start_Array_Aggr (Arr_Aggr, Ghdl_Rti_Array, Unsigned_32 (Nbr_Indexes)); + Start_Array_Aggr (Arr_Aggr, Stype, Unsigned_32 (Nbr_Indexes)); for I in 1 .. Nbr_Indexes loop Index := Get_Index_Type (List, I - 1); New_Array_Aggr_El diff --git a/src/vhdl/translate/translation.adb b/src/vhdl/translate/translation.adb index 519671970..b510a7ae5 100644 --- a/src/vhdl/translate/translation.adb +++ b/src/vhdl/translate/translation.adb @@ -1364,8 +1364,10 @@ package body Translation is -- Max length of a scalar type. -- Note: this type is not correctly aligned. Restricted use only. -- type __ghdl_scalar_bytes is __ghdl_chararray (0 .. 8); - Ghdl_Scalar_Bytes := New_Constrained_Array_Type - (Chararray_Type, New_Unsigned_Literal (Ghdl_Index_Type, 8)); + Ghdl_Scalar_Bytes := New_Array_Subtype + (Chararray_Type, + Char_Type_Node, + New_Unsigned_Literal (Ghdl_Index_Type, 8)); New_Type_Decl (Get_Identifier ("__ghdl_scalar_bytes"), Ghdl_Scalar_Bytes); @@ -2130,8 +2132,8 @@ package body Translation is -- Std_Ulogic indexed array of STD.Boolean. -- Used by PSL to convert Std_Ulogic to boolean. - Std_Ulogic_Boolean_Array_Type := - New_Constrained_Array_Type (Std_Boolean_Array_Type, New_Index_Lit (9)); + Std_Ulogic_Boolean_Array_Type := New_Array_Subtype + (Std_Boolean_Array_Type, Std_Boolean_Type_Node, New_Index_Lit (9)); New_Type_Decl (Get_Identifier ("__ghdl_std_ulogic_boolean_array_type"), Std_Ulogic_Boolean_Array_Type); New_Const_Decl (Ghdl_Std_Ulogic_To_Boolean_Array, |