xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/jit/dummy-frontend.c (revision e6c7e151de239c49d2e38720a061ed9d1fa99309)
1 /* jit.c -- Dummy "frontend" for use during JIT-compilation.
2    Copyright (C) 2013-2017 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 "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"
29 
30 
31 #include <mpfr.h>
32 
33 /* Language-dependent contents of a type.  */
34 
35 struct GTY(()) lang_type
36 {
37   char dummy;
38 };
39 
40 /* Language-dependent contents of a decl.  */
41 
42 struct GTY((variable_size)) lang_decl
43 {
44   char dummy;
45 };
46 
47 /* Language-dependent contents of an identifier.  This must include a
48    tree_identifier.  */
49 
50 struct GTY(()) lang_identifier
51 {
52   struct tree_identifier common;
53 };
54 
55 /* The resulting tree type.  */
56 
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
60 {
61   union tree_node GTY((tag ("0"),
62 		       desc ("tree_node_structure (&%h)"))) generic;
63   struct lang_identifier GTY((tag ("1"))) identifier;
64 };
65 
66 /* We don't use language_function.  */
67 
68 struct GTY(()) language_function
69 {
70   int dummy;
71 };
72 
73 /* GC-marking callback for use from jit_root_tab.
74 
75    If there's an active playback context, call its marking method
76    so that it can mark any pointers it references.  */
77 
78 static void my_ggc_walker (void *)
79 {
80   if (gcc::jit::active_playback_ctxt)
81     gcc::jit::active_playback_ctxt->gt_ggc_mx ();
82 }
83 
84 const char *dummy;
85 
86 struct ggc_root_tab jit_root_tab[] =
87   {
88     {
89       &dummy, 1, 0, my_ggc_walker, NULL
90     },
91     LAST_GGC_ROOT_TAB
92   };
93 
94 /* JIT-specific implementation of diagnostic callbacks.  */
95 
96 /* Implementation of "begin_diagnostic".  */
97 
98 static void
99 jit_begin_diagnostic (diagnostic_context */*context*/,
100 		      diagnostic_info */*diagnostic*/)
101 {
102   gcc_assert (gcc::jit::active_playback_ctxt);
103   JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
104 
105   /* No-op (apart from logging); the real error-handling is done in the
106      "end_diagnostic" hook.  */
107 }
108 
109 /* Implementation of "end_diagnostic".  */
110 
111 static void
112 jit_end_diagnostic (diagnostic_context *context,
113 		    diagnostic_info *diagnostic)
114 {
115   gcc_assert (gcc::jit::active_playback_ctxt);
116   JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
117 
118   /* Delegate to the playback context (and thence to the
119      recording context).  */
120   gcc::jit::active_playback_ctxt->add_diagnostic (context, diagnostic);
121 }
122 
123 /* Language hooks.  */
124 
125 static bool
126 jit_langhook_init (void)
127 {
128   gcc_assert (gcc::jit::active_playback_ctxt);
129   JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ());
130 
131   static bool registered_root_tab = false;
132   if (!registered_root_tab)
133     {
134       ggc_register_root_tab (jit_root_tab);
135       registered_root_tab = true;
136     }
137 
138   gcc_assert (global_dc);
139   global_dc->begin_diagnostic = jit_begin_diagnostic;
140   global_dc->end_diagnostic = jit_end_diagnostic;
141 
142   build_common_tree_nodes (false);
143 
144   /* I don't know why this has to be done explicitly.  */
145   void_list_node = build_tree_list (NULL_TREE, void_type_node);
146 
147   build_common_builtin_nodes ();
148 
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);
153 
154   return true;
155 }
156 
157 static void
158 jit_langhook_parse_file (void)
159 {
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 ();
163 }
164 
165 static tree
166 jit_langhook_type_for_mode (enum machine_mode mode, int unsignedp)
167 {
168   if (mode == TYPE_MODE (float_type_node))
169     return float_type_node;
170 
171   if (mode == TYPE_MODE (double_type_node))
172     return double_type_node;
173 
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;
184 
185   if (mode == TYPE_MODE (integer_type_node))
186     return unsignedp ? unsigned_type_node : integer_type_node;
187 
188   if (mode == TYPE_MODE (long_integer_type_node))
189     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
190 
191   if (mode == TYPE_MODE (long_long_integer_type_node))
192     return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
193 
194   if (COMPLEX_MODE_P (mode))
195     {
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;
204     }
205 
206   /* gcc_unreachable */
207   return NULL;
208 }
209 
210 /* Record a builtin function.  We just ignore builtin functions.  */
211 
212 static tree
213 jit_langhook_builtin_function (tree decl)
214 {
215   return decl;
216 }
217 
218 static bool
219 jit_langhook_global_bindings_p (void)
220 {
221   gcc_unreachable ();
222   return true;
223 }
224 
225 static tree
226 jit_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED)
227 {
228   gcc_unreachable ();
229 }
230 
231 static tree
232 jit_langhook_getdecls (void)
233 {
234   return NULL;
235 }
236 
237 #undef LANG_HOOKS_NAME
238 #define LANG_HOOKS_NAME		"libgccjit"
239 
240 #undef LANG_HOOKS_INIT
241 #define LANG_HOOKS_INIT		jit_langhook_init
242 
243 #undef LANG_HOOKS_PARSE_FILE
244 #define LANG_HOOKS_PARSE_FILE		jit_langhook_parse_file
245 
246 #undef LANG_HOOKS_TYPE_FOR_MODE
247 #define LANG_HOOKS_TYPE_FOR_MODE	jit_langhook_type_for_mode
248 
249 #undef LANG_HOOKS_BUILTIN_FUNCTION
250 #define LANG_HOOKS_BUILTIN_FUNCTION	jit_langhook_builtin_function
251 
252 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
253 #define LANG_HOOKS_GLOBAL_BINDINGS_P	jit_langhook_global_bindings_p
254 
255 #undef LANG_HOOKS_PUSHDECL
256 #define LANG_HOOKS_PUSHDECL		jit_langhook_pushdecl
257 
258 #undef LANG_HOOKS_GETDECLS
259 #define LANG_HOOKS_GETDECLS		jit_langhook_getdecls
260 
261 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
262 
263 #include "gt-jit-dummy-frontend.h"
264 #include "gtype-jit.h"
265