aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2016-09-06 05:42:42 +0200
committerTristan Gingold <tgingold@free.fr>2016-09-12 06:34:44 +0200
commitae0c2b7a53851af64a2a25460c91f8f2fb0d10f9 (patch)
tree9ff8f3ffc78b5fbb65c4137f9be19d3531a85bec
parent5b3d16293f2f8a67d371eb870d48146a83510e0a (diff)
downloadghdl-ae0c2b7a53851af64a2a25460c91f8f2fb0d10f9.tar.gz
ghdl-ae0c2b7a53851af64a2a25460c91f8f2fb0d10f9.tar.bz2
ghdl-ae0c2b7a53851af64a2a25460c91f8f2fb0d10f9.zip
vhdl08: strengthten nested packages.
-rw-r--r--NEWS1
-rw-r--r--src/vhdl/sem_scopes.adb3
-rw-r--r--src/vhdl/translate/trans-chap2.adb52
-rw-r--r--src/vhdl/translate/trans-chap4.adb5
-rw-r--r--src/vhdl/translate/trans-rtis.adb9
5 files changed, 57 insertions, 13 deletions
diff --git a/NEWS b/NEWS
index 219bbac7d..2a0e6d92b 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ New in 0.34 (XXXX-XX-XX)
* Docs available on rtd: https://ghdl.readthedocs.org/en/latest/
* Speed improved.
* New option --psl-report, to report status of psl assert and cover.
+* vhdl 2008: support nested packages
New in 0.33 (2015-10-04)
* Improve support of vhdl 2008
diff --git a/src/vhdl/sem_scopes.adb b/src/vhdl/sem_scopes.adb
index 422bd9ba4..8831d0538 100644
--- a/src/vhdl/sem_scopes.adb
+++ b/src/vhdl/sem_scopes.adb
@@ -1043,6 +1043,9 @@ package body Sem_Scopes is
| Iir_Kind_Function_Body =>
null;
+ when Iir_Kind_Package_Body =>
+ null;
+
when Iir_Kind_Attribute_Specification
| Iir_Kind_Configuration_Specification
| Iir_Kind_Disconnection_Specification =>
diff --git a/src/vhdl/translate/trans-chap2.adb b/src/vhdl/translate/trans-chap2.adb
index 1273760fa..351157aba 100644
--- a/src/vhdl/translate/trans-chap2.adb
+++ b/src/vhdl/translate/trans-chap2.adb
@@ -388,6 +388,11 @@ package body Trans.Chap2 is
| Iir_Kind_Interface_Type_Definition =>
null;
end case;
+ when Iir_Kind_Package_Declaration
+ | Iir_Kind_Package_Body =>
+ if Has_Nested_Subprograms (Decl) then
+ return True;
+ end if;
when others =>
null;
end case;
@@ -801,7 +806,11 @@ package body Trans.Chap2 is
end if;
-- Translate subprograms declarations.
- Chap4.Translate_Declaration_Chain_Subprograms (Decl);
+ if not Is_Nested then
+ -- For nested package, this will be translated when translating
+ -- subprograms.
+ Chap4.Translate_Declaration_Chain_Subprograms (Decl);
+ end if;
-- Declare elaborator for the body.
if not Is_Nested then
@@ -860,7 +869,6 @@ package body Trans.Chap2 is
if Is_Nested then
Pop_Identifier_Prefix (Mark);
end if;
-
end Translate_Package_Declaration;
procedure Translate_Package_Body (Bod : Iir_Package_Body)
@@ -868,9 +876,14 @@ package body Trans.Chap2 is
Is_Nested : constant Boolean := Is_Nested_Package (Bod);
Spec : constant Iir_Package_Declaration := Get_Package (Bod);
Info : constant Ortho_Info_Acc := Get_Info (Spec);
- Prev_Subprg_Instance : Subprgs.Subprg_Instance_Stack;
Prev_Storage : constant O_Storage := Global_Storage;
+ Prev_Subprg_Instance : Subprgs.Subprg_Instance_Stack;
+ Mark : Id_Mark_Type;
begin
+ if Is_Nested then
+ Push_Identifier_Prefix (Mark, Get_Identifier (Spec));
+ end if;
+
-- Translate declarations.
if Is_Uninstantiated_Package (Spec) then
Push_Package_Instance_Factory (Spec);
@@ -879,16 +892,17 @@ package body Trans.Chap2 is
Chap4.Translate_Declaration_Chain (Bod);
Pop_Package_Instance_Factory (Spec);
+ end if;
- if Global_Storage = O_Storage_External then
- return;
- end if;
- else
- -- May be called during elaboration to generate RTI.
- if Global_Storage = O_Storage_External then
- return;
+ -- May be called during elaboration to generate RTI.
+ if Global_Storage = O_Storage_External then
+ if Is_Nested then
+ Pop_Identifier_Prefix (Mark);
end if;
+ return;
+ end if;
+ if not Is_Uninstantiated_Package (Spec) then
Restore_Local_Identifier (Info.Package_Local_Id);
Chap4.Translate_Declaration_Chain (Bod);
@@ -896,7 +910,9 @@ package body Trans.Chap2 is
Global_Storage := O_Storage_Private;
- if Flag_Rti then
+ -- Generate RTI, but not for nested packages (RTI will be generated as
+ -- a declaration by the parent).
+ if not Is_Nested and then Flag_Rti then
Rtis.Generate_Unit (Bod);
end if;
@@ -910,7 +926,11 @@ package body Trans.Chap2 is
Info.Package_Body_Scope'Access);
end if;
- Chap4.Translate_Declaration_Chain_Subprograms (Bod);
+ if not Is_Nested then
+ -- Translate subprograms. For nested package, this has to be called
+ -- when translating subprograms.
+ Chap4.Translate_Declaration_Chain_Subprograms (Bod);
+ end if;
if Is_Uninstantiated_Package (Spec) then
Clear_Scope (Info.Package_Spec_Scope);
@@ -922,6 +942,10 @@ package body Trans.Chap2 is
end if;
Global_Storage := Prev_Storage;
+
+ if Is_Nested then
+ Pop_Identifier_Prefix (Mark);
+ end if;
end Translate_Package_Body;
procedure Elab_Package (Spec : Iir_Package_Declaration)
@@ -1289,6 +1313,10 @@ package body Trans.Chap2 is
(Create_Var_Identifier (Inst),
Get_Scope_Type (Pkg_Info.Package_Body_Scope));
+ if Is_Nested_Package (Inst) then
+ return;
+ end if;
+
-- FIXME: this is correct only for global instantiation, and only if
-- there is only one.
Set_Scope_Via_Decl (Info.Package_Instance_Body_Scope,
diff --git a/src/vhdl/translate/trans-chap4.adb b/src/vhdl/translate/trans-chap4.adb
index 3e7f18b75..9634fbe57 100644
--- a/src/vhdl/translate/trans-chap4.adb
+++ b/src/vhdl/translate/trans-chap4.adb
@@ -1732,6 +1732,8 @@ package body Trans.Chap4 is
Chap2.Translate_Package_Declaration (Decl);
when Iir_Kind_Package_Body =>
Chap2.Translate_Package_Body (Decl);
+ when Iir_Kind_Package_Instantiation_Declaration =>
+ Chap2.Translate_Package_Instantiation_Declaration (Decl);
when Iir_Kind_Group_Template_Declaration =>
null;
@@ -2367,6 +2369,9 @@ package body Trans.Chap4 is
when Iir_Kind_Protected_Type_Body =>
Chap3.Translate_Protected_Type_Body (El);
Chap3.Translate_Protected_Type_Body_Subprograms (El);
+ when Iir_Kind_Package_Declaration
+ | Iir_Kind_Package_Body =>
+ Translate_Declaration_Chain_Subprograms (El);
when others =>
null;
end case;
diff --git a/src/vhdl/translate/trans-rtis.adb b/src/vhdl/translate/trans-rtis.adb
index 8c06460aa..35b2e8ce8 100644
--- a/src/vhdl/translate/trans-rtis.adb
+++ b/src/vhdl/translate/trans-rtis.adb
@@ -2088,7 +2088,7 @@ package body Trans.Rtis is
Add_Rti_Node (Info.Comp_Rti_Const);
end Generate_Component_Declaration;
- -- Generate RTIs only for types.
+ -- Generate RTIs only for types. This is needed for 'image/'value
procedure Generate_Declaration_Chain_Depleted (Chain : Iir)
is
Decl : Iir;
@@ -2148,6 +2148,9 @@ package body Trans.Rtis is
when Iir_Kind_Group_Template_Declaration
| Iir_Kind_Group_Declaration =>
null;
+ when Iir_Kind_Package_Declaration
+ | Iir_Kind_Package_Body =>
+ null;
when others =>
Error_Kind ("rti.generate_declaration_chain_depleted", Decl);
end case;
@@ -2310,6 +2313,10 @@ package body Trans.Rtis is
Pop_Identifier_Prefix (Mark);
end;
+ when Iir_Kind_Package_Instantiation_Declaration =>
+ -- FIXME: todo
+ null;
+
when others =>
Error_Kind ("rti.generate_declaration_chain", Decl);
end case;