langhooks.h revision 259268
1/* The lang_hooks data structure. 2 Copyright 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 3 4This file is part of GCC. 5 6GCC is free software; you can redistribute it and/or modify 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 11GCC 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 GCC; see the file COPYING. If not, write to 18the Free Software Foundation, 51 Franklin Street, Fifth Floor, 19Boston, MA 02110-1301, 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 26struct diagnostic_context; 27 28struct gimplify_omp_ctx; 29 30/* A print hook for print_tree (). */ 31typedef void (*lang_print_tree_hook) (FILE *, tree, int indent); 32 33/* The following hooks are documented in langhooks.c. Must not be 34 NULL. */ 35 36struct lang_hooks_for_tree_inlining 37{ 38 tree (*walk_subtrees) (tree *, int *, 39 tree (*) (tree *, int *, void *), 40 void *, struct pointer_set_t*); 41 int (*cannot_inline_tree_fn) (tree *); 42 int (*disregard_inline_limits) (tree); 43 tree (*add_pending_fn_decls) (void *, tree); 44 int (*auto_var_in_fn_p) (tree, 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 52struct 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. */ 64struct 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 84struct 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 96struct 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 /* True if the type is an instantiation of a generic type, 123 e.g. C++ template implicit specializations. */ 124 bool (*generic_p) (tree); 125 126 /* Given a type, apply default promotions to unnamed function 127 arguments and return the new type. Return the same type if no 128 change. Required by any language that supports variadic 129 arguments. The default hook dies. */ 130 tree (*type_promotes_to) (tree); 131 132 /* Register TYPE as a builtin type with the indicated NAME. The 133 TYPE is placed in the outermost lexical scope. The semantics 134 should be analogous to: 135 136 typedef TYPE NAME; 137 138 in C. The default hook ignores the declaration. */ 139 void (*register_builtin_type) (tree, const char *); 140 141 /* This routine is called in tree.c to print an error message for 142 invalid use of an incomplete type. VALUE is the expression that 143 was used (or 0 if that isn't known) and TYPE is the type that was 144 invalid. */ 145 void (*incomplete_type_error) (tree value, tree type); 146 147 /* Called from assign_temp to return the maximum size, if there is one, 148 for a type. */ 149 tree (*max_size) (tree); 150 151 /* Register language specific type size variables as potentially OpenMP 152 firstprivate variables. */ 153 void (*omp_firstprivatize_type_sizes) (struct gimplify_omp_ctx *, tree); 154 155 /* Nonzero if types that are identical are to be hashed so that only 156 one copy is kept. If a language requires unique types for each 157 user-specified type, such as Ada, this should be set to TRUE. */ 158 bool hash_types; 159}; 160 161/* Language hooks related to decls and the symbol table. */ 162 163struct lang_hooks_for_decls 164{ 165 /* Returns nonzero if we are in the global binding level. Ada 166 returns -1 for an undocumented reason used in stor-layout.c. */ 167 int (*global_bindings_p) (void); 168 169 /* Insert BLOCK at the end of the list of subblocks of the 170 current binding level. This is used when a BIND_EXPR is expanded, 171 to handle the BLOCK node inside the BIND_EXPR. */ 172 void (*insert_block) (tree); 173 174 /* Function to add a decl to the current scope level. Takes one 175 argument, a decl to add. Returns that decl, or, if the same 176 symbol is already declared, may return a different decl for that 177 name. */ 178 tree (*pushdecl) (tree); 179 180 /* Returns the chain of decls so far in the current scope level. */ 181 tree (*getdecls) (void); 182 183 /* Returns true when we should warn for an unused global DECL. 184 We will already have checked that it has static binding. */ 185 bool (*warn_unused_global) (tree); 186 187 /* Obtain a list of globals and do final output on them at end 188 of compilation */ 189 void (*final_write_globals) (void); 190 191 /* Do necessary preparations before assemble_variable can proceed. */ 192 void (*prepare_assemble_variable) (tree); 193 194 /* True if this decl may be called via a sibcall. */ 195 bool (*ok_for_sibcall) (tree); 196 197 /* Return the COMDAT group into which this DECL should be placed. 198 It is known that the DECL belongs in *some* COMDAT group when 199 this hook is called. The return value will be used immediately, 200 but not explicitly deallocated, so implementations should not use 201 xmalloc to allocate the string returned. (Typically, the return 202 value will be the string already stored in an 203 IDENTIFIER_NODE.) */ 204 const char * (*comdat_group) (tree); 205 206 /* True if OpenMP should privatize what this DECL points to rather 207 than the DECL itself. */ 208 bool (*omp_privatize_by_reference) (tree); 209 210 /* Return sharing kind if OpenMP sharing attribute of DECL is 211 predetermined, OMP_CLAUSE_DEFAULT_UNSPECIFIED otherwise. */ 212 enum omp_clause_default_kind (*omp_predetermined_sharing) (tree); 213 214 /* Return true if DECL's DECL_VALUE_EXPR (if any) should be 215 disregarded in OpenMP construct, because it is going to be 216 remapped during OpenMP lowering. SHARED is true if DECL 217 is going to be shared, false if it is going to be privatized. */ 218 bool (*omp_disregard_value_expr) (tree, bool); 219 220 /* Return true if DECL that is shared iff SHARED is true should 221 be put into OMP_CLAUSE_PRIVATE_DEBUG. */ 222 bool (*omp_private_debug_clause) (tree, bool); 223 224 /* Build and return code for a default constructor for DECL in 225 response to CLAUSE. Return NULL if nothing to be done. */ 226 tree (*omp_clause_default_ctor) (tree clause, tree decl); 227 228 /* Build and return code for a copy constructor from SRC to DST. */ 229 tree (*omp_clause_copy_ctor) (tree clause, tree dst, tree src); 230 231 /* Similarly, except use an assignment operator instead. */ 232 tree (*omp_clause_assign_op) (tree clause, tree dst, tree src); 233 234 /* Build and return code destructing DECL. Return NULL if nothing 235 to be done. */ 236 tree (*omp_clause_dtor) (tree clause, tree decl); 237}; 238 239/* Language-specific hooks. See langhooks-def.h for defaults. */ 240 241struct lang_hooks 242{ 243 /* String identifying the front end. e.g. "GNU C++". */ 244 const char *name; 245 246 /* sizeof (struct lang_identifier), so make_node () creates 247 identifier nodes long enough for the language-specific slots. */ 248 size_t identifier_size; 249 250 /* Determines the size of any language-specific tcc_constant or 251 tcc_exceptional nodes. Since it is called from make_node, the 252 only information available is the tree code. Expected to die 253 on unrecognized codes. */ 254 size_t (*tree_size) (enum tree_code); 255 256 /* The first callback made to the front end, for simple 257 initialization needed before any calls to handle_option. Return 258 the language mask to filter the switch array with. */ 259 unsigned int (*init_options) (unsigned int argc, const char **argv); 260 261 /* Callback used to perform language-specific initialization for the 262 global diagnostic context structure. */ 263 void (*initialize_diagnostics) (struct diagnostic_context *); 264 265 /* Handle the switch CODE, which has real type enum opt_code from 266 options.h. If the switch takes an argument, it is passed in ARG 267 which points to permanent storage. The handler is responsible for 268 checking whether ARG is NULL, which indicates that no argument 269 was in fact supplied. For -f and -W switches, VALUE is 1 or 0 270 for the positive and negative forms respectively. 271 272 Return 1 if the switch is valid, 0 if invalid, and -1 if it's 273 valid and should not be treated as language-independent too. */ 274 int (*handle_option) (size_t code, const char *arg, int value); 275 276 /* Return false to use the default complaint about a missing 277 argument, otherwise output a complaint and return true. */ 278 bool (*missing_argument) (const char *opt, size_t code); 279 280 /* Called when all command line options have been parsed to allow 281 further processing and initialization 282 283 Should return true to indicate that a compiler back-end is 284 not required, such as with the -E option. 285 286 If errorcount is nonzero after this call the compiler exits 287 immediately and the finish hook is not called. */ 288 bool (*post_options) (const char **); 289 290 /* Called after post_options to initialize the front end. Return 291 false to indicate that no further compilation be performed, in 292 which case the finish hook is called immediately. */ 293 bool (*init) (void); 294 295 /* Called at the end of compilation, as a finalizer. */ 296 void (*finish) (void); 297 298 /* Parses the entire file. The argument is nonzero to cause bison 299 parsers to dump debugging information during parsing. */ 300 void (*parse_file) (int); 301 302 /* Called immediately after parsing to clear the binding stack. */ 303 void (*clear_binding_stack) (void); 304 305 /* Called to obtain the alias set to be used for an expression or type. 306 Returns -1 if the language does nothing special for it. */ 307 HOST_WIDE_INT (*get_alias_set) (tree); 308 309 /* Called with an expression that is to be processed as a constant. 310 Returns either the same expression or a language-independent 311 constant equivalent to its input. */ 312 tree (*expand_constant) (tree); 313 314 /* Called by expand_expr for language-specific tree codes. 315 Fourth argument is actually an enum expand_modifier. */ 316 rtx (*expand_expr) (tree, rtx, enum machine_mode, int, rtx *); 317 318 /* Called by expand_expr to generate the definition of a decl. Returns 319 1 if handled, 0 otherwise. */ 320 int (*expand_decl) (tree); 321 322 /* Hook called by safe_from_p for language-specific tree codes. It is 323 up to the language front-end to install a hook if it has any such 324 codes that safe_from_p needs to know about. Since same_from_p will 325 recursively explore the TREE_OPERANDs of an expression, this hook 326 should not reexamine those pieces. This routine may recursively 327 call safe_from_p; it should always pass `0' as the TOP_P 328 parameter. */ 329 int (*safe_from_p) (rtx, tree); 330 331 /* Function to finish handling an incomplete decl at the end of 332 compilation. Default hook is does nothing. */ 333 void (*finish_incomplete_decl) (tree); 334 335 /* Mark EXP saying that we need to be able to take the address of 336 it; it should not be allocated in a register. Return true if 337 successful. */ 338 bool (*mark_addressable) (tree); 339 340 /* Hook called by staticp for language-specific tree codes. */ 341 tree (*staticp) (tree); 342 343 /* Replace the DECL_LANG_SPECIFIC data, which may be NULL, of the 344 DECL_NODE with a newly GC-allocated copy. */ 345 void (*dup_lang_specific_decl) (tree); 346 347 /* Set the DECL_ASSEMBLER_NAME for a node. If it is the sort of 348 thing that the assembler should talk about, set 349 DECL_ASSEMBLER_NAME to an appropriate IDENTIFIER_NODE. 350 Otherwise, set it to the ERROR_MARK_NODE to ensure that the 351 assembler does not talk about it. */ 352 void (*set_decl_assembler_name) (tree); 353 354 /* Return nonzero if fold-const is free to use bit-field 355 optimizations, for instance in fold_truthop(). */ 356 bool (*can_use_bit_fields_p) (void); 357 358 /* Nonzero if operations on types narrower than their mode should 359 have their results reduced to the precision of the type. */ 360 bool reduce_bit_field_operations; 361 362 /* Nonzero if this front end does not generate a dummy BLOCK between 363 the outermost scope of the function and the FUNCTION_DECL. See 364 is_body_block in stmt.c, and its callers. */ 365 bool no_body_blocks; 366 367 /* The front end can add its own statistics to -fmem-report with 368 this hook. It should output to stderr. */ 369 void (*print_statistics) (void); 370 371 /* Called by print_tree when there is a tree of class tcc_exceptional 372 that it doesn't know how to display. */ 373 lang_print_tree_hook print_xnode; 374 375 /* Called to print language-dependent parts of tcc_decl, tcc_type, 376 and IDENTIFIER_NODE nodes. */ 377 lang_print_tree_hook print_decl; 378 lang_print_tree_hook print_type; 379 lang_print_tree_hook print_identifier; 380 381 /* Computes the name to use to print a declaration. DECL is the 382 non-NULL declaration in question. VERBOSITY determines what 383 information will be printed: 0: DECL_NAME, demangled as 384 necessary. 1: and scope information. 2: and any other 385 information that might be interesting, such as function parameter 386 types in C++. */ 387 const char *(*decl_printable_name) (tree decl, int verbosity); 388 389 /* Computes the dwarf-2/3 name for a tree. VERBOSITY determines what 390 information will be printed: 0: DECL_NAME, demangled as 391 necessary. 1: and scope information. */ 392 const char *(*dwarf_name) (tree, int verbosity); 393 394 /* This compares two types for equivalence ("compatible" in C-based languages). 395 This routine should only return 1 if it is sure. It should not be used 396 in contexts where erroneously returning 0 causes problems. */ 397 int (*types_compatible_p) (tree x, tree y); 398 399 /* Given a CALL_EXPR, return a function decl that is its target. */ 400 tree (*lang_get_callee_fndecl) (tree); 401 402 /* Called by report_error_function to print out function name. */ 403 void (*print_error_function) (struct diagnostic_context *, const char *); 404 405 /* Called from expr_size to calculate the size of the value of an 406 expression in a language-dependent way. Returns a tree for the size 407 in bytes. A frontend can call lhd_expr_size to get the default 408 semantics in cases that it doesn't want to handle specially. */ 409 tree (*expr_size) (tree); 410 411 /* Convert a character from the host's to the target's character 412 set. The character should be in what C calls the "basic source 413 character set" (roughly, the set of characters defined by plain 414 old ASCII). The default is to return the character unchanged, 415 which is correct in most circumstances. Note that both argument 416 and result should be sign-extended under -fsigned-char, 417 zero-extended under -fno-signed-char. */ 418 HOST_WIDE_INT (*to_target_charset) (HOST_WIDE_INT); 419 420 /* Pointers to machine-independent attribute tables, for front ends 421 using attribs.c. If one is NULL, it is ignored. Respectively, a 422 table of attributes specific to the language, a table of 423 attributes common to two or more languages (to allow easy 424 sharing), and a table of attributes for checking formats. */ 425 const struct attribute_spec *attribute_table; 426 const struct attribute_spec *common_attribute_table; 427 const struct attribute_spec *format_attribute_table; 428 429 /* Function-related language hooks. */ 430 struct lang_hooks_for_functions function; 431 432 struct lang_hooks_for_tree_inlining tree_inlining; 433 434 struct lang_hooks_for_callgraph callgraph; 435 436 struct lang_hooks_for_tree_dump tree_dump; 437 438 struct lang_hooks_for_decls decls; 439 440 struct lang_hooks_for_types types; 441 442 /* Perform language-specific gimplification on the argument. Returns an 443 enum gimplify_status, though we can't see that type here. */ 444 int (*gimplify_expr) (tree *, tree *, tree *); 445 446 /* Fold an OBJ_TYPE_REF expression to the address of a function. 447 KNOWN_TYPE carries the true type of the OBJ_TYPE_REF_OBJECT. */ 448 tree (*fold_obj_type_ref) (tree, tree); 449 450 /* Return a definition for a builtin function named NAME and whose data type 451 is TYPE. TYPE should be a function type with argument types. 452 FUNCTION_CODE tells later passes how to compile calls to this function. 453 See tree.h for its possible values. 454 455 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, 456 the name to be called if we can't opencode the function. If 457 ATTRS is nonzero, use that for the function's attribute list. */ 458 tree (*builtin_function) (const char *name, tree type, int function_code, 459 enum built_in_class bt_class, 460 const char *library_name, tree attrs); 461 462 /* Used to set up the tree_contains_structure array for a frontend. */ 463 void (*init_ts) (void); 464 465 /* Called by recompute_tree_invariant_for_addr_expr to go from EXPR 466 to a contained expression or DECL, possibly updating *TC, *TI or 467 *SE if in the process TREE_CONSTANT, TREE_INVARIANT or 468 TREE_SIDE_EFFECTS need updating. */ 469 tree (*expr_to_decl) (tree expr, bool *tc, bool *ti, bool *se); 470 471 /* Whenever you add entries here, make sure you adjust langhooks-def.h 472 and langhooks.c accordingly. */ 473}; 474 475/* Each front end provides its own. */ 476extern const struct lang_hooks lang_hooks; 477 478#endif /* GCC_LANG_HOOKS_H */ 479