From 61315151bc011a063d6a07937fd36068bdff53b6 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Tue, 29 Dec 2020 18:32:36 +0100 Subject: trans-chap3: compute size of subelements for unconstrained parent subtypes Fix #1549 --- src/synth/synth-insts.adb | 1 + src/vhdl/translate/trans-chap3.adb | 47 +++++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/synth/synth-insts.adb b/src/synth/synth-insts.adb index 5c95dce07..3598d594b 100644 --- a/src/synth/synth-insts.adb +++ b/src/synth/synth-insts.adb @@ -837,6 +837,7 @@ package body Synth.Insts is end loop; if Inst_Obj.Encoding = Name_Parameters then + -- Copy values of the generics to module parameters. declare Inter : Node; Vt : Valtyp; diff --git a/src/vhdl/translate/trans-chap3.adb b/src/vhdl/translate/trans-chap3.adb index 0e2474085..6892cad99 100644 --- a/src/vhdl/translate/trans-chap3.adb +++ b/src/vhdl/translate/trans-chap3.adb @@ -798,6 +798,42 @@ package body Trans.Chap3 is Close_Temp; end Elab_Composite_Subtype_Layout; + procedure Elab_Composite_Subtype_Size (Def : Iir; Target : Mnode) + is + Info : constant Type_Info_Acc := Get_Info (Def); + T : Mnode; + begin + case Type_Mode_Composite (Info.Type_Mode) is + when Type_Mode_Static_Record + | Type_Mode_Static_Array => + -- Precomputed. + null; + when Type_Mode_Complex_Record + | Type_Mode_Complex_Array => + Open_Temp; + T := Stabilize (Target); + Gen_Call_Type_Builder (T, Def, Mode_Value); + if Get_Has_Signal_Flag (Def) then + Gen_Call_Type_Builder (T, Def, Mode_Signal); + end if; + Close_Temp; + when Type_Mode_Unbounded_Record => + null; + when Type_Mode_Unbounded_Array => + if Get_Array_Element_Constraint (Def) = Null_Iir then + -- Element is defined by the subtype. + return; + end if; + Elab_Composite_Subtype_Size + (Get_Element_Subtype (Def), + Array_Bounds_To_Element_Layout (Layout_To_Bounds (Target), + Def)); + when Type_Mode_Protected => + -- Not expected. + raise Internal_Error; + end case; + end Elab_Composite_Subtype_Size; + procedure Elab_Composite_Subtype_Layout (Def : Iir) is Info : constant Type_Info_Acc := Get_Info (Def); @@ -807,16 +843,11 @@ package body Trans.Chap3 is return; end if; + -- Fill ranges and length. Elab_Composite_Subtype_Layout (Def, Get_Composite_Type_Layout (Info)); - if Is_Complex_Type (Info) then - Gen_Call_Type_Builder - (Get_Composite_Type_Layout (Info), Def, Mode_Value); - if Get_Has_Signal_Flag (Def) then - Gen_Call_Type_Builder - (Get_Composite_Type_Layout (Info), Def, Mode_Signal); - end if; - end if; + -- Compute sizes. + Elab_Composite_Subtype_Size (Def, Get_Composite_Type_Layout (Info)); end Elab_Composite_Subtype_Layout; -- Create a variable containing the layout for composite subtype DEF. -- cgit v1.2.3