except.h (eh_status): Adjust documentation for x_protect_list.
[platform/upstream/gcc.git] / gcc / except.h
1 /* Exception Handling interface routines.
2    Copyright (C) 1996, 1997, 1998 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 #ifdef TREE_CODE
28
29 /* A stack of labels. CHAIN points to the next entry in the stack.  */
30
31 struct label_node {
32   union {
33     rtx rlabel;
34     tree tlabel;
35   } u;
36   struct label_node *chain;
37 };
38
39 /* An eh_entry is used to describe one exception handling region.
40
41    OUTER_CONTEXT is the label used for rethrowing into the outer context.
42
43    EXCEPTION_HANDLER_LABEL is the label corresponding to the handler
44    for this region.
45
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
50    FALSE_LABEL is used when either setjmp/longjmp exceptions are in
51    use, or old style table exceptions. It contains the label for 
52    branching to the next runtime type check as handlers are processed.
53
54    FINALIZATION is the tree codes for the handler, or is NULL_TREE if
55    one hasn't been generated yet, or is integer_zero_node to mark the
56    end of a group of try blocks.  */
57
58 struct eh_entry {
59   rtx outer_context;
60   rtx exception_handler_label;
61   tree finalization;
62   int label_used;
63   rtx false_label;
64   rtx rethrow_label;
65   /* If non-zero, this entry is for a handler created when we left an
66      exception-region via goto.  */
67   unsigned goto_entry_p : 1;
68 };
69 #else
70 struct label_node;
71 struct eh_entry;
72 #endif
73
74 /* A list of EH_ENTRYs. ENTRY is the entry; CHAIN points to the next
75    entry in the list, or is NULL if this is the last entry.  */
76
77 struct eh_node {
78   struct eh_entry *entry;
79   struct eh_node *chain;
80 };
81
82 /* A stack of EH_ENTRYs. TOP is the topmost entry on the stack. TOP is
83    NULL if the stack is empty.  */
84
85 struct eh_stack {
86   struct eh_node *top;
87 };
88
89 /* A queue of EH_ENTRYs. HEAD is the front of the queue; TAIL is the
90    end (the latest entry). HEAD and TAIL are NULL if the queue is
91    empty.  */
92
93 struct eh_queue {
94   struct eh_node *head;
95   struct eh_node *tail;
96 };
97
98 /* Used to save exception handling status for each function.  */
99 struct eh_status
100 {
101   /* A stack used for keeping track of the currently active exception
102      handling region.  As each exception region is started, an entry
103      describing the region is pushed onto this stack.  The current
104      region can be found by looking at the top of the stack, and as we
105      exit regions, the corresponding entries are popped. 
106
107      Entries cannot overlap; they can be nested. So there is only one
108      entry at most that corresponds to the current instruction, and that
109      is the entry on the top of the stack.  */
110   struct eh_stack x_ehstack;
111   /* This stack is used to represent what the current eh region is
112      for the catch blocks beings processed */
113   struct eh_stack x_catchstack;
114   /* A queue used for tracking which exception regions have closed.
115      As we exit a region, we enqueue a new entry. The entries are then
116      dequeued during expand_leftover_cleanups and
117      expand_start_all_catch.  */
118   struct eh_queue x_ehqueue;
119   /* Insns for all of the exception handlers for the current function.
120      They are currently emitted by the frontend code.  */
121   rtx x_catch_clauses;
122   /* A random data area for the front end's own use.  */
123   struct label_node *x_false_label_stack;
124   /* Keeps track of the label to resume to should one want to resume
125      normal control flow out of a handler (instead of, say, returning to
126      the caller of the current function or exiting the program).  */
127   struct label_node *x_caught_return_label_stack;
128   /* A stack (TREE_LIST) of lists of handlers.  The TREE_VALUE of each
129      node is itself a TREE_CHAINed list of handlers for regions that
130      are not yet closed. The TREE_VALUE of each entry contains the
131      handler for the corresponding entry on the ehstack.  */
132   union tree_node *x_protect_list;
133   /* The EH context.  Nonzero if the function has already
134      fetched a pointer to the EH context  for exception handling.  */
135   rtx ehc;
136   /* The label generated by expand_builtin_eh_return.  */
137   rtx x_eh_return_stub_label;
138 };
139
140 #define ehstack (current_function->eh->x_ehstack)
141 #define catchstack (current_function->eh->x_catchstack)
142 #define ehqueue (current_function->eh->x_ehqueue)
143 #define catch_clauses (current_function->eh->x_catch_clauses)
144 #define false_label_stack (current_function->eh->x_false_label_stack)
145 #define caught_return_label_stack (current_function->eh->x_caught_return_label_stack)
146 #define protect_list (current_function->eh->x_protect_list)
147 #define current_function_ehc (current_function->eh->ehc)
148 #define eh_return_stub_label (current_function->eh->x_eh_return_stub_label)
149
150 #ifdef TREE_CODE
151 /* Start an exception handling region.  All instructions emitted after
152    this point are considered to be part of the region until
153    expand_eh_region_end () is invoked.  */
154
155 extern void expand_eh_region_start              PROTO((void));
156
157 /* Just like expand_eh_region_start, except if a cleanup action is
158    entered on the cleanup chain, the TREE_PURPOSE of the element put
159    on the chain is DECL.  DECL should be the associated VAR_DECL, if
160    any, otherwise it should be NULL_TREE.  */
161
162 extern void expand_eh_region_start_for_decl     PROTO((tree));
163
164 /* Start an exception handling region for the given cleanup action.
165    All instructions emitted after this point are considered to be part
166    of the region until expand_eh_region_end () is invoked.  CLEANUP is
167    the cleanup action to perform.  The return value is true if the
168    exception region was optimized away.  If that case,
169    expand_eh_region_end does not need to be called for this cleanup,
170    nor should it be.
171
172    This routine notices one particular common case in C++ code
173    generation, and optimizes it so as to not need the exception
174    region.  */
175
176 extern int expand_eh_region_start_tree          PROTO((tree, tree));
177
178 /* End an exception handling region.  The information about the region
179    is found on the top of ehstack.
180
181    HANDLER is either the cleanup for the exception region, or if we're
182    marking the end of a try block, HANDLER is integer_zero_node.
183
184    HANDLER will be transformed to rtl when expand_leftover_cleanups ()
185    is invoked.  */
186
187 extern void expand_eh_region_end                PROTO((tree));
188
189 /* Push RLABEL or TLABEL onto LABELSTACK. Only one of RLABEL or TLABEL
190    should be set; the other must be NULL.  */
191
192 extern void push_label_entry                    PROTO((struct label_node **labelstack, rtx rlabel, tree tlabel));
193
194 /* Pop the topmost entry from LABELSTACK and return its value as an
195    rtx node. If LABELSTACK is empty, return NULL.  */
196
197 extern rtx pop_label_entry                      PROTO((struct label_node **labelstack));
198
199 /* Return the topmost entry of LABELSTACK as a tree node, or return
200    NULL_TREE if LABELSTACK is empty.  */
201
202 extern tree top_label_entry                     PROTO((struct label_node **labelstack));
203
204 #endif
205
206 /* Test: is exception handling turned on? */
207
208 extern int doing_eh                                    PROTO ((int));
209
210 /* Toplevel initialization for EH.  */
211
212 void set_exception_lang_code                    PROTO((int));
213 void set_exception_version_code                 PROTO((int));
214
215 /* A list of handlers asocciated with an exception region. HANDLER_LABEL
216    is the the label that control should be transfered to if the data
217    in TYPE_INFO matches an exception. a value of NULL_TREE for TYPE_INFO
218    means This is a cleanup, and must always be called. A value of
219    CATCH_ALL_TYPE works like a cleanup, but a call to the runtime matcher
220    is still performed to avoid being caught by a different language
221    exception. NEXT is a pointer to the next handler for this region. 
222    NULL means there are no more. */
223
224 typedef struct handler_info 
225 {
226   rtx handler_label;
227   int handler_number;
228   void *type_info;
229   struct handler_info *next;
230 } handler_info;
231
232
233 /* Add new handler information to an exception range. The  first parameter
234    specifies the range number (returned from new_eh_entry()). The second
235    parameter specifies the handler.  By default the handler is inserted at
236    the end of the list. A handler list may contain only ONE NULL_TREE
237    typeinfo entry. Regardless where it is positioned, a NULL_TREE entry
238    is always output as the LAST handler in the exception table for a region. */
239
240 void add_new_handler                       PROTO((int, struct handler_info *));
241
242 /* Remove a handler label. The handler label is being deleted, so all
243    regions which reference this handler should have it removed from their
244    list of possible handlers. Any region which has the final handler
245    removed can be deleted. */
246
247 void remove_handler                        PROTO((rtx));
248
249 /* Create a new handler structure initialized with the handler label and
250    typeinfo fields passed in. */
251
252 struct handler_info *get_new_handler            PROTO((rtx, void *));
253
254 /* Make a duplicate of an exception region by copying all the handlers
255    for an exception region. Return the new handler index. */
256
257 int duplicate_eh_handlers                       PROTO((int, int, rtx (*)(rtx)));
258
259 /* map symbol refs for rethrow */
260
261 rtx rethrow_symbol_map                          PROTO((rtx, rtx (*)(rtx)));
262
263 /* Is the rethrow label for a region used? */
264
265 int rethrow_used                                PROTO((int));
266
267 /* Update the rethrow references to reflect rethrows which have been
268    optimized away.  */
269
270 void update_rethrow_references                  PROTO((void));
271
272 /* Get a pointer to the first handler in an exception region's list. */
273
274 struct handler_info *get_first_handler          PROTO((int));
275
276 /* Find all the runtime handlers type matches currently referenced */
277
278 int find_all_handler_type_matches               PROTO((void ***));
279
280 /* The eh_nesting_info structure is used to find a list of valid handlers
281    for any arbitrary exception region.  When init_eh_nesting_info is called,
282    the information is all pre-calculated and entered in this structure.
283    REGION_INDEX is a vector over all possible region numbers.  Since the
284    number of regions is typically much smaller than the range of block
285    numbers, this is a sparse vector and the other data structures are 
286    represented as dense vectors.  Indexed with an exception region number, this
287    returns the index to use in the other data structures to retreive the
288    correct information.
289    HANDLERS is an array of vectors which point to handler_info structures.
290    when indexed, it gives the list of all possible handlers which can 
291    be reached by a throw from this exception region.
292    NUM_HANDLERS is the equivilent array indicating how many handler
293    pointers there are in the HANDLERS vector.
294    OUTER_INDEX indicates which index represents the information for the
295    outer block.  0 indicates there is no outer context.
296    REGION_COUNT is the number of regions.  */
297
298 typedef struct eh_nesting 
299 {
300   int *region_index;
301   handler_info ***handlers;
302   int *num_handlers;
303   int *outer_index;
304   int region_count;
305 } eh_nesting_info;
306
307 /* Initialize the eh_nesting_info structure.  */
308
309 eh_nesting_info *init_eh_nesting_info           PROTO((void));
310
311 /* Get a list of handlers reachable from a an exception region/insn.  */
312
313 int reachable_handlers                  PROTO((int, eh_nesting_info *, rtx, 
314                                                handler_info ***handlers));
315
316 /* Free the eh_nesting_info structure.  */
317
318 void free_eh_nesting_info                       PROTO((eh_nesting_info *));
319
320 extern void init_eh                             PROTO((void));
321
322 /* Initialization for the per-function EH data.  */
323
324 extern void init_eh_for_function                PROTO((void));
325
326 /* Generate an exception label. Use instead of gen_label_rtx */
327
328 extern rtx gen_exception_label                  PROTO((void));
329
330 /* Adds an EH table entry for EH entry number N. Called from
331    final_scan_insn for NOTE_INSN_EH_REGION_BEG.  */
332
333 extern void add_eh_table_entry                  PROTO((int n));
334
335 /* Start a catch clause, triggered by runtime value paramter. */
336
337 #ifdef TREE_CODE
338 extern void start_catch_handler                 PROTO((tree));
339 #endif
340
341 /* End an individual catch clause. */
342
343 extern void end_catch_handler                   PROTO((void));
344
345 /* Returns a non-zero value if we need to output an exception table.  */
346
347 extern int exception_table_p                    PROTO((void));
348
349 /* Outputs the exception table if we have one.  */
350
351 extern void output_exception_table              PROTO((void));
352
353 /* Given a return address in ADDR, determine the address we should use
354    to find the corresponding EH region.  */
355
356 extern rtx eh_outer_context                     PROTO((rtx addr));
357
358 /* Called at the start of a block of try statements for which there is
359    a supplied catch handler.  */
360
361 extern void expand_start_try_stmts              PROTO((void));
362
363 /* Called at the start of a block of catch statements. It terminates the
364    previous set of try statements.  */
365
366 extern void expand_start_all_catch              PROTO((void));
367
368 /* Called at the end of a block of catch statements.  */
369
370 extern void expand_end_all_catch                PROTO((void));
371
372 /* Begin a region that will contain entries created with
373    add_partial_entry.  */
374
375 extern void begin_protect_partials              PROTO((void));
376
377 #ifdef TREE_CODE
378 /* Create a new exception region and add the handler for the region
379    onto a list. These regions will be ended (and their handlers
380    emitted) when end_protect_partials is invoked.  */
381
382 extern void add_partial_entry                   PROTO((tree handler));
383 #endif
384
385 /* End all of the pending exception regions that have handlers added with
386    push_protect_entry ().  */
387
388 extern void end_protect_partials                PROTO((void));
389
390 /* An internal throw.  */
391
392 extern void expand_internal_throw               PROTO((void));
393
394 /* Called from expand_exception_blocks and expand_end_catch_block to
395    expand and pending handlers.  */
396
397 extern void expand_leftover_cleanups            PROTO((void));
398
399 /* If necessary, emit insns to get EH context for the current
400    function. */
401
402 extern void emit_eh_context                     PROTO((void));
403
404 /* Builds a list of handler labels and puts them in the global
405    variable exception_handler_labels.  */
406
407 extern void find_exception_handler_labels       PROTO((void));
408
409 /* Determine if an arbitrary label is an exception label */
410
411 extern int is_exception_handler_label           PROTO((int));
412
413 /* Performs sanity checking on the check_exception_handler_labels
414    list.  */
415
416 extern void check_exception_handler_labels      PROTO((void));
417
418 /* Keeps track of the label used as the context of a throw to rethrow an
419    exception to the outer exception region.  */
420
421 extern struct label_node *outer_context_label_stack;
422
423 /* A list of labels used for exception handlers. It is created by
424    find_exception_handler_labels for the optimization passes.  */
425
426 extern rtx exception_handler_labels;
427
428 /* Performs optimizations for exception handling, such as removing
429    unnecessary exception regions. Invoked from jump_optimize ().  */
430
431 extern void exception_optimize                  PROTO((void));
432
433 /* Return EH context (and set it up once per fn).  */
434 extern rtx get_eh_context                       PROTO((void));
435
436 /* Get the dynamic handler chain.  */
437 extern rtx get_dynamic_handler_chain            PROTO((void));
438
439 /* Get the dynamic cleanup chain.  */
440 extern rtx get_dynamic_cleanup_chain            PROTO((void));
441
442 /* Throw an exception.  */
443
444 extern void emit_throw                          PROTO((void));
445
446 /* One to use setjmp/longjmp method of generating code.  */
447
448 extern int exceptions_via_longjmp;
449
450 /* One to enable asynchronous exception support.  */
451
452 extern int asynchronous_exceptions;
453
454 /* One to protect cleanup actions with a handler that calls
455    __terminate, zero otherwise.  */
456
457 extern int protect_cleanup_actions_with_terminate;
458
459 #ifdef TREE_CODE
460 extern tree protect_with_terminate              PROTO((tree));
461 #endif
462
463 extern void expand_fixup_region_start   PROTO((void));
464 #ifdef TREE_CODE
465 extern void expand_fixup_region_end     PROTO((tree));
466 #endif
467
468 /* Various hooks for the DWARF 2 __throw routine.  */
469
470 void expand_builtin_unwind_init         PROTO((void));
471 rtx expand_builtin_dwarf_fp_regnum      PROTO((void));
472 #ifdef TREE_CODE
473 rtx expand_builtin_frob_return_addr     PROTO((tree));
474 rtx expand_builtin_extract_return_addr  PROTO((tree));
475 void expand_builtin_init_dwarf_reg_sizes        PROTO((tree));
476 void expand_builtin_eh_return           PROTO((tree, tree, tree));
477 #endif
478 void expand_eh_return                   PROTO((void));
479
480
481 /* Checking whether 2 instructions are within the same exception region. */
482
483 int in_same_eh_region                   PROTO((rtx, rtx));
484 void free_insn_eh_region                PROTO((void));
485 void init_insn_eh_region                PROTO((rtx, int));
486
487 #ifdef rtx
488 #undef rtx
489 #endif