2015-07-14 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / jit / dummy-frontend.c
blob1a6b09a35d125919210160a642cb7b5a7d4a0c28
1 /* jit.c -- Dummy "frontend" for use during JIT-compilation.
2 Copyright (C) 2013-2015 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 "opts.h"
24 #include "alias.h"
25 #include "tree.h"
26 #include "stor-layout.h"
27 #include "inchash.h"
28 #include "debug.h"
29 #include "langhooks.h"
30 #include "langhooks-def.h"
31 #include "hash-map.h"
32 #include "vec.h"
33 #include "hashtab.h"
34 #include "tm.h"
35 #include "hard-reg-set.h"
36 #include "function.h"
37 #include "dumpfile.h"
38 #include "cgraph.h"
40 #include "jit-common.h"
41 #include "jit-logging.h"
42 #include "jit-playback.h"
44 #include <mpfr.h>
46 /* Language-dependent contents of a type. */
48 struct GTY(()) lang_type
50 char dummy;
53 /* Language-dependent contents of a decl. */
55 struct GTY((variable_size)) lang_decl
57 char dummy;
60 /* Language-dependent contents of an identifier. This must include a
61 tree_identifier. */
63 struct GTY(()) lang_identifier
65 struct tree_identifier common;
68 /* The resulting tree type. */
70 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
71 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
72 lang_tree_node
74 union tree_node GTY((tag ("0"),
75 desc ("tree_node_structure (&%h)"))) generic;
76 struct lang_identifier GTY((tag ("1"))) identifier;
79 /* We don't use language_function. */
81 struct GTY(()) language_function
83 int dummy;
86 /* GC-marking callback for use from jit_root_tab.
88 If there's an active playback context, call its marking method
89 so that it can mark any pointers it references. */
91 static void my_ggc_walker (void *)
93 if (gcc::jit::active_playback_ctxt)
94 gcc::jit::active_playback_ctxt->gt_ggc_mx ();
97 const char *dummy;
99 struct ggc_root_tab jit_root_tab[] =
102 &dummy, 1, 0, my_ggc_walker, NULL
104 LAST_GGC_ROOT_TAB
107 /* Language hooks. */
109 static bool
110 jit_langhook_init (void)
112 gcc_assert (gcc::jit::active_playback_ctxt);
113 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
115 static bool registered_root_tab = false;
116 if (!registered_root_tab)
118 ggc_register_root_tab (jit_root_tab);
119 registered_root_tab = true;
122 build_common_tree_nodes (false, false);
124 /* I don't know why this has to be done explicitly. */
125 void_list_node = build_tree_list (NULL_TREE, void_type_node);
127 build_common_builtin_nodes ();
129 /* The default precision for floating point numbers. This is used
130 for floating point constants with abstract type. This may
131 eventually be controllable by a command line option. */
132 mpfr_set_default_prec (256);
134 return true;
137 static void
138 jit_langhook_parse_file (void)
140 /* Replay the activity by the client, recorded on the context. */
141 gcc_assert (gcc::jit::active_playback_ctxt);
142 gcc::jit::active_playback_ctxt->replay ();
145 static tree
146 jit_langhook_type_for_mode (enum machine_mode mode, int unsignedp)
148 if (mode == TYPE_MODE (float_type_node))
149 return float_type_node;
151 if (mode == TYPE_MODE (double_type_node))
152 return double_type_node;
154 if (mode == TYPE_MODE (intQI_type_node))
155 return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
156 if (mode == TYPE_MODE (intHI_type_node))
157 return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
158 if (mode == TYPE_MODE (intSI_type_node))
159 return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
160 if (mode == TYPE_MODE (intDI_type_node))
161 return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
162 if (mode == TYPE_MODE (intTI_type_node))
163 return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
165 if (mode == TYPE_MODE (integer_type_node))
166 return unsignedp ? unsigned_type_node : integer_type_node;
168 if (mode == TYPE_MODE (long_integer_type_node))
169 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
171 if (mode == TYPE_MODE (long_long_integer_type_node))
172 return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
174 if (COMPLEX_MODE_P (mode))
176 if (mode == TYPE_MODE (complex_float_type_node))
177 return complex_float_type_node;
178 if (mode == TYPE_MODE (complex_double_type_node))
179 return complex_double_type_node;
180 if (mode == TYPE_MODE (complex_long_double_type_node))
181 return complex_long_double_type_node;
182 if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
183 return complex_integer_type_node;
186 /* gcc_unreachable */
187 return NULL;
190 static tree
191 jit_langhook_type_for_size (unsigned int bits ATTRIBUTE_UNUSED,
192 int unsignedp ATTRIBUTE_UNUSED)
194 gcc_unreachable ();
195 return NULL;
198 /* Record a builtin function. We just ignore builtin functions. */
200 static tree
201 jit_langhook_builtin_function (tree decl)
203 return decl;
206 static bool
207 jit_langhook_global_bindings_p (void)
209 gcc_unreachable ();
210 return true;
213 static tree
214 jit_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED)
216 gcc_unreachable ();
219 static tree
220 jit_langhook_getdecls (void)
222 return NULL;
225 #undef LANG_HOOKS_NAME
226 #define LANG_HOOKS_NAME "libgccjit"
228 #undef LANG_HOOKS_INIT
229 #define LANG_HOOKS_INIT jit_langhook_init
231 #undef LANG_HOOKS_PARSE_FILE
232 #define LANG_HOOKS_PARSE_FILE jit_langhook_parse_file
234 #undef LANG_HOOKS_TYPE_FOR_MODE
235 #define LANG_HOOKS_TYPE_FOR_MODE jit_langhook_type_for_mode
237 #undef LANG_HOOKS_TYPE_FOR_SIZE
238 #define LANG_HOOKS_TYPE_FOR_SIZE jit_langhook_type_for_size
240 #undef LANG_HOOKS_BUILTIN_FUNCTION
241 #define LANG_HOOKS_BUILTIN_FUNCTION jit_langhook_builtin_function
243 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
244 #define LANG_HOOKS_GLOBAL_BINDINGS_P jit_langhook_global_bindings_p
246 #undef LANG_HOOKS_PUSHDECL
247 #define LANG_HOOKS_PUSHDECL jit_langhook_pushdecl
249 #undef LANG_HOOKS_GETDECLS
250 #define LANG_HOOKS_GETDECLS jit_langhook_getdecls
252 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
254 #include "gt-jit-dummy-frontend.h"
255 #include "gtype-jit.h"