annotate gcc/go/go-lang.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
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.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2009-2018 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;
111
kono
parents:
diff changeset
121 args.linemap = go_get_linemap();
kono
parents:
diff changeset
122 args.backend = go_get_backend();
kono
parents:
diff changeset
123 go_create_gogo (&args);
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 build_common_builtin_nodes ();
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 /* The default precision for floating point numbers. This is used
kono
parents:
diff changeset
128 for floating point constants with abstract type. This may
kono
parents:
diff changeset
129 eventually be controllable by a command line option. */
kono
parents:
diff changeset
130 mpfr_set_default_prec (256);
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 /* Go uses exceptions. */
kono
parents:
diff changeset
133 using_eh_for_cleanups ();
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 return true;
kono
parents:
diff changeset
136 }
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 /* The option mask. */
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 static unsigned int
kono
parents:
diff changeset
141 go_langhook_option_lang_mask (void)
kono
parents:
diff changeset
142 {
kono
parents:
diff changeset
143 return CL_Go;
kono
parents:
diff changeset
144 }
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 /* Initialize the options structure. */
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 static void
kono
parents:
diff changeset
149 go_langhook_init_options_struct (struct gcc_options *opts)
kono
parents:
diff changeset
150 {
kono
parents:
diff changeset
151 /* Go says that signed overflow is precisely defined. */
kono
parents:
diff changeset
152 opts->x_flag_wrapv = 1;
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 /* We default to using strict aliasing, since Go pointers are safe.
kono
parents:
diff changeset
155 This is turned off for code that imports the "unsafe" package,
kono
parents:
diff changeset
156 because using unsafe.pointer violates C style aliasing
kono
parents:
diff changeset
157 requirements. */
kono
parents:
diff changeset
158 opts->x_flag_strict_aliasing = 1;
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 /* Default to avoiding range issues for complex multiply and
kono
parents:
diff changeset
161 divide. */
kono
parents:
diff changeset
162 opts->x_flag_complex_method = 2;
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 /* The builtin math functions should not set errno. */
kono
parents:
diff changeset
165 opts->x_flag_errno_math = 0;
kono
parents:
diff changeset
166 opts->frontend_set_flag_errno_math = true;
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 /* Exceptions are used to handle recovering from panics. */
kono
parents:
diff changeset
169 opts->x_flag_exceptions = 1;
kono
parents:
diff changeset
170 opts->x_flag_non_call_exceptions = 1;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 /* We need to keep pointers live for the garbage collector. */
kono
parents:
diff changeset
173 opts->x_flag_keep_gc_roots_live = 1;
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 /* Go programs expect runtime.Callers to work, and that uses
kono
parents:
diff changeset
176 libbacktrace that uses debug info. Set the debug info level to 1
kono
parents:
diff changeset
177 by default. In post_options we will set the debug type if the
kono
parents:
diff changeset
178 debug info level was not set back to 0 on the command line. */
kono
parents:
diff changeset
179 opts->x_debug_info_level = DINFO_LEVEL_TERSE;
kono
parents:
diff changeset
180 }
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 /* Infrastructure for a vector of char * pointers. */
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 typedef const char *go_char_p;
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 /* The list of directories to search after all the Go specific
kono
parents:
diff changeset
187 directories have been searched. */
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 static vec<go_char_p> go_search_dirs;
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 /* Handle Go specific options. Return 0 if we didn't do anything. */
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 static bool
kono
parents:
diff changeset
194 go_langhook_handle_option (
kono
parents:
diff changeset
195 size_t scode,
kono
parents:
diff changeset
196 const char *arg,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
197 HOST_WIDE_INT value,
111
kono
parents:
diff changeset
198 int kind ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
199 location_t loc ATTRIBUTE_UNUSED,
kono
parents:
diff changeset
200 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
201 {
kono
parents:
diff changeset
202 enum opt_code code = (enum opt_code) scode;
kono
parents:
diff changeset
203 bool ret = true;
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 switch (code)
kono
parents:
diff changeset
206 {
kono
parents:
diff changeset
207 case OPT_I:
kono
parents:
diff changeset
208 go_add_search_path (arg);
kono
parents:
diff changeset
209 break;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 case OPT_L:
kono
parents:
diff changeset
212 /* A -L option is assumed to come from the compiler driver.
kono
parents:
diff changeset
213 This is a system directory. We search the following
kono
parents:
diff changeset
214 directories, if they exist, before this one:
kono
parents:
diff changeset
215 dir/go/VERSION
kono
parents:
diff changeset
216 dir/go/VERSION/MACHINE
kono
parents:
diff changeset
217 This is like include/c++. */
kono
parents:
diff changeset
218 {
kono
parents:
diff changeset
219 static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
kono
parents:
diff changeset
220 size_t len;
kono
parents:
diff changeset
221 char *p;
kono
parents:
diff changeset
222 struct stat st;
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 len = strlen (arg);
kono
parents:
diff changeset
225 p = XALLOCAVEC (char,
kono
parents:
diff changeset
226 (len + sizeof "go" + sizeof DEFAULT_TARGET_VERSION
kono
parents:
diff changeset
227 + sizeof DEFAULT_TARGET_MACHINE + 3));
kono
parents:
diff changeset
228 strcpy (p, arg);
kono
parents:
diff changeset
229 if (len > 0 && !IS_DIR_SEPARATOR (p[len - 1]))
kono
parents:
diff changeset
230 strcat (p, dir_separator_str);
kono
parents:
diff changeset
231 strcat (p, "go");
kono
parents:
diff changeset
232 strcat (p, dir_separator_str);
kono
parents:
diff changeset
233 strcat (p, DEFAULT_TARGET_VERSION);
kono
parents:
diff changeset
234 if (stat (p, &st) == 0 && S_ISDIR (st.st_mode))
kono
parents:
diff changeset
235 {
kono
parents:
diff changeset
236 go_add_search_path (p);
kono
parents:
diff changeset
237 strcat (p, dir_separator_str);
kono
parents:
diff changeset
238 strcat (p, DEFAULT_TARGET_MACHINE);
kono
parents:
diff changeset
239 if (stat (p, &st) == 0 && S_ISDIR (st.st_mode))
kono
parents:
diff changeset
240 go_add_search_path (p);
kono
parents:
diff changeset
241 }
kono
parents:
diff changeset
242
kono
parents:
diff changeset
243 /* Search ARG too, but only after we've searched to Go
kono
parents:
diff changeset
244 specific directories for all -L arguments. */
kono
parents:
diff changeset
245 go_search_dirs.safe_push (arg);
kono
parents:
diff changeset
246 }
kono
parents:
diff changeset
247 break;
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 case OPT_fgo_dump_:
kono
parents:
diff changeset
250 ret = go_enable_dump (arg) ? true : false;
kono
parents:
diff changeset
251 break;
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 case OPT_fgo_optimize_:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
254 ret = go_enable_optimize (arg, value) ? true : false;
111
kono
parents:
diff changeset
255 break;
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 case OPT_fgo_pkgpath_:
kono
parents:
diff changeset
258 go_pkgpath = arg;
kono
parents:
diff changeset
259 break;
kono
parents:
diff changeset
260
kono
parents:
diff changeset
261 case OPT_fgo_prefix_:
kono
parents:
diff changeset
262 go_prefix = arg;
kono
parents:
diff changeset
263 break;
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 case OPT_fgo_relative_import_path_:
kono
parents:
diff changeset
266 go_relative_import_path = arg;
kono
parents:
diff changeset
267 break;
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 case OPT_fgo_c_header_:
kono
parents:
diff changeset
270 go_c_header = arg;
kono
parents:
diff changeset
271 break;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 default:
kono
parents:
diff changeset
274 /* Just return 1 to indicate that the option is valid. */
kono
parents:
diff changeset
275 break;
kono
parents:
diff changeset
276 }
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 return ret;
kono
parents:
diff changeset
279 }
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 /* Run after parsing options. */
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 static bool
kono
parents:
diff changeset
284 go_langhook_post_options (const char **pfilename ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
285 {
kono
parents:
diff changeset
286 unsigned int ix;
kono
parents:
diff changeset
287 const char *dir;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 gcc_assert (num_in_fnames > 0);
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 FOR_EACH_VEC_ELT (go_search_dirs, ix, dir)
kono
parents:
diff changeset
292 go_add_search_path (dir);
kono
parents:
diff changeset
293 go_search_dirs.release ();
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 if (flag_excess_precision_cmdline == EXCESS_PRECISION_DEFAULT)
kono
parents:
diff changeset
296 flag_excess_precision_cmdline = EXCESS_PRECISION_STANDARD;
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 /* Tail call optimizations can confuse uses of runtime.Callers. */
kono
parents:
diff changeset
299 if (!global_options_set.x_flag_optimize_sibling_calls)
kono
parents:
diff changeset
300 global_options.x_flag_optimize_sibling_calls = 0;
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 /* If the debug info level is still 1, as set in init_options, make
kono
parents:
diff changeset
303 sure that some debugging type is selected. */
kono
parents:
diff changeset
304 if (global_options.x_debug_info_level == DINFO_LEVEL_TERSE
kono
parents:
diff changeset
305 && global_options.x_write_symbols == NO_DEBUG)
kono
parents:
diff changeset
306 global_options.x_write_symbols = PREFERRED_DEBUGGING_TYPE;
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 /* We turn on stack splitting if we can. */
kono
parents:
diff changeset
309 if (!global_options_set.x_flag_split_stack
kono
parents:
diff changeset
310 && targetm_common.supports_split_stack (false, &global_options))
kono
parents:
diff changeset
311 global_options.x_flag_split_stack = 1;
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 /* If stack splitting is turned on, and the user did not explicitly
kono
parents:
diff changeset
314 request function partitioning, turn off partitioning, as it
kono
parents:
diff changeset
315 confuses the linker when trying to handle partitioned split-stack
kono
parents:
diff changeset
316 code that calls a non-split-stack function. */
kono
parents:
diff changeset
317 if (global_options.x_flag_split_stack
kono
parents:
diff changeset
318 && global_options.x_flag_reorder_blocks_and_partition
kono
parents:
diff changeset
319 && !global_options_set.x_flag_reorder_blocks_and_partition)
kono
parents:
diff changeset
320 global_options.x_flag_reorder_blocks_and_partition = 0;
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 /* Returning false means that the backend should be used. */
kono
parents:
diff changeset
323 return false;
kono
parents:
diff changeset
324 }
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 static void
kono
parents:
diff changeset
327 go_langhook_parse_file (void)
kono
parents:
diff changeset
328 {
kono
parents:
diff changeset
329 go_parse_input_files (in_fnames, num_in_fnames, flag_syntax_only,
kono
parents:
diff changeset
330 go_require_return_statement);
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 /* Final processing of globals and early debug info generation. */
kono
parents:
diff changeset
333 go_write_globals ();
kono
parents:
diff changeset
334 }
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 static tree
kono
parents:
diff changeset
337 go_langhook_type_for_size (unsigned int bits, int unsignedp)
kono
parents:
diff changeset
338 {
kono
parents:
diff changeset
339 tree type;
kono
parents:
diff changeset
340 if (unsignedp)
kono
parents:
diff changeset
341 {
kono
parents:
diff changeset
342 if (bits == INT_TYPE_SIZE)
kono
parents:
diff changeset
343 type = unsigned_type_node;
kono
parents:
diff changeset
344 else if (bits == CHAR_TYPE_SIZE)
kono
parents:
diff changeset
345 type = unsigned_char_type_node;
kono
parents:
diff changeset
346 else if (bits == SHORT_TYPE_SIZE)
kono
parents:
diff changeset
347 type = short_unsigned_type_node;
kono
parents:
diff changeset
348 else if (bits == LONG_TYPE_SIZE)
kono
parents:
diff changeset
349 type = long_unsigned_type_node;
kono
parents:
diff changeset
350 else if (bits == LONG_LONG_TYPE_SIZE)
kono
parents:
diff changeset
351 type = long_long_unsigned_type_node;
kono
parents:
diff changeset
352 else
kono
parents:
diff changeset
353 type = make_unsigned_type(bits);
kono
parents:
diff changeset
354 }
kono
parents:
diff changeset
355 else
kono
parents:
diff changeset
356 {
kono
parents:
diff changeset
357 if (bits == INT_TYPE_SIZE)
kono
parents:
diff changeset
358 type = integer_type_node;
kono
parents:
diff changeset
359 else if (bits == CHAR_TYPE_SIZE)
kono
parents:
diff changeset
360 type = signed_char_type_node;
kono
parents:
diff changeset
361 else if (bits == SHORT_TYPE_SIZE)
kono
parents:
diff changeset
362 type = short_integer_type_node;
kono
parents:
diff changeset
363 else if (bits == LONG_TYPE_SIZE)
kono
parents:
diff changeset
364 type = long_integer_type_node;
kono
parents:
diff changeset
365 else if (bits == LONG_LONG_TYPE_SIZE)
kono
parents:
diff changeset
366 type = long_long_integer_type_node;
kono
parents:
diff changeset
367 else
kono
parents:
diff changeset
368 type = make_signed_type(bits);
kono
parents:
diff changeset
369 }
kono
parents:
diff changeset
370 return type;
kono
parents:
diff changeset
371 }
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 static tree
kono
parents:
diff changeset
374 go_langhook_type_for_mode (machine_mode mode, int unsignedp)
kono
parents:
diff changeset
375 {
kono
parents:
diff changeset
376 tree type;
kono
parents:
diff changeset
377 /* Go has no vector types. Build them here. FIXME: It does not
kono
parents:
diff changeset
378 make sense for the middle-end to ask the frontend for a type
kono
parents:
diff changeset
379 which the frontend does not support. However, at least for now
kono
parents:
diff changeset
380 it is required. See PR 46805. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
381 if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
382 && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
383 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
384 unsigned int elem_bits = vector_element_size (GET_MODE_BITSIZE (mode),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
385 GET_MODE_NUNITS (mode));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
386 tree bool_type = build_nonstandard_boolean_type (elem_bits);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
387 return build_vector_type_for_mode (bool_type, mode);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
388 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
389 else if (VECTOR_MODE_P (mode)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
390 && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
111
kono
parents:
diff changeset
391 {
kono
parents:
diff changeset
392 tree inner;
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 inner = go_langhook_type_for_mode (GET_MODE_INNER (mode), unsignedp);
kono
parents:
diff changeset
395 if (inner != NULL_TREE)
kono
parents:
diff changeset
396 return build_vector_type_for_mode (inner, mode);
kono
parents:
diff changeset
397 return NULL_TREE;
kono
parents:
diff changeset
398 }
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 scalar_int_mode imode;
kono
parents:
diff changeset
401 scalar_float_mode fmode;
kono
parents:
diff changeset
402 complex_mode cmode;
kono
parents:
diff changeset
403 if (is_int_mode (mode, &imode))
kono
parents:
diff changeset
404 return go_langhook_type_for_size (GET_MODE_BITSIZE (imode), unsignedp);
kono
parents:
diff changeset
405 else if (is_float_mode (mode, &fmode))
kono
parents:
diff changeset
406 {
kono
parents:
diff changeset
407 switch (GET_MODE_BITSIZE (fmode))
kono
parents:
diff changeset
408 {
kono
parents:
diff changeset
409 case 32:
kono
parents:
diff changeset
410 return float_type_node;
kono
parents:
diff changeset
411 case 64:
kono
parents:
diff changeset
412 return double_type_node;
kono
parents:
diff changeset
413 default:
kono
parents:
diff changeset
414 // We have to check for long double in order to support
kono
parents:
diff changeset
415 // i386 excess precision.
kono
parents:
diff changeset
416 if (fmode == TYPE_MODE(long_double_type_node))
kono
parents:
diff changeset
417 return long_double_type_node;
kono
parents:
diff changeset
418 }
kono
parents:
diff changeset
419 }
kono
parents:
diff changeset
420 else if (is_complex_float_mode (mode, &cmode))
kono
parents:
diff changeset
421 {
kono
parents:
diff changeset
422 switch (GET_MODE_BITSIZE (cmode))
kono
parents:
diff changeset
423 {
kono
parents:
diff changeset
424 case 64:
kono
parents:
diff changeset
425 return complex_float_type_node;
kono
parents:
diff changeset
426 case 128:
kono
parents:
diff changeset
427 return complex_double_type_node;
kono
parents:
diff changeset
428 default:
kono
parents:
diff changeset
429 // We have to check for long double in order to support
kono
parents:
diff changeset
430 // i386 excess precision.
kono
parents:
diff changeset
431 if (cmode == TYPE_MODE(complex_long_double_type_node))
kono
parents:
diff changeset
432 return complex_long_double_type_node;
kono
parents:
diff changeset
433 }
kono
parents:
diff changeset
434 }
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 #if HOST_BITS_PER_WIDE_INT >= 64
kono
parents:
diff changeset
437 /* The middle-end and some backends rely on TImode being supported
kono
parents:
diff changeset
438 for 64-bit HWI. */
kono
parents:
diff changeset
439 if (mode == TImode)
kono
parents:
diff changeset
440 {
kono
parents:
diff changeset
441 type = build_nonstandard_integer_type (GET_MODE_BITSIZE (TImode),
kono
parents:
diff changeset
442 unsignedp);
kono
parents:
diff changeset
443 if (type && TYPE_MODE (type) == TImode)
kono
parents:
diff changeset
444 return type;
kono
parents:
diff changeset
445 }
kono
parents:
diff changeset
446 #endif
kono
parents:
diff changeset
447 return NULL_TREE;
kono
parents:
diff changeset
448 }
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 /* Record a builtin function. We just ignore builtin functions. */
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 static tree
kono
parents:
diff changeset
453 go_langhook_builtin_function (tree decl)
kono
parents:
diff changeset
454 {
kono
parents:
diff changeset
455 return decl;
kono
parents:
diff changeset
456 }
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 /* Return true if we are in the global binding level. */
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 static bool
kono
parents:
diff changeset
461 go_langhook_global_bindings_p (void)
kono
parents:
diff changeset
462 {
kono
parents:
diff changeset
463 return current_function_decl == NULL_TREE;
kono
parents:
diff changeset
464 }
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 /* Push a declaration into the current binding level. We can't
kono
parents:
diff changeset
467 usefully implement this since we don't want to convert from tree
kono
parents:
diff changeset
468 back to one of our internal data structures. I think the only way
kono
parents:
diff changeset
469 this is used is to record a decl which is to be returned by
kono
parents:
diff changeset
470 getdecls, and we could implement it for that purpose if
kono
parents:
diff changeset
471 necessary. */
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 static tree
kono
parents:
diff changeset
474 go_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
475 {
kono
parents:
diff changeset
476 gcc_unreachable ();
kono
parents:
diff changeset
477 }
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 /* This hook is used to get the current list of declarations as trees.
kono
parents:
diff changeset
480 We don't support that; instead we use the write_globals hook. This
kono
parents:
diff changeset
481 can't simply crash because it is called by -gstabs. */
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 static tree
kono
parents:
diff changeset
484 go_langhook_getdecls (void)
kono
parents:
diff changeset
485 {
kono
parents:
diff changeset
486 return NULL;
kono
parents:
diff changeset
487 }
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 /* Go specific gimplification. We need to gimplify
kono
parents:
diff changeset
490 CALL_EXPR_STATIC_CHAIN, because the gimplifier doesn't handle
kono
parents:
diff changeset
491 it. */
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 static int
kono
parents:
diff changeset
494 go_langhook_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
kono
parents:
diff changeset
495 {
kono
parents:
diff changeset
496 if (TREE_CODE (*expr_p) == CALL_EXPR
kono
parents:
diff changeset
497 && CALL_EXPR_STATIC_CHAIN (*expr_p) != NULL_TREE)
kono
parents:
diff changeset
498 gimplify_expr (&CALL_EXPR_STATIC_CHAIN (*expr_p), pre_p, post_p,
kono
parents:
diff changeset
499 is_gimple_val, fb_rvalue);
kono
parents:
diff changeset
500 return GS_UNHANDLED;
kono
parents:
diff changeset
501 }
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 /* Return a decl for the exception personality function. The function
kono
parents:
diff changeset
504 itself is implemented in libgo/runtime/go-unwind.c. */
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 static tree
kono
parents:
diff changeset
507 go_langhook_eh_personality (void)
kono
parents:
diff changeset
508 {
kono
parents:
diff changeset
509 static tree personality_decl;
kono
parents:
diff changeset
510 if (personality_decl == NULL_TREE)
kono
parents:
diff changeset
511 {
kono
parents:
diff changeset
512 personality_decl = build_personality_function ("gccgo");
kono
parents:
diff changeset
513 go_preserve_from_gc (personality_decl);
kono
parents:
diff changeset
514 }
kono
parents:
diff changeset
515 return personality_decl;
kono
parents:
diff changeset
516 }
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 /* Functions called directly by the generic backend. */
kono
parents:
diff changeset
519
kono
parents:
diff changeset
520 tree
kono
parents:
diff changeset
521 convert (tree type, tree expr)
kono
parents:
diff changeset
522 {
kono
parents:
diff changeset
523 if (type == error_mark_node
kono
parents:
diff changeset
524 || expr == error_mark_node
kono
parents:
diff changeset
525 || TREE_TYPE (expr) == error_mark_node)
kono
parents:
diff changeset
526 return error_mark_node;
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 if (type == TREE_TYPE (expr))
kono
parents:
diff changeset
529 return expr;
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (TREE_TYPE (expr)))
kono
parents:
diff changeset
532 return fold_convert (type, expr);
kono
parents:
diff changeset
533
kono
parents:
diff changeset
534 switch (TREE_CODE (type))
kono
parents:
diff changeset
535 {
kono
parents:
diff changeset
536 case VOID_TYPE:
kono
parents:
diff changeset
537 case BOOLEAN_TYPE:
kono
parents:
diff changeset
538 return fold_convert (type, expr);
kono
parents:
diff changeset
539 case INTEGER_TYPE:
kono
parents:
diff changeset
540 return fold (convert_to_integer (type, expr));
kono
parents:
diff changeset
541 case POINTER_TYPE:
kono
parents:
diff changeset
542 return fold (convert_to_pointer (type, expr));
kono
parents:
diff changeset
543 case REAL_TYPE:
kono
parents:
diff changeset
544 return fold (convert_to_real (type, expr));
kono
parents:
diff changeset
545 case COMPLEX_TYPE:
kono
parents:
diff changeset
546 return fold (convert_to_complex (type, expr));
kono
parents:
diff changeset
547 default:
kono
parents:
diff changeset
548 break;
kono
parents:
diff changeset
549 }
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 gcc_unreachable ();
kono
parents:
diff changeset
552 }
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 /* FIXME: This is a hack to preserve trees that we create from the
kono
parents:
diff changeset
555 garbage collector. */
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 static GTY(()) tree go_gc_root;
kono
parents:
diff changeset
558
kono
parents:
diff changeset
559 void
kono
parents:
diff changeset
560 go_preserve_from_gc (tree t)
kono
parents:
diff changeset
561 {
kono
parents:
diff changeset
562 go_gc_root = tree_cons (NULL_TREE, t, go_gc_root);
kono
parents:
diff changeset
563 }
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 /* Convert an identifier for use in an error message. */
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 const char *
kono
parents:
diff changeset
568 go_localize_identifier (const char *ident)
kono
parents:
diff changeset
569 {
kono
parents:
diff changeset
570 return identifier_to_locale (ident);
kono
parents:
diff changeset
571 }
kono
parents:
diff changeset
572
kono
parents:
diff changeset
573 #undef LANG_HOOKS_NAME
kono
parents:
diff changeset
574 #undef LANG_HOOKS_INIT
kono
parents:
diff changeset
575 #undef LANG_HOOKS_OPTION_LANG_MASK
kono
parents:
diff changeset
576 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
kono
parents:
diff changeset
577 #undef LANG_HOOKS_HANDLE_OPTION
kono
parents:
diff changeset
578 #undef LANG_HOOKS_POST_OPTIONS
kono
parents:
diff changeset
579 #undef LANG_HOOKS_PARSE_FILE
kono
parents:
diff changeset
580 #undef LANG_HOOKS_TYPE_FOR_MODE
kono
parents:
diff changeset
581 #undef LANG_HOOKS_TYPE_FOR_SIZE
kono
parents:
diff changeset
582 #undef LANG_HOOKS_BUILTIN_FUNCTION
kono
parents:
diff changeset
583 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
kono
parents:
diff changeset
584 #undef LANG_HOOKS_PUSHDECL
kono
parents:
diff changeset
585 #undef LANG_HOOKS_GETDECLS
kono
parents:
diff changeset
586 #undef LANG_HOOKS_GIMPLIFY_EXPR
kono
parents:
diff changeset
587 #undef LANG_HOOKS_EH_PERSONALITY
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589 #define LANG_HOOKS_NAME "GNU Go"
kono
parents:
diff changeset
590 #define LANG_HOOKS_INIT go_langhook_init
kono
parents:
diff changeset
591 #define LANG_HOOKS_OPTION_LANG_MASK go_langhook_option_lang_mask
kono
parents:
diff changeset
592 #define LANG_HOOKS_INIT_OPTIONS_STRUCT go_langhook_init_options_struct
kono
parents:
diff changeset
593 #define LANG_HOOKS_HANDLE_OPTION go_langhook_handle_option
kono
parents:
diff changeset
594 #define LANG_HOOKS_POST_OPTIONS go_langhook_post_options
kono
parents:
diff changeset
595 #define LANG_HOOKS_PARSE_FILE go_langhook_parse_file
kono
parents:
diff changeset
596 #define LANG_HOOKS_TYPE_FOR_MODE go_langhook_type_for_mode
kono
parents:
diff changeset
597 #define LANG_HOOKS_TYPE_FOR_SIZE go_langhook_type_for_size
kono
parents:
diff changeset
598 #define LANG_HOOKS_BUILTIN_FUNCTION go_langhook_builtin_function
kono
parents:
diff changeset
599 #define LANG_HOOKS_GLOBAL_BINDINGS_P go_langhook_global_bindings_p
kono
parents:
diff changeset
600 #define LANG_HOOKS_PUSHDECL go_langhook_pushdecl
kono
parents:
diff changeset
601 #define LANG_HOOKS_GETDECLS go_langhook_getdecls
kono
parents:
diff changeset
602 #define LANG_HOOKS_GIMPLIFY_EXPR go_langhook_gimplify_expr
kono
parents:
diff changeset
603 #define LANG_HOOKS_EH_PERSONALITY go_langhook_eh_personality
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
kono
parents:
diff changeset
606
kono
parents:
diff changeset
607 #include "gt-go-go-lang.h"
kono
parents:
diff changeset
608 #include "gtype-go.h"