]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/jit/dummy-frontend.c
New jit API entrypoint: gcc_jit_context_set_logfile
[thirdparty/gcc.git] / gcc / jit / dummy-frontend.c
1 /* jit.c -- Dummy "frontend" for use during JIT-compilation.
2 Copyright (C) 2013-2015 Free Software Foundation, Inc.
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"
22 #include "coretypes.h"
23 #include "opts.h"
24 #include "signop.h"
25 #include "tree-core.h"
26 #include "stor-layout.h"
27 #include "tree.h"
28 #include "debug.h"
29 #include "langhooks.h"
30 #include "langhooks-def.h"
31 #include "hash-map.h"
32 #include "is-a.h"
33 #include "plugin-api.h"
34 #include "vec.h"
35 #include "hashtab.h"
36 #include "hash-set.h"
37 #include "machmode.h"
38 #include "tm.h"
39 #include "hard-reg-set.h"
40 #include "function.h"
41 #include "ipa-ref.h"
42 #include "dumpfile.h"
43 #include "cgraph.h"
44
45 #include "jit-common.h"
46 #include "jit-logging.h"
47 #include "jit-playback.h"
48
49 #include <mpfr.h>
50
51 /* Language-dependent contents of a type. */
52
53 struct GTY(()) lang_type
54 {
55 char dummy;
56 };
57
58 /* Language-dependent contents of a decl. */
59
60 struct GTY((variable_size)) lang_decl
61 {
62 char dummy;
63 };
64
65 /* Language-dependent contents of an identifier. This must include a
66 tree_identifier. */
67
68 struct GTY(()) lang_identifier
69 {
70 struct tree_identifier common;
71 };
72
73 /* The resulting tree type. */
74
75 union GTY((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"),
76 chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN (&%h.generic)) : NULL")))
77 lang_tree_node
78 {
79 union tree_node GTY((tag ("0"),
80 desc ("tree_node_structure (&%h)"))) generic;
81 struct lang_identifier GTY((tag ("1"))) identifier;
82 };
83
84 /* We don't use language_function. */
85
86 struct GTY(()) language_function
87 {
88 int dummy;
89 };
90
91 /* GC-marking callback for use from jit_root_tab.
92
93 If there's an active playback context, call its marking method
94 so that it can mark any pointers it references. */
95
96 static void my_ggc_walker (void *)
97 {
98 if (gcc::jit::active_playback_ctxt)
99 gcc::jit::active_playback_ctxt->gt_ggc_mx ();
100 }
101
102 const char *dummy;
103
104 struct ggc_root_tab jit_root_tab[] =
105 {
106 {
107 &dummy, 1, 0, my_ggc_walker, NULL
108 },
109 LAST_GGC_ROOT_TAB
110 };
111
112 /* Language hooks. */
113
114 static bool
115 jit_langhook_init (void)
116 {
117 gcc_assert (gcc::jit::active_playback_ctxt);
118 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
119
120 static bool registered_root_tab = false;
121 if (!registered_root_tab)
122 {
123 ggc_register_root_tab (jit_root_tab);
124 registered_root_tab = true;
125 }
126
127 build_common_tree_nodes (false, false);
128
129 /* I don't know why this has to be done explicitly. */
130 void_list_node = build_tree_list (NULL_TREE, void_type_node);
131
132 build_common_builtin_nodes ();
133
134 /* The default precision for floating point numbers. This is used
135 for floating point constants with abstract type. This may
136 eventually be controllable by a command line option. */
137 mpfr_set_default_prec (256);
138
139 return true;
140 }
141
142 static void
143 jit_langhook_parse_file (void)
144 {
145 /* Replay the activity by the client, recorded on the context. */
146 gcc_assert (gcc::jit::active_playback_ctxt);
147 gcc::jit::active_playback_ctxt->replay ();
148 }
149
150 static tree
151 jit_langhook_type_for_mode (enum machine_mode mode, int unsignedp)
152 {
153 if (mode == TYPE_MODE (float_type_node))
154 return float_type_node;
155
156 if (mode == TYPE_MODE (double_type_node))
157 return double_type_node;
158
159 if (mode == TYPE_MODE (integer_type_node))
160 return unsignedp ? unsigned_type_node : integer_type_node;
161
162 if (mode == TYPE_MODE (long_integer_type_node))
163 return unsignedp ? long_unsigned_type_node : long_integer_type_node;
164
165 if (COMPLEX_MODE_P (mode))
166 {
167 if (mode == TYPE_MODE (complex_float_type_node))
168 return complex_float_type_node;
169 if (mode == TYPE_MODE (complex_double_type_node))
170 return complex_double_type_node;
171 if (mode == TYPE_MODE (complex_long_double_type_node))
172 return complex_long_double_type_node;
173 if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp)
174 return complex_integer_type_node;
175 }
176
177 /* gcc_unreachable */
178 return NULL;
179 }
180
181 static tree
182 jit_langhook_type_for_size (unsigned int bits ATTRIBUTE_UNUSED,
183 int unsignedp ATTRIBUTE_UNUSED)
184 {
185 gcc_unreachable ();
186 return NULL;
187 }
188
189 /* Record a builtin function. We just ignore builtin functions. */
190
191 static tree
192 jit_langhook_builtin_function (tree decl)
193 {
194 return decl;
195 }
196
197 static bool
198 jit_langhook_global_bindings_p (void)
199 {
200 gcc_unreachable ();
201 return true;
202 }
203
204 static tree
205 jit_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED)
206 {
207 gcc_unreachable ();
208 }
209
210 static tree
211 jit_langhook_getdecls (void)
212 {
213 return NULL;
214 }
215
216 static void
217 jit_langhook_write_globals (void)
218 {
219 gcc_assert (gcc::jit::active_playback_ctxt);
220 JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
221
222 /* This is the hook that runs the middle and backends: */
223 symtab->finalize_compilation_unit ();
224 }
225
226 #undef LANG_HOOKS_NAME
227 #define LANG_HOOKS_NAME "libgccjit"
228
229 #undef LANG_HOOKS_INIT
230 #define LANG_HOOKS_INIT jit_langhook_init
231
232 #undef LANG_HOOKS_PARSE_FILE
233 #define LANG_HOOKS_PARSE_FILE jit_langhook_parse_file
234
235 #undef LANG_HOOKS_TYPE_FOR_MODE
236 #define LANG_HOOKS_TYPE_FOR_MODE jit_langhook_type_for_mode
237
238 #undef LANG_HOOKS_TYPE_FOR_SIZE
239 #define LANG_HOOKS_TYPE_FOR_SIZE jit_langhook_type_for_size
240
241 #undef LANG_HOOKS_BUILTIN_FUNCTION
242 #define LANG_HOOKS_BUILTIN_FUNCTION jit_langhook_builtin_function
243
244 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
245 #define LANG_HOOKS_GLOBAL_BINDINGS_P jit_langhook_global_bindings_p
246
247 #undef LANG_HOOKS_PUSHDECL
248 #define LANG_HOOKS_PUSHDECL jit_langhook_pushdecl
249
250 #undef LANG_HOOKS_GETDECLS
251 #define LANG_HOOKS_GETDECLS jit_langhook_getdecls
252
253 #undef LANG_HOOKS_WRITE_GLOBALS
254 #define LANG_HOOKS_WRITE_GLOBALS jit_langhook_write_globals
255
256 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
257
258 #include "gt-jit-dummy-frontend.h"
259 #include "gtype-jit.h"