Remove assert in get_def_bb_for_const
[official-gcc.git] / gcc / jit / dummy-frontend.c
blob26311536186fda5276157628341ac5c2cf75d0e8
1 /* jit.c -- Dummy "frontend" for use during JIT-compilation.
2 Copyright (C) 2013-2016 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "jit-playback.h"
24 #include "stor-layout.h"
25 #include "debug.h"
26 #include "langhooks.h"
27 #include "langhooks-def.h"
28 #include "diagnostic.h"
31 #include <mpfr.h>
33 /* Language-dependent contents of a type. */
35 struct GTY(()) lang_type
37 char dummy;
40 /* Language-dependent contents of a decl. */
42 struct GTY((variable_size)) lang_decl
44 char dummy;
47 /* Language-dependent contents of an identifier. This must include a
48 tree_identifier. */
50 struct GTY(()) lang_identifier
52 struct tree_identifier common;
55 /* The resulting tree type. */
57 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
58 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
59 lang_tree_node
61 union tree_node GTY((tag ("0"),
62 desc ("tree_node_structure (&%h)"))) generic;
63 struct lang_identifier GTY((tag ("1"))) identifier;
66 /* We don't use language_function. */
68 struct GTY(()) language_function
70 int dummy;
73 /* GC-marking callback for use from jit_root_tab.
75 If there's an active playback context, call its marking method
76 so that it can mark any pointers it references. */
78 static void my_ggc_walker (void *)
80 if (gcc::jit::active_playback_ctxt)
81 gcc::jit::active_playback_ctxt->gt_ggc_mx ();
84 const char *dummy;
86 struct ggc_root_tab jit_root_tab[] =
89 &dummy, 1, 0, my_ggc_walker, NULL
91 LAST_GGC_ROOT_TAB
94 /* JIT-specific implementation of diagnostic callbacks. */
96 /* Implementation of "begin_diagnostic". */
98 static void
99 jit_begin_diagnostic (diagnostic_context */*context*/,
100 diagnostic_info */*diagnostic*/)
102 gcc_assert (gcc::jit::active_playback_ctxt);
103 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
105 /* No-op (apart from logging); the real error-handling is done in the
106 "end_diagnostic" hook. */
109 /* Implementation of "end_diagnostic". */
111 static void
112 jit_end_diagnostic (diagnostic_context *context,
113 diagnostic_info *diagnostic)
115 gcc_assert (gcc::jit::active_playback_ctxt);
116 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
118 /* Delegate to the playback context (and thence to the
119 recording context). */
120 gcc::jit::active_playback_ctxt->add_diagnostic (context, diagnostic);
123 /* Language hooks. */
125 static bool
126 jit_langhook_init (void)
128 gcc_assert (gcc::jit::active_playback_ctxt);
129 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
131 static bool registered_root_tab = false;
132 if (!registered_root_tab)
134 ggc_register_root_tab (jit_root_tab);
135 registered_root_tab = true;
138 gcc_assert (global_dc);
139 global_dc->begin_diagnostic = jit_begin_diagnostic;
140 global_dc->end_diagnostic = jit_end_diagnostic;
142 build_common_tree_nodes (false);
144 /* I don't know why this has to be done explicitly. */
145 void_list_node = build_tree_list (NULL_TREE, void_type_node);
147 build_common_builtin_nodes ();
149 /* The default precision for floating point numbers. This is used
150 for floating point constants with abstract type. This may
151 eventually be controllable by a command line option. */
152 mpfr_set_default_prec (256);
154 return true;
157 static void
158 jit_langhook_parse_file (void)
160 /* Replay the activity by the client, recorded on the context. */
161 gcc_assert (gcc::jit::active_playback_ctxt);
162 gcc::jit::active_playback_ctxt->replay ();
165 static tree
166 jit_langhook_type_for_mode (enum machine_mode mode, int unsignedp)
168 if (mode == TYPE_MODE (float_type_node))
169 return float_type_node;
171 if (mode == TYPE_MODE (double_type_node))
172 return double_type_node;
174 if (mode == TYPE_MODE (intQI_type_node))
175 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
176 if (mode == TYPE_MODE (intHI_type_node))
177 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
178 if (mode == TYPE_MODE (intSI_type_node))
179 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
180 if (mode == TYPE_MODE (intDI_type_node))
181 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
182 if (mode == TYPE_MODE (intTI_type_node))
183 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
185 if (mode == TYPE_MODE (integer_type_node))
186 return unsignedp ? unsigned_type_node : integer_type_node;
188 if (mode == TYPE_MODE (long_integer_type_node))
189 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
191 if (mode == TYPE_MODE (long_long_integer_type_node))
192 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
194 if (COMPLEX_MODE_P (mode))
196 if (mode == TYPE_MODE (complex_float_type_node))
197 return complex_float_type_node;
198 if (mode == TYPE_MODE (complex_double_type_node))
199 return complex_double_type_node;
200 if (mode == TYPE_MODE (complex_long_double_type_node))
201 return complex_long_double_type_node;
202 if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
203 return complex_integer_type_node;
206 /* gcc_unreachable */
207 return NULL;
210 static tree
211 jit_langhook_type_for_size (unsigned int bits ATTRIBUTE_UNUSED,
212 int unsignedp ATTRIBUTE_UNUSED)
214 gcc_unreachable ();
215 return NULL;
218 /* Record a builtin function. We just ignore builtin functions. */
220 static tree
221 jit_langhook_builtin_function (tree decl)
223 return decl;
226 static bool
227 jit_langhook_global_bindings_p (void)
229 gcc_unreachable ();
230 return true;
233 static tree
234 jit_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED)
236 gcc_unreachable ();
239 static tree
240 jit_langhook_getdecls (void)
242 return NULL;
245 #undef LANG_HOOKS_NAME
246 #define LANG_HOOKS_NAME "libgccjit"
248 #undef LANG_HOOKS_INIT
249 #define LANG_HOOKS_INIT jit_langhook_init
251 #undef LANG_HOOKS_PARSE_FILE
252 #define LANG_HOOKS_PARSE_FILE jit_langhook_parse_file
254 #undef LANG_HOOKS_TYPE_FOR_MODE
255 #define LANG_HOOKS_TYPE_FOR_MODE jit_langhook_type_for_mode
257 #undef LANG_HOOKS_TYPE_FOR_SIZE
258 #define LANG_HOOKS_TYPE_FOR_SIZE jit_langhook_type_for_size
260 #undef LANG_HOOKS_BUILTIN_FUNCTION
261 #define LANG_HOOKS_BUILTIN_FUNCTION jit_langhook_builtin_function
263 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
264 #define LANG_HOOKS_GLOBAL_BINDINGS_P jit_langhook_global_bindings_p
266 #undef LANG_HOOKS_PUSHDECL
267 #define LANG_HOOKS_PUSHDECL jit_langhook_pushdecl
269 #undef LANG_HOOKS_GETDECLS
270 #define LANG_HOOKS_GETDECLS jit_langhook_getdecls
272 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
274 #include "gt-jit-dummy-frontend.h"
275 #include "gtype-jit.h"