aboutsummaryrefslogtreecommitdiffstats
path: root/src/synth
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-01-14 18:52:53 +0100
committerTristan Gingold <tgingold@free.fr>2023-01-15 09:47:14 +0100
commit9fcf6b6d1b125c0d8a98a6363e4b14618f8686c1 (patch)
tree086201e9ecfed68fe0a2e10cab3e4f15f5e042ff /src/synth
parenta72c06fdfbf4a18bc8fc9728113f5a99ee25d6eb (diff)
downloadghdl-9fcf6b6d1b125c0d8a98a6363e4b14618f8686c1.tar.gz
ghdl-9fcf6b6d1b125c0d8a98a6363e4b14618f8686c1.tar.bz2
ghdl-9fcf6b6d1b125c0d8a98a6363e4b14618f8686c1.zip
synth: avoid a crash on use before elaboration
Diffstat (limited to 'src/synth')
-rw-r--r--src/synth/elab-vhdl_insts.adb24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/synth/elab-vhdl_insts.adb b/src/synth/elab-vhdl_insts.adb
index a24d62713..c1a282d20 100644
--- a/src/synth/elab-vhdl_insts.adb
+++ b/src/synth/elab-vhdl_insts.adb
@@ -238,17 +238,12 @@ package body Elab.Vhdl_Insts is
procedure Elab_Package_Instantiation
(Parent_Inst : Synth_Instance_Acc; Pkg : Node)
is
+ Uninst : constant Node := Get_Uninstantiated_Package_Decl (Pkg);
Bod : Node;
Sub_Inst : Synth_Instance_Acc;
begin
Sub_Inst := Create_Package_Instance (Parent_Inst, Pkg);
- Elab_Generics_Association
- (Sub_Inst, Parent_Inst,
- Get_Generic_Chain (Pkg), Get_Generic_Map_Aspect_Chain (Pkg));
-
- Elab_Declarations (Sub_Inst, Get_Declaration_Chain (Pkg));
-
if Get_Kind (Pkg) = Iir_Kind_Interface_Package_Declaration then
-- Not yet implemented: macro-expanded body for mapped package.
Bod := Null_Node;
@@ -256,6 +251,21 @@ package body Elab.Vhdl_Insts is
Bod := Get_Instance_Package_Body (Pkg);
end if;
+ -- Set uninstantiated scope.
+ -- Technically this can be done later as it is needed only when
+ -- the body is used. However some designs do access before elaboration,
+ -- and we need to detect that.
+ if Bod = Null_Node then
+ -- Shared body
+ Set_Uninstantiated_Scope (Sub_Inst, Uninst);
+ end if;
+
+ Elab_Generics_Association
+ (Sub_Inst, Parent_Inst,
+ Get_Generic_Chain (Pkg), Get_Generic_Map_Aspect_Chain (Pkg));
+
+ Elab_Declarations (Sub_Inst, Get_Declaration_Chain (Pkg));
+
if Bod /= Null_Node then
-- Macro expanded package instantiation.
Elab_Declarations
@@ -263,10 +273,8 @@ package body Elab.Vhdl_Insts is
else
-- Shared body
declare
- Uninst : constant Node := Get_Uninstantiated_Package_Decl (Pkg);
Uninst_Bod : constant Node := Get_Package_Body (Uninst);
begin
- Set_Uninstantiated_Scope (Sub_Inst, Uninst);
-- Synth declarations of (optional) body.
if Uninst_Bod /= Null_Node then
Elab_Declarations