diff options
author | Tristan Gingold <tgingold@free.fr> | 2021-08-06 02:32:24 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2021-08-06 02:32:24 +0200 |
commit | 2d74a05dd686dce11c0f4584e2524ec76ed7ecf6 (patch) | |
tree | 490413e25372b99176ca7bb95f382df0d429f68a | |
parent | 6f7e1ccde2eab638c15d7c651c23629af6f0f8b6 (diff) | |
download | ghdl-2d74a05dd686dce11c0f4584e2524ec76ed7ecf6.tar.gz ghdl-2d74a05dd686dce11c0f4584e2524ec76ed7ecf6.tar.bz2 ghdl-2d74a05dd686dce11c0f4584e2524ec76ed7ecf6.zip |
trans-chap3: do not create same range_var for enumeration subtype.
As there is not ranges for enumerated type, a range_var was always created for
subtypes of enumerated types even if they had the same range.
Create the range_var for bool types.
-rw-r--r-- | src/vhdl/translate/trans-chap3.adb | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index ce01f0a26..2599a35bc 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -1200,17 +1200,7 @@ package body Trans.Chap3 is pragma Assert (El_Tinfo.S.Composite_Layout = Null_Var); El_Tinfo.S.Subtype_Owner := Get_Info (Def); when Kind_Type_Scalar => - if El_Tinfo.S.Range_Var = Null_Var then - -- Happen only for subtypes of enumeration type ? - declare - El_Parent_Type : constant Iir := - Get_Element_Subtype (Parent_Type); - El_Parent_Tinfo : constant Type_Info_Acc := - Get_Info (El_Parent_Type); - begin - El_Tinfo.S.Range_Var := El_Parent_Tinfo.S.Range_Var; - end; - end if; + pragma Assert (El_Tinfo.S.Range_Var /= Null_Var); when Kind_Type_File | Kind_Type_Protected => raise Internal_Error; @@ -2178,24 +2168,47 @@ package body Trans.Chap3 is -- If the range is the same as its parent (its type_mark), set -- Same_Range and return (so that no new range variable would be -- created). - if Get_Kind (Base) in Iir_Kinds_Scalar_Subtype_Definition then - declare - Tm_Rng : constant Iir := Get_Range_Constraint (Base); - begin - if Tm_Rng = Rng then - Subtype_Info.S.Same_Range := True; - return; - elsif Get_Kind (Rng) = Iir_Kind_Range_Expression - and then Get_Kind (Tm_Rng) = Iir_Kind_Range_Expression - and then Get_Left_Limit (Rng) = Get_Left_Limit (Tm_Rng) - and then Get_Right_Limit (Rng) = Get_Right_Limit (Tm_Rng) - and then Get_Direction (Rng) = Get_Direction (Tm_Rng) + case Get_Kind (Base) is + when Iir_Kinds_Scalar_Subtype_Definition => + declare + Tm_Rng : constant Iir := Get_Range_Constraint (Base); + begin + if Tm_Rng = Rng then + Subtype_Info.S.Same_Range := True; + return; + elsif Get_Kind (Rng) = Iir_Kind_Range_Expression + and then Get_Kind (Tm_Rng) = Iir_Kind_Range_Expression + and then Get_Left_Limit (Rng) = Get_Left_Limit (Tm_Rng) + and then Get_Right_Limit (Rng) = Get_Right_Limit (Tm_Rng) + and then Get_Direction (Rng) = Get_Direction (Tm_Rng) + then + Subtype_Info.S.Same_Range := True; + return; + end if; + end; + when Iir_Kind_Enumeration_Type_Definition => + if Get_Kind (Rng) = Iir_Kind_Range_Expression + and then Get_Direction (Rng) = Dir_To then - Subtype_Info.S.Same_Range := True; - return; + declare + Left : constant Iir := Get_Left_Limit (Rng); + Right : constant Iir := Get_Right_Limit (Rng); + begin + if Get_Kind (Left) = Iir_Kind_Enumeration_Literal + and then Get_Enum_Pos (Left) = 0 + and then Get_Kind (Right) = Iir_Kind_Enumeration_Literal + and then Natural (Get_Enum_Pos (Right)) + = (Get_Nbr_Elements + (Get_Enumeration_Literal_List (Base)) - 1) + then + Subtype_Info.S.Same_Range := True; + return; + end if; + end; end if; - end; - end if; + when others => + null; + end case; -- So range is not the same. Subtype_Info.S.Same_Range := False; @@ -2437,6 +2450,7 @@ package body Trans.Chap3 is -- This is usually done in translate_type_definition, but boolean -- types are not handled by translate_type_definition. Create_Scalar_Type_Range_Type (Def, True); + Create_Type_Range_Var (Def); end Translate_Bool_Type_Definition; procedure Translate_Subtype_Definition |