aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2016-11-12 07:28:40 +0100
committerTristan Gingold <tgingold@free.fr>2016-11-12 07:34:03 +0100
commit70416572726fdd450fe89421be45916d1674eba0 (patch)
treedd2a6a3dc48828a1a66a913603a170a7cc8271af /src
parent69f57116f3d9a1f95c635e15ca85a9a96d3fc626 (diff)
downloadghdl-70416572726fdd450fe89421be45916d1674eba0.tar.gz
ghdl-70416572726fdd450fe89421be45916d1674eba0.tar.bz2
ghdl-70416572726fdd450fe89421be45916d1674eba0.zip
Handle top-level instantiation of macro-expansed packages.
Fix #199
Diffstat (limited to 'src')
-rw-r--r--src/libraries.adb28
-rw-r--r--src/vhdl/canon.adb29
-rw-r--r--src/vhdl/translate/trans-chap12.adb4
-rw-r--r--src/vhdl/translate/translation.adb6
4 files changed, 49 insertions, 18 deletions
diff --git a/src/libraries.adb b/src/libraries.adb
index 40764e56b..6173af87d 100644
--- a/src/libraries.adb
+++ b/src/libraries.adb
@@ -35,6 +35,7 @@ with Std_Package;
with Disp_Tree;
with Disp_Vhdl;
with Sem;
+with Sem_Inst;
with Post_Sems;
with Canon;
with Nodes_GC;
@@ -1551,8 +1552,9 @@ package body Libraries is
procedure Finish_Compilation
(Unit : Iir_Design_Unit; Main : Boolean := False)
is
- Lib_Unit : constant Iir := Get_Library_Unit (Unit);
+ Lib_Unit : Iir;
begin
+ Lib_Unit := Get_Library_Unit (Unit);
if (Main or Flags.Dump_All) and then Flags.Dump_Parse then
Disp_Tree.Disp_Tree (Unit);
end if;
@@ -1603,21 +1605,43 @@ package body Libraries is
Canon.Canonicalize (Unit);
+ -- The library unit may have been changed from package instantiation
+ -- to package declaration.
+ Lib_Unit := Get_Library_Unit (Unit);
+
-- FIXME: for Main only ?
if Get_Kind (Lib_Unit) = Iir_Kind_Package_Declaration
and then not Get_Need_Body (Lib_Unit)
and then Get_Need_Instance_Bodies (Lib_Unit)
then
- -- Create the bodies for instances
+ -- This is a package declaration without body. If there are package
+ -- instantiations within that package and if the instances need
+ -- bodies, create them. Ideally they should be created in the
+ -- package body, but as we don't know if there is one, do it now.
Set_Package_Instantiation_Bodies_Chain
(Lib_Unit, Canon.Create_Instantiation_Bodies (Lib_Unit, Lib_Unit));
elsif Get_Kind (Lib_Unit) = Iir_Kind_Package_Body
and then Get_Need_Instance_Bodies (Get_Package (Lib_Unit))
then
+ -- If there are package instances in the package declaration and if
+ -- they need bodies, create them now that the body (of the package
+ -- containing the instances) is analyzed.
Iir_Chains.Append_Chain
(Lib_Unit, Nodes_Meta.Field_Declaration_Chain,
Canon.Create_Instantiation_Bodies (Get_Package (Lib_Unit),
Lib_Unit));
+ elsif Get_Kind (Lib_Unit) = Iir_Kind_Package_Declaration
+ and then Get_Package_Origin (Lib_Unit) /= Null_Iir
+ and then (Get_Kind (Get_Package_Origin (Lib_Unit))
+ = Iir_Kind_Package_Instantiation_Declaration)
+ then
+ -- Instantiate the body for package instantiation.
+ declare
+ Bod : Iir;
+ begin
+ Bod := Sem_Inst.Instantiate_Package_Body (Lib_Unit);
+ Set_Package_Body (Lib_Unit, Bod);
+ end;
end if;
if (Main or Flags.Dump_All) and then Flags.Dump_Canon then
diff --git a/src/vhdl/canon.adb b/src/vhdl/canon.adb
index a23bbeb3f..471058843 100644
--- a/src/vhdl/canon.adb
+++ b/src/vhdl/canon.adb
@@ -2613,7 +2613,7 @@ package body Canon is
Location_Copy (New_Decl, Decl);
Set_Parent (New_Decl, Get_Parent (Decl));
Set_Identifier (New_Decl, Get_Identifier (Decl));
- Set_Need_Body (New_Decl, Get_Need_Body (Pkg));
+ Set_Need_Body (New_Decl, False);
New_Hdr := Create_Iir (Iir_Kind_Package_Header);
Set_Package_Header (New_Decl, New_Hdr);
@@ -2643,25 +2643,24 @@ package body Canon is
First, Last : Iir;
El : Iir;
Bod : Iir;
+ Orig : Iir;
begin
- First := Null_Iir;
- Last := Null_Iir; -- Kill the warning
+ Sub_Chain_Init (First, Last);
El := Get_Declaration_Chain (Decl);
while Is_Valid (El) loop
- if Get_Kind (El) = Iir_Kind_Package_Declaration
- and then Get_Need_Body (El)
- and then Get_Package_Origin (El) /= Null_Iir
- then
- Bod := Sem_Inst.Instantiate_Package_Body (El);
- Set_Parent (Bod, Parent);
+ if Get_Kind (El) = Iir_Kind_Package_Declaration then
+ Orig := Get_Package_Origin (El);
+ if Orig /= Null_Iir
+ and then Get_Need_Body (Get_Uninstantiated_Package_Decl (Orig))
+ then
+ -- That's a package instantiation of a package that needs a
+ -- body. Therefore, the instantiation also needs a body.
+ -- Create it.
+ Bod := Sem_Inst.Instantiate_Package_Body (El);
+ Set_Parent (Bod, Parent);
- -- Append.
- if First = Null_Iir then
- First := Bod;
- else
- Set_Chain (Last, Bod);
+ Sub_Chain_Append (First, Last, Bod);
end if;
- Last := Bod;
end if;
El := Get_Chain (El);
end loop;
diff --git a/src/vhdl/translate/trans-chap12.adb b/src/vhdl/translate/trans-chap12.adb
index 28883babb..4d25fd77e 100644
--- a/src/vhdl/translate/trans-chap12.adb
+++ b/src/vhdl/translate/trans-chap12.adb
@@ -711,7 +711,9 @@ package body Trans.Chap12 is
Lib_Unit := Get_Library_Unit (Unit);
case Get_Kind (Lib_Unit) is
when Iir_Kind_Package_Declaration =>
- if not Get_Elab_Flag (Unit) then
+ if not Get_Elab_Flag (Unit)
+ and then Get_Package_Origin (Lib_Unit) = Null_Iir
+ then
Chap2.Elab_Package_Body (Lib_Unit, Null_Iir);
end if;
when Iir_Kind_Entity_Declaration =>
diff --git a/src/vhdl/translate/translation.adb b/src/vhdl/translate/translation.adb
index 1a4703f95..bc69661bb 100644
--- a/src/vhdl/translate/translation.adb
+++ b/src/vhdl/translate/translation.adb
@@ -289,6 +289,12 @@ package body Translation is
New_Debug_Comment_Decl
("package declaration " & Image_Identifier (Lib_Unit));
Chap2.Translate_Package_Declaration (Lib_Unit);
+ if Get_Package_Origin (Lib_Unit) /= Null_Iir
+ and then Get_Package_Body (Lib_Unit) /= Null_Iir
+ then
+ -- Corresponding body for package instantiation.
+ Chap2.Translate_Package_Body (Get_Package_Body (Lib_Unit));
+ end if;
when Iir_Kind_Package_Body =>
New_Debug_Comment_Decl
("package body " & Image_Identifier (Lib_Unit));