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