aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-04-13 19:13:07 +0200
committerTristan Gingold <tgingold@free.fr>2023-04-13 19:13:07 +0200
commitf335b3756fd0b347209ea877557f04909334b9af (patch)
tree8f2ccbb9adb47c995a312988a5b7bd05b283bec7
parentba2f4832b4f5bce70610a41be9dbb92d20b7f871 (diff)
downloadghdl-f335b3756fd0b347209ea877557f04909334b9af.tar.gz
ghdl-f335b3756fd0b347209ea877557f04909334b9af.tar.bz2
ghdl-f335b3756fd0b347209ea877557f04909334b9af.zip
translate: improve support of nested uninstantiated packages
-rw-r--r--src/vhdl/translate/trans-chap2.adb118
-rw-r--r--src/vhdl/translate/trans-chap2.ads2
-rw-r--r--src/vhdl/translate/trans-chap4.adb20
3 files changed, 105 insertions, 35 deletions
diff --git a/src/vhdl/translate/trans-chap2.adb b/src/vhdl/translate/trans-chap2.adb
index cd84d4168..479d6a1df 100644
--- a/src/vhdl/translate/trans-chap2.adb
+++ b/src/vhdl/translate/trans-chap2.adb
@@ -844,8 +844,10 @@ package body Trans.Chap2 is
Push_Instance_Factory (Info.Package_Spec_Scope'Access);
Chap4.Translate_Generic_Chain (Header);
Chap4.Translate_Declaration_Chain (Decl);
- Info.Package_Elab_Var := Create_Var
- (Create_Var_Identifier ("ELABORATED"), Ghdl_Bool_Type);
+ if not Is_Nested_Package (Decl) then
+ Info.Package_Elab_Var := Create_Var
+ (Create_Var_Identifier ("ELABORATED"), Ghdl_Bool_Type);
+ end if;
Pop_Instance_Factory (Info.Package_Spec_Scope'Access);
-- Name the spec instance and create a pointer.
@@ -973,18 +975,44 @@ package body Trans.Chap2 is
(Bod : Iir_Package_Body; What : Subprg_Translate_Kind)
is
Spec : constant Iir := Get_Package (Bod);
+ Is_Uninst : constant Boolean := Is_Uninstantiated_Package (Spec);
+ Info : constant Ortho_Info_Acc := Get_Info (Spec);
+ Prev_Subprg_Instance : Subprgs.Subprg_Instance_Stack;
Mark : Id_Mark_Type;
begin
- if Is_Uninstantiated_Package (Spec) then
- if Get_Macro_Expanded_Flag (Spec) then
- return;
+ if Is_Uninst and then Get_Macro_Expanded_Flag (Spec) then
+ -- Nothing to do for macro-expanded packages.
+ return;
+ end if;
+
+ Push_Identifier_Prefix (Mark, Get_Identifier (Spec));
+
+ if Is_Uninst then
+ -- An extra parameter for the package instance needs to be added
+ -- to the subprograms.
+ Subprgs.Push_Subprg_Instance
+ (Info.Package_Body_Scope'Access, Info.Package_Body_Ptr_Type,
+ Wki_Instance, Prev_Subprg_Instance);
+
+ -- For nested package, this will be translated when translating
+ -- subprograms.
+ Set_Scope_Via_Field (Info.Package_Spec_Scope,
+ Info.Package_Spec_Field,
+ Info.Package_Body_Scope'Access);
+ end if;
+
+ Chap4.Translate_Declaration_Chain_Subprograms (Bod, What);
+
+ if Is_Uninst then
+ Clear_Scope (Info.Package_Spec_Scope);
+ Subprgs.Pop_Subprg_Instance (Wki_Instance, Prev_Subprg_Instance);
+
+ if What in Subprg_Translate_Body then
+ Elab_Package_Body (Spec, Bod);
end if;
- raise Internal_Error;
- else
- Push_Identifier_Prefix (Mark, Get_Identifier (Spec));
- Chap4.Translate_Declaration_Chain_Subprograms (Bod, What);
- Pop_Identifier_Prefix (Mark);
end if;
+
+ Pop_Identifier_Prefix (Mark);
end Translate_Package_Body_Subprograms;
procedure Translate_Package_Declaration (Decl : Iir_Package_Declaration)
@@ -1224,12 +1252,14 @@ package body Trans.Chap2 is
-- If the package was already elaborated, return now,
-- else mark the package as elaborated.
- Start_If_Stmt (If_Blk, New_Value (Get_Var (Info.Package_Elab_Var)));
- New_Return_Stmt;
- New_Else_Stmt (If_Blk);
- New_Assign_Stmt (Get_Var (Info.Package_Elab_Var),
- New_Lit (Ghdl_Bool_True_Node));
- Finish_If_Stmt (If_Blk);
+ if Info.Package_Elab_Var /= Null_Var then
+ Start_If_Stmt (If_Blk, New_Value (Get_Var (Info.Package_Elab_Var)));
+ New_Return_Stmt;
+ New_Else_Stmt (If_Blk);
+ New_Assign_Stmt (Get_Var (Info.Package_Elab_Var),
+ New_Lit (Ghdl_Bool_True_Node));
+ Finish_If_Stmt (If_Blk);
+ end if;
-- Elab Spec.
Start_Association (Constr, Info.Package_Elab_Spec_Subprg);
@@ -1237,7 +1267,10 @@ package body Trans.Chap2 is
New_Procedure_Call (Constr);
if Bod /= Null_Iir then
- Elab_Dependence (Get_Design_Unit (Bod));
+ if not Is_Nested_Package (Bod) then
+ Elab_Dependence (Get_Design_Unit (Bod));
+ end if;
+
Open_Temp;
Chap4.Elab_Declaration_Chain (Bod, Final);
Close_Temp;
@@ -1803,6 +1836,57 @@ package body Trans.Chap2 is
Pop_Identifier_Prefix (Mark);
end Translate_Package_Instantiation_Declaration;
+ procedure Translate_Package_Instantiation_Declaration_Subprograms
+ (Inst : Iir; What : Subprg_Translate_Kind) is
+ begin
+ if Get_Macro_Expanded_Flag (Get_Uninstantiated_Package_Decl (Inst)) then
+ declare
+ Bod : constant Iir := Get_Instance_Package_Body (Inst);
+ Mark : Id_Mark_Type;
+ begin
+ Push_Identifier_Prefix (Mark, Get_Identifier (Inst));
+ Chap4.Translate_Declaration_Chain_Subprograms (Inst, What);
+ if Is_Valid (Bod)
+ and then Global_Storage /= O_Storage_External
+ and then Get_Immediate_Body_Flag (Inst)
+ then
+ Chap4.Translate_Declaration_Chain_Subprograms (Bod, What);
+ end if;
+ Pop_Identifier_Prefix (Mark);
+ end;
+ else
+ if What in Subprg_Translate_Spec then
+ -- Update info for subprgs.
+ declare
+ El : Iir;
+ begin
+ El := Get_Declaration_Chain (Inst);
+ while El /= Null_Iir loop
+ case Get_Kind (El) is
+ when Iir_Kind_Function_Declaration
+ | Iir_Kind_Procedure_Declaration =>
+ declare
+ Orig : constant Iir :=
+ Vhdl.Sem_Inst.Get_Origin (El);
+ pragma Assert (Orig /= Null_Iir);
+ Orig_Info : constant Ortho_Info_Acc :=
+ Get_Info (Orig);
+ Info : constant Ortho_Info_Acc := Get_Info (El);
+ begin
+ if False then
+ Info.Subprg_Node := Orig_Info.Subprg_Node;
+ end if;
+ end;
+ when others =>
+ null;
+ end case;
+ El := Get_Chain (El);
+ end loop;
+ end;
+ end if;
+ end if;
+ end Translate_Package_Instantiation_Declaration_Subprograms;
+
procedure Translate_Package_Instantiation_Declaration_Unit (Inst : Iir)
is
Spec : constant Iir := Get_Uninstantiated_Package_Decl (Inst);
diff --git a/src/vhdl/translate/trans-chap2.ads b/src/vhdl/translate/trans-chap2.ads
index 6aae49895..155b91487 100644
--- a/src/vhdl/translate/trans-chap2.ads
+++ b/src/vhdl/translate/trans-chap2.ads
@@ -44,6 +44,8 @@ package Trans.Chap2 is
(Decl : Iir_Package_Declaration; What : Subprg_Translate_Kind);
procedure Translate_Package_Body_Subprograms
(Bod : Iir_Package_Body; What : Subprg_Translate_Kind);
+ procedure Translate_Package_Instantiation_Declaration_Subprograms
+ (Inst : Iir; What : Subprg_Translate_Kind);
procedure Elab_Package_Declaration (Spec : Iir);
procedure Elab_Package_Body (Spec : Iir_Package_Declaration; Bod : Iir);
procedure Elab_Package_Instantiation_Declaration (Inst : Iir);
diff --git a/src/vhdl/translate/trans-chap4.adb b/src/vhdl/translate/trans-chap4.adb
index 4e49b14dd..2c33231c4 100644
--- a/src/vhdl/translate/trans-chap4.adb
+++ b/src/vhdl/translate/trans-chap4.adb
@@ -2697,24 +2697,8 @@ package body Trans.Chap4 is
when Iir_Kind_Package_Body =>
Chap2.Translate_Package_Body_Subprograms (El, What);
when Iir_Kind_Package_Instantiation_Declaration =>
- if Get_Macro_Expanded_Flag
- (Get_Uninstantiated_Package_Decl (El))
- then
- declare
- Bod : constant Iir := Get_Instance_Package_Body (El);
- Mark : Id_Mark_Type;
- begin
- Push_Identifier_Prefix (Mark, Get_Identifier (El));
- Translate_Declaration_Chain_Subprograms (El, What);
- if Is_Valid (Bod)
- and then Global_Storage /= O_Storage_External
- and then Get_Immediate_Body_Flag (El)
- then
- Translate_Declaration_Chain_Subprograms (Bod, What);
- end if;
- Pop_Identifier_Prefix (Mark);
- end;
- end if;
+ Chap2.Translate_Package_Instantiation_Declaration_Subprograms
+ (El, What);
when Iir_Kind_Package_Instantiation_Body =>
declare
Mark : Id_Mark_Type;