190075Sobrien/* The lang_hooks data structure. 2169689Skan Copyright 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. 390075Sobrien 4132718SkanThis file is part of GCC. 590075Sobrien 6132718SkanGCC is free software; you can redistribute it and/or modify 790075Sobrienit under the terms of the GNU General Public License as published by 890075Sobrienthe Free Software Foundation; either version 2, or (at your option) 990075Sobrienany later version. 1090075Sobrien 11132718SkanGCC is distributed in the hope that it will be useful, 1290075Sobrienbut WITHOUT ANY WARRANTY; without even the implied warranty of 1390075SobrienMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1490075SobrienGNU General Public License for more details. 1590075Sobrien 1690075SobrienYou should have received a copy of the GNU General Public License 17132718Skanalong with GCC; see the file COPYING. If not, write to 18169689Skanthe Free Software Foundation, 51 Franklin Street, Fifth Floor, 19169689SkanBoston, MA 02110-1301, USA. */ 2090075Sobrien 2190075Sobrien#ifndef GCC_LANG_HOOKS_H 2290075Sobrien#define GCC_LANG_HOOKS_H 2390075Sobrien 24117395Skan/* This file should be #include-d after tree.h. */ 25117395Skan 26117395Skanstruct diagnostic_context; 27117395Skan 28169689Skanstruct gimplify_omp_ctx; 29169689Skan 3090075Sobrien/* A print hook for print_tree (). */ 31132718Skantypedef void (*lang_print_tree_hook) (FILE *, tree, int indent); 3290075Sobrien 3390075Sobrien/* The following hooks are documented in langhooks.c. Must not be 3490075Sobrien NULL. */ 3590075Sobrien 3690075Sobrienstruct lang_hooks_for_tree_inlining 3790075Sobrien{ 38132718Skan tree (*walk_subtrees) (tree *, int *, 39132718Skan tree (*) (tree *, int *, void *), 40169689Skan void *, struct pointer_set_t*); 41132718Skan int (*cannot_inline_tree_fn) (tree *); 42132718Skan int (*disregard_inline_limits) (tree); 43132718Skan tree (*add_pending_fn_decls) (void *, tree); 44132718Skan int (*auto_var_in_fn_p) (tree, tree); 45132718Skan int (*anon_aggr_type_p) (tree); 46169689Skan bool (*var_mod_type_p) (tree, tree); 47132718Skan int (*start_inlining) (tree); 48132718Skan void (*end_inlining) (tree); 49132718Skan tree (*convert_parm_for_inlining) (tree, tree, tree, int); 5090075Sobrien}; 5190075Sobrien 52132718Skanstruct lang_hooks_for_callgraph 53132718Skan{ 54132718Skan /* The node passed is a language-specific tree node. If its contents 55132718Skan are relevant to use of other declarations, mark them. */ 56132718Skan tree (*analyze_expr) (tree *, int *, tree); 57132718Skan 58132718Skan /* Produce RTL for function passed as argument. */ 59132718Skan void (*expand_function) (tree); 60132718Skan}; 61132718Skan 62117395Skan/* Lang hooks for management of language-specific data or status 63117395Skan when entering / leaving functions etc. */ 64117395Skanstruct lang_hooks_for_functions 65117395Skan{ 66117395Skan /* Called when entering a function. */ 67132718Skan void (*init) (struct function *); 68117395Skan 69117395Skan /* Called when leaving a function. */ 70132718Skan void (*final) (struct function *); 71117395Skan 72117395Skan /* Called when entering a nested function. */ 73132718Skan void (*enter_nested) (struct function *); 74117395Skan 75117395Skan /* Called when leaving a nested function. */ 76132718Skan void (*leave_nested) (struct function *); 77117395Skan 78169689Skan /* Determines if it's ok for a function to have no noreturn attribute. */ 79169689Skan bool (*missing_noreturn_ok_p) (tree); 80132718Skan}; 81132718Skan 8290075Sobrien/* The following hooks are used by tree-dump.c. */ 8390075Sobrien 8490075Sobrienstruct lang_hooks_for_tree_dump 8590075Sobrien{ 86117395Skan /* Dump language-specific parts of tree nodes. Returns nonzero if it 8790075Sobrien does not want the usual dumping of the second argument. */ 88132718Skan bool (*dump_tree) (void *, tree); 8990075Sobrien 9090075Sobrien /* Determine type qualifiers in a language-specific way. */ 91132718Skan int (*type_quals) (tree); 9290075Sobrien}; 9390075Sobrien 94117395Skan/* Hooks related to types. */ 95117395Skan 96117395Skanstruct lang_hooks_for_types 97117395Skan{ 98117395Skan /* Return a new type (with the indicated CODE), doing whatever 99117395Skan language-specific processing is required. */ 100132718Skan tree (*make_type) (enum tree_code); 101117395Skan 102117395Skan /* Given MODE and UNSIGNEDP, return a suitable type-tree with that 103117395Skan mode. */ 104132718Skan tree (*type_for_mode) (enum machine_mode, int); 105117395Skan 106117395Skan /* Given PRECISION and UNSIGNEDP, return a suitable type-tree for an 107117395Skan integer type with at least that precision. */ 108132718Skan tree (*type_for_size) (unsigned, int); 109117395Skan 110117395Skan /* Given an integer type T, return a type like T but unsigned. 111117395Skan If T is unsigned, the value is T. */ 112132718Skan tree (*unsigned_type) (tree); 113117395Skan 114117395Skan /* Given an integer type T, return a type like T but signed. 115117395Skan If T is signed, the value is T. */ 116132718Skan tree (*signed_type) (tree); 117117395Skan 118117395Skan /* Return a type the same as TYPE except unsigned or signed 119117395Skan according to UNSIGNEDP. */ 120132718Skan tree (*signed_or_unsigned_type) (int, tree); 121117395Skan 122117395Skan /* Given a type, apply default promotions to unnamed function 123117395Skan arguments and return the new type. Return the same type if no 124117395Skan change. Required by any language that supports variadic 125169689Skan arguments. The default hook dies. */ 126132718Skan tree (*type_promotes_to) (tree); 127117395Skan 128132718Skan /* Register TYPE as a builtin type with the indicated NAME. The 129132718Skan TYPE is placed in the outermost lexical scope. The semantics 130132718Skan should be analogous to: 131132718Skan 132132718Skan typedef TYPE NAME; 133132718Skan 134132718Skan in C. The default hook ignores the declaration. */ 135132718Skan void (*register_builtin_type) (tree, const char *); 136132718Skan 137117395Skan /* This routine is called in tree.c to print an error message for 138117395Skan invalid use of an incomplete type. VALUE is the expression that 139117395Skan was used (or 0 if that isn't known) and TYPE is the type that was 140117395Skan invalid. */ 141132718Skan void (*incomplete_type_error) (tree value, tree type); 142169689Skan 143169689Skan /* Called from assign_temp to return the maximum size, if there is one, 144169689Skan for a type. */ 145169689Skan tree (*max_size) (tree); 146169689Skan 147169689Skan /* Register language specific type size variables as potentially OpenMP 148169689Skan firstprivate variables. */ 149169689Skan void (*omp_firstprivatize_type_sizes) (struct gimplify_omp_ctx *, tree); 150169689Skan 151169689Skan /* Nonzero if types that are identical are to be hashed so that only 152169689Skan one copy is kept. If a language requires unique types for each 153169689Skan user-specified type, such as Ada, this should be set to TRUE. */ 154169689Skan bool hash_types; 155117395Skan}; 156117395Skan 157117395Skan/* Language hooks related to decls and the symbol table. */ 158117395Skan 159117395Skanstruct lang_hooks_for_decls 160117395Skan{ 161117395Skan /* Returns nonzero if we are in the global binding level. Ada 162117395Skan returns -1 for an undocumented reason used in stor-layout.c. */ 163132718Skan int (*global_bindings_p) (void); 164117395Skan 165117395Skan /* Insert BLOCK at the end of the list of subblocks of the 166117395Skan current binding level. This is used when a BIND_EXPR is expanded, 167117395Skan to handle the BLOCK node inside the BIND_EXPR. */ 168132718Skan void (*insert_block) (tree); 169117395Skan 170117395Skan /* Function to add a decl to the current scope level. Takes one 171117395Skan argument, a decl to add. Returns that decl, or, if the same 172117395Skan symbol is already declared, may return a different decl for that 173117395Skan name. */ 174132718Skan tree (*pushdecl) (tree); 175117395Skan 176117395Skan /* Returns the chain of decls so far in the current scope level. */ 177132718Skan tree (*getdecls) (void); 178117395Skan 179117395Skan /* Returns true when we should warn for an unused global DECL. 180117395Skan We will already have checked that it has static binding. */ 181132718Skan bool (*warn_unused_global) (tree); 182117395Skan 183117395Skan /* Obtain a list of globals and do final output on them at end 184117395Skan of compilation */ 185132718Skan void (*final_write_globals) (void); 186117395Skan 187132718Skan /* Do necessary preparations before assemble_variable can proceed. */ 188132718Skan void (*prepare_assemble_variable) (tree); 189132718Skan 190117395Skan /* True if this decl may be called via a sibcall. */ 191132718Skan bool (*ok_for_sibcall) (tree); 192169689Skan 193169689Skan /* Return the COMDAT group into which this DECL should be placed. 194169689Skan It is known that the DECL belongs in *some* COMDAT group when 195169689Skan this hook is called. The return value will be used immediately, 196169689Skan but not explicitly deallocated, so implementations should not use 197169689Skan xmalloc to allocate the string returned. (Typically, the return 198169689Skan value will be the string already stored in an 199169689Skan IDENTIFIER_NODE.) */ 200169689Skan const char * (*comdat_group) (tree); 201169689Skan 202169689Skan /* True if OpenMP should privatize what this DECL points to rather 203169689Skan than the DECL itself. */ 204169689Skan bool (*omp_privatize_by_reference) (tree); 205169689Skan 206169689Skan /* Return sharing kind if OpenMP sharing attribute of DECL is 207169689Skan predetermined, OMP_CLAUSE_DEFAULT_UNSPECIFIED otherwise. */ 208169689Skan enum omp_clause_default_kind (*omp_predetermined_sharing) (tree); 209169689Skan 210169689Skan /* Return true if DECL's DECL_VALUE_EXPR (if any) should be 211169689Skan disregarded in OpenMP construct, because it is going to be 212169689Skan remapped during OpenMP lowering. SHARED is true if DECL 213169689Skan is going to be shared, false if it is going to be privatized. */ 214169689Skan bool (*omp_disregard_value_expr) (tree, bool); 215169689Skan 216169689Skan /* Return true if DECL that is shared iff SHARED is true should 217169689Skan be put into OMP_CLAUSE_PRIVATE_DEBUG. */ 218169689Skan bool (*omp_private_debug_clause) (tree, bool); 219169689Skan 220169689Skan /* Build and return code for a default constructor for DECL in 221169689Skan response to CLAUSE. Return NULL if nothing to be done. */ 222169689Skan tree (*omp_clause_default_ctor) (tree clause, tree decl); 223169689Skan 224169689Skan /* Build and return code for a copy constructor from SRC to DST. */ 225169689Skan tree (*omp_clause_copy_ctor) (tree clause, tree dst, tree src); 226169689Skan 227169689Skan /* Similarly, except use an assignment operator instead. */ 228169689Skan tree (*omp_clause_assign_op) (tree clause, tree dst, tree src); 229169689Skan 230169689Skan /* Build and return code destructing DECL. Return NULL if nothing 231169689Skan to be done. */ 232169689Skan tree (*omp_clause_dtor) (tree clause, tree decl); 233117395Skan}; 234117395Skan 23590075Sobrien/* Language-specific hooks. See langhooks-def.h for defaults. */ 23690075Sobrien 23790075Sobrienstruct lang_hooks 23890075Sobrien{ 23990075Sobrien /* String identifying the front end. e.g. "GNU C++". */ 24090075Sobrien const char *name; 24190075Sobrien 24290075Sobrien /* sizeof (struct lang_identifier), so make_node () creates 24390075Sobrien identifier nodes long enough for the language-specific slots. */ 24490075Sobrien size_t identifier_size; 24590075Sobrien 246169689Skan /* Determines the size of any language-specific tcc_constant or 247169689Skan tcc_exceptional nodes. Since it is called from make_node, the 248169689Skan only information available is the tree code. Expected to die 249169689Skan on unrecognized codes. */ 250132718Skan size_t (*tree_size) (enum tree_code); 251132718Skan 25290075Sobrien /* The first callback made to the front end, for simple 253132718Skan initialization needed before any calls to handle_option. Return 254132718Skan the language mask to filter the switch array with. */ 255132718Skan unsigned int (*init_options) (unsigned int argc, const char **argv); 25690075Sobrien 257132718Skan /* Callback used to perform language-specific initialization for the 258132718Skan global diagnostic context structure. */ 259132718Skan void (*initialize_diagnostics) (struct diagnostic_context *); 26090075Sobrien 261132718Skan /* Handle the switch CODE, which has real type enum opt_code from 262132718Skan options.h. If the switch takes an argument, it is passed in ARG 263132718Skan which points to permanent storage. The handler is responsible for 264132718Skan checking whether ARG is NULL, which indicates that no argument 265132718Skan was in fact supplied. For -f and -W switches, VALUE is 1 or 0 266132718Skan for the positive and negative forms respectively. 267102780Skan 268132718Skan Return 1 if the switch is valid, 0 if invalid, and -1 if it's 269132718Skan valid and should not be treated as language-independent too. */ 270132718Skan int (*handle_option) (size_t code, const char *arg, int value); 271132718Skan 272132718Skan /* Return false to use the default complaint about a missing 273132718Skan argument, otherwise output a complaint and return true. */ 274132718Skan bool (*missing_argument) (const char *opt, size_t code); 275132718Skan 276132718Skan /* Called when all command line options have been parsed to allow 277132718Skan further processing and initialization 278132718Skan 279132718Skan Should return true to indicate that a compiler back-end is 280132718Skan not required, such as with the -E option. 281132718Skan 282117395Skan If errorcount is nonzero after this call the compiler exits 283102780Skan immediately and the finish hook is not called. */ 284132718Skan bool (*post_options) (const char **); 28590075Sobrien 286132718Skan /* Called after post_options to initialize the front end. Return 287132718Skan false to indicate that no further compilation be performed, in 288132718Skan which case the finish hook is called immediately. */ 289132718Skan bool (*init) (void); 29090075Sobrien 29190075Sobrien /* Called at the end of compilation, as a finalizer. */ 292132718Skan void (*finish) (void); 29390075Sobrien 294117395Skan /* Parses the entire file. The argument is nonzero to cause bison 295117395Skan parsers to dump debugging information during parsing. */ 296132718Skan void (*parse_file) (int); 297117395Skan 29890075Sobrien /* Called immediately after parsing to clear the binding stack. */ 299132718Skan void (*clear_binding_stack) (void); 30090075Sobrien 30190075Sobrien /* Called to obtain the alias set to be used for an expression or type. 30290075Sobrien Returns -1 if the language does nothing special for it. */ 303132718Skan HOST_WIDE_INT (*get_alias_set) (tree); 30490075Sobrien 30590075Sobrien /* Called with an expression that is to be processed as a constant. 30690075Sobrien Returns either the same expression or a language-independent 30790075Sobrien constant equivalent to its input. */ 308132718Skan tree (*expand_constant) (tree); 30990075Sobrien 310117395Skan /* Called by expand_expr for language-specific tree codes. 311117395Skan Fourth argument is actually an enum expand_modifier. */ 312132718Skan rtx (*expand_expr) (tree, rtx, enum machine_mode, int, rtx *); 313117395Skan 314169689Skan /* Called by expand_expr to generate the definition of a decl. Returns 315169689Skan 1 if handled, 0 otherwise. */ 316169689Skan int (*expand_decl) (tree); 317117395Skan 31890075Sobrien /* Hook called by safe_from_p for language-specific tree codes. It is 31990075Sobrien up to the language front-end to install a hook if it has any such 32090075Sobrien codes that safe_from_p needs to know about. Since same_from_p will 32190075Sobrien recursively explore the TREE_OPERANDs of an expression, this hook 32290075Sobrien should not reexamine those pieces. This routine may recursively 32390075Sobrien call safe_from_p; it should always pass `0' as the TOP_P 32490075Sobrien parameter. */ 325132718Skan int (*safe_from_p) (rtx, tree); 32690075Sobrien 327117395Skan /* Function to finish handling an incomplete decl at the end of 328117395Skan compilation. Default hook is does nothing. */ 329132718Skan void (*finish_incomplete_decl) (tree); 330117395Skan 331117395Skan /* Mark EXP saying that we need to be able to take the address of 332117395Skan it; it should not be allocated in a register. Return true if 333117395Skan successful. */ 334132718Skan bool (*mark_addressable) (tree); 335117395Skan 33690075Sobrien /* Hook called by staticp for language-specific tree codes. */ 337169689Skan tree (*staticp) (tree); 33890075Sobrien 339117395Skan /* Replace the DECL_LANG_SPECIFIC data, which may be NULL, of the 340117395Skan DECL_NODE with a newly GC-allocated copy. */ 341132718Skan void (*dup_lang_specific_decl) (tree); 342117395Skan 343117395Skan /* Set the DECL_ASSEMBLER_NAME for a node. If it is the sort of 344117395Skan thing that the assembler should talk about, set 345117395Skan DECL_ASSEMBLER_NAME to an appropriate IDENTIFIER_NODE. 346117395Skan Otherwise, set it to the ERROR_MARK_NODE to ensure that the 347117395Skan assembler does not talk about it. */ 348132718Skan void (*set_decl_assembler_name) (tree); 349117395Skan 350117395Skan /* Return nonzero if fold-const is free to use bit-field 351117395Skan optimizations, for instance in fold_truthop(). */ 352132718Skan bool (*can_use_bit_fields_p) (void); 353117395Skan 354169689Skan /* Nonzero if operations on types narrower than their mode should 355169689Skan have their results reduced to the precision of the type. */ 356169689Skan bool reduce_bit_field_operations; 35790075Sobrien 358132718Skan /* Nonzero if this front end does not generate a dummy BLOCK between 359132718Skan the outermost scope of the function and the FUNCTION_DECL. See 360132718Skan is_body_block in stmt.c, and its callers. */ 361132718Skan bool no_body_blocks; 362132718Skan 36390075Sobrien /* The front end can add its own statistics to -fmem-report with 36490075Sobrien this hook. It should output to stderr. */ 365132718Skan void (*print_statistics) (void); 36690075Sobrien 367169689Skan /* Called by print_tree when there is a tree of class tcc_exceptional 368169689Skan that it doesn't know how to display. */ 36990075Sobrien lang_print_tree_hook print_xnode; 37090075Sobrien 371169689Skan /* Called to print language-dependent parts of tcc_decl, tcc_type, 372169689Skan and IDENTIFIER_NODE nodes. */ 37390075Sobrien lang_print_tree_hook print_decl; 37490075Sobrien lang_print_tree_hook print_type; 37590075Sobrien lang_print_tree_hook print_identifier; 37690075Sobrien 377117395Skan /* Computes the name to use to print a declaration. DECL is the 378117395Skan non-NULL declaration in question. VERBOSITY determines what 379117395Skan information will be printed: 0: DECL_NAME, demangled as 380117395Skan necessary. 1: and scope information. 2: and any other 381117395Skan information that might be interesting, such as function parameter 382117395Skan types in C++. */ 383132718Skan const char *(*decl_printable_name) (tree decl, int verbosity); 38490075Sobrien 385169689Skan /* Computes the dwarf-2/3 name for a tree. VERBOSITY determines what 386169689Skan information will be printed: 0: DECL_NAME, demangled as 387169689Skan necessary. 1: and scope information. */ 388169689Skan const char *(*dwarf_name) (tree, int verbosity); 389169689Skan 390169689Skan /* This compares two types for equivalence ("compatible" in C-based languages). 391169689Skan This routine should only return 1 if it is sure. It should not be used 392169689Skan in contexts where erroneously returning 0 causes problems. */ 393169689Skan int (*types_compatible_p) (tree x, tree y); 394169689Skan 395132718Skan /* Given a CALL_EXPR, return a function decl that is its target. */ 396132718Skan tree (*lang_get_callee_fndecl) (tree); 397132718Skan 398117395Skan /* Called by report_error_function to print out function name. */ 399132718Skan void (*print_error_function) (struct diagnostic_context *, const char *); 400117395Skan 401102780Skan /* Called from expr_size to calculate the size of the value of an 402102780Skan expression in a language-dependent way. Returns a tree for the size 403102780Skan in bytes. A frontend can call lhd_expr_size to get the default 404102780Skan semantics in cases that it doesn't want to handle specially. */ 405132718Skan tree (*expr_size) (tree); 406102780Skan 407169689Skan /* Convert a character from the host's to the target's character 408169689Skan set. The character should be in what C calls the "basic source 409169689Skan character set" (roughly, the set of characters defined by plain 410169689Skan old ASCII). The default is to return the character unchanged, 411169689Skan which is correct in most circumstances. Note that both argument 412169689Skan and result should be sign-extended under -fsigned-char, 413169689Skan zero-extended under -fno-signed-char. */ 414169689Skan HOST_WIDE_INT (*to_target_charset) (HOST_WIDE_INT); 415132718Skan 416117395Skan /* Pointers to machine-independent attribute tables, for front ends 417117395Skan using attribs.c. If one is NULL, it is ignored. Respectively, a 418117395Skan table of attributes specific to the language, a table of 419117395Skan attributes common to two or more languages (to allow easy 420117395Skan sharing), and a table of attributes for checking formats. */ 421117395Skan const struct attribute_spec *attribute_table; 422117395Skan const struct attribute_spec *common_attribute_table; 423117395Skan const struct attribute_spec *format_attribute_table; 424117395Skan 425117395Skan /* Function-related language hooks. */ 426117395Skan struct lang_hooks_for_functions function; 427117395Skan 42890075Sobrien struct lang_hooks_for_tree_inlining tree_inlining; 429117395Skan 430132718Skan struct lang_hooks_for_callgraph callgraph; 431132718Skan 43290075Sobrien struct lang_hooks_for_tree_dump tree_dump; 43390075Sobrien 434117395Skan struct lang_hooks_for_decls decls; 435117395Skan 436117395Skan struct lang_hooks_for_types types; 437117395Skan 438169689Skan /* Perform language-specific gimplification on the argument. Returns an 439169689Skan enum gimplify_status, though we can't see that type here. */ 440169689Skan int (*gimplify_expr) (tree *, tree *, tree *); 441132718Skan 442169689Skan /* Fold an OBJ_TYPE_REF expression to the address of a function. 443169689Skan KNOWN_TYPE carries the true type of the OBJ_TYPE_REF_OBJECT. */ 444169689Skan tree (*fold_obj_type_ref) (tree, tree); 445169689Skan 446169689Skan /* Return a definition for a builtin function named NAME and whose data type 447169689Skan is TYPE. TYPE should be a function type with argument types. 448169689Skan FUNCTION_CODE tells later passes how to compile calls to this function. 449169689Skan See tree.h for its possible values. 450169689Skan 451169689Skan If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, 452169689Skan the name to be called if we can't opencode the function. If 453169689Skan ATTRS is nonzero, use that for the function's attribute list. */ 454169689Skan tree (*builtin_function) (const char *name, tree type, int function_code, 455169689Skan enum built_in_class bt_class, 456169689Skan const char *library_name, tree attrs); 457169689Skan 458169689Skan /* Used to set up the tree_contains_structure array for a frontend. */ 459169689Skan void (*init_ts) (void); 460169689Skan 461169689Skan /* Called by recompute_tree_invariant_for_addr_expr to go from EXPR 462169689Skan to a contained expression or DECL, possibly updating *TC, *TI or 463169689Skan *SE if in the process TREE_CONSTANT, TREE_INVARIANT or 464169689Skan TREE_SIDE_EFFECTS need updating. */ 465169689Skan tree (*expr_to_decl) (tree expr, bool *tc, bool *ti, bool *se); 466169689Skan 46790075Sobrien /* Whenever you add entries here, make sure you adjust langhooks-def.h 46890075Sobrien and langhooks.c accordingly. */ 46990075Sobrien}; 47090075Sobrien 47190075Sobrien/* Each front end provides its own. */ 47290075Sobrienextern const struct lang_hooks lang_hooks; 47390075Sobrien 47490075Sobrien#endif /* GCC_LANG_HOOKS_H */ 475