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