aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2022-06-16 06:52:12 +0200
committerTristan Gingold <tgingold@free.fr>2022-06-16 06:52:12 +0200
commite260d4cf6b985a99cfc2a0af5ef4b5e03b51cff1 (patch)
tree5d67df8b217907a4a3e73ff83cee1c31744cbd86
parent78b32ad57f7ed510f25954e0bd93cd649fa8a1b8 (diff)
downloadghdl-e260d4cf6b985a99cfc2a0af5ef4b5e03b51cff1.tar.gz
ghdl-e260d4cf6b985a99cfc2a0af5ef4b5e03b51cff1.tar.bz2
ghdl-e260d4cf6b985a99cfc2a0af5ef4b5e03b51cff1.zip
vhdl/translate: handle inertial association in recursive instantiation
Fix #2065
-rw-r--r--src/vhdl/translate/trans-chap4.adb17
-rw-r--r--src/vhdl/translate/trans-chap5.ads1
2 files changed, 16 insertions, 2 deletions
diff --git a/src/vhdl/translate/trans-chap4.adb b/src/vhdl/translate/trans-chap4.adb
index d9feeb16d..f1db4d40b 100644
--- a/src/vhdl/translate/trans-chap4.adb
+++ b/src/vhdl/translate/trans-chap4.adb
@@ -3123,6 +3123,7 @@ package body Trans.Chap4 is
Entity : Iir)
is
pragma Unreferenced (Num);
+ use Trans.Chap5;
Formal : constant Iir := Get_Association_Formal (Assoc, Inter);
Actual : constant Iir := Get_Actual (Assoc);
Block_Info : constant Block_Info_Acc := Get_Info (Base_Block);
@@ -3131,6 +3132,7 @@ package body Trans.Chap4 is
Entity_Info : Ortho_Info_Acc;
Targ : Mnode;
Val : Mnode;
+ Act_Env : Map_Env;
begin
-- Declare the subprogram.
Assoc_Info := Add_Info (Assoc, Kind_Inertial_Assoc);
@@ -3153,6 +3155,7 @@ package body Trans.Chap4 is
Open_Temp;
-- Access for formals.
+ Act_Env.Scope_Ptr := null;
if Entity /= Null_Iir then
Entity_Info := Get_Info (Entity);
declare
@@ -3177,9 +3180,13 @@ package body Trans.Chap4 is
Inst_Info.Block_Link_Field),
Rtis.Ghdl_Component_Link_Instance)),
Entity_Info.Block_Decls_Ptr_Type));
+ -- Save previous scope for recursive instantiation.
+ Save_Map_Env (Act_Env, Entity_Info.Block_Scope'Access);
+ if not Is_Null (Entity_Info.Block_Scope) then
+ Clear_Scope (Entity_Info.Block_Scope);
+ end if;
Set_Scope_Via_Param_Ptr (Entity_Info.Block_Scope, V);
end if;
-
end;
end if;
@@ -3187,6 +3194,11 @@ package body Trans.Chap4 is
-- 1. Translate target (translate_name)
Targ := Chap6.Translate_Name (Formal, Mode_Signal);
+ if Act_Env.Scope_Ptr /= null then
+ -- Switch to the actual environment (if any).
+ Set_Map_Env (Act_Env);
+ end if;
+
-- 2. Translate expression
Val := Chap7.Translate_Expression (Actual, Get_Type (Formal));
@@ -3201,9 +3213,10 @@ package body Trans.Chap4 is
if Entity /= Null_Iir then
if Entity_Info.Kind = Kind_Component then
+ pragma Assert (Act_Env.Scope_Ptr = null);
Clear_Scope (Entity_Info.Comp_Scope);
else
- Clear_Scope (Entity_Info.Block_Scope);
+ Restore_Map_Env (Act_Env);
end if;
end if;
diff --git a/src/vhdl/translate/trans-chap5.ads b/src/vhdl/translate/trans-chap5.ads
index ab54e67da..88627da56 100644
--- a/src/vhdl/translate/trans-chap5.ads
+++ b/src/vhdl/translate/trans-chap5.ads
@@ -42,6 +42,7 @@ package Trans.Chap5 is
-- Save and restore the map environment defined by ENV.
procedure Save_Map_Env (Env : out Map_Env; Scope_Ptr : Var_Scope_Acc);
procedure Set_Map_Env (Env : Map_Env);
+ procedure Restore_Map_Env (Env : Map_Env);
procedure Elab_Generic_Map_Aspect
(Header : Iir; Map : Iir; Formal_Env : Map_Env);