GCC 重要数据之 lang_hooks

来源:互联网 发布:mac视频播放器 编辑:程序博客网 时间:2024/06/14 15:45
每个前端处理都有这样一个对象,比如C,C++,java等。
/* Each front end provides its own.  */extern struct lang_hooks lang_hooks;

/* Language-specific hooks.  See langhooks-def.h for defaults.  */

struct lang_hooks{  /* String identifying the front end and optionally language standard     version, e.g. "GNU C++98" or "GNU Java".  */  const char *name;

  /* sizeof (struct lang_identifier), so make_node () creates     identifier nodes long enough for the language-specific slots.  */  size_t identifier_size;

  /* Remove any parts of the tree that are used only by the FE. */  void (*free_lang_data) (tree);

  /* Determines the size of any language-specific tcc_constant or     tcc_exceptional nodes.  Since it is called from make_node, the     only information available is the tree code.  Expected to die     on unrecognized codes.  */  size_t (*tree_size) (enum tree_code);

  /* Return the language mask used for converting argv into a sequence     of options.  */  unsigned int (*option_lang_mask) (void);

  /* Initialize variables in an options structure.  */  void (*init_options_struct) (struct gcc_options *opts);

  /* After the initialize_diagnostics hook is called, do any simple     initialization needed before any calls to handle_option, other     than that done by the init_options_struct hook.  */  void (*init_options) (unsigned int decoded_options_count,   struct cl_decoded_option *decoded_options);

  /* Callback used to perform language-specific initialization for the     global diagnostic context structure.  */  void (*initialize_diagnostics) (diagnostic_context *);

  /* Return true if a warning should be given about option OPTION,     which is for the wrong language, false if it should be quietly     ignored.  */  bool (*complain_wrong_lang_p) (const struct cl_option *option);

  /* Handle the switch CODE, which has real type enum opt_code from     options.h.  If the switch takes an argument, it is passed in ARG     which points to permanent storage.  The handler is responsible for     checking whether ARG is NULL, which indicates that no argument     was in fact supplied.  For -f and -W switches, VALUE is 1 or 0     for the positive and negative forms respectively.  HANDLERS should     be passed to any recursive handle_option calls.  LOC is the     location of the option.

     Return true if the switch is valid, false if invalid.  */  bool (*handle_option) (size_t code, const char *arg, int value, int kind,    location_t loc,    const struct cl_option_handlers *handlers);

  /* Called when all command line options have been parsed to allow     further processing and initialization

     Should return true to indicate that a compiler back-end is     not required, such as with the -E option.

     If errorcount is nonzero after this call the compiler exits     immediately and the finish hook is not called.  */  bool (*post_options) (const char **);

  /* Called after post_options to initialize the front end.  Return     false to indicate that no further compilation be performed, in     which case the finish hook is called immediately.  */  bool (*init) (void);

  /* Called at the end of compilation, as a finalizer.  */  void (*finish) (void);

  /* Parses the entire file.  */  void (*parse_file) (void);

  /* Determines if it's ok for a function to have no noreturn attribute.  */  bool (*missing_noreturn_ok_p) (tree);

  /* Called to obtain the alias set to be used for an expression or type.     Returns -1 if the language does nothing special for it.  */  alias_set_type (*get_alias_set) (tree);

  /* Function to finish handling an incomplete decl at the end of     compilation.  Default hook is does nothing.  */  void (*finish_incomplete_decl) (tree);

  /* Replace the DECL_LANG_SPECIFIC data, which may be NULL, of the     DECL_NODE with a newly GC-allocated copy.  */  void (*dup_lang_specific_decl) (tree);

  /* Set the DECL_ASSEMBLER_NAME for a node.  If it is the sort of     thing that the assembler should talk about, set     DECL_ASSEMBLER_NAME to an appropriate IDENTIFIER_NODE.     Otherwise, set it to the ERROR_MARK_NODE to ensure that the     assembler does not talk about it.  */  void (*set_decl_assembler_name) (tree);

  /* The front end can add its own statistics to -fmem-report with     this hook.  It should output to stderr.  */  void (*print_statistics) (void);

  /* Called by print_tree when there is a tree of class tcc_exceptional     that it doesn't know how to display.  */  lang_print_tree_hook print_xnode;

  /* Called to print language-dependent parts of tcc_decl, tcc_type,     and IDENTIFIER_NODE nodes.  */  lang_print_tree_hook print_decl;  lang_print_tree_hook print_type;  lang_print_tree_hook print_identifier;

  /* Computes the name to use to print a declaration.  DECL is the     non-NULL declaration in question.  VERBOSITY determines what     information will be printed: 0: DECL_NAME, demangled as     necessary.  1: and scope information.  2: and any other     information that might be interesting, such as function parameter     types in C++.  The name is in the internal character set and     needs to be converted to the locale character set of diagnostics,     or to the execution character set for strings such as     __PRETTY_FUNCTION__.  */  const char *(*decl_printable_name) (tree decl, int verbosity);

  /* Computes the dwarf-2/3 name for a tree.  VERBOSITY determines what     information will be printed: 0: DECL_NAME, demangled as     necessary.  1: and scope information.  */  const char *(*dwarf_name) (tree, int verbosity);

  /* This compares two types for equivalence ("compatible" in C-based languages).     This routine should only return 1 if it is sure.  It should not be used     in contexts where erroneously returning 0 causes problems.  */  int (*types_compatible_p) (tree x, tree y);

  /* Called by report_error_function to print out function name.  */  void (*print_error_function) (diagnostic_context *, const char *,    struct diagnostic_info *);

  /* Convert a character from the host's to the target's character     set.  The character should be in what C calls the "basic source     character set" (roughly, the set of characters defined by plain     old ASCII).  The default is to return the character unchanged,     which is correct in most circumstances.  Note that both argument     and result should be sign-extended under -fsigned-char,     zero-extended under -fno-signed-char.  */  HOST_WIDE_INT (*to_target_charset) (HOST_WIDE_INT);

  /* Pointers to machine-independent attribute tables, for front ends     using attribs.c.  If one is NULL, it is ignored.  Respectively, a     table of attributes specific to the language, a table of     attributes common to two or more languages (to allow easy     sharing), and a table of attributes for checking formats.  */  const struct attribute_spec *attribute_table;  const struct attribute_spec *common_attribute_table;  const struct attribute_spec *format_attribute_table;

  struct lang_hooks_for_tree_inlining tree_inlining;

  struct lang_hooks_for_tree_dump tree_dump;

  struct lang_hooks_for_decls decls;

  struct lang_hooks_for_types types;    struct lang_hooks_for_lto lto;

  /* Returns a TREE_VEC of the generic parameters of an instantiation of     a generic type or decl, e.g. C++ template instantiation.  If     TREE_CHAIN of the return value is set, it is an INTEGER_CST     indicating how many of the elements are non-default.  */  tree (*get_innermost_generic_parms) (const_tree);

  /* Returns the TREE_VEC of arguments of an instantiation     of a generic type of decl, e.g. C++ template instantiation.  */  tree (*get_innermost_generic_args) (const_tree);

  /* Determine if a tree is a function parameter pack.  */  bool (*function_parameter_pack_p) (const_tree);

  /* Perform language-specific gimplification on the argument.  Returns an     enum gimplify_status, though we can't see that type here.  */  int (*gimplify_expr) (tree *, gimple_seq *, gimple_seq *);

  /* Do language specific processing in the builtin function DECL  */  tree (*builtin_function) (tree decl);

  /* Like builtin_function, but make sure the scope is the external scope.     This is used to delay putting in back end builtin functions until the ISA     that defines the builtin is declared via function specific target options,     which can save memory for machines like the x86_64 that have multiple     ISAs.  If this points to the same function as builtin_function, the     backend must add all of the builtins at program initialization time.  */  tree (*builtin_function_ext_scope) (tree decl);

  /* Used to set up the tree_contains_structure array for a frontend. */  void (*init_ts) (void);

  /* Called by recompute_tree_invariant_for_addr_expr to go from EXPR     to a contained expression or DECL, possibly updating *TC or *SE     if in the process TREE_CONSTANT or TREE_SIDE_EFFECTS need updating.  */  tree (*expr_to_decl) (tree expr, bool *tc, bool *se);

  /* The EH personality function decl.  */  tree (*eh_personality) (void);

  /* Map a type to a runtime object to match type.  */  tree (*eh_runtime_type) (tree);

  /* If non-NULL, this is a function that returns a function decl to be     executed if an unhandled exception is propagated out of a cleanup     region.  For example, in C++, an exception thrown by a destructor     during stack unwinding is required to result in a call to     `std::terminate', so the C++ version of this function returns a     FUNCTION_DECL for `std::terminate'.  */  tree (*eh_protect_cleanup_actions) (void);

  /* Return true if a stmt can fallthru.  Used by block_may_fallthru     to possibly handle language trees.  */  bool (*block_may_fallthru) (const_tree);

  /* True if this language uses __cxa_end_cleanup when the ARM EABI     is enabled.  */  bool eh_use_cxa_end_cleanup;

  /* True if this language requires deep unsharing of tree nodes prior to     gimplification.  */  bool deep_unsharing;

  /* Whenever you add entries here, make sure you adjust langhooks-def.h     and langhooks.c accordingly.  */};

 
0 0