1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This module handles two kinds of inlining activity:
29 -- a) Instantiation of generic bodies. This is done unconditionally, after
30 -- analysis and expansion of the main unit.
32 -- b) Compilation of unit bodies that contain the bodies of inlined sub-
33 -- programs. This is done only if inlining is enabled (-gnatn). Full inlining
34 -- requires that a) an b) be mutually recursive, because each step may
35 -- generate another generic expansion and further inlined calls. For now each
36 -- of them uses a workpile algorithm, but they are called independently from
37 -- Frontend, and thus are not mutually recursive.
41 with Types
; use Types
;
45 --------------------------------
46 -- Generic Body Instantiation --
47 --------------------------------
49 -- The bodies of generic instantiations are built after semantic analysis
50 -- of the main unit is complete. Generic instantiations are saved in a
51 -- global data structure, and the bodies constructed by means of a separate
52 -- analysis and expansion step.
54 -- See full description in body of Sem_Ch12 for details
56 type Pending_Body_Info
is record
58 -- Node for instantiation that requires the body
61 -- Declaration for package or subprogram spec for instantiation
63 Expander_Status
: Boolean;
64 -- If the body is instantiated only for semantic checking, expansion
67 Current_Sem_Unit
: Unit_Number_Type
;
68 -- The semantic unit within which the instantiation is found. Must
69 -- be restored when compiling the body, to insure that internal enti-
70 -- ties use the same counter and are unique over spec and body.
73 package Pending_Instantiations
is new Table
.Table
(
74 Table_Component_Type
=> Pending_Body_Info
,
75 Table_Index_Type
=> Int
,
77 Table_Initial
=> Alloc
.Pending_Instantiations_Initial
,
78 Table_Increment
=> Alloc
.Pending_Instantiations_Increment
,
79 Table_Name
=> "Pending_Instantiations");
81 -- The following table records subprograms and packages for which
82 -- generation of subprogram descriptors must be delayed.
84 package Pending_Descriptor
is new Table
.Table
(
85 Table_Component_Type
=> Entity_Id
,
86 Table_Index_Type
=> Int
,
88 Table_Initial
=> Alloc
.Pending_Instantiations_Initial
,
89 Table_Increment
=> Alloc
.Pending_Instantiations_Increment
,
90 Table_Name
=> "Pending_Descriptor");
92 Analyzing_Inlined_Bodies
: Boolean;
93 -- This flag is set False by the call to Initialize, and then is set
94 -- True by the call to Analyze_Inlined_Bodies. It is used to suppress
95 -- generation of subprogram descriptors for inlined bodies.
101 procedure Initialize
;
102 -- Initialize internal tables
105 -- Lock internal tables before calling backend
107 procedure Instantiate_Bodies
;
108 -- This procedure is called after semantic analysis is complete, to
109 -- instantiate the bodies of generic instantiations that appear in the
112 procedure Add_Inlined_Body
(E
: Entity_Id
);
113 -- E is an inlined subprogram appearing in a call, either explicitly, or
114 -- a discriminant check for which gigi builds a call. Add E's enclosing
115 -- unit to Inlined_Bodies so that body of E can be subsequently retrieved
118 procedure Analyze_Inlined_Bodies
;
119 -- At end of compilation, analyze the bodies of all units that contain
120 -- inlined subprograms that are actually called.
122 procedure Check_Body_For_Inlining
(N
: Node_Id
; P
: Entity_Id
);
123 -- If front-end inlining is enabled and a package declaration contains
124 -- inlined subprograms, load and compile the package body to collect the
125 -- bodies of these subprograms, so they are available to inline calls.
126 -- N is the compilation unit for the package.
128 procedure Remove_Dead_Instance
(N
: Node_Id
);
129 -- If an instantiation appears in unreachable code, delete the pending