]>
Commit | Line | Data |
---|---|---|
4956d07c | 1 | /* Exception Handling interface routines. |
e9a25f70 | 2 | Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
4956d07c MS |
3 | Contributed by Mike Stump <mrs@cygnus.com>. |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | ||
23 | #ifndef GET_CODE | |
24 | #define rtx int * | |
25 | #endif | |
26 | ||
27 | #ifdef TREE_CODE | |
28 | ||
911fdd58 RK |
29 | /* A stack of labels. CHAIN points to the next entry in the stack. */ |
30 | ||
4956d07c MS |
31 | struct label_node { |
32 | union { | |
33 | rtx rlabel; | |
34 | tree tlabel; | |
35 | } u; | |
36 | struct label_node *chain; | |
37 | }; | |
38 | ||
911fdd58 RK |
39 | /* An eh_entry is used to describe one exception handling region. |
40 | ||
478b0752 | 41 | OUTER_CONTEXT is the label used for rethrowing into the outer context. |
911fdd58 RK |
42 | |
43 | EXCEPTION_HANDLER_LABEL is the label corresponding to the handler | |
44 | for this region. | |
45 | ||
9a0d1e1b AM |
46 | LABEL_USED indicates whether a CATCH block has already used this |
47 | label or not. New ones are needed for additional catch blocks if | |
48 | it has. | |
49 | ||
911fdd58 RK |
50 | FINALIZATION is the tree codes for the handler, or is NULL_TREE if |
51 | one hasn't been generated yet, or is integer_zero_node to mark the | |
52 | end of a group of try blocks. */ | |
53 | ||
4956d07c | 54 | struct eh_entry { |
478b0752 | 55 | rtx outer_context; |
4956d07c | 56 | rtx exception_handler_label; |
4956d07c | 57 | tree finalization; |
9a0d1e1b | 58 | int label_used; |
4956d07c MS |
59 | }; |
60 | ||
911fdd58 RK |
61 | /* A list of EH_ENTRYs. ENTRY is the entry; CHAIN points to the next |
62 | entry in the list, or is NULL if this is the last entry. */ | |
63 | ||
4956d07c MS |
64 | struct eh_node { |
65 | struct eh_entry *entry; | |
66 | struct eh_node *chain; | |
67 | }; | |
68 | ||
911fdd58 RK |
69 | /* A stack of EH_ENTRYs. TOP is the topmost entry on the stack. TOP is |
70 | NULL if the stack is empty. */ | |
71 | ||
4956d07c MS |
72 | struct eh_stack { |
73 | struct eh_node *top; | |
74 | }; | |
75 | ||
911fdd58 RK |
76 | /* A queue of EH_ENTRYs. HEAD is the front of the queue; TAIL is the |
77 | end (the latest entry). HEAD and TAIL are NULL if the queue is | |
78 | empty. */ | |
79 | ||
4956d07c MS |
80 | struct eh_queue { |
81 | struct eh_node *head; | |
82 | struct eh_node *tail; | |
83 | }; | |
84 | ||
85 | ||
e976b8b2 MS |
86 | /* Start an exception handling region. All instructions emitted after |
87 | this point are considered to be part of the region until | |
88 | expand_eh_region_end () is invoked. */ | |
89 | ||
911fdd58 RK |
90 | extern void expand_eh_region_start PROTO((void)); |
91 | ||
4c581243 MS |
92 | /* Just like expand_eh_region_start, except if a cleanup action is |
93 | entered on the cleanup chain, the TREE_PURPOSE of the element put | |
94 | on the chain is DECL. DECL should be the associated VAR_DECL, if | |
95 | any, otherwise it should be NULL_TREE. */ | |
96 | ||
97 | extern void expand_eh_region_start_for_decl PROTO((tree)); | |
98 | ||
e976b8b2 MS |
99 | /* Start an exception handling region for the given cleanup action. |
100 | All instructions emitted after this point are considered to be part | |
101 | of the region until expand_eh_region_end () is invoked. CLEANUP is | |
102 | the cleanup action to perform. The return value is true if the | |
103 | exception region was optimized away. If that case, | |
104 | expand_eh_region_end does not need to be called for this cleanup, | |
105 | nor should it be. | |
106 | ||
107 | This routine notices one particular common case in C++ code | |
108 | generation, and optimizes it so as to not need the exception | |
109 | region. */ | |
110 | ||
4c581243 | 111 | extern int expand_eh_region_start_tree PROTO((tree, tree)); |
e976b8b2 MS |
112 | |
113 | /* End an exception handling region. The information about the region | |
114 | is found on the top of ehstack. | |
115 | ||
116 | HANDLER is either the cleanup for the exception region, or if we're | |
117 | marking the end of a try block, HANDLER is integer_zero_node. | |
118 | ||
119 | HANDLER will be transformed to rtl when expand_leftover_cleanups () | |
120 | is invoked. */ | |
121 | ||
911fdd58 RK |
122 | extern void expand_eh_region_end PROTO((tree)); |
123 | ||
124 | /* Push RLABEL or TLABEL onto LABELSTACK. Only one of RLABEL or TLABEL | |
125 | should be set; the other must be NULL. */ | |
126 | ||
4956d07c | 127 | extern void push_label_entry PROTO((struct label_node **labelstack, rtx rlabel, tree tlabel)); |
911fdd58 RK |
128 | |
129 | /* Pop the topmost entry from LABELSTACK and return its value as an | |
130 | rtx node. If LABELSTACK is empty, return NULL. */ | |
131 | ||
4956d07c | 132 | extern rtx pop_label_entry PROTO((struct label_node **labelstack)); |
911fdd58 RK |
133 | |
134 | /* Return the topmost entry of LABELSTACK as a tree node, or return | |
135 | NULL_TREE if LABELSTACK is empty. */ | |
136 | ||
4956d07c MS |
137 | extern tree top_label_entry PROTO((struct label_node **labelstack)); |
138 | ||
911fdd58 RK |
139 | /* A set of insns for the catch clauses in the current function. They |
140 | will be emitted at the end of the current function. */ | |
141 | ||
4956d07c | 142 | extern rtx catch_clauses; |
4956d07c MS |
143 | |
144 | #endif | |
145 | ||
d6f4ec51 KG |
146 | /* Test: is exception handling turned on? */ |
147 | ||
148 | extern int doing_eh PROTO ((int)); | |
149 | ||
911fdd58 RK |
150 | /* Toplevel initialization for EH. */ |
151 | ||
9a0d1e1b AM |
152 | #ifdef NEW_EH_MODEL |
153 | ||
154 | void set_exception_lang_code PROTO((short)); | |
155 | void set_exception_version_code PROTO((short)); | |
156 | ||
157 | #endif | |
158 | ||
159 | /* A list of handlers asocciated with an exception region. HANDLER_LABEL | |
160 | is the the label that control should be transfered to if the data | |
161 | in TYPE_INFO matches an exception. a value of NULL_TREE for TYPE_INFO | |
162 | means This is a cleanup, and must always be called. A value of | |
163 | CATCH_ALL_TYPE works like a cleanup, but a call to the runtime matcher | |
164 | is still performed to avoid being caught by a different language | |
165 | exception. NEXT is a pointer to the next handler for this region. | |
166 | NULL means there are no more. */ | |
167 | ||
168 | #define CATCH_ALL_TYPE (tree *) -1 | |
169 | ||
170 | typedef struct handler_info | |
171 | { | |
172 | rtx handler_label; | |
173 | void *type_info; | |
174 | struct handler_info *next; | |
175 | } handler_info; | |
176 | ||
177 | ||
178 | /* Add a new eh_entry for this function, The parameter specifies what | |
179 | exception region number NOTE insns use to delimit this range. | |
180 | The integer returned is uniquely identifies this exception range | |
181 | within an internal table. */ | |
182 | ||
183 | int new_eh_region_entry PROTO((int)); | |
184 | ||
185 | /* Add new handler information to an exception range. The first parameter | |
186 | specifies the range number (returned from new_eh_entry()). The second | |
187 | parameter specifies the handler. By default the handler is inserted at | |
188 | the end of the list. A handler list may contain only ONE NULL_TREE | |
189 | typeinfo entry. Regardless where it is positioned, a NULL_TREE entry | |
190 | is always output as the LAST handler in the exception table for a region. */ | |
191 | ||
192 | void add_new_handler PROTO((int, struct handler_info *)); | |
193 | ||
194 | /* Create a new handler structure initialized with the handler label and | |
195 | typeinfo fields passed in. */ | |
196 | ||
197 | struct handler_info *get_new_handler PROTO((rtx, void *)); | |
198 | ||
199 | /* Make a duplicate of an exception region by copying all the handlers | |
200 | for an exception region. Return the new handler index. */ | |
201 | ||
202 | int duplicate_handlers PROTO((int, int)); | |
203 | ||
204 | ||
205 | /* Get a pointer to the first handler in an exception region's list. */ | |
206 | ||
207 | struct handler_info *get_first_handler PROTO((int)); | |
208 | ||
209 | ||
4956d07c | 210 | extern void init_eh PROTO((void)); |
911fdd58 RK |
211 | |
212 | /* Initialization for the per-function EH data. */ | |
213 | ||
4956d07c | 214 | extern void init_eh_for_function PROTO((void)); |
911fdd58 | 215 | |
9a0d1e1b AM |
216 | /* Generate an exception label. Use instead of gen_label_rtx */ |
217 | ||
218 | extern rtx gen_exception_label PROTO((void)); | |
219 | ||
911fdd58 RK |
220 | /* Adds an EH table entry for EH entry number N. Called from |
221 | final_scan_insn for NOTE_INSN_EH_REGION_BEG. */ | |
222 | ||
223 | extern void add_eh_table_entry PROTO((int n)); | |
224 | ||
9a0d1e1b AM |
225 | /* Start a catch clause, triggered by runtime value paramter. */ |
226 | ||
227 | #ifdef TREE_CODE | |
228 | extern void expand_start_catch PROTO((tree)); | |
229 | #endif | |
230 | ||
231 | /* End a catch clause. */ | |
232 | ||
233 | extern void expand_end_catch PROTO((void)); | |
234 | ||
911fdd58 RK |
235 | /* Returns a non-zero value if we need to output an exception table. */ |
236 | ||
4956d07c | 237 | extern int exception_table_p PROTO((void)); |
911fdd58 RK |
238 | |
239 | /* Outputs the exception table if we have one. */ | |
240 | ||
4956d07c | 241 | extern void output_exception_table PROTO((void)); |
911fdd58 RK |
242 | |
243 | /* Given a return address in ADDR, determine the address we should use | |
244 | to find the corresponding EH region. */ | |
245 | ||
246 | extern rtx eh_outer_context PROTO((rtx addr)); | |
247 | ||
248 | /* Called at the start of a block of try statements for which there is | |
249 | a supplied catch handler. */ | |
250 | ||
251 | extern void expand_start_try_stmts PROTO((void)); | |
252 | ||
253 | /* Called at the start of a block of catch statements. It terminates the | |
254 | previous set of try statements. */ | |
255 | ||
256 | extern void expand_start_all_catch PROTO((void)); | |
257 | ||
258 | /* Called at the end of a block of catch statements. */ | |
259 | ||
260 | extern void expand_end_all_catch PROTO((void)); | |
261 | ||
262 | #ifdef TREE_CODE | |
263 | /* Create a new exception region and add the handler for the region | |
264 | onto a list. These regions will be ended (and their handlers | |
265 | emitted) when end_protect_partials is invoked. */ | |
266 | ||
267 | extern void add_partial_entry PROTO((tree handler)); | |
268 | #endif | |
269 | ||
270 | /* End all of the pending exception regions that have handlers added with | |
271 | push_protect_entry (). */ | |
272 | ||
273 | extern void end_protect_partials PROTO((void)); | |
274 | ||
e701eb4d | 275 | /* An internal throw. */ |
911fdd58 | 276 | |
e701eb4d | 277 | extern void expand_internal_throw PROTO((void)); |
911fdd58 RK |
278 | |
279 | /* Called from expand_exception_blocks and expand_end_catch_block to | |
280 | expand and pending handlers. */ | |
281 | ||
282 | extern void expand_leftover_cleanups PROTO((void)); | |
283 | ||
154bba13 TT |
284 | /* If necessary, emit insns to get EH context for the current |
285 | function. */ | |
286 | ||
287 | extern void emit_eh_context PROTO((void)); | |
288 | ||
911fdd58 RK |
289 | /* If necessary, emit insns for the start of per-function unwinder for |
290 | the current function. */ | |
291 | ||
4956d07c | 292 | extern void emit_unwinder PROTO((void)); |
911fdd58 RK |
293 | |
294 | /* If necessary, emit insns for the end of the per-function unwinder | |
295 | for the current function. */ | |
296 | ||
4956d07c | 297 | extern void end_eh_unwinder PROTO((void)); |
4956d07c | 298 | |
911fdd58 RK |
299 | /* Builds a list of handler labels and puts them in the global |
300 | variable exception_handler_labels. */ | |
301 | ||
302 | extern void find_exception_handler_labels PROTO((void)); | |
303 | ||
9a0d1e1b AM |
304 | /* Determine if an arbitrary label is an exception label */ |
305 | ||
306 | extern int is_exception_handler_label PROTO((int)); | |
307 | ||
911fdd58 RK |
308 | /* Performs sanity checking on the check_exception_handler_labels |
309 | list. */ | |
310 | ||
311 | extern void check_exception_handler_labels PROTO((void)); | |
312 | ||
313 | /* A stack used to keep track of the label used to resume normal program | |
314 | flow out of the current exception handler region. */ | |
4956d07c MS |
315 | |
316 | extern struct label_node *caught_return_label_stack; | |
911fdd58 | 317 | |
956d6950 JL |
318 | /* Keeps track of the label used as the context of a throw to rethrow an |
319 | exception to the outer exception region. */ | |
320 | ||
321 | extern struct label_node *outer_context_label_stack; | |
322 | ||
911fdd58 RK |
323 | /* A random area used for purposes elsewhere. */ |
324 | ||
4956d07c MS |
325 | extern struct label_node *false_label_stack; |
326 | ||
911fdd58 RK |
327 | /* A list of labels used for exception handlers. It is created by |
328 | find_exception_handler_labels for the optimization passes. */ | |
329 | ||
4956d07c MS |
330 | extern rtx exception_handler_labels; |
331 | ||
911fdd58 RK |
332 | /* Performs optimizations for exception handling, such as removing |
333 | unnecessary exception regions. Invoked from jump_optimize (). */ | |
334 | ||
4956d07c | 335 | extern void exception_optimize PROTO((void)); |
e976b8b2 | 336 | |
01eb7f9a | 337 | /* Return EH context (and set it up once per fn). */ |
154bba13 TT |
338 | extern rtx get_eh_context PROTO((void)); |
339 | ||
e976b8b2 MS |
340 | /* Get the dynamic handler chain. */ |
341 | extern rtx get_dynamic_handler_chain PROTO((void)); | |
342 | ||
343 | /* Get the dynamic cleanup chain. */ | |
344 | extern rtx get_dynamic_cleanup_chain PROTO((void)); | |
345 | ||
346 | /* Throw an exception. */ | |
347 | ||
348 | extern void emit_throw PROTO((void)); | |
349 | ||
350 | /* One to use setjmp/longjmp method of generating code. */ | |
351 | ||
352 | extern int exceptions_via_longjmp; | |
353 | ||
354 | /* One to enable asynchronous exception support. */ | |
355 | ||
356 | extern int asynchronous_exceptions; | |
357 | ||
358 | /* One to protect cleanup actions with a handler that calls | |
359 | __terminate, zero otherwise. */ | |
360 | ||
361 | extern int protect_cleanup_actions_with_terminate; | |
362 | ||
363 | #ifdef TREE_CODE | |
364 | extern tree protect_with_terminate PROTO((tree)); | |
365 | #endif | |
0021b564 JM |
366 | |
367 | /* Various hooks for the DWARF 2 __throw routine. */ | |
368 | ||
369 | void expand_builtin_unwind_init PROTO((void)); | |
370 | rtx expand_builtin_dwarf_fp_regnum PROTO((void)); | |
371 | rtx expand_builtin_eh_stub PROTO((void)); | |
372 | #ifdef TREE_CODE | |
373 | rtx expand_builtin_frob_return_addr PROTO((tree)); | |
374 | rtx expand_builtin_extract_return_addr PROTO((tree)); | |
375 | void expand_builtin_set_return_addr_reg PROTO((tree)); | |
376 | void expand_builtin_set_eh_regs PROTO((tree, tree)); | |
2f3ca9e7 | 377 | rtx expand_builtin_dwarf_reg_size PROTO((tree, rtx)); |
0021b564 | 378 | #endif |
5aa55043 AM |
379 | |
380 | ||
381 | /* Checking whether 2 instructions are within the same exception region. */ | |
382 | ||
383 | int in_same_eh_region PROTO((rtx, rtx)); | |
384 | void free_insn_eh_region PROTO((void)); | |
385 | void init_insn_eh_region PROTO((rtx, int)); |