]>
Commit | Line | Data |
---|---|---|
e53b6e56 | 1 | /* go-lang.cc -- Go frontend gcc interface. |
83ffe9cd | 2 | Copyright (C) 2009-2023 Free Software Foundation, Inc. |
7a938933 ILT |
3 | |
4 | This file is part of GCC. | |
5 | ||
6 | GCC is free software; you can redistribute it and/or modify it under | |
7 | the terms of the GNU General Public License as published by the Free | |
8 | Software Foundation; either version 3, or (at your option) any later | |
9 | version. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 | for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING3. If not see | |
18 | <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "config.h" | |
21 | #include "system.h" | |
7a938933 | 22 | #include "coretypes.h" |
2adfab87 | 23 | #include "target.h" |
2adfab87 AM |
24 | #include "tree.h" |
25 | #include "gimple-expr.h" | |
26 | #include "diagnostic.h" | |
7a938933 | 27 | #include "opts.h" |
40e23961 | 28 | #include "fold-const.h" |
45b0be94 | 29 | #include "gimplify.h" |
d8a2d370 | 30 | #include "stor-layout.h" |
7a938933 | 31 | #include "debug.h" |
7a938933 | 32 | #include "convert.h" |
7a938933 ILT |
33 | #include "langhooks.h" |
34 | #include "langhooks-def.h" | |
677f3fa8 | 35 | #include "common/common-target.h" |
7a938933 ILT |
36 | |
37 | #include <mpfr.h> | |
38 | ||
39 | #include "go-c.h" | |
3c061ac0 | 40 | #include "go-gcc.h" |
7a938933 | 41 | |
acdef7f8 TR |
42 | #ifndef TARGET_AIX |
43 | #define TARGET_AIX 0 | |
44 | #endif | |
45 | ||
7a938933 ILT |
46 | /* Language-dependent contents of a type. */ |
47 | ||
48 | struct GTY(()) lang_type | |
49 | { | |
50 | char dummy; | |
51 | }; | |
52 | ||
53 | /* Language-dependent contents of a decl. */ | |
54 | ||
766090c2 | 55 | struct GTY(()) lang_decl |
7a938933 ILT |
56 | { |
57 | char dummy; | |
58 | }; | |
59 | ||
60 | /* Language-dependent contents of an identifier. This must include a | |
61 | tree_identifier. */ | |
62 | ||
63 | struct GTY(()) lang_identifier | |
64 | { | |
65 | struct tree_identifier common; | |
66 | }; | |
67 | ||
68 | /* The resulting tree type. */ | |
69 | ||
70 | union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"), | |
81f653d6 | 71 | chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL"))) |
7a938933 ILT |
72 | lang_tree_node |
73 | { | |
74 | union tree_node GTY((tag ("0"), | |
75 | desc ("tree_node_structure (&%h)"))) generic; | |
76 | struct lang_identifier GTY((tag ("1"))) identifier; | |
77 | }; | |
78 | ||
79 | /* We don't use language_function. */ | |
80 | ||
81 | struct GTY(()) language_function | |
82 | { | |
83 | int dummy; | |
84 | }; | |
85 | ||
097b12fb ILT |
86 | /* Option information we need to pass to go_create_gogo. */ |
87 | ||
88 | static const char *go_pkgpath = NULL; | |
89 | static const char *go_prefix = NULL; | |
4e1866fe | 90 | static const char *go_relative_import_path = NULL; |
2adb671d | 91 | static const char *go_c_header = NULL; |
bf183413 | 92 | static const char *go_embedcfg = NULL; |
097b12fb | 93 | |
7a938933 ILT |
94 | /* Language hooks. */ |
95 | ||
96 | static bool | |
97 | go_langhook_init (void) | |
98 | { | |
a011cd92 | 99 | build_common_tree_nodes (false); |
7a938933 ILT |
100 | |
101 | /* We must create the gogo IR after calling build_common_tree_nodes | |
102 | (because Gogo::define_builtin_function_trees refers indirectly | |
103 | to, e.g., unsigned_char_type_node) but before calling | |
104 | build_common_builtin_nodes (because it calls, indirectly, | |
105 | go_type_for_size). */ | |
2adb671d ILT |
106 | struct go_create_gogo_args args; |
107 | args.int_type_size = INT_TYPE_SIZE; | |
108 | args.pointer_size = POINTER_SIZE; | |
109 | args.pkgpath = go_pkgpath; | |
110 | args.prefix = go_prefix; | |
111 | args.relative_import_path = go_relative_import_path; | |
112 | args.c_header = go_c_header; | |
bf183413 | 113 | args.embedcfg = go_embedcfg; |
2adb671d ILT |
114 | args.check_divide_by_zero = go_check_divide_zero; |
115 | args.check_divide_overflow = go_check_divide_overflow; | |
116 | args.compiling_runtime = go_compiling_runtime; | |
117 | args.debug_escape_level = go_debug_escape_level; | |
594d0e51 | 118 | args.debug_escape_hash = go_debug_escape_hash; |
acdef7f8 | 119 | args.nil_check_size_threshold = TARGET_AIX ? -1 : 4096; |
f837b9c4 | 120 | args.debug_optimization = go_debug_optimization; |
f4b9b136 | 121 | args.need_eqtype = TARGET_AIX ? true : false; |
3c061ac0 TM |
122 | args.linemap = go_get_linemap(); |
123 | args.backend = go_get_backend(); | |
2adb671d | 124 | go_create_gogo (&args); |
7a938933 ILT |
125 | |
126 | build_common_builtin_nodes (); | |
127 | ||
7a938933 ILT |
128 | /* The default precision for floating point numbers. This is used |
129 | for floating point constants with abstract type. This may | |
130 | eventually be controllable by a command line option. */ | |
1ec20ea1 | 131 | mpfr_set_default_prec (256); |
7a938933 | 132 | |
03ea48ff ILT |
133 | /* If necessary, override GCC's choice of minimum and maximum |
134 | exponents. This should only affect GCC middle-end | |
135 | compilation-time, not correctness. */ | |
136 | mpfr_exp_t exp = mpfr_get_emax (); | |
137 | if (exp < (1 << 16) - 1) | |
138 | mpfr_set_emax ((1 << 16) - 1); | |
139 | exp = mpfr_get_emin (); | |
140 | if (exp > - ((1 << 16) - 1)) | |
141 | mpfr_set_emin (- ((1 << 16) - 1)); | |
142 | ||
7a938933 ILT |
143 | /* Go uses exceptions. */ |
144 | using_eh_for_cleanups (); | |
145 | ||
146 | return true; | |
147 | } | |
148 | ||
149 | /* The option mask. */ | |
150 | ||
151 | static unsigned int | |
152 | go_langhook_option_lang_mask (void) | |
153 | { | |
154 | return CL_Go; | |
155 | } | |
156 | ||
157 | /* Initialize the options structure. */ | |
158 | ||
159 | static void | |
160 | go_langhook_init_options_struct (struct gcc_options *opts) | |
161 | { | |
162 | /* Go says that signed overflow is precisely defined. */ | |
163 | opts->x_flag_wrapv = 1; | |
164 | ||
165 | /* We default to using strict aliasing, since Go pointers are safe. | |
166 | This is turned off for code that imports the "unsafe" package, | |
167 | because using unsafe.pointer violates C style aliasing | |
168 | requirements. */ | |
169 | opts->x_flag_strict_aliasing = 1; | |
170 | ||
171 | /* Default to avoiding range issues for complex multiply and | |
172 | divide. */ | |
173 | opts->x_flag_complex_method = 2; | |
a64697d7 | 174 | opts->x_flag_default_complex_method = opts->x_flag_complex_method; |
7a938933 ILT |
175 | |
176 | /* The builtin math functions should not set errno. */ | |
177 | opts->x_flag_errno_math = 0; | |
9b548472 | 178 | opts->frontend_set_flag_errno_math = true; |
7a938933 | 179 | |
7a938933 ILT |
180 | /* Exceptions are used to handle recovering from panics. */ |
181 | opts->x_flag_exceptions = 1; | |
182 | opts->x_flag_non_call_exceptions = 1; | |
818424b2 | 183 | |
ede67376 ILT |
184 | /* We need to keep pointers live for the garbage collector. */ |
185 | opts->x_flag_keep_gc_roots_live = 1; | |
186 | ||
818424b2 ILT |
187 | /* Go programs expect runtime.Callers to work, and that uses |
188 | libbacktrace that uses debug info. Set the debug info level to 1 | |
189 | by default. In post_options we will set the debug type if the | |
190 | debug info level was not set back to 0 on the command line. */ | |
191 | opts->x_debug_info_level = DINFO_LEVEL_TERSE; | |
7a938933 ILT |
192 | } |
193 | ||
9771b263 | 194 | /* Infrastructure for a vector of char * pointers. */ |
ac819ba5 ILT |
195 | |
196 | typedef const char *go_char_p; | |
ac819ba5 ILT |
197 | |
198 | /* The list of directories to search after all the Go specific | |
199 | directories have been searched. */ | |
200 | ||
9771b263 | 201 | static vec<go_char_p> go_search_dirs; |
ac819ba5 | 202 | |
7a938933 ILT |
203 | /* Handle Go specific options. Return 0 if we didn't do anything. */ |
204 | ||
205 | static bool | |
206 | go_langhook_handle_option ( | |
207 | size_t scode, | |
208 | const char *arg, | |
00abf86c | 209 | HOST_WIDE_INT value, |
7a938933 ILT |
210 | int kind ATTRIBUTE_UNUSED, |
211 | location_t loc ATTRIBUTE_UNUSED, | |
212 | const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED) | |
213 | { | |
214 | enum opt_code code = (enum opt_code) scode; | |
215 | bool ret = true; | |
216 | ||
217 | switch (code) | |
218 | { | |
219 | case OPT_I: | |
7a938933 ILT |
220 | go_add_search_path (arg); |
221 | break; | |
222 | ||
ac819ba5 ILT |
223 | case OPT_L: |
224 | /* A -L option is assumed to come from the compiler driver. | |
225 | This is a system directory. We search the following | |
226 | directories, if they exist, before this one: | |
227 | dir/go/VERSION | |
228 | dir/go/VERSION/MACHINE | |
229 | This is like include/c++. */ | |
230 | { | |
231 | static const char dir_separator_str[] = { DIR_SEPARATOR, 0 }; | |
232 | size_t len; | |
233 | char *p; | |
234 | struct stat st; | |
235 | ||
236 | len = strlen (arg); | |
237 | p = XALLOCAVEC (char, | |
238 | (len + sizeof "go" + sizeof DEFAULT_TARGET_VERSION | |
239 | + sizeof DEFAULT_TARGET_MACHINE + 3)); | |
240 | strcpy (p, arg); | |
241 | if (len > 0 && !IS_DIR_SEPARATOR (p[len - 1])) | |
242 | strcat (p, dir_separator_str); | |
243 | strcat (p, "go"); | |
244 | strcat (p, dir_separator_str); | |
245 | strcat (p, DEFAULT_TARGET_VERSION); | |
246 | if (stat (p, &st) == 0 && S_ISDIR (st.st_mode)) | |
247 | { | |
248 | go_add_search_path (p); | |
249 | strcat (p, dir_separator_str); | |
250 | strcat (p, DEFAULT_TARGET_MACHINE); | |
251 | if (stat (p, &st) == 0 && S_ISDIR (st.st_mode)) | |
252 | go_add_search_path (p); | |
253 | } | |
254 | ||
255 | /* Search ARG too, but only after we've searched to Go | |
256 | specific directories for all -L arguments. */ | |
9771b263 | 257 | go_search_dirs.safe_push (arg); |
ac819ba5 ILT |
258 | } |
259 | break; | |
260 | ||
7a938933 ILT |
261 | case OPT_fgo_dump_: |
262 | ret = go_enable_dump (arg) ? true : false; | |
263 | break; | |
264 | ||
706cd57f | 265 | case OPT_fgo_optimize_: |
2794baab | 266 | ret = go_enable_optimize (arg, value) ? true : false; |
706cd57f RL |
267 | break; |
268 | ||
097b12fb ILT |
269 | case OPT_fgo_pkgpath_: |
270 | go_pkgpath = arg; | |
271 | break; | |
272 | ||
7a938933 | 273 | case OPT_fgo_prefix_: |
097b12fb | 274 | go_prefix = arg; |
7a938933 ILT |
275 | break; |
276 | ||
4e1866fe ILT |
277 | case OPT_fgo_relative_import_path_: |
278 | go_relative_import_path = arg; | |
279 | break; | |
280 | ||
2adb671d ILT |
281 | case OPT_fgo_c_header_: |
282 | go_c_header = arg; | |
283 | break; | |
284 | ||
bf183413 ILT |
285 | case OPT_fgo_embedcfg_: |
286 | go_embedcfg = arg; | |
287 | break; | |
288 | ||
7a938933 ILT |
289 | default: |
290 | /* Just return 1 to indicate that the option is valid. */ | |
291 | break; | |
292 | } | |
293 | ||
294 | return ret; | |
295 | } | |
296 | ||
297 | /* Run after parsing options. */ | |
298 | ||
299 | static bool | |
300 | go_langhook_post_options (const char **pfilename ATTRIBUTE_UNUSED) | |
301 | { | |
ac819ba5 ILT |
302 | unsigned int ix; |
303 | const char *dir; | |
304 | ||
7a938933 ILT |
305 | gcc_assert (num_in_fnames > 0); |
306 | ||
9771b263 | 307 | FOR_EACH_VEC_ELT (go_search_dirs, ix, dir) |
ac819ba5 | 308 | go_add_search_path (dir); |
9771b263 | 309 | go_search_dirs.release (); |
ac819ba5 | 310 | |
df375b03 JJ |
311 | if (flag_excess_precision == EXCESS_PRECISION_DEFAULT) |
312 | flag_excess_precision = EXCESS_PRECISION_STANDARD; | |
7a938933 | 313 | |
0fdd268f | 314 | /* Tail call optimizations can confuse uses of runtime.Callers. */ |
6ed76044 ML |
315 | SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
316 | flag_optimize_sibling_calls, 0); | |
0fdd268f | 317 | |
f44526e3 ILT |
318 | /* Partial inlining can confuses uses of runtime.Callers. |
319 | See https://gcc.gnu.org/PR91663. */ | |
6ed76044 ML |
320 | SET_OPTION_IF_UNSET (&global_options, &global_options_set, |
321 | flag_partial_inlining, 0); | |
f44526e3 | 322 | |
9a02d31b ILT |
323 | /* Go programs expect runtime.Callers to give the right answers, |
324 | which means that we can't combine functions even if they look the | |
325 | same. */ | |
326 | SET_OPTION_IF_UNSET (&global_options, &global_options_set, | |
327 | flag_ipa_icf_functions, 0); | |
328 | ||
818424b2 ILT |
329 | /* If the debug info level is still 1, as set in init_options, make |
330 | sure that some debugging type is selected. */ | |
331 | if (global_options.x_debug_info_level == DINFO_LEVEL_TERSE | |
332 | && global_options.x_write_symbols == NO_DEBUG) | |
333 | global_options.x_write_symbols = PREFERRED_DEBUGGING_TYPE; | |
334 | ||
cb3306e5 | 335 | /* We turn on stack splitting if we can. */ |
6ed76044 ML |
336 | if (targetm_common.supports_split_stack (false, &global_options)) |
337 | SET_OPTION_IF_UNSET (&global_options, &global_options_set, | |
338 | flag_split_stack, 1); | |
cb3306e5 | 339 | |
a1f427e9 ILT |
340 | /* If stack splitting is turned on, and the user did not explicitly |
341 | request function partitioning, turn off partitioning, as it | |
342 | confuses the linker when trying to handle partitioned split-stack | |
343 | code that calls a non-split-stack function. */ | |
344 | if (global_options.x_flag_split_stack | |
6ed76044 ML |
345 | && global_options.x_flag_reorder_blocks_and_partition) |
346 | SET_OPTION_IF_UNSET (&global_options, &global_options_set, | |
347 | flag_reorder_blocks_and_partition, 0); | |
a1f427e9 | 348 | |
7a938933 ILT |
349 | /* Returning false means that the backend should be used. */ |
350 | return false; | |
351 | } | |
352 | ||
353 | static void | |
354 | go_langhook_parse_file (void) | |
355 | { | |
356 | go_parse_input_files (in_fnames, num_in_fnames, flag_syntax_only, | |
357 | go_require_return_statement); | |
d7438551 AH |
358 | |
359 | /* Final processing of globals and early debug info generation. */ | |
360 | go_write_globals (); | |
7a938933 ILT |
361 | } |
362 | ||
363 | static tree | |
364 | go_langhook_type_for_size (unsigned int bits, int unsignedp) | |
365 | { | |
ad5b68e0 CM |
366 | tree type; |
367 | if (unsignedp) | |
368 | { | |
369 | if (bits == INT_TYPE_SIZE) | |
370 | type = unsigned_type_node; | |
371 | else if (bits == CHAR_TYPE_SIZE) | |
372 | type = unsigned_char_type_node; | |
373 | else if (bits == SHORT_TYPE_SIZE) | |
374 | type = short_unsigned_type_node; | |
375 | else if (bits == LONG_TYPE_SIZE) | |
376 | type = long_unsigned_type_node; | |
377 | else if (bits == LONG_LONG_TYPE_SIZE) | |
378 | type = long_long_unsigned_type_node; | |
379 | else | |
380 | type = make_unsigned_type(bits); | |
381 | } | |
382 | else | |
383 | { | |
384 | if (bits == INT_TYPE_SIZE) | |
385 | type = integer_type_node; | |
386 | else if (bits == CHAR_TYPE_SIZE) | |
387 | type = signed_char_type_node; | |
388 | else if (bits == SHORT_TYPE_SIZE) | |
389 | type = short_integer_type_node; | |
390 | else if (bits == LONG_TYPE_SIZE) | |
391 | type = long_integer_type_node; | |
392 | else if (bits == LONG_LONG_TYPE_SIZE) | |
393 | type = long_long_integer_type_node; | |
394 | else | |
395 | type = make_signed_type(bits); | |
396 | } | |
397 | return type; | |
7a938933 ILT |
398 | } |
399 | ||
400 | static tree | |
ef4bddc2 | 401 | go_langhook_type_for_mode (machine_mode mode, int unsignedp) |
7a938933 | 402 | { |
c2b13bb6 | 403 | tree type; |
0e29f7e5 ILT |
404 | /* Go has no vector types. Build them here. FIXME: It does not |
405 | make sense for the middle-end to ask the frontend for a type | |
406 | which the frontend does not support. However, at least for now | |
407 | it is required. See PR 46805. */ | |
5c0caeb3 | 408 | if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL |
928686b1 | 409 | && valid_vector_subparts_p (GET_MODE_NUNITS (mode))) |
5c0caeb3 RS |
410 | { |
411 | unsigned int elem_bits = vector_element_size (GET_MODE_BITSIZE (mode), | |
412 | GET_MODE_NUNITS (mode)); | |
413 | tree bool_type = build_nonstandard_boolean_type (elem_bits); | |
414 | return build_vector_type_for_mode (bool_type, mode); | |
415 | } | |
416 | else if (VECTOR_MODE_P (mode) | |
417 | && valid_vector_subparts_p (GET_MODE_NUNITS (mode))) | |
0e29f7e5 ILT |
418 | { |
419 | tree inner; | |
420 | ||
421 | inner = go_langhook_type_for_mode (GET_MODE_INNER (mode), unsignedp); | |
422 | if (inner != NULL_TREE) | |
423 | return build_vector_type_for_mode (inner, mode); | |
424 | return NULL_TREE; | |
425 | } | |
426 | ||
b4206259 | 427 | scalar_int_mode imode; |
e386a52f | 428 | scalar_float_mode fmode; |
a97390bf | 429 | complex_mode cmode; |
b4206259 RS |
430 | if (is_int_mode (mode, &imode)) |
431 | return go_langhook_type_for_size (GET_MODE_BITSIZE (imode), unsignedp); | |
e386a52f | 432 | else if (is_float_mode (mode, &fmode)) |
ad5b68e0 | 433 | { |
e386a52f | 434 | switch (GET_MODE_BITSIZE (fmode)) |
ad5b68e0 CM |
435 | { |
436 | case 32: | |
437 | return float_type_node; | |
438 | case 64: | |
439 | return double_type_node; | |
440 | default: | |
441 | // We have to check for long double in order to support | |
442 | // i386 excess precision. | |
e386a52f | 443 | if (fmode == TYPE_MODE(long_double_type_node)) |
ad5b68e0 CM |
444 | return long_double_type_node; |
445 | } | |
446 | } | |
a97390bf | 447 | else if (is_complex_float_mode (mode, &cmode)) |
ad5b68e0 | 448 | { |
a97390bf | 449 | switch (GET_MODE_BITSIZE (cmode)) |
ad5b68e0 CM |
450 | { |
451 | case 64: | |
452 | return complex_float_type_node; | |
453 | case 128: | |
454 | return complex_double_type_node; | |
455 | default: | |
456 | // We have to check for long double in order to support | |
457 | // i386 excess precision. | |
a97390bf | 458 | if (cmode == TYPE_MODE(complex_long_double_type_node)) |
ad5b68e0 CM |
459 | return complex_long_double_type_node; |
460 | } | |
461 | } | |
c2b13bb6 JJ |
462 | |
463 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
464 | /* The middle-end and some backends rely on TImode being supported | |
465 | for 64-bit HWI. */ | |
466 | if (mode == TImode) | |
467 | { | |
468 | type = build_nonstandard_integer_type (GET_MODE_BITSIZE (TImode), | |
469 | unsignedp); | |
470 | if (type && TYPE_MODE (type) == TImode) | |
471 | return type; | |
472 | } | |
473 | #endif | |
474 | return NULL_TREE; | |
7a938933 ILT |
475 | } |
476 | ||
477 | /* Record a builtin function. We just ignore builtin functions. */ | |
478 | ||
479 | static tree | |
480 | go_langhook_builtin_function (tree decl) | |
481 | { | |
482 | return decl; | |
483 | } | |
484 | ||
c99c0026 EB |
485 | /* Return true if we are in the global binding level. */ |
486 | ||
487 | static bool | |
7a938933 ILT |
488 | go_langhook_global_bindings_p (void) |
489 | { | |
c99c0026 | 490 | return current_function_decl == NULL_TREE; |
7a938933 ILT |
491 | } |
492 | ||
493 | /* Push a declaration into the current binding level. We can't | |
494 | usefully implement this since we don't want to convert from tree | |
495 | back to one of our internal data structures. I think the only way | |
496 | this is used is to record a decl which is to be returned by | |
497 | getdecls, and we could implement it for that purpose if | |
498 | necessary. */ | |
499 | ||
500 | static tree | |
501 | go_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED) | |
502 | { | |
503 | gcc_unreachable (); | |
504 | } | |
505 | ||
506 | /* This hook is used to get the current list of declarations as trees. | |
7e0db0cd | 507 | We don't support that; instead we use the write_globals hook. */ |
7a938933 ILT |
508 | |
509 | static tree | |
510 | go_langhook_getdecls (void) | |
511 | { | |
512 | return NULL; | |
513 | } | |
514 | ||
7a938933 ILT |
515 | /* Go specific gimplification. We need to gimplify |
516 | CALL_EXPR_STATIC_CHAIN, because the gimplifier doesn't handle | |
517 | it. */ | |
518 | ||
519 | static int | |
520 | go_langhook_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) | |
521 | { | |
522 | if (TREE_CODE (*expr_p) == CALL_EXPR | |
523 | && CALL_EXPR_STATIC_CHAIN (*expr_p) != NULL_TREE) | |
524 | gimplify_expr (&CALL_EXPR_STATIC_CHAIN (*expr_p), pre_p, post_p, | |
525 | is_gimple_val, fb_rvalue); | |
526 | return GS_UNHANDLED; | |
527 | } | |
528 | ||
529 | /* Return a decl for the exception personality function. The function | |
530 | itself is implemented in libgo/runtime/go-unwind.c. */ | |
531 | ||
532 | static tree | |
533 | go_langhook_eh_personality (void) | |
534 | { | |
535 | static tree personality_decl; | |
536 | if (personality_decl == NULL_TREE) | |
537 | { | |
538 | personality_decl = build_personality_function ("gccgo"); | |
539 | go_preserve_from_gc (personality_decl); | |
540 | } | |
541 | return personality_decl; | |
542 | } | |
543 | ||
6cf276dd DM |
544 | /* Get a value for the SARIF v2.1.0 "artifact.sourceLanguage" property, |
545 | based on the list in SARIF v2.1.0 Appendix J. */ | |
546 | ||
547 | static const char * | |
548 | go_get_sarif_source_language (const char *) | |
549 | { | |
550 | return "go"; | |
551 | } | |
552 | ||
7a938933 ILT |
553 | /* Functions called directly by the generic backend. */ |
554 | ||
555 | tree | |
556 | convert (tree type, tree expr) | |
557 | { | |
558 | if (type == error_mark_node | |
559 | || expr == error_mark_node | |
560 | || TREE_TYPE (expr) == error_mark_node) | |
561 | return error_mark_node; | |
562 | ||
563 | if (type == TREE_TYPE (expr)) | |
564 | return expr; | |
565 | ||
566 | if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr))) | |
567 | return fold_convert (type, expr); | |
568 | ||
569 | switch (TREE_CODE (type)) | |
570 | { | |
571 | case VOID_TYPE: | |
572 | case BOOLEAN_TYPE: | |
573 | return fold_convert (type, expr); | |
574 | case INTEGER_TYPE: | |
575 | return fold (convert_to_integer (type, expr)); | |
576 | case POINTER_TYPE: | |
577 | return fold (convert_to_pointer (type, expr)); | |
578 | case REAL_TYPE: | |
579 | return fold (convert_to_real (type, expr)); | |
580 | case COMPLEX_TYPE: | |
581 | return fold (convert_to_complex (type, expr)); | |
582 | default: | |
583 | break; | |
584 | } | |
585 | ||
586 | gcc_unreachable (); | |
587 | } | |
588 | ||
589 | /* FIXME: This is a hack to preserve trees that we create from the | |
590 | garbage collector. */ | |
591 | ||
592 | static GTY(()) tree go_gc_root; | |
593 | ||
594 | void | |
595 | go_preserve_from_gc (tree t) | |
596 | { | |
597 | go_gc_root = tree_cons (NULL_TREE, t, go_gc_root); | |
598 | } | |
599 | ||
600 | /* Convert an identifier for use in an error message. */ | |
601 | ||
602 | const char * | |
603 | go_localize_identifier (const char *ident) | |
604 | { | |
605 | return identifier_to_locale (ident); | |
606 | } | |
607 | ||
608 | #undef LANG_HOOKS_NAME | |
609 | #undef LANG_HOOKS_INIT | |
610 | #undef LANG_HOOKS_OPTION_LANG_MASK | |
611 | #undef LANG_HOOKS_INIT_OPTIONS_STRUCT | |
612 | #undef LANG_HOOKS_HANDLE_OPTION | |
613 | #undef LANG_HOOKS_POST_OPTIONS | |
614 | #undef LANG_HOOKS_PARSE_FILE | |
615 | #undef LANG_HOOKS_TYPE_FOR_MODE | |
616 | #undef LANG_HOOKS_TYPE_FOR_SIZE | |
617 | #undef LANG_HOOKS_BUILTIN_FUNCTION | |
618 | #undef LANG_HOOKS_GLOBAL_BINDINGS_P | |
619 | #undef LANG_HOOKS_PUSHDECL | |
620 | #undef LANG_HOOKS_GETDECLS | |
7a938933 ILT |
621 | #undef LANG_HOOKS_GIMPLIFY_EXPR |
622 | #undef LANG_HOOKS_EH_PERSONALITY | |
6cf276dd | 623 | #undef LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE |
7a938933 ILT |
624 | |
625 | #define LANG_HOOKS_NAME "GNU Go" | |
626 | #define LANG_HOOKS_INIT go_langhook_init | |
627 | #define LANG_HOOKS_OPTION_LANG_MASK go_langhook_option_lang_mask | |
628 | #define LANG_HOOKS_INIT_OPTIONS_STRUCT go_langhook_init_options_struct | |
629 | #define LANG_HOOKS_HANDLE_OPTION go_langhook_handle_option | |
630 | #define LANG_HOOKS_POST_OPTIONS go_langhook_post_options | |
631 | #define LANG_HOOKS_PARSE_FILE go_langhook_parse_file | |
632 | #define LANG_HOOKS_TYPE_FOR_MODE go_langhook_type_for_mode | |
633 | #define LANG_HOOKS_TYPE_FOR_SIZE go_langhook_type_for_size | |
634 | #define LANG_HOOKS_BUILTIN_FUNCTION go_langhook_builtin_function | |
635 | #define LANG_HOOKS_GLOBAL_BINDINGS_P go_langhook_global_bindings_p | |
636 | #define LANG_HOOKS_PUSHDECL go_langhook_pushdecl | |
637 | #define LANG_HOOKS_GETDECLS go_langhook_getdecls | |
7a938933 ILT |
638 | #define LANG_HOOKS_GIMPLIFY_EXPR go_langhook_gimplify_expr |
639 | #define LANG_HOOKS_EH_PERSONALITY go_langhook_eh_personality | |
6cf276dd | 640 | #define LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE go_get_sarif_source_language |
7a938933 ILT |
641 | |
642 | struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; | |
643 | ||
644 | #include "gt-go-go-lang.h" | |
645 | #include "gtype-go.h" |