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