OSDN Git Service

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