From 9df3cb21ad765f38561fff0a568ce94359d4d977 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 15 Dec 2021 08:18:10 +0100 Subject: synth: handle interface type in generics. For #412 --- src/synth/elab-vhdl_insts.adb | 12 ++++++++-- src/synth/elab-vhdl_types.adb | 4 +++- src/synth/synth-vhdl_insts.adb | 50 +++++++++++++++++++++++------------------- src/vhdl/vhdl-annotations.adb | 11 +++++++--- 4 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/synth/elab-vhdl_insts.adb b/src/synth/elab-vhdl_insts.adb index 71adc953d..b8b53517d 100644 --- a/src/synth/elab-vhdl_insts.adb +++ b/src/synth/elab-vhdl_insts.adb @@ -106,6 +106,15 @@ package body Elab.Vhdl_Insts is Create_Package_Interface (Sub_Inst, Inter, Pkg_Inst); end; + when Iir_Kind_Interface_Type_Declaration => + declare + Act_Typ : Type_Acc; + begin + Act_Typ := Synth_Subtype_Indication + (Syn_Inst, Get_Actual (Assoc)); + Create_Subtype_Object (Sub_Inst, Get_Type (Inter), Act_Typ); + end; + when Iir_Kind_Interface_Variable_Declaration | Iir_Kind_Interface_File_Declaration | Iir_Kind_Interface_Signal_Declaration @@ -113,8 +122,7 @@ package body Elab.Vhdl_Insts is | Iir_Kind_Interface_Terminal_Declaration => raise Internal_Error; - when Iir_Kinds_Interface_Subprogram_Declaration - | Iir_Kind_Interface_Type_Declaration => + when Iir_Kinds_Interface_Subprogram_Declaration => raise Internal_Error; end case; diff --git a/src/synth/elab-vhdl_types.adb b/src/synth/elab-vhdl_types.adb index 300f57427..7d726d154 100644 --- a/src/synth/elab-vhdl_types.adb +++ b/src/synth/elab-vhdl_types.adb @@ -530,7 +530,9 @@ package body Elab.Vhdl_Types is when Iir_Kinds_Denoting_Name => Atype := Get_Named_Entity (Atype); when Iir_Kind_Subtype_Declaration - | Iir_Kind_Type_Declaration => + | Iir_Kind_Type_Declaration + | Iir_Kind_Subtype_Attribute + | Iir_Kind_Interface_Type_Declaration => -- Type already declared, so already handled. return Null_Node; when Iir_Kind_Array_Subtype_Definition diff --git a/src/synth/synth-vhdl_insts.adb b/src/synth/synth-vhdl_insts.adb index dfb42b532..235d9ed8e 100644 --- a/src/synth/synth-vhdl_insts.adb +++ b/src/synth/synth-vhdl_insts.adb @@ -254,28 +254,34 @@ package body Synth.Vhdl_Insts is Gen_Decl := Generics; while Gen_Decl /= Null_Node loop - Gen := Get_Value (Params.Syn_Inst, Gen_Decl); - Strip_Const (Gen); - case Gen.Typ.Kind is - when Type_Discrete => - declare - S : constant String := - Uns64'Image (To_Uns64 (Read_Discrete (Gen))); - begin - if Len + S'Length > Str_Len then - Has_Hash := True; - Hash_Const (Ctxt, Gen.Val, Gen.Typ); - else - Str (Len + 1 .. Len + S'Length) := S; - pragma Assert (Str (Len + 1) = ' '); - Str (Len + 1) := '_'; -- Overwrite the space. - Len := Len + S'Length; - end if; - end; - when others => - Has_Hash := True; - Hash_Const (Ctxt, Gen.Val, Gen.Typ); - end case; + if Get_Kind (Gen_Decl) = Iir_Kind_Interface_Constant_Declaration + then + Gen := Get_Value (Params.Syn_Inst, Gen_Decl); + Strip_Const (Gen); + case Gen.Typ.Kind is + when Type_Discrete => + declare + S : constant String := + Uns64'Image (To_Uns64 (Read_Discrete (Gen))); + begin + if Len + S'Length > Str_Len then + Has_Hash := True; + Hash_Const (Ctxt, Gen.Val, Gen.Typ); + else + Str (Len + 1 .. Len + S'Length) := S; + pragma Assert (Str (Len + 1) = ' '); + Str (Len + 1) := '_'; -- Overwrite the space. + Len := Len + S'Length; + end if; + end; + when others => + Has_Hash := True; + Hash_Const (Ctxt, Gen.Val, Gen.Typ); + end case; + else + -- TODO: add a unique number (index) + null; + end if; Gen_Decl := Get_Chain (Gen_Decl); end loop; diff --git a/src/vhdl/vhdl-annotations.adb b/src/vhdl/vhdl-annotations.adb index b1a36646e..13aa8bf3b 100644 --- a/src/vhdl/vhdl-annotations.adb +++ b/src/vhdl/vhdl-annotations.adb @@ -431,7 +431,8 @@ package body Vhdl.Annotations is when Iir_Kind_Protected_Type_Declaration => Annotate_Protected_Type_Declaration (Block_Info, Def); - when Iir_Kind_Incomplete_Type_Definition => + when Iir_Kind_Incomplete_Type_Definition + | Iir_Kind_Subtype_Attribute => null; when Iir_Kind_Foreign_Vector_Type_Definition => @@ -509,8 +510,12 @@ package body Vhdl.Annotations is Create_Object_Info (Block_Info, Decl); when Iir_Kind_Interface_Package_Declaration => Annotate_Interface_Package_Declaration (Block_Info, Decl); - when Iir_Kinds_Interface_Subprogram_Declaration - | Iir_Kind_Interface_Type_Declaration => + when Iir_Kind_Interface_Type_Declaration => + if Flag_Synthesis then + -- Create an info on the interface_type_definition + Create_Object_Info (Block_Info, Get_Type (Decl)); + end if; + when Iir_Kinds_Interface_Subprogram_Declaration => -- Macro-expanded null; when others => -- cgit v1.2.3