diff options
author | Tristan Gingold <tgingold@free.fr> | 2019-10-07 20:41:53 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2019-10-07 20:41:53 +0200 |
commit | 4f695902d589085bb0266294432453277455a102 (patch) | |
tree | d8ef7690b157a9039139a4032a5b40dd7ce80c2e /src/synth | |
parent | 91a554e511ee36d213488c939e8afbde6d2abcb0 (diff) | |
download | ghdl-4f695902d589085bb0266294432453277455a102.tar.gz ghdl-4f695902d589085bb0266294432453277455a102.tar.bz2 ghdl-4f695902d589085bb0266294432453277455a102.zip |
synth: handle package bodies.
Diffstat (limited to 'src/synth')
-rw-r--r-- | src/synth/synth-context.adb | 32 | ||||
-rw-r--r-- | src/synth/synth-context.ads | 4 | ||||
-rw-r--r-- | src/synth/synth-decls.adb | 17 | ||||
-rw-r--r-- | src/synth/synth-decls.ads | 2 | ||||
-rw-r--r-- | src/synth/synth-insts.adb | 22 | ||||
-rw-r--r-- | src/synth/synth-stmts.adb | 1 |
6 files changed, 69 insertions, 9 deletions
diff --git a/src/synth/synth-context.adb b/src/synth/synth-context.adb index 48a362220..a806c7591 100644 --- a/src/synth/synth-context.adb +++ b/src/synth/synth-context.adb @@ -184,6 +184,13 @@ package body Synth.Context is return Create_Value_Instance (Packages_Table.Last); end Create_Value_Instance; + function Get_Value_Instance (Inst : Instance_Id) + return Synth_Instance_Acc is + begin + pragma Assert (Inst in Packages_Table.First .. Packages_Table.Last); + return Packages_Table.Table (Inst); + end Get_Value_Instance; + procedure Create_Object (Syn_Inst : Synth_Instance_Acc; Slot : Object_Slot_Type; Num : Object_Slot_Type := 1) is @@ -228,6 +235,21 @@ package body Synth.Context is Syn_Inst.Objects (Info.Pkg_Slot) := Val; end Create_Package_Object; + function Get_Package_Object + (Syn_Inst : Synth_Instance_Acc; Info : Sim_Info_Acc) return Value_Acc + is + Parent : Synth_Instance_Acc; + begin + Parent := Get_Instance_By_Scope (Syn_Inst, Info.Pkg_Parent); + return Parent.Objects (Info.Pkg_Slot); + end Get_Package_Object; + + function Get_Package_Object + (Syn_Inst : Synth_Instance_Acc; Pkg : Node) return Value_Acc is + begin + return Get_Package_Object (Syn_Inst, Get_Info (Pkg)); + end Get_Package_Object; + procedure Destroy_Object (Syn_Inst : Synth_Instance_Acc; Decl : Node) is @@ -289,14 +311,10 @@ package body Synth.Context is else -- Instantiated package. declare - Parent : Synth_Instance_Acc; - Inst : Instance_Id; + Inst : Value_Acc; begin - Parent := Get_Instance_By_Scope (Syn_Inst, Scope.Pkg_Parent); - Inst := Parent.Objects (Scope.Pkg_Slot).Instance; - pragma Assert - (Inst in Packages_Table.First .. Packages_Table.Last); - return Packages_Table.Table (Inst); + Inst := Get_Package_Object (Syn_Inst, Scope); + return Get_Value_Instance (Inst.Instance); end; end if; when others => diff --git a/src/synth/synth-context.ads b/src/synth/synth-context.ads index 182cfa5d5..630639083 100644 --- a/src/synth/synth-context.ads +++ b/src/synth/synth-context.ads @@ -105,6 +105,10 @@ package Synth.Context is function Create_Value_Instance (Inst : Synth_Instance_Acc) return Value_Acc; + function Get_Value_Instance (Inst : Instance_Id) return Synth_Instance_Acc; + + function Get_Package_Object + (Syn_Inst : Synth_Instance_Acc; Pkg : Node) return Value_Acc; private type Objects_Array is array (Object_Slot_Type range <>) of Value_Acc; diff --git a/src/synth/synth-decls.adb b/src/synth/synth-decls.adb index 0460694f9..76a408203 100644 --- a/src/synth/synth-decls.adb +++ b/src/synth/synth-decls.adb @@ -504,7 +504,6 @@ package body Synth.Decls is procedure Synth_Package_Declaration (Parent_Inst : Synth_Instance_Acc; Pkg : Node) is - use Vhdl.Std_Package; pragma Assert (not Is_Uninstantiated_Package (Pkg)); Syn_Inst : Synth_Instance_Acc; Val : Value_Acc; @@ -512,8 +511,10 @@ package body Synth.Decls is Syn_Inst := Make_Instance (Parent_Inst, Pkg); Val := Create_Value_Instance (Syn_Inst); if Get_Kind (Get_Parent (Pkg)) = Iir_Kind_Design_Unit then + -- Global package: in no particular order. Create_Package_Object (Parent_Inst, Pkg, Val); else + -- Local package: check elaboration order. Create_Object (Parent_Inst, Pkg, Val); end if; Synth_Declarations (Syn_Inst, Get_Declaration_Chain (Pkg)); @@ -522,6 +523,20 @@ package body Synth.Decls is end if; end Synth_Package_Declaration; + procedure Synth_Package_Body + (Parent_Inst : Synth_Instance_Acc; Pkg : Node; Bod : Node) + is + Val : Value_Acc; + begin + if Get_Kind (Get_Parent (Pkg)) = Iir_Kind_Design_Unit then + Val := Get_Package_Object (Parent_Inst, Pkg); + else + Val := Get_Value (Parent_Inst, Pkg); + end if; + Synth_Declarations (Get_Value_Instance (Val.Instance), + Get_Declaration_Chain (Bod)); + end Synth_Package_Body; + procedure Synth_Declaration (Syn_Inst : Synth_Instance_Acc; Decl : Node; Is_Subprg : Boolean) is begin diff --git a/src/synth/synth-decls.ads b/src/synth/synth-decls.ads index 0c478d5a2..ddcb43cf6 100644 --- a/src/synth/synth-decls.ads +++ b/src/synth/synth-decls.ads @@ -47,4 +47,6 @@ package Synth.Decls is procedure Synth_Package_Declaration (Parent_Inst : Synth_Instance_Acc; Pkg : Node); + procedure Synth_Package_Body + (Parent_Inst : Synth_Instance_Acc; Pkg : Node; Bod : Node); end Synth.Decls; diff --git a/src/synth/synth-insts.adb b/src/synth/synth-insts.adb index ebbfedcab..9d450eda0 100644 --- a/src/synth/synth-insts.adb +++ b/src/synth/synth-insts.adb @@ -23,6 +23,7 @@ with Libraries; with Hash; use Hash; with Interning; with Synthesis; use Synthesis; +with Std_Names; with Netlists; use Netlists; with Netlists.Builders; @@ -651,7 +652,26 @@ package body Synth.Insts is when Iir_Kind_Context_Declaration => null; when Iir_Kind_Package_Declaration => - Synth_Package_Declaration (Parent_Inst, Dep_Unit); + declare + Bod : constant Node := Get_Package_Body (Dep_Unit); + Bod_Unit : Node; + begin + Synth_Package_Declaration (Parent_Inst, Dep_Unit); + if Bod /= Null_Node then + Bod_Unit := Get_Design_Unit (Bod); + -- Do not translate bodies of ieee packages. + case (Get_Identifier + (Get_Library (Get_Design_File (Bod_Unit)))) + is + when Std_Names.Name_Ieee + | Std_Names.Name_Std => + null; + when others => + Synth_Dependencies (Parent_Inst, Bod_Unit); + Synth_Package_Body (Parent_Inst, Dep_Unit, Bod); + end case; + end if; + end; when Iir_Kind_Package_Instantiation_Declaration => null; when Iir_Kind_Package_Body => diff --git a/src/synth/synth-stmts.adb b/src/synth/synth-stmts.adb index 05eb57e37..325836f8b 100644 --- a/src/synth/synth-stmts.adb +++ b/src/synth/synth-stmts.adb @@ -28,6 +28,7 @@ with Vhdl.Errors; use Vhdl.Errors; with Vhdl.Types; with Vhdl.Sem_Expr; with Vhdl.Utils; use Vhdl.Utils; +with Vhdl.Std_Package; with Vhdl.Ieee.Std_Logic_1164; with Vhdl.Evaluation; |