gcc/gcc/go/go-lang.c
Trevor Saunders 766090c20f use templates instead of gengtype for typed allocation functions
gcc/ChangeLog:

	* alias.c (record_alias_subset): Adjust.
	* bitmap.c (bitmap_element_allocate): Likewise.
	(bitmap_gc_alloc_stat): Likewise.
	* cfg.c (init_flow): Likewise.
	(alloc_block): Likewise.
	(unchecked_make_edge): Likewise.
	* cfgloop.c (alloc_loop): Likewise.
	(flow_loops_find): Likewise.
	(rescan_loop_exit): Likewise.
	* cfgrtl.c (init_rtl_bb_info): Likewise.
	* cgraph.c (insert_new_cgraph_node_version): Likewise.
	(cgraph_allocate_node): Likewise.
	(cgraph_create_edge_1): Likewise.
	(cgraph_allocate_init_indirect_info): Likewise.
	* cgraphclones.c (cgraph_clone_edge): Likewise.
	* cgraphunit.c (add_asm_node): Likewise.
	(init_lowered_empty_function): Likewise.
	* config/aarch64/aarch64.c (aarch64_init_machine_status):
	Likewise.
	* config/alpha/alpha.c (alpha_init_machine_status): Likewise.
	(alpha_use_linkage): Likewise.
	* config/arc/arc.c (arc_init_machine_status): Likewise.
	* config/arm/arm.c (arm_init_machine_status): Likewise.
	* config/avr/avr.c (avr_init_machine_status): Likewise.
	* config/bfin/bfin.c (bfin_init_machine_status): Likewise.
	* config/c6x/c6x.c (c6x_init_machine_status): Likewise.
	* config/cris/cris.c (cris_init_machine_status): Likewise.
	* config/darwin.c (machopic_indirection_name): Likewise.
	(darwin_build_constant_cfstring): Likewise.
	(darwin_enter_string_into_cfstring_table): Likewise.
	* config/epiphany/epiphany.c (epiphany_init_machine_status):
	* Likewise.
	* config/frv/frv.c (frv_init_machine_status): Likewise.
	* config/i386/i386.c (get_dllimport_decl): Likewise.
	(ix86_init_machine_status): Likewise.
	(assign_386_stack_local): Likewise.
	* config/i386/winnt.c (i386_pe_record_external_function):
	Likewise.
	(i386_pe_maybe_record_exported_symbol): Likewise.
	(i386_pe_record_stub): Likewise.
	* config/ia64/ia64.c (ia64_init_machine_status): Likewise.
	* config/iq2000/iq2000.c (iq2000_init_machine_status): Likewise.
	* config/m32c/m32c.c (m32c_init_machine_status): Likewise.
	(m32c_note_pragma_address): Likewise.
	* config/mep/mep.c (mep_init_machine_status): Likewise.
	(mep_note_pragma_flag): Likewise.
	* config/mips/mips.c (mflip_mips16_use_mips16_p): Likewise.
	(mips16_local_alias): Likewise.
	(mips_init_machine_status): Likewise.
	* config/mmix/mmix.c (mmix_init_machine_status): Likewise.
	* config/moxie/moxie.c (moxie_init_machine_status): Likewise.
	* config/msp430/msp430.c (msp430_init_machine_status): Likewise.
	* config/nds32/nds32.c (nds32_init_machine_status): Likewise.
	* config/nios2/nios2.c (nios2_init_machine_status): Likewise.
	* config/pa/pa.c (pa_init_machine_status): Likewise.
	(pa_get_deferred_plabel): Likewise.
	* config/rl78/rl78.c (rl78_init_machine_status): Likewise.
	* config/rs6000/rs6000.c (builtin_function_type): Likewise.
	(rs6000_init_machine_status): Likewise.
	(output_toc): Likewise.
	* config/s390/s390.c (s390_init_machine_status): Likewise.
	* config/score/score.c (score_output_external): Likewise.
	* config/sparc/sparc.c (sparc_init_machine_status): Likewise.
	* config/spu/spu.c (spu_init_machine_status): Likewise.
	* config/tilegx/tilegx.c (tilegx_init_machine_status): Likewise.
	* config/tilepro/tilepro.c (tilepro_init_machine_status):
	* Likewise.
	* config/xtensa/xtensa.c (xtensa_init_machine_status): Likewise.
	* coverage.c (coverage_end_function): Likewise.
	* dbxout.c (dbxout_init): Likewise.
	* doc/gty.texi: Don't mention variable_size attribute.
	* dwarf2cfi.c (new_cfi): Adjust.
	(new_cfi_row): Likewise.
	(copy_cfi_row): Likewise.
	(create_cie_data): Likewise.
	* dwarf2out.c (dwarf2out_alloc_current_fde): Likewise.
	(new_loc_descr): Likewise.
	(find_AT_string_in_table): Likewise.
	(add_addr_table_entry): Likewise.
	(new_die): Likewise.
	(add_var_loc_to_decl): Likewise.
	(clone_die): Likewise.
	(clone_as_declaration): Likewise.
	(break_out_comdat_types): Likewise.
	(new_loc_list): Likewise.
	(add_loc_descr_to_each): Likewise.
	(add_location_or_const_value_attribute): Likewise.
	(add_linkage_name): Likewise.
	(lookup_filename): Likewise.
	(dwarf2out_var_location): Likewise.
	(new_line_info_table): Likewise.
	(dwarf2out_init): Likewise.
	(mem_loc_descriptor): Likewise.
	(loc_descriptor): Likewise.
	(add_const_value_attribute): Likewise.
	(tree_add_const_value_attribute): Likewise.
	(comp_dir_string): Likewise.
	(dwarf2out_vms_debug_main_pointer): Likewise.
	(string_cst_pool_decl): Likewise.
	* emit-rtl.c (set_mem_attrs): Likewise.
	(get_reg_attrs): Likewise.
	(start_sequence): Likewise.
	(init_emit): Likewise.
	(init_emit_regs): Likewise.
	* except.c (init_eh_for_function): Likewise.
	(gen_eh_region): Likewise.
	(gen_eh_region_catch): Likewise.
	(gen_eh_landing_pad): Likewise.
	(add_call_site): Likewise.
	* function.c (add_frame_space): Likewise.
	(insert_temp_slot_address): Likewise.
	(assign_stack_temp_for_type): Likewise.
	(get_hard_reg_initial_val): Likewise.
	(allocate_struct_function): Likewise.
	(prepare_function_start): Likewise.
	(types_used_by_var_decl_insert): Likewise.
	* gengtype.c (variable_size_p): Remove function.
	(enum alloc_quantity): Remove enum.
	(write_typed_alloc_def): Remove function.
	(write_typed_struct_alloc_def): Likewise.
	(write_typed_typedef_alloc_def): Likewise.
	(write_typed_alloc_defns): Likewise.
	(main): Adjust.
	* ggc-common.c (ggc_cleared_alloc_htab_ignore_args): Adjust.
	(ggc_cleared_alloc_ptr_array_two_args): Likewise.
	* ggc.h (ggc_alloc): new function.
	(ggc_cleared_alloc): Likewise.
	(ggc_vec_alloc): Template on type of vector element, and remove
	element size argument.
	(ggc_cleared_vec_alloc): Likewise.
	* gimple.c (gimple_build_omp_for): Adjust.
	(gimple_copy): Likewise.
	* ipa-cp.c (get_replacement_map): Likewise.
	(find_aggregate_values_for_callers_subset): Likewise.
	(known_aggs_to_agg_replacement_list): Likewise.
	* ipa-devirt.c (get_odr_type): Likewise.
	* ipa-prop.c (ipa_node_duplication_hook): Likewise.
	(read_agg_replacement_chain): Likewise.
	* loop-iv.c (get_simple_loop_desc): Likewise.
	* lto-cgraph.c (input_node_opt_summary): Likewise.
	* lto-section-in.c (lto_new_in_decl_state): Likewise.
	* lto-streamer-in.c (lto_input_eh_catch_list): Likewise.
	(input_eh_region): Likewise.
	(input_eh_lp): Likewise.
	(input_cfg): Likewise.
	* optabs.c (set_optab_libfunc): Likewise.
	(init_tree_optimization_optabs): Likewise.
	(set_conv_libfunc): Likewise.
	* passes.c (do_per_function_toporder): Likewise.
	* rtl.h: Don't use variable_size gty attribute.
	* sese.c (if_region_set_false_region): Adjust.
	* stringpool.c (gt_pch_save_stringpool): Likewise.
	* target-globals.c (save_target_globals): Likewise.
	* toplev.c (general_init): Likewise.
	* trans-mem.c (record_tm_replacement): Likewise.
	(split_bb_make_tm_edge): Likewise.
	* tree-cfg.c (move_sese_region_to_fn): Likewise.
	* tree-data-ref.h (lambda_vector_new): Likewise.
	* tree-eh.c (add_stmt_to_eh_lp_fn): Likewise.
	* tree-iterator.c (tsi_link_before): Likewise.
	(tsi_link_after): Likewise.
	* tree-scalar-evolution.c (new_scev_info_str): Likewise.
	* tree-ssa-loop-niter.c (record_estimate): Likewise.
	* tree-ssa-operands.c (ssa_operand_alloc): Likewise.
	* tree-ssa-operands.h: Don't use variable_size gty attribute.
	* tree-ssa.c (init_tree_ssa): Adjust.
	* tree-ssanames.c (set_range_info): Likewise.
	(get_ptr_info): Likewise.
	(duplicate_ssa_name_ptr_info): Likewise.
	(duplicate_ssa_name_range_info): Likewise.
	* tree-streamer-in.c (unpack_ts_real_cst_value_fields): Likewise.
	(unpack_ts_fixed_cst_value_fields): Likewise.
	* tree.c (build_fixed): Likewise.
	(build_real): Likewise.
	(build_string): Likewise.
	(decl_priority_info): Likewise.
	(decl_debug_expr_insert): Likewise.
	(decl_value_expr_insert): Likewise.
	(decl_debug_args_insert): Likewise.
	(type_hash_add): Likewise.
	(build_omp_clause): Likewise.
	* ubsan.c (decl_for_type_insert): Likewise.
	* varasm.c (get_unnamed_section): Likewise.
	(get_noswitch_section): Likewise.
	(get_section): Likewise.
	(get_block_for_section): Likewise.
	(create_block_symbol): Likewise.
	(build_constant_desc): Likewise.
	(create_constant_pool): Likewise.
	(force_const_mem): Likewise.
	(record_tm_clone_pair): Likewise.
	* varpool.c (varpool_create_empty_node): Likewise.

gcc/c/ChangeLog:

	* c-decl.c (finish_struct): Adjust.
	(finish_enum): Likewise.
	(bind): Adjust.
	(record_inline_static): Likewise.
	(push_scope): Likewise.
	(make_label): Likewise.
	(lookup_label_for_goto): Likewise.
	(finish_struct): Likewise.
	(finish_enum): Likewise.
	(store_parm_decls): Likewise.
	(c_push_function_context): Likewise.
	* c-lang.h: Remove usage of variable_size gty attribute.
	* c-parser.c (c_parse_init): Adjust.
	(c_parse_file): Likewise.

gcc/java/ChangeLog:

	* class.c (add_method_1): Adjust.
	(java_treetreehash_new): Likewise.
	* constants.c (set_constant_entry): Likewise.
	(cpool_for_class): Likewise.
	* decl.c (make_binding_level): Likewise.
	(java_dup_lang_specific_decl): Likewise.
	* expr.c (add_type_assertion): Likewise.
	* java-tree.h (MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC): Likewise.
	(lang_decl): don't use variable_size gty attribute.
	(MAYBE_CREATE_TYPE_TYPE_LANG_SPECIFIC): Adjust.
	(lang_type): Don't use variable_size gty attribute.
	* jcf-parse.c (java_parse_file): Adjust.
	(process_zip_dir): Likewise.
	* jcf.h: Remove usage of variable_size gty attribute.
	* jcf-reader.c (jcf_parse_constant_pool): Adjust.
	(jcf_parse_bootstrap_methods): Likewise.

gcc/objc/ChangeLog:

	* objc-act.c (objc_build_string_object): Adjust.
	(continue_class): Likewise.
	* objc-act.h (ALLOC_OBJC_TYPE_LANG_SPECIFIC): Likewise.
	* objc-map.c (objc_map_alloc_ggc): Likewise.
	(objc_map_private_resize): Likewise.
	* objc-next-runtime-abi-02.c (objc_next_runtime_abi_02_init):
	Likewise.
	(hash_name_enter): Likewise.

gcc/cp/ChangeLog:

	* class.c (sorted_fields_type_new): Adjust.
	* cp-cilkplus.c (cilk_install_body_with_frame_cleanup): Likewise.
	* cp-objcp-common.c (decl_shadowed_for_var_insert): Likewise.
	* cp-tree.h: Remove usage of variable_size gty attribute.
	* decl.c (make_label_decl): Adjust.
	(check_goto): Likewise.
	(start_preparsed_function): Likewise.
	(save_function_data): Likewise.
	* lex.c (init_reswords): Likewise.
	(retrofit_lang_decl): Likewise.
	(cxx_dup_lang_specific_decl): Likewise.
	(copy_lang_type): Likewise.
	(cxx_make_type): Likewise.
	* name-lookup.c (binding_entry_make): Likewise.
	(binding_table_construct): Likewise.
	(binding_table_new): Likewise.
	(cxx_binding_make): Likewise.
	(pushdecl_maybe_friend_1): Likewise.
	(begin_scope): Likewise.
	(push_to_top_level): Likewise.
	* parser.c (cp_lexer_alloc): Likewise.
	(cp_lexer_new_from_tokens): Likewise.
	(cp_token_cache_new): Likewise.
	(cp_parser_context_new): Likewise.
	(cp_parser_new): Likewise.
	(cp_parser_nested_name_specifier_opt): Likewise.
	(cp_parser_template_id): Likewise.
	* pt.c (maybe_process_partial_specialization): Likewise.
	(register_specialization): Likewise.
	(add_pending_template): Likewise.
	(lookup_template_class_1): Likewise.
	(push_tinst_level): Likewise.
	* semantics.c (register_constexpr_fundef): Likewise.
	(cxx_eval_call_expression): Likewise.
	* typeck2.c (abstract_virtuals_error_sfinae): Likewise.

gcc/fortran/ChangeLog:

	* f95-lang.c (pushlevel): Adjust.
	* trans-decl.c (gfc_allocate_lang_decl): Adjust.
	(gfc_find_module): Likewise.
	* trans-types.c (gfc_get_nodesc_array_type): Likewise.
	(gfc_get_array_type_bounds): Likewise.
	(gfc_nonrestricted_type): Likewise.
	* trans.h: Don't use variable_size gty attribute.

gcc/ada/ChangeLog:

	* gcc-interface/ada-tree.h: Remove usage of variable_size gty
	annotation.
	* gcc-interface/decl.c (annotate_value): Adjust.
	* gcc-interface/trans.c (Attribute_to_gnu): Likewise.
	(push_range_check_info): Likewise.
	(Loop_Statement_to_gnu): Likewise.
	(Subprogram_Body_to_gnu): Likewise.
	(Compilation_Unit_to_gnu): Likewise.
	(start_stmt_group): Likewise.
	* gcc-interface/utils.c (init_gnat_utils): Likewise.
	(gnat_pushlevel): Likewise.
	(maybe_pad_type): Likewise.

gcc/go/ChangeLog:

	* go-lang.c (struct GTY): Don't use variable_size gty attribute.

gcc/c-family/ChangeLog:

	* c-common.h (sorted_fields_type): Remove variable_size GTY attribute.
	* c-pragma.c (push_alignment): Adjust.
	(handle_pragma_push_options): Likewise.

gcc/lto/ChangeLog:

	* lto-tree.h: Don't use variable_size gty attribute.
	* lto.c (lto_read_in_decl_state): Adjust.
	(create_subid_section_table): Likewise.
	(lto_flatten_files): Likewise.
	(read_cgraph_and_symbols): Likewise.

gcc/objcp/ChangeLog:

	* objcp-decl.h: Adjust.

From-SVN: r210566
2014-05-17 23:07:23 +00:00

562 lines
15 KiB
C

/* go-lang.c -- Go frontend gcc interface.
Copyright (C) 2009-2014 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include "config.h"
#include "system.h"
#include "ansidecl.h"
#include "coretypes.h"
#include "opts.h"
#include "tree.h"
#include "basic-block.h"
#include "gimple-expr.h"
#include "gimplify.h"
#include "stor-layout.h"
#include "toplev.h"
#include "debug.h"
#include "options.h"
#include "flags.h"
#include "convert.h"
#include "diagnostic.h"
#include "langhooks.h"
#include "langhooks-def.h"
#include "target.h"
#include "common/common-target.h"
#include <mpfr.h>
#include "go-c.h"
/* Language-dependent contents of a type. */
struct GTY(()) lang_type
{
char dummy;
};
/* Language-dependent contents of a decl. */
struct GTY(()) lang_decl
{
char dummy;
};
/* Language-dependent contents of an identifier. This must include a
tree_identifier. */
struct GTY(()) lang_identifier
{
struct tree_identifier common;
};
/* The resulting tree type. */
union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
lang_tree_node
{
union tree_node GTY((tag ("0"),
desc ("tree_node_structure (&%h)"))) generic;
struct lang_identifier GTY((tag ("1"))) identifier;
};
/* We don't use language_function. */
struct GTY(()) language_function
{
int dummy;
};
/* Option information we need to pass to go_create_gogo. */
static const char *go_pkgpath = NULL;
static const char *go_prefix = NULL;
static const char *go_relative_import_path = NULL;
/* Language hooks. */
static bool
go_langhook_init (void)
{
build_common_tree_nodes (false, false);
/* I don't know why this has to be done explicitly. */
void_list_node = build_tree_list (NULL_TREE, void_type_node);
/* We must create the gogo IR after calling build_common_tree_nodes
(because Gogo::define_builtin_function_trees refers indirectly
to, e.g., unsigned_char_type_node) but before calling
build_common_builtin_nodes (because it calls, indirectly,
go_type_for_size). */
go_create_gogo (INT_TYPE_SIZE, POINTER_SIZE, go_pkgpath, go_prefix,
go_relative_import_path, go_check_divide_zero,
go_check_divide_overflow);
build_common_builtin_nodes ();
/* The default precision for floating point numbers. This is used
for floating point constants with abstract type. This may
eventually be controllable by a command line option. */
mpfr_set_default_prec (256);
/* Go uses exceptions. */
using_eh_for_cleanups ();
return true;
}
/* The option mask. */
static unsigned int
go_langhook_option_lang_mask (void)
{
return CL_Go;
}
/* Initialize the options structure. */
static void
go_langhook_init_options_struct (struct gcc_options *opts)
{
/* Go says that signed overflow is precisely defined. */
opts->x_flag_wrapv = 1;
/* We default to using strict aliasing, since Go pointers are safe.
This is turned off for code that imports the "unsafe" package,
because using unsafe.pointer violates C style aliasing
requirements. */
opts->x_flag_strict_aliasing = 1;
/* Default to avoiding range issues for complex multiply and
divide. */
opts->x_flag_complex_method = 2;
/* The builtin math functions should not set errno. */
opts->x_flag_errno_math = 0;
opts->frontend_set_flag_errno_math = true;
/* We turn on stack splitting if we can. */
if (targetm_common.supports_split_stack (false, opts))
opts->x_flag_split_stack = 1;
/* Exceptions are used to handle recovering from panics. */
opts->x_flag_exceptions = 1;
opts->x_flag_non_call_exceptions = 1;
}
/* Infrastructure for a vector of char * pointers. */
typedef const char *go_char_p;
/* The list of directories to search after all the Go specific
directories have been searched. */
static vec<go_char_p> go_search_dirs;
/* Handle Go specific options. Return 0 if we didn't do anything. */
static bool
go_langhook_handle_option (
size_t scode,
const char *arg,
int value ATTRIBUTE_UNUSED,
int kind ATTRIBUTE_UNUSED,
location_t loc ATTRIBUTE_UNUSED,
const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
{
enum opt_code code = (enum opt_code) scode;
bool ret = true;
switch (code)
{
case OPT_I:
go_add_search_path (arg);
break;
case OPT_L:
/* A -L option is assumed to come from the compiler driver.
This is a system directory. We search the following
directories, if they exist, before this one:
dir/go/VERSION
dir/go/VERSION/MACHINE
This is like include/c++. */
{
static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
size_t len;
char *p;
struct stat st;
len = strlen (arg);
p = XALLOCAVEC (char,
(len + sizeof "go" + sizeof DEFAULT_TARGET_VERSION
+ sizeof DEFAULT_TARGET_MACHINE + 3));
strcpy (p, arg);
if (len > 0 && !IS_DIR_SEPARATOR (p[len - 1]))
strcat (p, dir_separator_str);
strcat (p, "go");
strcat (p, dir_separator_str);
strcat (p, DEFAULT_TARGET_VERSION);
if (stat (p, &st) == 0 && S_ISDIR (st.st_mode))
{
go_add_search_path (p);
strcat (p, dir_separator_str);
strcat (p, DEFAULT_TARGET_MACHINE);
if (stat (p, &st) == 0 && S_ISDIR (st.st_mode))
go_add_search_path (p);
}
/* Search ARG too, but only after we've searched to Go
specific directories for all -L arguments. */
go_search_dirs.safe_push (arg);
}
break;
case OPT_fgo_dump_:
ret = go_enable_dump (arg) ? true : false;
break;
case OPT_fgo_optimize_:
ret = go_enable_optimize (arg) ? true : false;
break;
case OPT_fgo_pkgpath_:
go_pkgpath = arg;
break;
case OPT_fgo_prefix_:
go_prefix = arg;
break;
case OPT_fgo_relative_import_path_:
go_relative_import_path = arg;
break;
default:
/* Just return 1 to indicate that the option is valid. */
break;
}
return ret;
}
/* Run after parsing options. */
static bool
go_langhook_post_options (const char **pfilename ATTRIBUTE_UNUSED)
{
unsigned int ix;
const char *dir;
gcc_assert (num_in_fnames > 0);
FOR_EACH_VEC_ELT (go_search_dirs, ix, dir)
go_add_search_path (dir);
go_search_dirs.release ();
if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT)
flag_excess_precision_cmdline = EXCESS_PRECISION_STANDARD;
/* Tail call optimizations can confuse uses of runtime.Callers. */
if (!global_options_set.x_flag_optimize_sibling_calls)
global_options.x_flag_optimize_sibling_calls = 0;
/* Returning false means that the backend should be used. */
return false;
}
static void
go_langhook_parse_file (void)
{
go_parse_input_files (in_fnames, num_in_fnames, flag_syntax_only,
go_require_return_statement);
}
static tree
go_langhook_type_for_size (unsigned int bits, int unsignedp)
{
tree type;
if (unsignedp)
{
if (bits == INT_TYPE_SIZE)
type = unsigned_type_node;
else if (bits == CHAR_TYPE_SIZE)
type = unsigned_char_type_node;
else if (bits == SHORT_TYPE_SIZE)
type = short_unsigned_type_node;
else if (bits == LONG_TYPE_SIZE)
type = long_unsigned_type_node;
else if (bits == LONG_LONG_TYPE_SIZE)
type = long_long_unsigned_type_node;
else
type = make_unsigned_type(bits);
}
else
{
if (bits == INT_TYPE_SIZE)
type = integer_type_node;
else if (bits == CHAR_TYPE_SIZE)
type = signed_char_type_node;
else if (bits == SHORT_TYPE_SIZE)
type = short_integer_type_node;
else if (bits == LONG_TYPE_SIZE)
type = long_integer_type_node;
else if (bits == LONG_LONG_TYPE_SIZE)
type = long_long_integer_type_node;
else
type = make_signed_type(bits);
}
return type;
}
static tree
go_langhook_type_for_mode (enum machine_mode mode, int unsignedp)
{
tree type;
/* Go has no vector types. Build them here. FIXME: It does not
make sense for the middle-end to ask the frontend for a type
which the frontend does not support. However, at least for now
it is required. See PR 46805. */
if (VECTOR_MODE_P (mode))
{
tree inner;
inner = go_langhook_type_for_mode (GET_MODE_INNER (mode), unsignedp);
if (inner != NULL_TREE)
return build_vector_type_for_mode (inner, mode);
return NULL_TREE;
}
// FIXME: This static_cast should be in machmode.h.
enum mode_class mc = static_cast<enum mode_class>(GET_MODE_CLASS(mode));
if (mc == MODE_INT)
return go_langhook_type_for_size(GET_MODE_BITSIZE(mode), unsignedp);
else if (mc == MODE_FLOAT)
{
switch (GET_MODE_BITSIZE (mode))
{
case 32:
return float_type_node;
case 64:
return double_type_node;
default:
// We have to check for long double in order to support
// i386 excess precision.
if (mode == TYPE_MODE(long_double_type_node))
return long_double_type_node;
}
}
else if (mc == MODE_COMPLEX_FLOAT)
{
switch (GET_MODE_BITSIZE (mode))
{
case 64:
return complex_float_type_node;
case 128:
return complex_double_type_node;
default:
// We have to check for long double in order to support
// i386 excess precision.
if (mode == TYPE_MODE(complex_long_double_type_node))
return complex_long_double_type_node;
}
}
#if HOST_BITS_PER_WIDE_INT >= 64
/* The middle-end and some backends rely on TImode being supported
for 64-bit HWI. */
if (mode == TImode)
{
type = build_nonstandard_integer_type (GET_MODE_BITSIZE (TImode),
unsignedp);
if (type && TYPE_MODE (type) == TImode)
return type;
}
#endif
return NULL_TREE;
}
/* Record a builtin function. We just ignore builtin functions. */
static tree
go_langhook_builtin_function (tree decl)
{
return decl;
}
/* Return true if we are in the global binding level. */
static bool
go_langhook_global_bindings_p (void)
{
return current_function_decl == NULL_TREE;
}
/* Push a declaration into the current binding level. We can't
usefully implement this since we don't want to convert from tree
back to one of our internal data structures. I think the only way
this is used is to record a decl which is to be returned by
getdecls, and we could implement it for that purpose if
necessary. */
static tree
go_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED)
{
gcc_unreachable ();
}
/* This hook is used to get the current list of declarations as trees.
We don't support that; instead we use the write_globals hook. This
can't simply crash because it is called by -gstabs. */
static tree
go_langhook_getdecls (void)
{
return NULL;
}
/* Write out globals. */
static void
go_langhook_write_globals (void)
{
go_write_globals ();
}
/* Go specific gimplification. We need to gimplify
CALL_EXPR_STATIC_CHAIN, because the gimplifier doesn't handle
it. */
static int
go_langhook_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
{
if (TREE_CODE (*expr_p) == CALL_EXPR
&& CALL_EXPR_STATIC_CHAIN (*expr_p) != NULL_TREE)
gimplify_expr (&CALL_EXPR_STATIC_CHAIN (*expr_p), pre_p, post_p,
is_gimple_val, fb_rvalue);
return GS_UNHANDLED;
}
/* Return a decl for the exception personality function. The function
itself is implemented in libgo/runtime/go-unwind.c. */
static tree
go_langhook_eh_personality (void)
{
static tree personality_decl;
if (personality_decl == NULL_TREE)
{
personality_decl = build_personality_function ("gccgo");
go_preserve_from_gc (personality_decl);
}
return personality_decl;
}
/* Functions called directly by the generic backend. */
tree
convert (tree type, tree expr)
{
if (type == error_mark_node
|| expr == error_mark_node
|| TREE_TYPE (expr) == error_mark_node)
return error_mark_node;
if (type == TREE_TYPE (expr))
return expr;
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
return fold_convert (type, expr);
switch (TREE_CODE (type))
{
case VOID_TYPE:
case BOOLEAN_TYPE:
return fold_convert (type, expr);
case INTEGER_TYPE:
return fold (convert_to_integer (type, expr));
case POINTER_TYPE:
return fold (convert_to_pointer (type, expr));
case REAL_TYPE:
return fold (convert_to_real (type, expr));
case COMPLEX_TYPE:
return fold (convert_to_complex (type, expr));
default:
break;
}
gcc_unreachable ();
}
/* FIXME: This is a hack to preserve trees that we create from the
garbage collector. */
static GTY(()) tree go_gc_root;
void
go_preserve_from_gc (tree t)
{
go_gc_root = tree_cons (NULL_TREE, t, go_gc_root);
}
/* Convert an identifier for use in an error message. */
const char *
go_localize_identifier (const char *ident)
{
return identifier_to_locale (ident);
}
#undef LANG_HOOKS_NAME
#undef LANG_HOOKS_INIT
#undef LANG_HOOKS_OPTION_LANG_MASK
#undef LANG_HOOKS_INIT_OPTIONS_STRUCT
#undef LANG_HOOKS_HANDLE_OPTION
#undef LANG_HOOKS_POST_OPTIONS
#undef LANG_HOOKS_PARSE_FILE
#undef LANG_HOOKS_TYPE_FOR_MODE
#undef LANG_HOOKS_TYPE_FOR_SIZE
#undef LANG_HOOKS_BUILTIN_FUNCTION
#undef LANG_HOOKS_GLOBAL_BINDINGS_P
#undef LANG_HOOKS_PUSHDECL
#undef LANG_HOOKS_GETDECLS
#undef LANG_HOOKS_WRITE_GLOBALS
#undef LANG_HOOKS_GIMPLIFY_EXPR
#undef LANG_HOOKS_EH_PERSONALITY
#define LANG_HOOKS_NAME "GNU Go"
#define LANG_HOOKS_INIT go_langhook_init
#define LANG_HOOKS_OPTION_LANG_MASK go_langhook_option_lang_mask
#define LANG_HOOKS_INIT_OPTIONS_STRUCT go_langhook_init_options_struct
#define LANG_HOOKS_HANDLE_OPTION go_langhook_handle_option
#define LANG_HOOKS_POST_OPTIONS go_langhook_post_options
#define LANG_HOOKS_PARSE_FILE go_langhook_parse_file
#define LANG_HOOKS_TYPE_FOR_MODE go_langhook_type_for_mode
#define LANG_HOOKS_TYPE_FOR_SIZE go_langhook_type_for_size
#define LANG_HOOKS_BUILTIN_FUNCTION go_langhook_builtin_function
#define LANG_HOOKS_GLOBAL_BINDINGS_P go_langhook_global_bindings_p
#define LANG_HOOKS_PUSHDECL go_langhook_pushdecl
#define LANG_HOOKS_GETDECLS go_langhook_getdecls
#define LANG_HOOKS_WRITE_GLOBALS go_langhook_write_globals
#define LANG_HOOKS_GIMPLIFY_EXPR go_langhook_gimplify_expr
#define LANG_HOOKS_EH_PERSONALITY go_langhook_eh_personality
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
#include "gt-go-go-lang.h"
#include "gtype-go.h"