]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/langhooks.h
* gcov-dump.c (dump_file): Fix missing address operator.
[thirdparty/gcc.git] / gcc / langhooks.h
CommitLineData
b0278d39 1/* The lang_hooks data structure.
3ad4992f 2 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
e8602e56 3
4642865b 4This file is part of GCC.
e8602e56 5
4642865b 6GCC is free software; you can redistribute it and/or modify
e8602e56 7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
4642865b 11GCC is distributed in the hope that it will be useful,
e8602e56 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
4642865b 17along with GCC; see the file COPYING. If not, write to
e8602e56 18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#ifndef GCC_LANG_HOOKS_H
22#define GCC_LANG_HOOKS_H
23
b467ecc1 24/* This file should be #include-d after tree.h. */
25
6c7ff025 26struct diagnostic_context;
27
b7fced5e 28/* A print hook for print_tree (). */
3ad4992f 29typedef void (*lang_print_tree_hook) (FILE *, tree, int indent);
b7fced5e 30
b0278d39 31/* The following hooks are documented in langhooks.c. Must not be
32 NULL. */
33
34struct lang_hooks_for_tree_inlining
35{
3ad4992f 36 union tree_node *(*walk_subtrees) (union tree_node **, int *,
37 union tree_node *(*)
38 (union tree_node **, int *, void *),
39 void *, void *);
40 int (*cannot_inline_tree_fn) (union tree_node **);
41 int (*disregard_inline_limits) (union tree_node *);
42 union tree_node *(*add_pending_fn_decls) (void *, union tree_node *);
43 int (*tree_chain_matters_p) (union tree_node *);
44 int (*auto_var_in_fn_p) (union tree_node *, union tree_node *);
45 union tree_node *(*copy_res_decl_for_inlining) (union tree_node *,
46 union tree_node *,
47 union tree_node *,
48 void *, int *, tree);
49 int (*anon_aggr_type_p) (union tree_node *);
50 bool (*var_mod_type_p) (union tree_node *);
51 int (*start_inlining) (union tree_node *);
52 void (*end_inlining) (union tree_node *);
53 union tree_node *(*convert_parm_for_inlining) (union tree_node *,
54 union tree_node *,
55 union tree_node *);
309c7c52 56 int (*estimate_num_insns) (union tree_node *);
b0278d39 57};
58
833eb724 59struct lang_hooks_for_callgraph
60{
61 /* Function passed as argument is needed and will be compiled.
62 Lower the representation so the calls are explicit. */
3ad4992f 63 void (*lower_function) (union tree_node *);
833eb724 64 /* Produce RTL for function passed as argument. */
3ad4992f 65 void (*expand_function) (union tree_node *);
833eb724 66};
67
c80c4f22 68/* Lang hooks for management of language-specific data or status
69 when entering / leaving functions etc. */
70struct lang_hooks_for_functions
71{
72 /* Called when entering a function. */
3ad4992f 73 void (*init) (struct function *);
c80c4f22 74
75 /* Called when leaving a function. */
3ad4992f 76 void (*final) (struct function *);
c80c4f22 77
78 /* Called when entering a nested function. */
3ad4992f 79 void (*enter_nested) (struct function *);
c80c4f22 80
81 /* Called when leaving a nested function. */
3ad4992f 82 void (*leave_nested) (struct function *);
c80c4f22 83};
84
3119c950 85/* The following hooks are used by tree-dump.c. */
86
87struct lang_hooks_for_tree_dump
88{
6ef828f9 89 /* Dump language-specific parts of tree nodes. Returns nonzero if it
3119c950 90 does not want the usual dumping of the second argument. */
3ad4992f 91 bool (*dump_tree) (void *, tree);
3119c950 92
93 /* Determine type qualifiers in a language-specific way. */
3ad4992f 94 int (*type_quals) (tree);
3119c950 95};
96
a1f71e15 97/* Hooks related to types. */
98
99struct lang_hooks_for_types
100{
771d21fa 101 /* Return a new type (with the indicated CODE), doing whatever
102 language-specific processing is required. */
3ad4992f 103 tree (*make_type) (enum tree_code);
8851e806 104
771d21fa 105 /* Given MODE and UNSIGNEDP, return a suitable type-tree with that
106 mode. */
3ad4992f 107 tree (*type_for_mode) (enum machine_mode, int);
771d21fa 108
109 /* Given PRECISION and UNSIGNEDP, return a suitable type-tree for an
110 integer type with at least that precision. */
3ad4992f 111 tree (*type_for_size) (unsigned, int);
4070745f 112
113 /* Given an integer type T, return a type like T but unsigned.
114 If T is unsigned, the value is T. */
3ad4992f 115 tree (*unsigned_type) (tree);
4070745f 116
117 /* Given an integer type T, return a type like T but signed.
118 If T is signed, the value is T. */
3ad4992f 119 tree (*signed_type) (tree);
4070745f 120
121 /* Return a type the same as TYPE except unsigned or signed
122 according to UNSIGNEDP. */
3ad4992f 123 tree (*signed_or_unsigned_type) (int, tree);
1dd25100 124
63c62881 125 /* Given a type, apply default promotions to unnamed function
126 arguments and return the new type. Return the same type if no
127 change. Required by any language that supports variadic
128 arguments. The default hook aborts. */
3ad4992f 129 tree (*type_promotes_to) (tree);
63c62881 130
1dd25100 131 /* This routine is called in tree.c to print an error message for
132 invalid use of an incomplete type. VALUE is the expression that
133 was used (or 0 if that isn't known) and TYPE is the type that was
134 invalid. */
3ad4992f 135 void (*incomplete_type_error) (tree value, tree type);
a1f71e15 136};
137
20325f61 138/* Language hooks related to decls and the symbol table. */
139
140struct lang_hooks_for_decls
141{
142 /* Enter a new lexical scope. Argument is always zero when called
143 from outside the front end. */
3ad4992f 144 void (*pushlevel) (int);
20325f61 145
146 /* Exit a lexical scope and return a BINDING for that scope.
147 Takes three arguments:
148 KEEP -- nonzero if there were declarations in this scope.
149 REVERSE -- reverse the order of decls before returning them.
150 FUNCTIONBODY -- nonzero if this level is the body of a function. */
3ad4992f 151 tree (*poplevel) (int, int, int);
20325f61 152
6ef828f9 153 /* Returns nonzero if we are in the global binding level. Ada
20325f61 154 returns -1 for an undocumented reason used in stor-layout.c. */
3ad4992f 155 int (*global_bindings_p) (void);
20325f61 156
157 /* Insert BLOCK at the end of the list of subblocks of the
158 current binding level. This is used when a BIND_EXPR is expanded,
159 to handle the BLOCK node inside the BIND_EXPR. */
3ad4992f 160 void (*insert_block) (tree);
20325f61 161
162 /* Set the BLOCK node for the current scope level. */
3ad4992f 163 void (*set_block) (tree);
20325f61 164
165 /* Function to add a decl to the current scope level. Takes one
166 argument, a decl to add. Returns that decl, or, if the same
167 symbol is already declared, may return a different decl for that
168 name. */
3ad4992f 169 tree (*pushdecl) (tree);
20325f61 170
171 /* Returns the chain of decls so far in the current scope level. */
3ad4992f 172 tree (*getdecls) (void);
8d58a5a7 173
174 /* Returns true when we should warn for an unused global DECL.
175 We will already have checked that it has static binding. */
3ad4992f 176 bool (*warn_unused_global) (tree);
28db4d96 177
178 /* Obtain a list of globals and do final output on them at end
179 of compilation */
3ad4992f 180 void (*final_write_globals) (void);
e2e9c55b 181
8efca15a 182 /* Do necessary preparations before assemble_variable can proceed. */
3ad4992f 183 void (*prepare_assemble_variable) (tree);
8efca15a 184
e2e9c55b 185 /* True if this decl may be called via a sibcall. */
3ad4992f 186 bool (*ok_for_sibcall) (tree);
20325f61 187};
188
b0278d39 189/* Language-specific hooks. See langhooks-def.h for defaults. */
190
191struct lang_hooks
192{
d19bd1f0 193 /* String identifying the front end. e.g. "GNU C++". */
194 const char *name;
195
196 /* sizeof (struct lang_identifier), so make_node () creates
197 identifier nodes long enough for the language-specific slots. */
198 size_t identifier_size;
199
295e387a 200 /* Determines the size of any language-specific 'x' or 'c' nodes.
201 Since it is called from make_node, the only information available
202 is the tree code. Expected to abort on unrecognized codes. */
3ad4992f 203 size_t (*tree_size) (enum tree_code);
295e387a 204
435fb09b 205 /* The first callback made to the front end, for simple
5457b645 206 initialization needed before any calls to handle_option. Return
207 the language mask to filter the switch array with. */
4838a8b6 208 unsigned int (*init_options) (unsigned int argc, const char **argv);
b0278d39 209
5457b645 210 /* Handle the switch CODE, which has real type enum opt_code from
211 options.h. If the switch takes an argument, it is passed in ARG
917bbcab 212 which points to permanent storage. The handler is responsible for
5457b645 213 checking whether ARG is NULL, which indicates that no argument
214 was in fact supplied. For -f and -W switches, VALUE is 1 or 0
215 for the positive and negative forms respectively.
216
217 Return 1 if the switch is valid, 0 if invalid, and -1 if it's
218 valid and should not be treated as language-independent too. */
219 int (*handle_option) (size_t code, const char *arg, int value);
220
76bf7746 221 /* Handle a filename on the command line. */
222 void (*handle_filename) (const char *filename);
223
224 /* Return false to use the default complaint about a missing
225 argument, otherwise output a complaint and return true. */
226 bool (*missing_argument) (const char *opt, size_t code);
227
03bde601 228 /* Called when all command line options have been parsed to allow
229 further processing and initialization
dd436eaf 230
03bde601 231 Should return true to indicate that a compiler back-end is
232 not required, such as with the -E option.
3ad4992f 233
6ef828f9 234 If errorcount is nonzero after this call the compiler exits
dd436eaf 235 immediately and the finish hook is not called. */
3ad4992f 236 bool (*post_options) (const char **);
03bde601 237
238 /* Called after post_options to initialize the front end. Return
239 false to indicate that no further compilation be performed, in
240 which case the finish hook is called immediately. */
3ad4992f 241 bool (*init) (void);
435fb09b 242
243 /* Called at the end of compilation, as a finalizer. */
3ad4992f 244 void (*finish) (void);
435fb09b 245
6ef828f9 246 /* Parses the entire file. The argument is nonzero to cause bison
1c542e4c 247 parsers to dump debugging information during parsing. */
3ad4992f 248 void (*parse_file) (int);
b78207a0 249
435fb09b 250 /* Called immediately after parsing to clear the binding stack. */
3ad4992f 251 void (*clear_binding_stack) (void);
435fb09b 252
b0278d39 253 /* Called to obtain the alias set to be used for an expression or type.
254 Returns -1 if the language does nothing special for it. */
3ad4992f 255 HOST_WIDE_INT (*get_alias_set) (tree);
b0278d39 256
b3187c7c 257 /* Called with an expression that is to be processed as a constant.
258 Returns either the same expression or a language-independent
259 constant equivalent to its input. */
3ad4992f 260 tree (*expand_constant) (tree);
b3187c7c 261
b467ecc1 262 /* Called by expand_expr for language-specific tree codes.
263 Fourth argument is actually an enum expand_modifier. */
3ad4992f 264 rtx (*expand_expr) (tree, rtx, enum machine_mode, int);
b467ecc1 265
aff9e656 266 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR or other logical
267 operation.
268
269 This preparation consists of taking the ordinary representation
270 of an expression expr and producing a valid tree boolean
271 expression describing whether expr is nonzero. We could simply
272 always do build_binary_op (NE_EXPR, expr, integer_zero_node, 1),
273 but we optimize comparisons, &&, ||, and !.
274
275 The result should be an expression of boolean type (if not an
276 error_mark_node). */
3ad4992f 277 tree (*truthvalue_conversion) (tree);
aff9e656 278
26ca6c20 279 /* Possibly apply default attributes to a function (represented by
280 a FUNCTION_DECL). */
3ad4992f 281 void (*insert_default_attributes) (tree);
26ca6c20 282
b3187c7c 283 /* Hook called by safe_from_p for language-specific tree codes. It is
284 up to the language front-end to install a hook if it has any such
285 codes that safe_from_p needs to know about. Since same_from_p will
286 recursively explore the TREE_OPERANDs of an expression, this hook
287 should not reexamine those pieces. This routine may recursively
288 call safe_from_p; it should always pass `0' as the TOP_P
289 parameter. */
3ad4992f 290 int (*safe_from_p) (rtx, tree);
b3187c7c 291
ee23fd7b 292 /* Function to finish handling an incomplete decl at the end of
293 compilation. Default hook is does nothing. */
3ad4992f 294 void (*finish_incomplete_decl) (tree);
ee23fd7b 295
296 /* Function used by unsafe_for_reeval. A non-negative number is
297 returned directly from unsafe_for_reeval, a negative number falls
298 through. The default hook returns a negative number. */
3ad4992f 299 int (*unsafe_for_reeval) (tree);
ee23fd7b 300
9b86eec0 301 /* Mark EXP saying that we need to be able to take the address of
302 it; it should not be allocated in a register. Return true if
303 successful. */
3ad4992f 304 bool (*mark_addressable) (tree);
9b86eec0 305
f1833f1b 306 /* Hook called by staticp for language-specific tree codes. */
3ad4992f 307 int (*staticp) (tree);
f1833f1b 308
dbc42b78 309 /* Replace the DECL_LANG_SPECIFIC data, which may be NULL, of the
310 DECL_NODE with a newly GC-allocated copy. */
3ad4992f 311 void (*dup_lang_specific_decl) (tree);
dbc42b78 312
1d347c23 313 /* Called before its argument, an UNSAVE_EXPR, is to be
314 unsaved. Modify it in-place so that all the evaluate only once
315 things are cleared out. */
3ad4992f 316 tree (*unsave_expr_now) (tree);
1d347c23 317
04745efb 318 /* Called by expand_expr to build and return the cleanup-expression
319 for the passed TARGET_EXPR. Return NULL if there is none. */
3ad4992f 320 tree (*maybe_build_cleanup) (tree);
04745efb 321
d1f6c8f2 322 /* Set the DECL_ASSEMBLER_NAME for a node. If it is the sort of
323 thing that the assembler should talk about, set
324 DECL_ASSEMBLER_NAME to an appropriate IDENTIFIER_NODE.
325 Otherwise, set it to the ERROR_MARK_NODE to ensure that the
326 assembler does not talk about it. */
3ad4992f 327 void (*set_decl_assembler_name) (tree);
d1f6c8f2 328
d50b22af 329 /* Return nonzero if fold-const is free to use bit-field
330 optimizations, for instance in fold_truthop(). */
3ad4992f 331 bool (*can_use_bit_fields_p) (void);
d50b22af 332
b0278d39 333 /* Nonzero if TYPE_READONLY and TREE_READONLY should always be honored. */
334 bool honor_readonly;
335
685b5cc2 336 /* Nonzero if this front end does not generate a dummy BLOCK between
337 the outermost scope of the function and the FUNCTION_DECL. See
338 is_body_block in stmt.c, and its callers. */
339 bool no_body_blocks;
340
b7fced5e 341 /* The front end can add its own statistics to -fmem-report with
342 this hook. It should output to stderr. */
3ad4992f 343 void (*print_statistics) (void);
b7fced5e 344
345 /* Called by print_tree when there is a tree of class 'x' that it
346 doesn't know how to display. */
347 lang_print_tree_hook print_xnode;
348
349 /* Called to print language-dependent parts of a class 'd', class
350 't', and IDENTIFIER_NODE nodes. */
351 lang_print_tree_hook print_decl;
352 lang_print_tree_hook print_type;
353 lang_print_tree_hook print_identifier;
354
96554925 355 /* Computes the name to use to print a declaration. DECL is the
356 non-NULL declaration in question. VERBOSITY determines what
357 information will be printed: 0: DECL_NAME, demangled as
358 necessary. 1: and scope information. 2: and any other
359 information that might be interesting, such as function parameter
360 types in C++. */
3ad4992f 361 const char *(*decl_printable_name) (tree decl, int verbosity);
96554925 362
6c7ff025 363 /* Called by report_error_function to print out function name. */
3ad4992f 364 void (*print_error_function) (struct diagnostic_context *, const char *);
6c7ff025 365
c3f16ae3 366 /* Called from expr_size to calculate the size of the value of an
367 expression in a language-dependent way. Returns a tree for the size
368 in bytes. A frontend can call lhd_expr_size to get the default
369 semantics in cases that it doesn't want to handle specially. */
3ad4992f 370 tree (*expr_size) (tree);
c3f16ae3 371
f8e93a2e 372 /* Pointers to machine-independent attribute tables, for front ends
373 using attribs.c. If one is NULL, it is ignored. Respectively, a
374 table of attributes specific to the language, a table of
375 attributes common to two or more languages (to allow easy
376 sharing), and a table of attributes for checking formats. */
377 const struct attribute_spec *attribute_table;
378 const struct attribute_spec *common_attribute_table;
379 const struct attribute_spec *format_attribute_table;
380
c80c4f22 381 /* Function-related language hooks. */
382 struct lang_hooks_for_functions function;
383
b0278d39 384 struct lang_hooks_for_tree_inlining tree_inlining;
8851e806 385
833eb724 386 struct lang_hooks_for_callgraph callgraph;
387
3119c950 388 struct lang_hooks_for_tree_dump tree_dump;
b0278d39 389
20325f61 390 struct lang_hooks_for_decls decls;
391
a1f71e15 392 struct lang_hooks_for_types types;
393
3119c950 394 /* Whenever you add entries here, make sure you adjust langhooks-def.h
b0278d39 395 and langhooks.c accordingly. */
396};
397
398/* Each front end provides its own. */
d19bd1f0 399extern const struct lang_hooks lang_hooks;
e8602e56 400
401#endif /* GCC_LANG_HOOKS_H */