diff options
author | Tristan Gingold <tgingold@free.fr> | 2017-01-02 05:51:48 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2017-01-02 05:51:48 +0100 |
commit | 43a504a9722b739ab33393ecb2d1abc6962cc52f (patch) | |
tree | 5fa83a8745b239cbb4b8f7c5d06079db681f67f0 /src/vhdl | |
parent | 0f62d8b9acc29a4726a17c72c315a0a94ec18688 (diff) | |
download | ghdl-43a504a9722b739ab33393ecb2d1abc6962cc52f.tar.gz ghdl-43a504a9722b739ab33393ecb2d1abc6962cc52f.tar.bz2 ghdl-43a504a9722b739ab33393ecb2d1abc6962cc52f.zip |
iirs_utils: reimplement Are_Bounds_Locally_Static.
Diffstat (limited to 'src/vhdl')
-rw-r--r-- | src/vhdl/iirs_utils.adb | 52 | ||||
-rw-r--r-- | src/vhdl/iirs_utils.ads | 8 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap3.adb | 66 | ||||
-rw-r--r-- | src/vhdl/translate/trans-chap7.adb | 4 |
4 files changed, 81 insertions, 49 deletions
diff --git a/src/vhdl/iirs_utils.adb b/src/vhdl/iirs_utils.adb index f12ef8661..5aceb7a3a 100644 --- a/src/vhdl/iirs_utils.adb +++ b/src/vhdl/iirs_utils.adb @@ -1054,7 +1054,7 @@ package body Iirs_Utils is return Get_Nbr_Elements (Get_Index_Subtype_List (Array_Type)); end Get_Nbr_Dimensions; - function Are_Bounds_Locally_Static (Array_Type : Iir) return Boolean + function Are_Array_Indexes_Locally_Static (Array_Type : Iir) return Boolean is Indexes : constant Iir_List := Get_Index_Subtype_List (Array_Type); Index : Iir; @@ -1067,6 +1067,56 @@ package body Iirs_Utils is end if; end loop; return True; + end Are_Array_Indexes_Locally_Static; + + -- Return true if array/record bounds are locally static. + function Are_Bounds_Locally_Static (Def : Iir) return Boolean + is + pragma Assert (Get_Constraint_State (Def) = Fully_Constrained); + begin + case Get_Kind (Def) is + when Iir_Kind_Array_Subtype_Definition => + declare + El_Btype : Iir; + begin + -- Indexes. + if not Are_Array_Indexes_Locally_Static (Def) then + return False; + end if; + + -- Element. + El_Btype := Get_Element_Subtype (Get_Base_Type (Def)); + if not Is_Fully_Constrained_Type (El_Btype) then + return Are_Bounds_Locally_Static (Get_Element_Subtype (Def)); + else + -- Element was fully constrained. + return True; + end if; + end; + when Iir_Kind_Record_Subtype_Definition => + declare + Base_Type : constant Iir := Get_Base_Type (Def); + El_List : constant Iir_List := + Get_Elements_Declaration_List (Def); + El_Blist : constant Iir_List := + Get_Elements_Declaration_List (Base_Type); + El, Bel : Iir; + begin + for I in Natural loop + Bel := Get_Nth_Element (El_Blist, I); + exit when Bel = Null_Iir; + if not Is_Fully_Constrained_Type (Bel) then + El := Get_Nth_Element (El_List, I); + if not Are_Bounds_Locally_Static (El) then + return False; + end if; + end if; + end loop; + return True; + end; + when others => + Error_Kind ("get_bounds_staticness", Def); + end case; end Are_Bounds_Locally_Static; function Get_Denoted_Type_Mark (Subtyp : Iir) return Iir diff --git a/src/vhdl/iirs_utils.ads b/src/vhdl/iirs_utils.ads index 771172fca..fbe4c1127 100644 --- a/src/vhdl/iirs_utils.ads +++ b/src/vhdl/iirs_utils.ads @@ -223,8 +223,12 @@ package Iirs_Utils is -- Number of dimensions (1..n) for ARRAY_TYPE. function Get_Nbr_Dimensions (Array_Type : Iir) return Natural; - -- Return True iff the all bounds of ARRAY_TYPE are locally static. - function Are_Bounds_Locally_Static (Array_Type : Iir) return Boolean; + -- Return True iff the all indexes of ARRAY_TYPE are locally static. + function Are_Array_Indexes_Locally_Static (Array_Type : Iir) return Boolean; + + -- Return true if array/record bounds are locally static. Only fully + -- constrained records or arrays are allowed. + function Are_Bounds_Locally_Static (Def : Iir) return Boolean; -- Return the type or subtype definition of the SUBTYP type mark. function Get_Denoted_Type_Mark (Subtyp : Iir) return Iir; diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index 773f4ed8f..e8c0c779c 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -558,8 +558,7 @@ package body Trans.Chap3 is -- Declare the bounds types for DEF. procedure Translate_Array_Type_Bounds - (Def : Iir_Array_Type_Definition; - Info : Type_Info_Acc) + (Def : Iir_Array_Type_Definition; Info : Type_Info_Acc) is Indexes_List : constant Iir_List := Get_Index_Subtype_Definition_List (Def); @@ -828,22 +827,6 @@ package body Trans.Chap3 is Close_Temp; end Create_Array_Subtype_Bounds; - -- Get staticness of the array bounds. - function Get_Array_Bounds_Staticness (Def : Iir) return Iir_Staticness - is - List : constant Iir_List := Get_Index_Subtype_List (Def); - Idx_Type : Iir; - begin - for I in Natural loop - Idx_Type := Get_Index_Type (List, I); - exit when Idx_Type = Null_Iir; - if Get_Type_Staticness (Idx_Type) /= Locally then - return Globally; - end if; - end loop; - return Locally; - end Get_Array_Bounds_Staticness; - -- Create a variable containing the bounds for array subtype DEF. procedure Create_Array_Subtype_Bounds_Var (Def : Iir; Elab_Now : Boolean) is @@ -855,32 +838,27 @@ package body Trans.Chap3 is return; end if; Base_Info := Get_Info (Get_Base_Type (Def)); - case Get_Array_Bounds_Staticness (Def) is - when None - | Globally => - Info.S.Static_Bounds := False; - Info.S.Array_Bounds := Create_Var - (Create_Var_Identifier ("STB"), Base_Info.B.Bounds_Type); - if Elab_Now then - Create_Array_Subtype_Bounds - (Def, Get_Var (Info.S.Array_Bounds)); - end if; - when Locally => - Info.S.Static_Bounds := True; - if Global_Storage = O_Storage_External then - -- Do not create the value of the type desc, since it - -- is never dereferenced in a static type desc. - Val := O_Cnode_Null; - else - Val := Create_Static_Array_Subtype_Bounds (Def); - end if; - Info.S.Array_Bounds := Create_Global_Const - (Create_Identifier ("STB"), - Base_Info.B.Bounds_Type, Global_Storage, Val); - - when Unknown => - raise Internal_Error; - end case; + if Are_Bounds_Locally_Static (Def) then + Info.S.Static_Bounds := True; + if Global_Storage = O_Storage_External then + -- Do not create the value of the type desc, since it + -- is never dereferenced in a static type desc. + Val := O_Cnode_Null; + else + Val := Create_Static_Array_Subtype_Bounds (Def); + end if; + Info.S.Array_Bounds := Create_Global_Const + (Create_Identifier ("STB"), + Base_Info.B.Bounds_Type, Global_Storage, Val); + else + Info.S.Static_Bounds := False; + Info.S.Array_Bounds := Create_Var + (Create_Var_Identifier ("STB"), Base_Info.B.Bounds_Type); + if Elab_Now then + Create_Array_Subtype_Bounds + (Def, Get_Var (Info.S.Array_Bounds)); + end if; + end if; end Create_Array_Subtype_Bounds_Var; procedure Create_Array_Type_Builder diff --git a/src/vhdl/translate/trans-chap7.adb b/src/vhdl/translate/trans-chap7.adb index d9e14eadd..b393e6acb 100644 --- a/src/vhdl/translate/trans-chap7.adb +++ b/src/vhdl/translate/trans-chap7.adb @@ -438,7 +438,7 @@ package body Trans.Chap7 is R : O_Enode; begin if Get_Constraint_State (Str_Type) = Fully_Constrained - and then Are_Bounds_Locally_Static (Str_Type) + and then Are_Array_Indexes_Locally_Static (Str_Type) then Chap3.Create_Array_Subtype (Str_Type); case Get_Kind (Str) is @@ -454,7 +454,7 @@ package body Trans.Chap7 is when others => raise Internal_Error; end case; - Is_Static := Are_Bounds_Locally_Static (Res_Type); + Is_Static := Are_Array_Indexes_Locally_Static (Res_Type); if Is_Static then Res := Translate_Static_Implicit_Conv (Res, Str_Type, Res_Type); |