PR c++/3637
[official-gcc.git] / gcc / ada / s-mastop.ads
blobef0282bf524ef40363caf033dd049e92f9ec1b3f
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- SYSTEM.MACHINE_STATE_OPERATIONS --
6 -- --
7 -- S p e c --
8 -- --
9 -- $Revision: 1.4 $
10 -- --
11 -- Copyright (C) 1999-2001 Ada Core Technologies, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 -- --
34 ------------------------------------------------------------------------------
36 pragma Polling (Off);
37 -- We must turn polling off for this unit, because otherwise we get
38 -- elaboration circularities with System.Exception_Tables.
40 with System.Storage_Elements;
41 with System.Exceptions;
43 package System.Machine_State_Operations is
45 subtype Code_Loc is System.Address;
46 -- Code location used in building exception tables and for call
47 -- addresses when propagating an exception (also traceback table)
48 -- Values of this type are created by using Label'Address or
49 -- extracted from machine states using Get_Code_Loc.
51 type Machine_State is new System.Address;
52 -- The table based exception handling approach (see a-except.adb) isolates
53 -- the target dependent aspects using an abstract data type interface
54 -- to the type Machine_State, which is represented as a System.Address
55 -- value (presumably implemented as a pointer to an appropriate record
56 -- structure).
58 function Machine_State_Length return System.Storage_Elements.Storage_Offset;
59 -- Function to determine the length of the Storage_Array needed to hold
60 -- a machine state. The machine state will always be maximally aligned.
61 -- The value returned is a constant that will be used to allocate space
62 -- for a machine state value.
64 function Allocate_Machine_State return Machine_State;
65 -- Allocate the required space for a Machine_State
67 procedure Free_Machine_State (M : in out Machine_State);
68 -- Free the dynamic memory taken by Machine_State
70 -- The initial value of type Machine_State is created by the low level
71 -- routine that actually raises an exception using the special builtin
72 -- _builtin_machine_state. This value will typically encode the value
73 -- of the program counter, and relevant registers. The following
74 -- operations are defined on Machine_State values:
76 function Get_Code_Loc (M : Machine_State) return Code_Loc;
77 -- This function extracts the program counter value from a machine
78 -- state, which the caller uses for searching the exception tables,
79 -- and also for recording entries in the traceback table. The call
80 -- returns a value of Null_Loc if the machine state represents the
81 -- outer level, or some other frame for which no information can be
82 -- provided.
84 procedure Pop_Frame
85 (M : Machine_State;
86 Info : System.Exceptions.Subprogram_Info_Type);
87 -- This procedure pops the machine state M so that it represents the
88 -- call point, as though the current subprogram had returned. It
89 -- changes only the value referenced by M, and does not affect
90 -- the current stack environment.
92 -- The Info parameter represents information generated by the backend
93 -- (see description of Subprogram_Info node in sinfo.ads). This
94 -- information is stored as static data during compilation. The
95 -- caller then passes this information to Pop_Frame, which will
96 -- use it to determine what must be changed in the machine state
97 -- (e.g. which save-over-call registers must be restored, and from
98 -- where on the stack frame they must be restored).
100 -- A value of No_Info for Info means either that the backend provided
101 -- no information for current frame, or that the current frame is an
102 -- other language frame for which no information exists, or that this
103 -- is an outer level subprogram. In any case, Pop_Frame sets the code
104 -- location to Null_Address when it pops past such a frame, and this
105 -- is taken as an indication that the exception is unhandled.
107 -- Note: at the current time, Info, if present is always a copy of
108 -- the entry point of the procedure, as found by searching the
109 -- subprogram table. For the case where a procedure is indeed in
110 -- the table (either it is an Ada procedure, or a foreign procedure
111 -- which is registered using pragma Propagate_Exceptions), then the
112 -- entry point information will indeed be correct. It may well be
113 -- possible for Pop_Frame to avoid using the Info parameter (for
114 -- example if it consults auxiliary Dwarf tables to do its job).
115 -- This is desirable if it can be done, because it means that it
116 -- will work fine to propagate exceptions through unregistered
117 -- foreign procedures. What will happen is that the search in the
118 -- Ada subprogram table will find a junk entry. Even if this junk
119 -- entry has an exception table, none of them will apply to the
120 -- current location, so they will be ignored, and then Pop_Frame
121 -- will be called to pop the frame. The Info parameter for this
122 -- call will be junk, but if it is not used that does not matter.
123 -- Note that the address recorded in the traceback table is of
124 -- the exception location, so the traceback will be correct even
125 -- in this case.
127 procedure Enter_Handler
128 (M : Machine_State;
129 Handler : System.Exceptions.Handler_Loc);
130 -- When Propagate_Handler locates an applicable exception handler, it
131 -- calls Enter_Handler, passing it two parameters. The first is the
132 -- machine state that corresponds to what is required for entry to
133 -- the handler, as computed by repeated Pop_Frame calls to reach the
134 -- handler to be entered. The second is the code location for the
135 -- handler itself which is the address of the label at the start of
136 -- the handler code.
138 -- Note: The machine state M is likely stored on the part of the
139 -- stack that will be popped by the call, so care must be taken
140 -- not to pop the stack until the Machine_State is entirely read.
141 -- The value passed as Handler was obtained from elaboration of
142 -- an N_Handler_Loc node by the backend.
144 function Fetch_Code (Loc : Code_Loc) return Code_Loc;
145 -- Some architectures (notably VMS) use a descriptor to describe
146 -- a subprogram address. This function computes the actual starting
147 -- address of the code from Loc.
148 -- Do not add pragma Inline, see 9116-002.
149 -- ??? This function will go away when 'Code_Address is fixed on VMS.
151 procedure Set_Machine_State (M : Machine_State);
152 -- This routine sets M from the current machine state. It is called
153 -- when an exception is initially signalled to initialize the state.
155 procedure Set_Signal_Machine_State
156 (M : Machine_State;
157 Context : System.Address);
158 -- This routine sets M from the machine state that corresponds to the
159 -- point in the code where a signal was raised. The parameter Context
160 -- is a pointer to a structure created by the operating system when a
161 -- signal is raised, and made available to the signal handler. The
162 -- format of this context block, and the manner in which it is made
163 -- available to the handler, are implementation dependent.
165 end System.Machine_State_Operations;