diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-12-18 08:33:08 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-12-18 08:36:14 +0100 |
commit | 36c276363fa35f6856bbd44e7a37e712aaab2a1e (patch) | |
tree | 91364ca992157bf131d3e5bf89cf13bd5e6b9335 | |
parent | b25116679aac9f88ab54bca0ef2879fedc0faed2 (diff) | |
download | ghdl-36c276363fa35f6856bbd44e7a37e712aaab2a1e.tar.gz ghdl-36c276363fa35f6856bbd44e7a37e712aaab2a1e.tar.bz2 ghdl-36c276363fa35f6856bbd44e7a37e712aaab2a1e.zip |
synth: factorize code (Exec_Name_Subtype). Fix #2273
-rw-r--r-- | src/synth/elab-vhdl_expr.adb | 100 | ||||
-rw-r--r-- | src/synth/elab-vhdl_expr.ads | 4 | ||||
-rw-r--r-- | src/synth/elab-vhdl_insts.adb | 4 | ||||
-rw-r--r-- | src/synth/synth-vhdl_stmts.adb | 2 |
4 files changed, 26 insertions, 84 deletions
diff --git a/src/synth/elab-vhdl_expr.adb b/src/synth/elab-vhdl_expr.adb index 64c1a176a..ee15c7e52 100644 --- a/src/synth/elab-vhdl_expr.adb +++ b/src/synth/elab-vhdl_expr.adb @@ -292,16 +292,9 @@ package body Elab.Vhdl_Expr is when Iir_Kind_Simple_Name | Iir_Kind_Selected_Name => return Exec_Name_Subtype (Syn_Inst, Get_Named_Entity (Name)); - when Iir_Kind_Interface_Signal_Declaration - | Iir_Kind_Variable_Declaration - | Iir_Kind_Interface_Variable_Declaration - | Iir_Kind_Signal_Declaration - | Iir_Kind_Interface_Constant_Declaration - | Iir_Kind_Constant_Declaration - | Iir_Kind_Iterator_Declaration - | Iir_Kind_Object_Alias_Declaration - | Iir_Kind_File_Declaration - | Iir_Kind_Interface_File_Declaration => + when Iir_Kind_Parenthesis_Expression => + return Exec_Name_Subtype (Syn_Inst, Get_Expression (Name)); + when Iir_Kinds_Object_Declaration => return Get_Value (Syn_Inst, Name).Typ; when Iir_Kind_Selected_Element => declare @@ -322,46 +315,6 @@ package body Elab.Vhdl_Expr is Res := Exec_Name_Subtype (Syn_Inst, Pfx); return Res.Arr_El; end; - when Iir_Kind_Enumeration_Literal - | Iir_Kind_Unit_Declaration => - return Get_Subtype_Object (Syn_Inst, Get_Type (Name)); - when Iir_Kind_Implicit_Dereference - | Iir_Kind_Dereference => - declare - Val : Valtyp; - Obj : Memtyp; - begin - Val := Synth_Expression (Syn_Inst, Get_Prefix (Name)); - Obj := Elab.Vhdl_Heap.Synth_Dereference (Read_Access (Val)); - return Obj.Typ; - end; - when Iir_Kind_Function_Call => - declare - Val : Valtyp; - begin - Val := Synth.Vhdl_Expr.Synth_Expression (Syn_Inst, Name); - return Val.Typ; - end; - when others => - Error_Kind ("exec_name_subtype", Name); - end case; - end Exec_Name_Subtype; - - -- Return the type of EXPR without evaluating it. - function Exec_Type_Of_Object (Syn_Inst : Synth_Instance_Acc; Expr : Node) - return Type_Acc is - begin - case Get_Kind (Expr) is - when Iir_Kinds_Object_Declaration => - declare - Val : constant Valtyp := Get_Value (Syn_Inst, Expr); - begin - return Val.Typ; - end; - when Iir_Kind_Simple_Name => - return Exec_Type_Of_Object (Syn_Inst, Get_Named_Entity (Expr)); - when Iir_Kind_Parenthesis_Expression => - return Exec_Type_Of_Object (Syn_Inst, Get_Expression (Expr)); when Iir_Kind_Slice_Name => declare use Netlists; @@ -372,54 +325,47 @@ package body Elab.Vhdl_Expr is Sl_Off : Value_Offsets; Inp : Net; begin - Pfx_Typ := Exec_Type_Of_Object (Syn_Inst, Get_Prefix (Expr)); + Pfx_Typ := Exec_Name_Subtype (Syn_Inst, Get_Prefix (Name)); Get_Onedimensional_Array_Bounds (Pfx_Typ, Pfx_Bnd, El_Typ); - Synth_Slice_Suffix (Syn_Inst, Expr, Pfx_Bnd, El_Typ, + Synth_Slice_Suffix (Syn_Inst, Name, Pfx_Bnd, El_Typ, Res_Bnd, Inp, Sl_Off); pragma Assert (Inp = No_Net); return Create_Onedimensional_Array_Subtype (Pfx_Typ, Res_Bnd, El_Typ); end; - when Iir_Kind_Indexed_Name => - declare - Pfx_Typ : Type_Acc; - begin - Pfx_Typ := Exec_Type_Of_Object (Syn_Inst, Get_Prefix (Expr)); - return Get_Array_Element (Pfx_Typ); - end; - when Iir_Kind_Selected_Element => - declare - Idx : constant Iir_Index32 := - Get_Element_Position (Get_Named_Entity (Expr)); - Pfx_Typ : Type_Acc; - begin - Pfx_Typ := Exec_Type_Of_Object (Syn_Inst, Get_Prefix (Expr)); - return Pfx_Typ.Rec.E (Idx + 1).Typ; - end; - when Iir_Kind_Implicit_Dereference | Iir_Kind_Dereference => declare Val : Valtyp; - Res : Memtyp; + Obj : Memtyp; begin -- Maybe do not dereference it if its type is known ? - Val := Synth_Expression (Syn_Inst, Get_Prefix (Expr)); - Res := Elab.Vhdl_Heap.Synth_Dereference (Read_Access (Val)); - return Res.Typ; + Val := Synth_Expression (Syn_Inst, Get_Prefix (Name)); + Obj := Elab.Vhdl_Heap.Synth_Dereference (Read_Access (Val)); + return Obj.Typ; + end; + when Iir_Kind_Function_Call => + declare + Val : Valtyp; + begin + Val := Synth.Vhdl_Expr.Synth_Expression (Syn_Inst, Name); + return Val.Typ; end; + when Iir_Kind_Enumeration_Literal + | Iir_Kind_Unit_Declaration => + return Get_Subtype_Object (Syn_Inst, Get_Type (Name)); + when Iir_Kind_String_Literal8 | Iir_Kind_Aggregate => -- TODO: the value should be computed (once) and its type -- returned. - return Synth_Subtype_Indication (Syn_Inst, Get_Type (Expr)); + return Synth_Subtype_Indication (Syn_Inst, Get_Type (Name)); when others => - Vhdl.Errors.Error_Kind ("exec_type_of_object", Expr); + Error_Kind ("exec_name_subtype", Name); end case; - return null; - end Exec_Type_Of_Object; + end Exec_Name_Subtype; function Exec_String_Literal (Syn_Inst : Synth_Instance_Acc; Str : Node; diff --git a/src/synth/elab-vhdl_expr.ads b/src/synth/elab-vhdl_expr.ads index 8f78faa7a..3ef89d02c 100644 --- a/src/synth/elab-vhdl_expr.ads +++ b/src/synth/elab-vhdl_expr.ads @@ -34,10 +34,6 @@ package Elab.Vhdl_Expr is procedure Check_Matching_Bounds (L, R : Type_Acc; Loc : Node); - -- Return the type of EXPR without evaluating it. - function Exec_Type_Of_Object (Syn_Inst : Synth_Instance_Acc; Expr : Node) - return Type_Acc; - -- Get the type of NAME. No expressions are expected to be evaluated. function Exec_Name_Subtype (Syn_Inst : Synth_Instance_Acc; Name : Node) return Type_Acc; diff --git a/src/synth/elab-vhdl_insts.adb b/src/synth/elab-vhdl_insts.adb index 24c4d5b93..be7d5a7d5 100644 --- a/src/synth/elab-vhdl_insts.adb +++ b/src/synth/elab-vhdl_insts.adb @@ -411,12 +411,12 @@ package body Elab.Vhdl_Insts is else case Iir_Kinds_Association_Element_Parameters (Get_Kind (Assoc)) is when Iir_Kinds_Association_Element_By_Actual => - Res := Exec_Type_Of_Object (Syn_Inst, Get_Actual (Assoc)); + Res := Exec_Name_Subtype (Syn_Inst, Get_Actual (Assoc)); when Iir_Kind_Association_Element_By_Individual => Res := Synth_Subtype_Indication (Syn_Inst, Get_Actual_Type (Assoc)); when Iir_Kind_Association_Element_Open => - Res := Exec_Type_Of_Object + Res := Exec_Name_Subtype (Syn_Inst, Get_Default_Value (Inter)); end case; end if; diff --git a/src/synth/synth-vhdl_stmts.adb b/src/synth/synth-vhdl_stmts.adb index 5268e28d8..adab6e89a 100644 --- a/src/synth/synth-vhdl_stmts.adb +++ b/src/synth/synth-vhdl_stmts.adb @@ -331,7 +331,7 @@ package body Synth.Vhdl_Stmts is while Choice /= Null_Node loop pragma Assert (Get_Kind (Choice) = Iir_Kind_Choice_By_None); El := Get_Associated_Expr (Choice); - El_Typ := Elab.Vhdl_Expr.Exec_Type_Of_Object (Syn_Inst, El); + El_Typ := Elab.Vhdl_Expr.Exec_Name_Subtype (Syn_Inst, El); Bnd := Get_Array_Bound (El_Typ); Len := Len + Bnd.Len; Choice := Get_Chain (Choice); |