annotate gcc/go/go-lang.c @ 158:494b0b89df80 default tip

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