diff options
author | Tristan Gingold <tgingold@free.fr> | 2014-11-11 07:20:01 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2014-11-11 07:20:01 +0100 |
commit | d7792111d0c1f9ee050fa27257c2d4c16e4fceb2 (patch) | |
tree | 8f292c43ea7ac29d35eb3d805c79399165ae640b | |
parent | 5424f116417beac6609b8fde7f0b903eec72a019 (diff) | |
download | ghdl-d7792111d0c1f9ee050fa27257c2d4c16e4fceb2.tar.gz ghdl-d7792111d0c1f9ee050fa27257c2d4c16e4fceb2.tar.bz2 ghdl-d7792111d0c1f9ee050fa27257c2d4c16e4fceb2.zip |
Create_Range_From_Length: use Mnode instead of ptr. Style changes.
-rw-r--r-- | src/vhdl/translate/trans-chap3.adb | 55 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap3.ads | 9 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap4.adb | 31 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap7.adb | 90 | ||||
-rw-r--r-- | src/vhdl/translate/trans.ads | 10 |
5 files changed, 94 insertions, 101 deletions
diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index 30ea1fa08..30d24f411 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -1065,12 +1065,12 @@ package body Trans.Chap3 is New_Assign_Stmt (New_Obj (Var_Length), New_Dyadic_Op (ON_Mul_Ov, - New_Value (Get_Var (El_Info.C (Kind).Size_Var)), - Get_Bounds_Length (Dp2M (Bound, Info, - Mode_Value, - Info.T.Bounds_Type, - Info.T.Bounds_Ptr_Type), - Def))); + New_Value (Get_Var (El_Info.C (Kind).Size_Var)), + Get_Bounds_Length (Dp2M (Bound, Info, + Mode_Value, + Info.T.Bounds_Type, + Info.T.Bounds_Ptr_Type), + Def))); -- Find the innermost non-array element. while El_Info.Type_Mode = Type_Mode_Array loop @@ -3176,14 +3176,12 @@ package body Trans.Chap3 is end Check_Array_Match; procedure Create_Range_From_Array_Attribute_And_Length - (Array_Attr : Iir; Length : O_Dnode; Range_Ptr : O_Dnode) + (Array_Attr : Iir; Length : O_Dnode; Res : Mnode) is Attr_Kind : Iir_Kind; Arr_Rng : Mnode; Iinfo : Type_Info_Acc; - Res : Mnode; - Dir : O_Enode; Diff : O_Dnode; Left_Bound : Mnode; @@ -3195,10 +3193,8 @@ package body Trans.Chap3 is Iinfo := Get_Type_Info (Arr_Rng); Stabilize (Arr_Rng); - Res := Dp2M (Range_Ptr, Iinfo, Mode_Value); - -- Length. - New_Assign_Stmt (M2Lv (Range_To_Length (Arr_Rng)), + New_Assign_Stmt (M2Lv (Range_To_Length (Res)), New_Obj_Value (Length)); -- Direction. @@ -3227,9 +3223,9 @@ package body Trans.Chap3 is Start_If_Stmt (If_Blk, New_Compare_Op (ON_Eq, - New_Obj_Value (Length), - New_Lit (Ghdl_Index_0), - Ghdl_Bool_Type)); + New_Obj_Value (Length), + New_Lit (Ghdl_Index_0), + Ghdl_Bool_Type)); -- Null range. case Attr_Kind is when Iir_Kind_Range_Array_Attribute => @@ -3290,7 +3286,7 @@ package body Trans.Chap3 is end Create_Range_From_Array_Attribute_And_Length; procedure Create_Range_From_Length - (Index_Type : Iir; Length : O_Dnode; Range_Ptr : O_Dnode; Loc : Iir) + (Index_Type : Iir; Length : O_Dnode; Res : Mnode; Loc : Iir) is Iinfo : constant Type_Info_Acc := Get_Info (Index_Type); Range_Constr : constant Iir := Get_Range_Constraint (Index_Type); @@ -3299,21 +3295,29 @@ package body Trans.Chap3 is Left_Bound : O_Enode; Var_Right : O_Dnode; If_Blk : O_If_Block; + Res_Range : Mnode; begin if Get_Kind (Range_Constr) /= Iir_Kind_Range_Expression then + Open_Temp; + Res_Range := Stabilize (Res); + Create_Range_From_Array_Attribute_And_Length - (Range_Constr, Length, Range_Ptr); + (Range_Constr, Length, Res_Range); + + Close_Temp; return; end if; Start_Declare_Stmt; + Open_Local_Temp; + Res_Range := Stabilize (Res); + New_Var_Decl (Var_Right, Get_Identifier ("right_bound"), O_Storage_Local, Iinfo.Ortho_Type (Mode_Value)); New_Assign_Stmt - (New_Selected_Acc_Value (New_Obj (Range_Ptr), Iinfo.T.Range_Length), - New_Obj_Value (Length)); + (M2Lv (Range_To_Length (Res_Range)), New_Obj_Value (Length)); New_Assign_Stmt - (New_Selected_Acc_Value (New_Obj (Range_Ptr), Iinfo.T.Range_Dir), + (M2Lv (Range_To_Dir (Res_Range)), New_Lit (Chap7.Translate_Static_Range_Dir (Range_Constr))); case Get_Direction (Range_Constr) is @@ -3331,15 +3335,15 @@ package body Trans.Chap3 is Ghdl_Bool_Type)); -- Null range. New_Assign_Stmt - (New_Selected_Acc_Value (New_Obj (Range_Ptr), Iinfo.T.Range_Left), + (M2Lv (Range_To_Left (Res_Range)), Chap7.Translate_Range_Expression_Right (Range_Constr, Index_Type)); New_Assign_Stmt - (New_Selected_Acc_Value (New_Obj (Range_Ptr), Iinfo.T.Range_Right), + (M2Lv (Range_To_Right (Res_Range)), Chap7.Translate_Range_Expression_Left (Range_Constr, Index_Type)); New_Else_Stmt (If_Blk); New_Assign_Stmt - (New_Selected_Acc_Value (New_Obj (Range_Ptr), Iinfo.T.Range_Left), + (M2Lv (Range_To_Left (Res_Range)), Chap7.Translate_Range_Expression_Left (Range_Constr, Index_Type)); Left_Bound := Chap7.Translate_Range_Expression_Left (Range_Constr, Index_Type); @@ -3354,9 +3358,10 @@ package body Trans.Chap3 is -- Check the right bounds is inside the bounds of the index type. Chap3.Check_Range (Var_Right, Null_Iir, Index_Type, Loc); New_Assign_Stmt - (New_Selected_Acc_Value (New_Obj (Range_Ptr), Iinfo.T.Range_Right), - New_Obj_Value (Var_Right)); + (M2Lv (Range_To_Right (Res_Range)), New_Obj_Value (Var_Right)); Finish_If_Stmt (If_Blk); + + Close_Local_Temp; Finish_Declare_Stmt; end Create_Range_From_Length; end Trans.Chap3; diff --git a/src/vhdl/translate/trans-chap3.ads b/src/vhdl/translate/trans-chap3.ads index 1b1128560..d45dae06e 100644 --- a/src/vhdl/translate/trans-chap3.ads +++ b/src/vhdl/translate/trans-chap3.ads @@ -252,13 +252,12 @@ package Trans.Chap3 is R_Node : Mnode; Loc : Iir); - -- Create a subtype range to be stored into the location pointed by - -- RANGE_PTR from length LENGTH, which is of type INDEX_TYPE. + -- Create a subtype range to be stored into RES from length LENGTH, which + -- is of type INDEX_TYPE. -- This is done according to rules 7.2.4 of LRM93, ie: -- direction and left bound of the range is the same of INDEX_TYPE. - -- LENGTH and RANGE_PTR are variables. LOC is the location in case of - -- error. + -- LENGTH is a variable. LOC is the location in case of error. procedure Create_Range_From_Length - (Index_Type : Iir; Length : O_Dnode; Range_Ptr : O_Dnode; Loc : Iir); + (Index_Type : Iir; Length : O_Dnode; Res : Mnode; Loc : Iir); end Trans.Chap3; diff --git a/src/vhdl/translate/trans-chap4.adb b/src/vhdl/translate/trans-chap4.adb index 7b18f5744..3083e421c 100644 --- a/src/vhdl/translate/trans-chap4.adb +++ b/src/vhdl/translate/trans-chap4.adb @@ -1839,12 +1839,12 @@ package body Trans.Chap4 is V : Mnode; - Var_Bound : O_Dnode; - Var_Range_Ptr : O_Dnode; - Var_Array : O_Dnode; - Finfo : constant Subprg_Info_Acc := Get_Info (Func); - Rinfo : constant Subprg_Resolv_Info_Acc := Finfo.Subprg_Resolv; - Assoc : O_Assoc_List; + Var_Bound : O_Dnode; + Range_Ptr : Mnode; + Var_Array : O_Dnode; + Finfo : constant Subprg_Info_Acc := Get_Info (Func); + Rinfo : constant Subprg_Resolv_Info_Acc := Finfo.Subprg_Resolv; + Assoc : O_Assoc_List; Data : Read_Source_Data; begin @@ -1894,9 +1894,6 @@ package body Trans.Chap4 is New_Var_Decl (Var_Array, Get_Identifier ("ARRAY"), O_Storage_Local, Base_Info.Ortho_Type (Mode_Value)); - New_Var_Decl (Var_Range_Ptr, Get_Identifier ("RANGE_PTR"), - O_Storage_Local, Index_Tinfo.T.Range_Ptr_Type); - Open_Temp; case El_Info.Type_Mode is @@ -1914,16 +1911,14 @@ package body Trans.Chap4 is New_Obj_Value (Rinfo.Var_Vlen), New_Obj_Value (Rinfo.Var_Nbr_Ports))); - -- * range_ptr := BOUND.dim_1'address; - New_Assign_Stmt - (New_Obj (Var_Range_Ptr), - New_Address (New_Selected_Element (New_Obj (Var_Bound), - Index_Info.Index_Field), - Index_Tinfo.T.Range_Ptr_Type)); - -- Create range from length - Chap3.Create_Range_From_Length - (Index_Type, Var_Length, Var_Range_Ptr, Func); + Range_Ptr := Lv2M (New_Selected_Element (New_Obj (Var_Bound), + Index_Info.Index_Field), + Index_Tinfo, Mode_Value, + Index_Tinfo.T.Range_Type, + Index_Tinfo.T.Range_Ptr_Type); + Chap3.Create_Range_From_Length (Index_Type, Var_Length, Range_Ptr, Func); + New_Assign_Stmt (New_Selected_Element (New_Obj (Var_Array), Base_Info.T.Bounds_Field (Mode_Value)), diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb index 3dd54865e..63c0b8e21 100644 --- a/src/vhdl/translate/trans-chap7.adb +++ b/src/vhdl/translate/trans-chap7.adb @@ -1145,15 +1145,13 @@ package body Trans.Chap7 is function Translate_Predefined_Array_Operator (Left, Right : O_Enode; Func : Iir) return O_Enode is + Info : constant Type_Info_Acc := Get_Info (Get_Return_Type (Func)); + Func_Info : constant Subprg_Info_Acc := Get_Info (Func); Res : O_Dnode; Constr : O_Assoc_List; - Info : Type_Info_Acc; - Func_Info : Subprg_Info_Acc; begin Create_Temp_Stack2_Mark; - Info := Get_Info (Get_Return_Type (Func)); Res := Create_Temp (Info.Ortho_Type (Mode_Value)); - Func_Info := Get_Info (Func); Start_Association (Constr, Func_Info.Ortho_Func); Subprgs.Add_Subprg_Instance_Assoc (Constr, Func_Info.Subprg_Instance); New_Association (Constr, @@ -4401,18 +4399,19 @@ package body Trans.Chap7 is procedure Translate_Predefined_Array_Array_Concat (Subprg : Iir) is F_Info : Subprg_Info_Acc; - Arr_Type : Iir_Array_Type_Definition; - Arr_Ptr_Type : O_Tnode; + Arr_Type : constant Iir := Get_Return_Type (Subprg); -- Info for the array type. - Info : Type_Info_Acc; + Info : constant Type_Info_Acc := Get_Info (Arr_Type); + Arr_Ptr_Type : constant O_Tnode := Info.Ortho_Ptr_Type (Mode_Value); -- Info for the index type. Iinfo : Type_Info_Acc; Index_Type : Iir; + Id : constant Name_Id := Get_Identifier (Get_Type_Declarator (Arr_Type)); + Index_Otype : O_Tnode; - Id : Name_Id; Interface_List : O_Inter_List; Var_Res, Var_L, Var_R : O_Dnode; Res, L, R : Mnode; @@ -4421,11 +4420,6 @@ package body Trans.Chap7 is V_Bounds : Mnode; If_Blk : O_If_Block; begin - Arr_Type := Get_Return_Type (Subprg); - Info := Get_Info (Arr_Type); - Id := Get_Identifier (Get_Type_Declarator (Arr_Type)); - Arr_Ptr_Type := Info.Ortho_Ptr_Type (Mode_Value); - F_Info := Add_Info (Subprg, Kind_Subprg); F_Info.Use_Stack2 := True; @@ -4494,11 +4488,8 @@ package body Trans.Chap7 is end if; Start_If_Stmt - (If_Blk, - New_Compare_Op (ON_Eq, - Len, - New_Lit (Ghdl_Index_0), - Ghdl_Bool_Type)); + (If_Blk, New_Compare_Op (ON_Eq, Len, New_Lit (Ghdl_Index_0), + Ghdl_Bool_Type)); Copy_Fat_Pointer (Res, R); New_Return_Stmt; Finish_If_Stmt (If_Blk); @@ -4519,7 +4510,7 @@ package body Trans.Chap7 is -- Set length. New_Assign_Stmt (M2Lv (Chap3.Range_To_Length - (Chap3.Bounds_To_Range (V_Bounds, Arr_Type, 1))), + (Chap3.Bounds_To_Range (V_Bounds, Arr_Type, 1))), New_Obj_Value (Var_Length)); -- Set direction, left bound and right bound. @@ -4543,46 +4534,59 @@ package body Trans.Chap7 is O_Storage_Local, Iinfo.Ortho_Type (Mode_Value)); New_Var_Decl (Var_Length1, Get_Identifier ("length_1"), O_Storage_Local, Ghdl_Index_Type); + + -- Copy direction from left. New_Assign_Stmt (New_Obj (Var_Dir), M2E (Chap3.Range_To_Dir - (Chap3.Get_Array_Range (L, Arr_Type, 1)))); + (Chap3.Get_Array_Range (L, Arr_Type, 1)))); New_Assign_Stmt (M2Lv (Chap3.Range_To_Dir - (Chap3.Bounds_To_Range (V_Bounds, Arr_Type, 1))), + (Chap3.Bounds_To_Range (V_Bounds, Arr_Type, 1))), New_Obj_Value (Var_Dir)); + + -- Get left bound of left parameter and copy it to result. New_Assign_Stmt (New_Obj (Var_Left), M2E (Chap3.Range_To_Left - (Chap3.Get_Array_Range (L, Arr_Type, 1)))); + (Chap3.Get_Array_Range (L, Arr_Type, 1)))); + New_Assign_Stmt + (M2Lv (Chap3.Range_To_Left + (Chap3.Bounds_To_Range (V_Bounds, Arr_Type, 1))), + New_Obj_Value (Var_Left)); + -- Note this substraction cannot overflow, since LENGTH >= 1. New_Assign_Stmt (New_Obj (Var_Length1), New_Dyadic_Op (ON_Sub_Ov, - New_Obj_Value (Var_Length), - New_Lit (Ghdl_Index_1))); - New_Assign_Stmt - (M2Lv (Chap3.Range_To_Left - (Chap3.Bounds_To_Range (V_Bounds, Arr_Type, 1))), - New_Obj_Value (Var_Left)); + New_Obj_Value (Var_Length), + New_Lit (Ghdl_Index_1))); + + -- Compute right bound of result: + -- if dir = dir_to then + -- right := left + length_1; + -- else + -- right := left - length_1; + -- end if; Start_If_Stmt (If_Blk, New_Compare_Op (ON_Eq, New_Obj_Value (Var_Dir), - New_Lit (Ghdl_Dir_To_Node), Ghdl_Bool_Type)); + New_Lit (Ghdl_Dir_To_Node), Ghdl_Bool_Type)); New_Assign_Stmt (New_Obj (Var_Right), New_Dyadic_Op (ON_Add_Ov, - New_Obj_Value (Var_Left), - New_Convert_Ov (New_Obj_Value (Var_Length1), - Index_Otype))); + New_Obj_Value (Var_Left), + New_Convert_Ov (New_Obj_Value (Var_Length1), + Index_Otype))); New_Else_Stmt (If_Blk); New_Assign_Stmt (New_Obj (Var_Right), New_Dyadic_Op (ON_Sub_Ov, - New_Obj_Value (Var_Left), - New_Convert_Ov (New_Obj_Value (Var_Length1), - Index_Otype))); + New_Obj_Value (Var_Left), + New_Convert_Ov (New_Obj_Value (Var_Length1), + Index_Otype))); Finish_If_Stmt (If_Blk); + -- Check the right bounds is inside the bounds of the -- index type. Chap3.Check_Range (Var_Right, Null_Iir, Index_Type, Subprg); @@ -4599,19 +4603,9 @@ package body Trans.Chap7 is -- result. The direction of the result of the concatenation is -- the direction of S, and the left bound of the result is -- S'LEFT. - declare - Var_Range_Ptr : O_Dnode; - begin - Start_Declare_Stmt; - New_Var_Decl (Var_Range_Ptr, Get_Identifier ("range_ptr"), - O_Storage_Local, Iinfo.T.Range_Ptr_Type); - New_Assign_Stmt - (New_Obj (Var_Range_Ptr), - M2Addr (Chap3.Bounds_To_Range (V_Bounds, Arr_Type, 1))); - Chap3.Create_Range_From_Length - (Index_Type, Var_Length, Var_Range_Ptr, Subprg); - Finish_Declare_Stmt; - end; + Chap3.Create_Range_From_Length + (Index_Type, Var_Length, + Chap3.Bounds_To_Range (V_Bounds, Arr_Type, 1), Subprg); end if; -- Allocate array base. diff --git a/src/vhdl/translate/trans.ads b/src/vhdl/translate/trans.ads index 04aca3cb3..2bdb6fd96 100644 --- a/src/vhdl/translate/trans.ads +++ b/src/vhdl/translate/trans.ads @@ -1541,17 +1541,17 @@ package Trans is T : Type_Info_Acc; Kind : Object_Kind_Type) return Mnode; - function Lp2M (L : O_Lnode; T : Type_Info_Acc; Kind : Object_Kind_Type) - return Mnode; - - function Lp2M (L : O_Lnode; + function Lv2M (L : O_Lnode; T : Type_Info_Acc; Kind : Object_Kind_Type; Vtype : O_Tnode; Ptype : O_Tnode) return Mnode; - function Lv2M (L : O_Lnode; + function Lp2M (L : O_Lnode; T : Type_Info_Acc; Kind : Object_Kind_Type) + return Mnode; + + function Lp2M (L : O_Lnode; T : Type_Info_Acc; Kind : Object_Kind_Type; Vtype : O_Tnode; |