Fixed rare threading problem
[official-gcc.git] / gcc / langhooks.h
blob0ab10e05cbceded89cc41f80d9a7497b4d40faa5
1 /* The lang_hooks data structure.
2 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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. */
21 #ifndef GCC_LANG_HOOKS_H
22 #define GCC_LANG_HOOKS_H
24 /* This file should be #include-d after tree.h. */
26 struct diagnostic_context;
28 /* A print hook for print_tree (). */
29 typedef void (*lang_print_tree_hook) (FILE *, tree, int indent);
31 /* The following hooks are documented in langhooks.c. Must not be
32 NULL. */
34 struct lang_hooks_for_tree_inlining
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 *);
56 int (*estimate_num_insns) (union tree_node *);
59 struct lang_hooks_for_callgraph
61 /* Function passed as argument is needed and will be compiled.
62 Lower the representation so the calls are explicit. */
63 void (*lower_function) (union tree_node *);
64 /* Produce RTL for function passed as argument. */
65 void (*expand_function) (union tree_node *);
68 /* Lang hooks for management of language-specific data or status
69 when entering / leaving functions etc. */
70 struct lang_hooks_for_functions
72 /* Called when entering a function. */
73 void (*init) (struct function *);
75 /* Called when leaving a function. */
76 void (*final) (struct function *);
78 /* Called when entering a nested function. */
79 void (*enter_nested) (struct function *);
81 /* Called when leaving a nested function. */
82 void (*leave_nested) (struct function *);
85 /* The following hooks are used by tree-dump.c. */
87 struct lang_hooks_for_tree_dump
89 /* Dump language-specific parts of tree nodes. Returns nonzero if it
90 does not want the usual dumping of the second argument. */
91 bool (*dump_tree) (void *, tree);
93 /* Determine type qualifiers in a language-specific way. */
94 int (*type_quals) (tree);
97 /* Hooks related to types. */
99 struct lang_hooks_for_types
101 /* Return a new type (with the indicated CODE), doing whatever
102 language-specific processing is required. */
103 tree (*make_type) (enum tree_code);
105 /* Given MODE and UNSIGNEDP, return a suitable type-tree with that
106 mode. */
107 tree (*type_for_mode) (enum machine_mode, int);
109 /* Given PRECISION and UNSIGNEDP, return a suitable type-tree for an
110 integer type with at least that precision. */
111 tree (*type_for_size) (unsigned, int);
113 /* Given an integer type T, return a type like T but unsigned.
114 If T is unsigned, the value is T. */
115 tree (*unsigned_type) (tree);
117 /* Given an integer type T, return a type like T but signed.
118 If T is signed, the value is T. */
119 tree (*signed_type) (tree);
121 /* Return a type the same as TYPE except unsigned or signed
122 according to UNSIGNEDP. */
123 tree (*signed_or_unsigned_type) (int, tree);
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. */
129 tree (*type_promotes_to) (tree);
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. */
135 void (*incomplete_type_error) (tree value, tree type);
138 /* Language hooks related to decls and the symbol table. */
140 struct lang_hooks_for_decls
142 /* Enter a new lexical scope. Argument is always zero when called
143 from outside the front end. */
144 void (*pushlevel) (int);
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. */
151 tree (*poplevel) (int, int, int);
153 /* Returns nonzero if we are in the global binding level. Ada
154 returns -1 for an undocumented reason used in stor-layout.c. */
155 int (*global_bindings_p) (void);
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. */
160 void (*insert_block) (tree);
162 /* Set the BLOCK node for the current scope level. */
163 void (*set_block) (tree);
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. */
169 tree (*pushdecl) (tree);
171 /* Returns the chain of decls so far in the current scope level. */
172 tree (*getdecls) (void);
174 /* Returns true when we should warn for an unused global DECL.
175 We will already have checked that it has static binding. */
176 bool (*warn_unused_global) (tree);
178 /* Obtain a list of globals and do final output on them at end
179 of compilation */
180 void (*final_write_globals) (void);
182 /* Do necessary preparations before assemble_variable can proceed. */
183 void (*prepare_assemble_variable) (tree);
185 /* True if this decl may be called via a sibcall. */
186 bool (*ok_for_sibcall) (tree);
189 /* Language-specific hooks. See langhooks-def.h for defaults. */
191 struct lang_hooks
193 /* String identifying the front end. e.g. "GNU C++". */
194 const char *name;
196 /* sizeof (struct lang_identifier), so make_node () creates
197 identifier nodes long enough for the language-specific slots. */
198 size_t identifier_size;
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. */
203 size_t (*tree_size) (enum tree_code);
205 /* The first callback made to the front end, for simple
206 initialization needed before any calls to handle_option. Return
207 the language mask to filter the switch array with. */
208 unsigned int (*init_options) (unsigned int argc, const char **argv);
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
212 which points to permanent storage. The handler is responsible for
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.
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);
221 /* Handle a filename on the command line. */
222 void (*handle_filename) (const char *filename);
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);
228 /* Called when all command line options have been parsed to allow
229 further processing and initialization
231 Should return true to indicate that a compiler back-end is
232 not required, such as with the -E option.
234 If errorcount is nonzero after this call the compiler exits
235 immediately and the finish hook is not called. */
236 bool (*post_options) (const char **);
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. */
241 bool (*init) (void);
243 /* Called at the end of compilation, as a finalizer. */
244 void (*finish) (void);
246 /* Parses the entire file. The argument is nonzero to cause bison
247 parsers to dump debugging information during parsing. */
248 void (*parse_file) (int);
250 /* Called immediately after parsing to clear the binding stack. */
251 void (*clear_binding_stack) (void);
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. */
255 HOST_WIDE_INT (*get_alias_set) (tree);
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. */
260 tree (*expand_constant) (tree);
262 /* Called by expand_expr for language-specific tree codes.
263 Fourth argument is actually an enum expand_modifier. */
264 rtx (*expand_expr) (tree, rtx, enum machine_mode, int);
266 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR or other logical
267 operation.
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 !.
275 The result should be an expression of boolean type (if not an
276 error_mark_node). */
277 tree (*truthvalue_conversion) (tree);
279 /* Possibly apply default attributes to a function (represented by
280 a FUNCTION_DECL). */
281 void (*insert_default_attributes) (tree);
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. */
290 int (*safe_from_p) (rtx, tree);
292 /* Function to finish handling an incomplete decl at the end of
293 compilation. Default hook is does nothing. */
294 void (*finish_incomplete_decl) (tree);
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. */
299 int (*unsafe_for_reeval) (tree);
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. */
304 bool (*mark_addressable) (tree);
306 /* Hook called by staticp for language-specific tree codes. */
307 int (*staticp) (tree);
309 /* Replace the DECL_LANG_SPECIFIC data, which may be NULL, of the
310 DECL_NODE with a newly GC-allocated copy. */
311 void (*dup_lang_specific_decl) (tree);
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. */
316 tree (*unsave_expr_now) (tree);
318 /* Called by expand_expr to build and return the cleanup-expression
319 for the passed TARGET_EXPR. Return NULL if there is none. */
320 tree (*maybe_build_cleanup) (tree);
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. */
327 void (*set_decl_assembler_name) (tree);
329 /* Return nonzero if fold-const is free to use bit-field
330 optimizations, for instance in fold_truthop(). */
331 bool (*can_use_bit_fields_p) (void);
333 /* Nonzero if TYPE_READONLY and TREE_READONLY should always be honored. */
334 bool honor_readonly;
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;
341 /* The front end can add its own statistics to -fmem-report with
342 this hook. It should output to stderr. */
343 void (*print_statistics) (void);
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;
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;
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++. */
361 const char *(*decl_printable_name) (tree decl, int verbosity);
363 /* Called by report_error_function to print out function name. */
364 void (*print_error_function) (struct diagnostic_context *, const char *);
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. */
370 tree (*expr_size) (tree);
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;
381 /* Function-related language hooks. */
382 struct lang_hooks_for_functions function;
384 struct lang_hooks_for_tree_inlining tree_inlining;
386 struct lang_hooks_for_callgraph callgraph;
388 struct lang_hooks_for_tree_dump tree_dump;
390 struct lang_hooks_for_decls decls;
392 struct lang_hooks_for_types types;
394 /* Whenever you add entries here, make sure you adjust langhooks-def.h
395 and langhooks.c accordingly. */
398 /* Each front end provides its own. */
399 extern const struct lang_hooks lang_hooks;
401 #endif /* GCC_LANG_HOOKS_H */