1 /* Exception Handling interface routines.
2 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3 Contributed by Mike Stump <mrs@cygnus.com>.
5 This file is part of GNU CC.
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)
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.
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. */
22 #if !defined(NULL_RTX) && !defined(rtx)
23 typedef struct rtx_def *_except_rtx;
24 #define rtx _except_rtx
27 /* The labels generated by expand_builtin_eh_stub and
28 expand_builtin_eh_stub_old. */
30 extern rtx current_function_eh_stub_label;
31 extern rtx current_function_eh_old_stub_label;
35 /* A stack of labels. CHAIN points to the next entry in the stack. */
42 struct label_node *chain;
45 /* An eh_entry is used to describe one exception handling region.
47 OUTER_CONTEXT is the label used for rethrowing into the outer context.
49 EXCEPTION_HANDLER_LABEL is the label corresponding to the handler
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
56 FINALIZATION is the tree codes for the handler, or is NULL_TREE if
57 one hasn't been generated yet, or is integer_zero_node to mark the
58 end of a group of try blocks. */
62 rtx exception_handler_label;
67 /* A list of EH_ENTRYs. ENTRY is the entry; CHAIN points to the next
68 entry in the list, or is NULL if this is the last entry. */
71 struct eh_entry *entry;
72 struct eh_node *chain;
75 /* A stack of EH_ENTRYs. TOP is the topmost entry on the stack. TOP is
76 NULL if the stack is empty. */
82 /* A queue of EH_ENTRYs. HEAD is the front of the queue; TAIL is the
83 end (the latest entry). HEAD and TAIL are NULL if the queue is
91 /* Start an exception handling region. All instructions emitted after
92 this point are considered to be part of the region until
93 expand_eh_region_end () is invoked. */
95 extern void expand_eh_region_start PROTO((void));
97 /* Just like expand_eh_region_start, except if a cleanup action is
98 entered on the cleanup chain, the TREE_PURPOSE of the element put
99 on the chain is DECL. DECL should be the associated VAR_DECL, if
100 any, otherwise it should be NULL_TREE. */
102 extern void expand_eh_region_start_for_decl PROTO((tree));
104 /* Start an exception handling region for the given cleanup action.
105 All instructions emitted after this point are considered to be part
106 of the region until expand_eh_region_end () is invoked. CLEANUP is
107 the cleanup action to perform. The return value is true if the
108 exception region was optimized away. If that case,
109 expand_eh_region_end does not need to be called for this cleanup,
112 This routine notices one particular common case in C++ code
113 generation, and optimizes it so as to not need the exception
116 extern int expand_eh_region_start_tree PROTO((tree, tree));
118 /* End an exception handling region. The information about the region
119 is found on the top of ehstack.
121 HANDLER is either the cleanup for the exception region, or if we're
122 marking the end of a try block, HANDLER is integer_zero_node.
124 HANDLER will be transformed to rtl when expand_leftover_cleanups ()
127 extern void expand_eh_region_end PROTO((tree));
129 /* Push RLABEL or TLABEL onto LABELSTACK. Only one of RLABEL or TLABEL
130 should be set; the other must be NULL. */
132 extern void push_label_entry PROTO((struct label_node **labelstack, rtx rlabel, tree tlabel));
134 /* Pop the topmost entry from LABELSTACK and return its value as an
135 rtx node. If LABELSTACK is empty, return NULL. */
137 extern rtx pop_label_entry PROTO((struct label_node **labelstack));
139 /* Return the topmost entry of LABELSTACK as a tree node, or return
140 NULL_TREE if LABELSTACK is empty. */
142 extern tree top_label_entry PROTO((struct label_node **labelstack));
144 /* A set of insns for the catch clauses in the current function. They
145 will be emitted at the end of the current function. */
147 extern rtx catch_clauses;
151 /* Test: is exception handling turned on? */
153 extern int doing_eh PROTO ((int));
155 /* Toplevel initialization for EH. */
157 void set_exception_lang_code PROTO((int));
158 void set_exception_version_code PROTO((int));
160 /* A list of handlers asocciated with an exception region. HANDLER_LABEL
161 is the the label that control should be transfered to if the data
162 in TYPE_INFO matches an exception. a value of NULL_TREE for TYPE_INFO
163 means This is a cleanup, and must always be called. A value of
164 CATCH_ALL_TYPE works like a cleanup, but a call to the runtime matcher
165 is still performed to avoid being caught by a different language
166 exception. NEXT is a pointer to the next handler for this region.
167 NULL means there are no more. */
169 typedef struct handler_info
173 struct handler_info *next;
177 /* Add a new eh_entry for this function, The parameter specifies what
178 exception region number NOTE insns use to delimit this range.
179 The integer returned is uniquely identifies this exception range
180 within an internal table. */
182 int new_eh_region_entry PROTO((int));
184 /* Add new handler information to an exception range. The first parameter
185 specifies the range number (returned from new_eh_entry()). The second
186 parameter specifies the handler. By default the handler is inserted at
187 the end of the list. A handler list may contain only ONE NULL_TREE
188 typeinfo entry. Regardless where it is positioned, a NULL_TREE entry
189 is always output as the LAST handler in the exception table for a region. */
191 void add_new_handler PROTO((int, struct handler_info *));
193 /* Remove a handler label. The handler label is being deleted, so all
194 regions which reference this handler should have it removed from their
195 list of possible handlers. Any region which has the final handler
196 removed can be deleted. */
198 void remove_handler PROTO((rtx));
200 /* Create a new handler structure initialized with the handler label and
201 typeinfo fields passed in. */
203 struct handler_info *get_new_handler PROTO((rtx, void *));
205 /* Make a duplicate of an exception region by copying all the handlers
206 for an exception region. Return the new handler index. */
208 int duplicate_handlers PROTO((int, int));
211 /* Get a pointer to the first handler in an exception region's list. */
213 struct handler_info *get_first_handler PROTO((int));
215 /* Find all the runtime handlers type matches currently referenced */
217 int find_all_handler_type_matches PROTO((void ***));
219 extern void init_eh PROTO((void));
221 /* Initialization for the per-function EH data. */
223 extern void init_eh_for_function PROTO((void));
225 /* Generate an exception label. Use instead of gen_label_rtx */
227 extern rtx gen_exception_label PROTO((void));
229 /* Adds an EH table entry for EH entry number N. Called from
230 final_scan_insn for NOTE_INSN_EH_REGION_BEG. */
232 extern void add_eh_table_entry PROTO((int n));
234 /* Start a catch clause, triggered by runtime value paramter. */
237 extern void start_catch_handler PROTO((tree));
240 /* Returns a non-zero value if we need to output an exception table. */
242 extern int exception_table_p PROTO((void));
244 /* Outputs the exception table if we have one. */
246 extern void output_exception_table PROTO((void));
248 /* Given a return address in ADDR, determine the address we should use
249 to find the corresponding EH region. */
251 extern rtx eh_outer_context PROTO((rtx addr));
253 /* Called at the start of a block of try statements for which there is
254 a supplied catch handler. */
256 extern void expand_start_try_stmts PROTO((void));
258 /* Called at the start of a block of catch statements. It terminates the
259 previous set of try statements. */
261 extern void expand_start_all_catch PROTO((void));
263 /* Called at the end of a block of catch statements. */
265 extern void expand_end_all_catch PROTO((void));
268 /* Create a new exception region and add the handler for the region
269 onto a list. These regions will be ended (and their handlers
270 emitted) when end_protect_partials is invoked. */
272 extern void add_partial_entry PROTO((tree handler));
275 /* End all of the pending exception regions that have handlers added with
276 push_protect_entry (). */
278 extern void end_protect_partials PROTO((void));
280 /* An internal throw. */
282 extern void expand_internal_throw PROTO((void));
284 /* Called from expand_exception_blocks and expand_end_catch_block to
285 expand and pending handlers. */
287 extern void expand_leftover_cleanups PROTO((void));
289 /* If necessary, emit insns to get EH context for the current
292 extern void emit_eh_context PROTO((void));
294 /* Builds a list of handler labels and puts them in the global
295 variable exception_handler_labels. */
297 extern void find_exception_handler_labels PROTO((void));
299 /* Determine if an arbitrary label is an exception label */
301 extern int is_exception_handler_label PROTO((int));
303 /* Performs sanity checking on the check_exception_handler_labels
306 extern void check_exception_handler_labels PROTO((void));
308 /* A stack used to keep track of the label used to resume normal program
309 flow out of the current exception handler region. */
311 extern struct label_node *caught_return_label_stack;
313 /* Keeps track of the label used as the context of a throw to rethrow an
314 exception to the outer exception region. */
316 extern struct label_node *outer_context_label_stack;
318 /* A random area used for purposes elsewhere. */
320 extern struct label_node *false_label_stack;
322 /* A list of labels used for exception handlers. It is created by
323 find_exception_handler_labels for the optimization passes. */
325 extern rtx exception_handler_labels;
327 /* Performs optimizations for exception handling, such as removing
328 unnecessary exception regions. Invoked from jump_optimize (). */
330 extern void exception_optimize PROTO((void));
332 /* Return EH context (and set it up once per fn). */
333 extern rtx get_eh_context PROTO((void));
335 /* Get the dynamic handler chain. */
336 extern rtx get_dynamic_handler_chain PROTO((void));
338 /* Get the dynamic cleanup chain. */
339 extern rtx get_dynamic_cleanup_chain PROTO((void));
341 /* Throw an exception. */
343 extern void emit_throw PROTO((void));
345 /* One to use setjmp/longjmp method of generating code. */
347 extern int exceptions_via_longjmp;
349 /* One to enable asynchronous exception support. */
351 extern int asynchronous_exceptions;
353 /* One to protect cleanup actions with a handler that calls
354 __terminate, zero otherwise. */
356 extern int protect_cleanup_actions_with_terminate;
359 extern tree protect_with_terminate PROTO((tree));
362 extern void expand_fixup_region_start PROTO((void));
364 extern void expand_fixup_region_end PROTO((tree));
367 /* Various hooks for the DWARF 2 __throw routine. */
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 rtx expand_builtin_eh_stub_old PROTO((void));
374 rtx expand_builtin_frob_return_addr PROTO((tree));
375 rtx expand_builtin_extract_return_addr PROTO((tree));
376 void expand_builtin_set_return_addr_reg PROTO((tree));
377 void expand_builtin_set_eh_regs PROTO((tree, tree));
378 rtx expand_builtin_dwarf_reg_size PROTO((tree, rtx));
382 /* Checking whether 2 instructions are within the same exception region. */
384 int in_same_eh_region PROTO((rtx, rtx));
385 void free_insn_eh_region PROTO((void));
386 void init_insn_eh_region PROTO((rtx, int));