aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2023-04-12 06:31:41 +0200
committerTristan Gingold <tgingold@free.fr>2023-04-12 06:52:38 +0200
commit3495e979361d3464073a2cf4acf5a249943d5f23 (patch)
treeda02383f60d7fa82a3811019757c1348708fbdb7
parenta8051788b6596abb1e59f605fa0bc5a5b37c1b61 (diff)
downloadghdl-3495e979361d3464073a2cf4acf5a249943d5f23.tar.gz
ghdl-3495e979361d3464073a2cf4acf5a249943d5f23.tar.bz2
ghdl-3495e979361d3464073a2cf4acf5a249943d5f23.zip
translate: refactoring for package units
-rw-r--r--src/vhdl/translate/trans-chap2.adb149
-rw-r--r--src/vhdl/translate/trans-chap2.ads11
-rw-r--r--src/vhdl/translate/translation.adb6
3 files changed, 108 insertions, 58 deletions
diff --git a/src/vhdl/translate/trans-chap2.adb b/src/vhdl/translate/trans-chap2.adb
index ac49a96da..a7d008a8c 100644
--- a/src/vhdl/translate/trans-chap2.adb
+++ b/src/vhdl/translate/trans-chap2.adb
@@ -912,7 +912,18 @@ package body Trans.Chap2 is
Translate_Package (Decl, Get_Package_Header (Decl));
end Translate_Package_Declaration;
- procedure Translate_Package_Body (Bod : Iir_Package_Body)
+ procedure Translate_Package_Declaration_Unit
+ (Decl : Iir_Package_Declaration) is
+ begin
+ -- Skip uninstantiated package that have to be macro-expanded.
+ if Get_Macro_Expanded_Flag (Decl) then
+ return;
+ end if;
+
+ Translate_Package (Decl, Get_Package_Header (Decl));
+ end Translate_Package_Declaration_Unit;
+
+ procedure Translate_Package_Body_Internal (Bod : Iir_Package_Body)
is
Is_Nested : constant Boolean := Is_Nested_Package (Bod);
Spec : constant Iir_Package_Declaration := Get_Package (Bod);
@@ -1001,8 +1012,19 @@ package body Trans.Chap2 is
if Is_Nested then
Pop_Identifier_Prefix (Mark);
end if;
+ end Translate_Package_Body_Internal;
+
+ -- For a nested package body for nested package instantiation body.
+ procedure Translate_Package_Body (Bod : Iir_Package_Body) is
+ begin
+ Translate_Package_Body_Internal (Bod);
end Translate_Package_Body;
+ procedure Translate_Package_Body_Unit (Bod : Iir_Package_Body) is
+ begin
+ Translate_Package_Body (Bod);
+ end Translate_Package_Body_Unit;
+
-- Elaborate a package or a package instantiation.
procedure Elab_Package (Spec : Iir; Header : Iir)
is
@@ -1616,35 +1638,12 @@ package body Trans.Chap2 is
(Info.Package_Instance_Spec_Scope'Access);
end Instantiate_Info_Package;
- procedure Translate_Package_Instantiation_Declaration (Inst : Iir)
+ procedure Translate_Package_Instantiation_Declaration_Internal (Inst : Iir)
is
- Spec : constant Iir := Get_Uninstantiated_Package_Decl (Inst);
- Pkg_Info : constant Ortho_Info_Acc := Get_Info (Spec);
- Info : Ortho_Info_Acc;
- Interface_List : O_Inter_List;
+ Spec : constant Iir := Get_Uninstantiated_Package_Decl (Inst);
+ Pkg_Info : constant Ortho_Info_Acc := Get_Info (Spec);
+ Info : Ortho_Info_Acc;
begin
- if Get_Macro_Expanded_Flag (Spec) then
- -- Macro-expanded instantiations are translated like a package.
- Translate_Package (Inst, Inst);
-
- -- Generate code for the body.
- declare
- Bod : constant Iir := Get_Instance_Package_Body (Inst);
- begin
- if Get_Immediate_Body_Flag (Inst) then
- Translate_Package_Body (Bod);
- elsif not Get_Need_Body (Spec)
- and then not Is_Nested_Package (Inst)
- and then Global_Storage /= O_Storage_External
- then
- -- As an elaboration subprogram for the body is always
- -- needed, generate it.
- Elab_Package_Body (Inst, Null_Iir);
- end if;
- end;
- return;
- end if;
-
Info := Add_Info (Inst, Kind_Package_Instance);
-- Create the variable containing data for the package instance.
@@ -1661,36 +1660,83 @@ package body Trans.Chap2 is
Info.Package_Instance_Body_Scope'Access);
Instantiate_Info_Package (Inst);
+ end Translate_Package_Instantiation_Declaration_Internal;
- if Is_Nested_Package (Inst) or else not Flag_Elaboration then
- return;
+ procedure Translate_Package_Instantiation_Declaration_Macro (Inst : Iir)
+ is
+ Spec : constant Iir := Get_Uninstantiated_Package_Decl (Inst);
+ Bod : constant Iir := Get_Instance_Package_Body (Inst);
+ begin
+ -- Macro-expanded instantiations are translated like a package.
+ Translate_Package (Inst, Inst);
+
+ -- Generate code for the body.
+ if Get_Immediate_Body_Flag (Inst) then
+ Translate_Package_Body (Bod);
+ elsif not Get_Need_Body (Spec)
+ and then not Is_Nested_Package (Inst)
+ and then Global_Storage /= O_Storage_External
+ then
+ -- As an elaboration subprogram for the body is always
+ -- needed, generate it.
+ Elab_Package_Body (Inst, Null_Iir);
end if;
+ end Translate_Package_Instantiation_Declaration_Macro;
- -- Declare elaboration procedure
- Start_Procedure_Decl
- (Interface_List, Create_Identifier ("ELAB"), Global_Storage);
- -- Chap2.Add_Subprg_Instance_Interfaces
- -- (Interface_List, Info.Package_Instance_Elab_Instance);
- Finish_Subprogram_Decl
- (Interface_List, Info.Package_Instance_Elab_Subprg);
-
- if Global_Storage = O_Storage_External then
- return;
+ procedure Translate_Package_Instantiation_Declaration (Inst : Iir)
+ is
+ Spec : constant Iir := Get_Uninstantiated_Package_Decl (Inst);
+ begin
+ if Get_Macro_Expanded_Flag (Spec) then
+ Translate_Package_Instantiation_Declaration_Macro (Inst);
+ else
+ Translate_Package_Instantiation_Declaration_Internal (Inst);
end if;
+ end Translate_Package_Instantiation_Declaration;
+
+ procedure Translate_Package_Instantiation_Declaration_Unit (Inst : Iir)
+ is
+ Spec : constant Iir := Get_Uninstantiated_Package_Decl (Inst);
+ Interface_List : O_Inter_List;
+ Info : Ortho_Info_Acc;
+ begin
+ if Get_Macro_Expanded_Flag (Spec) then
+ Translate_Package_Instantiation_Declaration_Macro (Inst);
+ else
+ Translate_Package_Instantiation_Declaration_Internal (Inst);
- -- Elaborator:
- Start_Subprogram_Body (Info.Package_Instance_Elab_Subprg);
- -- Chap2.Start_Subprg_Instance_Use
- -- (Info.Package_Instance_Elab_Instance);
+ if not Flag_Elaboration then
+ return;
+ end if;
- Elab_Dependence (Get_Design_Unit (Inst));
+ Info := Get_Info (Inst);
- Elab_Package_Instantiation_Declaration (Inst);
+ -- Declare elaboration procedure
+ Start_Procedure_Decl
+ (Interface_List, Create_Identifier ("ELAB"), Global_Storage);
+ -- Chap2.Add_Subprg_Instance_Interfaces
+ -- (Interface_List, Info.Package_Instance_Elab_Instance);
+ Finish_Subprogram_Decl
+ (Interface_List, Info.Package_Instance_Elab_Subprg);
- -- Chap2.Finish_Subprg_Instance_Use
- -- (Info.Package_Instance_Elab_Instance);
- Finish_Subprogram_Body;
- end Translate_Package_Instantiation_Declaration;
+ if Global_Storage = O_Storage_External then
+ return;
+ end if;
+
+ -- Elaborator:
+ Start_Subprogram_Body (Info.Package_Instance_Elab_Subprg);
+ -- Chap2.Start_Subprg_Instance_Use
+ -- (Info.Package_Instance_Elab_Instance);
+
+ Elab_Dependence (Get_Design_Unit (Inst));
+
+ Elab_Package_Instantiation_Declaration (Inst);
+
+ -- Chap2.Finish_Subprg_Instance_Use
+ -- (Info.Package_Instance_Elab_Instance);
+ Finish_Subprogram_Body;
+ end if;
+ end Translate_Package_Instantiation_Declaration_Unit;
procedure Elab_Package_Instantiation_Declaration (Inst : Iir)
is
@@ -1702,12 +1748,11 @@ package body Trans.Chap2 is
-- Macro-expanded instances are handled like a regular package.
if Get_Macro_Expanded_Flag (Spec) then
declare
- Spec_Parent : constant Iir := Get_Parent (Spec);
Bod : constant Iir := Get_Package_Body (Spec);
begin
-- There are no routines generated to elaborate macro-expanded
-- packages, but dependencies still need to be elaborated.
- if Get_Kind (Spec_Parent) = Iir_Kind_Design_Unit then
+ if not Is_Nested_Package (Spec) then
Elab_Dependence (Get_Design_Unit (Spec));
if Bod /= Null_Iir then
Elab_Dependence (Get_Design_Unit (Bod));
diff --git a/src/vhdl/translate/trans-chap2.ads b/src/vhdl/translate/trans-chap2.ads
index a628b3133..0edd3201f 100644
--- a/src/vhdl/translate/trans-chap2.ads
+++ b/src/vhdl/translate/trans-chap2.ads
@@ -29,15 +29,20 @@ package Trans.Chap2 is
-- overload number if any.
procedure Push_Subprg_Identifier (Spec : Iir; Mark : out Id_Mark_Type);
+ -- Package declaration, body and instantiation when they are design units.
+ procedure Translate_Package_Declaration_Unit
+ (Decl : Iir_Package_Declaration);
+ procedure Translate_Package_Body_Unit (Bod : Iir_Package_Body);
+ procedure Translate_Package_Instantiation_Declaration_Unit (Inst : Iir);
+ procedure Elab_Package_Unit_Without_Body (Spec : Iir);
+
+ -- For nested packages.
procedure Translate_Package_Declaration (Decl : Iir_Package_Declaration);
procedure Translate_Package_Body (Bod : Iir_Package_Body);
procedure Translate_Package_Instantiation_Declaration (Inst : Iir);
-
procedure Elab_Package_Declaration (Spec : Iir);
procedure Elab_Package_Body (Spec : Iir_Package_Declaration; Bod : Iir);
-
procedure Elab_Package_Instantiation_Declaration (Inst : Iir);
- procedure Elab_Package_Unit_Without_Body (Spec : Iir);
-- Add info for an interface_package_declaration or a
-- package_instantiation_declaration
diff --git a/src/vhdl/translate/translation.adb b/src/vhdl/translate/translation.adb
index fcce29cdd..86a18e892 100644
--- a/src/vhdl/translate/translation.adb
+++ b/src/vhdl/translate/translation.adb
@@ -167,15 +167,15 @@ package body Translation is
when Iir_Kind_Package_Declaration =>
New_Debug_Comment_Decl
("package declaration " & Image_Identifier (Lib_Unit));
- Chap2.Translate_Package_Declaration (Lib_Unit);
+ Chap2.Translate_Package_Declaration_Unit (Lib_Unit);
when Iir_Kind_Package_Body =>
New_Debug_Comment_Decl
("package body " & Image_Identifier (Lib_Unit));
- Chap2.Translate_Package_Body (Lib_Unit);
+ Chap2.Translate_Package_Body_Unit (Lib_Unit);
when Iir_Kind_Package_Instantiation_Declaration =>
New_Debug_Comment_Decl
("package instantiation " & Image_Identifier (Lib_Unit));
- Chap2.Translate_Package_Instantiation_Declaration (Lib_Unit);
+ Chap2.Translate_Package_Instantiation_Declaration_Unit (Lib_Unit);
when Iir_Kind_Entity_Declaration =>
New_Debug_Comment_Decl ("entity " & Image_Identifier (Lib_Unit));
Chap1.Translate_Entity_Declaration (Lib_Unit);