1/* EH stuff
2   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6This program is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
19
20
21/* This file contains the structures required for the language
22   independant exception handling model. Both the static compiler and
23   the runtime library share this file. */
24
25/* The runtime flag flag_new_exceptions is used to determine whether the
26   compiler supports the new runtime typechecking mechanism or not. Under
27   the new model, runtime info is contained in the exception table, and
28   the __throw() library routine determines which handler to call based
29   on the results of a call to a matching function provided by the expcetion
30   thrower.  Otherwise the old scheme of calling any handler which matches
31   an exception range is used, and the handler is responsible for all
32   checking of runtime conditions. If the handler wasn't suppose to
33   get the exception, it performs a re-throw. */
34
35
36/* The handler_label field MUST be the first field in this structure. The
37   __throw()  library routine expects uses __eh_stub() from except.c, which
38   simply dereferences the context pointer to get the handler.
39   The routine get_dynamic_handler_chain() also has a dependancy on
40   the location of 'dynamic_handler_chain'. If its location is changed,
41   that routine must be modified as well. */
42
43struct eh_context
44{
45  void *handler_label;
46  void **dynamic_handler_chain;
47  /* This is language dependent part of the eh context. */
48  void *info;
49  /* This is used to remember where we threw for re-throws */
50  void *table_index;  /* address of exception table entry to rethrow from */
51};
52
53#ifndef EH_TABLE_LOOKUP
54
55typedef struct old_exception_table
56{
57  void *start_region;
58  void *end_region;
59  void *exception_handler;
60} old_exception_table;
61
62typedef struct exception_table
63{
64  void *start_region;
65  void *end_region;
66  void *exception_handler;
67  void *match_info;              /* runtime type info */
68} exception_table;
69
70
71/* The language identifying portion of an exception table */
72
73typedef struct exception_lang_info
74{
75  short language;
76  short version;
77} exception_lang_info;
78
79/* This value in the first field of the exception descriptor
80   identifies the descriptor as the new model format. This value would never
81   be present in this location under the old model */
82
83#define NEW_EH_RUNTIME  ((void *) -2)
84
85/* Each function has an exception_descriptor which contains the
86   language info, and a table of exception ranges and handlers */
87
88typedef struct exception_descriptor
89{
90  void *runtime_id_field;
91  exception_lang_info lang;
92  exception_table table[1];
93} exception_descriptor;
94
95
96/* A pointer to a matching function is initialized at runtime by the
97   specific language if run-time exceptions are supported.
98   The function takes 3 parameters
99    1 - runtime exception that has been thrown info. (__eh_info *)
100    2 - Match info pointer from the region being considered (void *)
101    3 - exception table region is in (exception descriptor *)
102*/
103
104typedef void * (*__eh_matcher)          PROTO ((void *, void *, void *));
105
106/* This value is to be checked as a 'match all' case in the runtime field. */
107
108#define CATCH_ALL_TYPE   ((void *) -1)
109
110/* This is the runtime exception information. This forms the minimum required
111   information for an exception info pointer in an eh_context structure. */
112
113
114typedef struct __eh_info
115{
116  __eh_matcher match_function;
117  short language;
118  short version;
119} __eh_info;
120
121/* Convienient language codes for ID the originating language. Similar
122   to the codes in dwarf2.h. */
123
124enum exception_source_language
125  {
126    EH_LANG_C89 = 0x0001,
127    EH_LANG_C = 0x0002,
128    EH_LANG_Ada83 = 0x0003,
129    EH_LANG_C_plus_plus = 0x0004,
130    EH_LANG_Cobol74 = 0x0005,
131    EH_LANG_Cobol85 = 0x0006,
132    EH_LANG_Fortran77 = 0x0007,
133    EH_LANG_Fortran90 = 0x0008,
134    EH_LANG_Pascal83 = 0x0009,
135    EH_LANG_Modula2 = 0x000a,
136    EH_LANG_Java = 0x000b,
137    EH_LANG_Mips_Assembler = 0x8001
138  };
139
140#endif  /* EH_TABLE_LOOKUP */
141
142
143