1 /* Exception Handling interface routines.
2 Copyright (C) 1996 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. */
29 /* A stack of labels. CHAIN points to the next entry in the stack. */
36 struct label_node *chain;
39 /* An eh_entry is used to describe one exception handling region.
41 START_LABEL is the label corresponding to the start of the region.
43 END_LABEL is the label corresponding to the end of the region.
45 EXCEPTION_HANDLER_LABEL is the label corresponding to the handler
48 FINALIZATION is the tree codes for the handler, or is NULL_TREE if
49 one hasn't been generated yet, or is integer_zero_node to mark the
50 end of a group of try blocks. */
55 rtx exception_handler_label;
60 /* A list of EH_ENTRYs. ENTRY is the entry; CHAIN points to the next
61 entry in the list, or is NULL if this is the last entry. */
64 struct eh_entry *entry;
65 struct eh_node *chain;
68 /* A stack of EH_ENTRYs. TOP is the topmost entry on the stack. TOP is
69 NULL if the stack is empty. */
75 /* A queue of EH_ENTRYs. HEAD is the front of the queue; TAIL is the
76 end (the latest entry). HEAD and TAIL are NULL if the queue is
85 /* Start an exception handling region. All instructions emitted after
86 this point are considered to be part of the region until
87 expand_eh_region_end () is invoked. */
89 extern void expand_eh_region_start PROTO((void));
91 /* Start an exception handling region for the given cleanup action.
92 All instructions emitted after this point are considered to be part
93 of the region until expand_eh_region_end () is invoked. CLEANUP is
94 the cleanup action to perform. The return value is true if the
95 exception region was optimized away. If that case,
96 expand_eh_region_end does not need to be called for this cleanup,
99 This routine notices one particular common case in C++ code
100 generation, and optimizes it so as to not need the exception
103 extern int expand_eh_region_start_tree PROTO((tree));
105 /* End an exception handling region. The information about the region
106 is found on the top of ehstack.
108 HANDLER is either the cleanup for the exception region, or if we're
109 marking the end of a try block, HANDLER is integer_zero_node.
111 HANDLER will be transformed to rtl when expand_leftover_cleanups ()
114 extern void expand_eh_region_end PROTO((tree));
116 /* Push RLABEL or TLABEL onto LABELSTACK. Only one of RLABEL or TLABEL
117 should be set; the other must be NULL. */
119 extern void push_label_entry PROTO((struct label_node **labelstack, rtx rlabel, tree tlabel));
121 /* Pop the topmost entry from LABELSTACK and return its value as an
122 rtx node. If LABELSTACK is empty, return NULL. */
124 extern rtx pop_label_entry PROTO((struct label_node **labelstack));
126 /* Return the topmost entry of LABELSTACK as a tree node, or return
127 NULL_TREE if LABELSTACK is empty. */
129 extern tree top_label_entry PROTO((struct label_node **labelstack));
131 /* A set of insns for the catch clauses in the current function. They
132 will be emitted at the end of the current function. */
134 extern rtx catch_clauses;
140 /* Toplevel initialization for EH. */
142 extern void init_eh PROTO((void));
144 /* Initialization for the per-function EH data. */
146 extern void init_eh_for_function PROTO((void));
148 /* Saves the current per-function EH data into P. */
150 extern void save_eh_status PROTO((struct function *p));
152 /* Restores the per-function EH data from P. */
154 extern void restore_eh_status PROTO((struct function *p));
156 /* Adds an EH table entry for EH entry number N. Called from
157 final_scan_insn for NOTE_INSN_EH_REGION_BEG. */
159 extern void add_eh_table_entry PROTO((int n));
161 /* Returns a non-zero value if we need to output an exception table. */
163 extern int exception_table_p PROTO((void));
165 /* Outputs the exception table if we have one. */
167 extern void output_exception_table PROTO((void));
169 /* Given a return address in ADDR, determine the address we should use
170 to find the corresponding EH region. */
172 extern rtx eh_outer_context PROTO((rtx addr));
174 /* Called at the start of a block of try statements for which there is
175 a supplied catch handler. */
177 extern void expand_start_try_stmts PROTO((void));
179 /* Called at the start of a block of catch statements. It terminates the
180 previous set of try statements. */
182 extern void expand_start_all_catch PROTO((void));
184 /* Called at the end of a block of catch statements. */
186 extern void expand_end_all_catch PROTO((void));
189 /* Create a new exception region and add the handler for the region
190 onto a list. These regions will be ended (and their handlers
191 emitted) when end_protect_partials is invoked. */
193 extern void add_partial_entry PROTO((tree handler));
196 /* End all of the pending exception regions that have handlers added with
197 push_protect_entry (). */
199 extern void end_protect_partials PROTO((void));
201 /* An internal throw with a direct CONTEXT we want to throw
202 from. CONTEXT must be a label. */
204 extern void expand_internal_throw PROTO((rtx context));
206 /* Called from expand_exception_blocks and expand_end_catch_block to
207 expand and pending handlers. */
209 extern void expand_leftover_cleanups PROTO((void));
211 /* If necessary, emit insns for the start of per-function unwinder for
212 the current function. */
214 extern void emit_unwinder PROTO((void));
216 /* If necessary, emit insns for the end of the per-function unwinder
217 for the current function. */
219 extern void end_eh_unwinder PROTO((void));
221 /* Builds a list of handler labels and puts them in the global
222 variable exception_handler_labels. */
224 extern void find_exception_handler_labels PROTO((void));
226 /* Performs sanity checking on the check_exception_handler_labels
229 extern void check_exception_handler_labels PROTO((void));
231 /* A stack used to keep track of the label used to resume normal program
232 flow out of the current exception handler region. */
234 extern struct label_node *caught_return_label_stack;
236 /* A random area used for purposes elsewhere. */
238 extern struct label_node *false_label_stack;
240 /* A list of labels used for exception handlers. It is created by
241 find_exception_handler_labels for the optimization passes. */
243 extern rtx exception_handler_labels;
245 /* The rtx for the saved PC value. */
247 extern rtx eh_saved_pc_rtx;
249 /* Performs optimizations for exception handling, such as removing
250 unnecessary exception regions. Invoked from jump_optimize (). */
252 extern void exception_optimize PROTO((void));
254 /* Get the dynamic handler chain. */
255 extern rtx get_dynamic_handler_chain PROTO((void));
257 /* Get the dynamic cleanup chain. */
258 extern rtx get_dynamic_cleanup_chain PROTO((void));
260 /* Throw an exception. */
262 extern void emit_throw PROTO((void));
264 /* One to use setjmp/longjmp method of generating code. */
266 extern int exceptions_via_longjmp;
268 /* One to enable asynchronous exception support. */
270 extern int asynchronous_exceptions;
272 /* One to protect cleanup actions with a handler that calls
273 __terminate, zero otherwise. */
275 extern int protect_cleanup_actions_with_terminate;
278 extern tree protect_with_terminate PROTO((tree));