diff options
author | Tristan Gingold <tgingold@free.fr> | 2022-12-26 16:02:25 +0100 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2022-12-26 17:33:38 +0100 |
commit | b458a7644447bb440ce4be6aa8458c71d54d8044 (patch) | |
tree | c4d534519515a8f0f6d9223a6e614199980ae008 /src | |
parent | 46f5ed830772009e7b6c82ee98a5a16b6ea97da0 (diff) | |
download | ghdl-b458a7644447bb440ce4be6aa8458c71d54d8044.tar.gz ghdl-b458a7644447bb440ce4be6aa8458c71d54d8044.tar.bz2 ghdl-b458a7644447bb440ce4be6aa8458c71d54d8044.zip |
synth: handle instance_name attribute
Diffstat (limited to 'src')
-rw-r--r-- | src/synth/elab-vhdl_context.adb | 18 | ||||
-rw-r--r-- | src/synth/elab-vhdl_context.ads | 3 | ||||
-rw-r--r-- | src/synth/elab-vhdl_expr.adb | 89 | ||||
-rw-r--r-- | src/synth/elab-vhdl_expr.ads | 2 | ||||
-rw-r--r-- | src/synth/synth-vhdl_expr.adb | 12 |
5 files changed, 115 insertions, 9 deletions
diff --git a/src/synth/elab-vhdl_context.adb b/src/synth/elab-vhdl_context.adb index d77b8ea6e..56de0563e 100644 --- a/src/synth/elab-vhdl_context.adb +++ b/src/synth/elab-vhdl_context.adb @@ -615,15 +615,21 @@ package body Elab.Vhdl_Context is end case; end Get_Instance_By_Scope; - function Get_Parent_Scope (Blk : Node) return Sim_Info_Acc + function Get_Info_Scope (Blk : Node) return Sim_Info_Acc is - Parent : Node; + N : Node; begin - Parent := Get_Parent (Blk); - if Get_Kind (Parent) = Iir_Kind_Architecture_Body then - Parent := Vhdl.Utils.Get_Entity (Parent); + if Get_Kind (Blk) = Iir_Kind_Architecture_Body then + N := Vhdl.Utils.Get_Entity (Blk); + else + N := Blk; end if; - return Get_Info (Parent); + return Get_Info (N); + end Get_Info_Scope; + + function Get_Parent_Scope (Blk : Node) return Sim_Info_Acc is + begin + return Get_Info_Scope (Get_Parent (Blk)); end Get_Parent_Scope; function Get_Value (Syn_Inst: Synth_Instance_Acc; Obj : Node) diff --git a/src/synth/elab-vhdl_context.ads b/src/synth/elab-vhdl_context.ads index 76fd35473..3a85cd089 100644 --- a/src/synth/elab-vhdl_context.ads +++ b/src/synth/elab-vhdl_context.ads @@ -190,6 +190,9 @@ package Elab.Vhdl_Context is function Get_Component_Instance (Syn_Inst : Synth_Instance_Acc) return Synth_Instance_Acc; + -- Return the scope of BLK. Deals with architecture bodies. + function Get_Info_Scope (Blk : Node) return Sim_Info_Acc; + -- Return the scope of the parent of BLK. Deals with architecture bodies. function Get_Parent_Scope (Blk : Node) return Sim_Info_Acc; diff --git a/src/synth/elab-vhdl_expr.adb b/src/synth/elab-vhdl_expr.adb index ee15c7e52..cb5e7a26d 100644 --- a/src/synth/elab-vhdl_expr.adb +++ b/src/synth/elab-vhdl_expr.adb @@ -37,6 +37,7 @@ with Synth.Errors; use Synth.Errors; with Grt.Types; with Grt.To_Strings; +with Grt.Vstrings; package body Elab.Vhdl_Expr is function Synth_Bounds_From_Length (Atype : Node; Len : Int32) @@ -420,4 +421,92 @@ package body Elab.Vhdl_Expr is return Res; end Exec_String_Literal; + function Exec_Path_Instance_Name_Attribute + (Inst : Synth_Instance_Acc; Attr : Iir) return Memtyp + is + use Grt.Vstrings; + use Name_Table; + + Is_Instance : constant Boolean := + Get_Kind (Attr) = Iir_Kind_Instance_Name_Attribute; + + Atype : constant Node := Get_Type (Attr); + Str_Typ : constant Type_Acc := Get_Subtype_Object (Inst, Atype); + Name : constant Path_Instance_Name_Type := + Get_Path_Instance_Name_Suffix (Attr); + Instance, Parent : Synth_Instance_Acc; + Rstr : Rstring; + Label : Node; + begin + if Name.Path_Instance = Null_Iir then + return String_To_Memtyp (Name.Suffix, Str_Typ); + end if; + + Instance := Get_Instance_By_Scope + (Inst, Get_Info_Scope (Name.Path_Instance)); + + loop + Parent := Get_Instance_Parent (Instance); + if Parent = Root_Instance then + Parent := null; + end if; + Label := Get_Source_Scope (Instance); + + case Get_Kind (Label) is + when Iir_Kind_Entity_Declaration => + if Parent = null then + Prepend (Rstr, Image (Get_Identifier (Label))); + exit; + end if; + when Iir_Kind_Architecture_Body => + if Is_Instance then + Prepend (Rstr, ')'); + Prepend (Rstr, Image (Get_Identifier (Label))); + Prepend (Rstr, '('); + end if; + + if Is_Instance or else Parent = null then + Prepend (Rstr, Image (Get_Identifier (Get_Entity (Label)))); + end if; + if Parent = null then + Prepend (Rstr, ':'); + exit; + end if; + when Iir_Kind_Block_Statement => + Prepend (Rstr, Image (Get_Label (Label))); + Prepend (Rstr, ':'); + when Iir_Kind_Iterator_Declaration => + declare + Val : Valtyp; + begin + Val := Get_Value (Instance, Label); + Prepend (Rstr, ')'); + Prepend (Rstr, + Synth_Image_Attribute_Str (Val, Get_Type (Label))); + Prepend (Rstr, '('); + end; + when Iir_Kind_Generate_Statement_Body => + Prepend (Rstr, Image (Get_Label (Get_Parent (Label)))); + Prepend (Rstr, ':'); + when Iir_Kind_Component_Instantiation_Statement => + if Is_Instance then + Prepend (Rstr, '@'); + end if; + Prepend (Rstr, Image (Get_Label (Label))); + Prepend (Rstr, ':'); + when others => + Error_Kind ("Execute_Path_Instance_Name_Attribute", + Label); + end case; + Instance := Parent; + end loop; + declare + Str1 : String (1 .. Length (Rstr)); + Len1 : Natural; + begin + Copy (Rstr, Str1, Len1); + Free (Rstr); + return String_To_Memtyp (Str1 & ':' & Name.Suffix, Str_Typ); + end; + end Exec_Path_Instance_Name_Attribute; end Elab.Vhdl_Expr; diff --git a/src/synth/elab-vhdl_expr.ads b/src/synth/elab-vhdl_expr.ads index 3ef89d02c..244f89154 100644 --- a/src/synth/elab-vhdl_expr.ads +++ b/src/synth/elab-vhdl_expr.ads @@ -55,6 +55,8 @@ package Elab.Vhdl_Expr is return Valtyp; function Exec_Instance_Name_Attribute (Syn_Inst : Synth_Instance_Acc; Attr : Node) return Valtyp; + function Exec_Path_Instance_Name_Attribute + (Inst : Synth_Instance_Acc; Attr : Iir) return Memtyp; function Exec_Simple_Aggregate (Syn_Inst : Synth_Instance_Acc; Aggr : Node) return Valtyp; diff --git a/src/synth/synth-vhdl_expr.adb b/src/synth/synth-vhdl_expr.adb index 83aecb420..c701be7c2 100644 --- a/src/synth/synth-vhdl_expr.adb +++ b/src/synth/synth-vhdl_expr.adb @@ -2367,9 +2367,15 @@ package body Synth.Vhdl_Expr is return Elab.Vhdl_Expr.Exec_Value_Attribute (Syn_Inst, Expr); when Iir_Kind_Image_Attribute => return Elab.Vhdl_Expr.Exec_Image_Attribute (Syn_Inst, Expr); - when Iir_Kind_Instance_Name_Attribute => - return Elab.Vhdl_Expr.Exec_Instance_Name_Attribute - (Syn_Inst, Expr); + when Iir_Kind_Path_Name_Attribute + | Iir_Kind_Instance_Name_Attribute => + declare + Mt : Memtyp; + begin + Mt := Elab.Vhdl_Expr.Exec_Path_Instance_Name_Attribute + (Syn_Inst, Expr); + return Create_Value_Memtyp (Mt); + end; when Iir_Kind_Null_Literal => return Create_Value_Access (Null_Heap_Index, Expr_Type); when Iir_Kind_Allocator_By_Subtype => |