annotate gcc/jit/libgccjit.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Implementation of the C API; all wrappers into the internal C++ API
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2013-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
8 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
10 any later version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but
kono
parents:
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
kono
parents:
diff changeset
15 General Public License for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 #include "config.h"
kono
parents:
diff changeset
22 #include "system.h"
kono
parents:
diff changeset
23 #include "coretypes.h"
kono
parents:
diff changeset
24 #include "timevar.h"
kono
parents:
diff changeset
25 #include "typed-splay-tree.h"
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 #include "libgccjit.h"
kono
parents:
diff changeset
28 #include "jit-recording.h"
kono
parents:
diff changeset
29 #include "jit-result.h"
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 /* The opaque types used by the public API are actually subclasses
kono
parents:
diff changeset
32 of the gcc::jit::recording classes. */
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 struct gcc_jit_context : public gcc::jit::recording::context
kono
parents:
diff changeset
35 {
kono
parents:
diff changeset
36 gcc_jit_context (gcc_jit_context *parent_ctxt) :
kono
parents:
diff changeset
37 context (parent_ctxt)
kono
parents:
diff changeset
38 {}
kono
parents:
diff changeset
39 };
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 struct gcc_jit_result : public gcc::jit::result
kono
parents:
diff changeset
42 {
kono
parents:
diff changeset
43 };
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 struct gcc_jit_object : public gcc::jit::recording::memento
kono
parents:
diff changeset
46 {
kono
parents:
diff changeset
47 };
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 struct gcc_jit_location : public gcc::jit::recording::location
kono
parents:
diff changeset
50 {
kono
parents:
diff changeset
51 };
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 struct gcc_jit_type : public gcc::jit::recording::type
kono
parents:
diff changeset
54 {
kono
parents:
diff changeset
55 };
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 struct gcc_jit_struct : public gcc::jit::recording::struct_
kono
parents:
diff changeset
58 {
kono
parents:
diff changeset
59 };
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 struct gcc_jit_field : public gcc::jit::recording::field
kono
parents:
diff changeset
62 {
kono
parents:
diff changeset
63 };
kono
parents:
diff changeset
64
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
65 struct gcc_jit_bitfield : public gcc::jit::recording::bitfield
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
66 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
67 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
68
111
kono
parents:
diff changeset
69 struct gcc_jit_function : public gcc::jit::recording::function
kono
parents:
diff changeset
70 {
kono
parents:
diff changeset
71 };
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 struct gcc_jit_block : public gcc::jit::recording::block
kono
parents:
diff changeset
74 {
kono
parents:
diff changeset
75 };
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 struct gcc_jit_rvalue : public gcc::jit::recording::rvalue
kono
parents:
diff changeset
78 {
kono
parents:
diff changeset
79 };
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 struct gcc_jit_lvalue : public gcc::jit::recording::lvalue
kono
parents:
diff changeset
82 {
kono
parents:
diff changeset
83 };
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 struct gcc_jit_param : public gcc::jit::recording::param
kono
parents:
diff changeset
86 {
kono
parents:
diff changeset
87 };
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 struct gcc_jit_case : public gcc::jit::recording::case_
kono
parents:
diff changeset
90 {
kono
parents:
diff changeset
91 };
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 struct gcc_jit_timer : public timer
kono
parents:
diff changeset
94 {
kono
parents:
diff changeset
95 };
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 /**********************************************************************
kono
parents:
diff changeset
98 Error-handling.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 We try to gracefully handle API usage errors by being defensive
kono
parents:
diff changeset
101 at the API boundary.
kono
parents:
diff changeset
102 **********************************************************************/
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 #define JIT_BEGIN_STMT do {
kono
parents:
diff changeset
105 #define JIT_END_STMT } while(0)
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 /* Each of these error-handling macros determines if TEST_EXPR holds.
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 If TEXT_EXPR fails to hold we return from the enclosing function and
kono
parents:
diff changeset
110 print an error, either via adding an error on the given context CTXT
kono
parents:
diff changeset
111 if CTXT is non-NULL, falling back to simply printing to stderr if CTXT
kono
parents:
diff changeset
112 is NULL.
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 They have to be macros since they inject their "return" into the
kono
parents:
diff changeset
115 function they are placed in.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 The variant macros express:
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 (A) whether or not we need to return a value:
kono
parents:
diff changeset
120 RETURN_VAL_IF_FAIL* vs
kono
parents:
diff changeset
121 RETURN_IF_FAIL*,
kono
parents:
diff changeset
122 with the former returning RETURN_EXPR, and
kono
parents:
diff changeset
123 RETURN_NULL_IF_FAIL*
kono
parents:
diff changeset
124 for the common case where a NULL value is to be returned on
kono
parents:
diff changeset
125 error, and
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 (B) whether the error message is to be directly printed:
kono
parents:
diff changeset
128 RETURN_*IF_FAIL
kono
parents:
diff changeset
129 or is a format string with some number of arguments:
kono
parents:
diff changeset
130 RETURN_*IF_FAIL_PRINTF*
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 They all use JIT_BEGIN_STMT/JIT_END_STMT so they can be written with
kono
parents:
diff changeset
133 trailing semicolons.
kono
parents:
diff changeset
134 */
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 #define RETURN_VAL_IF_FAIL(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_MSG) \
kono
parents:
diff changeset
137 JIT_BEGIN_STMT \
kono
parents:
diff changeset
138 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
139 { \
kono
parents:
diff changeset
140 jit_error ((CTXT), (LOC), "%s: %s", __func__, (ERR_MSG)); \
kono
parents:
diff changeset
141 return (RETURN_EXPR); \
kono
parents:
diff changeset
142 } \
kono
parents:
diff changeset
143 JIT_END_STMT
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 #define RETURN_VAL_IF_FAIL_PRINTF1(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0) \
kono
parents:
diff changeset
146 JIT_BEGIN_STMT \
kono
parents:
diff changeset
147 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
148 { \
kono
parents:
diff changeset
149 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
kono
parents:
diff changeset
150 __func__, (A0)); \
kono
parents:
diff changeset
151 return (RETURN_EXPR); \
kono
parents:
diff changeset
152 } \
kono
parents:
diff changeset
153 JIT_END_STMT
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 #define RETURN_VAL_IF_FAIL_PRINTF2(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1) \
kono
parents:
diff changeset
156 JIT_BEGIN_STMT \
kono
parents:
diff changeset
157 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
158 { \
kono
parents:
diff changeset
159 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
kono
parents:
diff changeset
160 __func__, (A0), (A1)); \
kono
parents:
diff changeset
161 return (RETURN_EXPR); \
kono
parents:
diff changeset
162 } \
kono
parents:
diff changeset
163 JIT_END_STMT
kono
parents:
diff changeset
164
kono
parents:
diff changeset
165 #define RETURN_VAL_IF_FAIL_PRINTF3(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2) \
kono
parents:
diff changeset
166 JIT_BEGIN_STMT \
kono
parents:
diff changeset
167 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
168 { \
kono
parents:
diff changeset
169 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
kono
parents:
diff changeset
170 __func__, (A0), (A1), (A2)); \
kono
parents:
diff changeset
171 return (RETURN_EXPR); \
kono
parents:
diff changeset
172 } \
kono
parents:
diff changeset
173 JIT_END_STMT
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 #define RETURN_VAL_IF_FAIL_PRINTF4(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \
kono
parents:
diff changeset
176 JIT_BEGIN_STMT \
kono
parents:
diff changeset
177 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
178 { \
kono
parents:
diff changeset
179 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
kono
parents:
diff changeset
180 __func__, (A0), (A1), (A2), (A3)); \
kono
parents:
diff changeset
181 return (RETURN_EXPR); \
kono
parents:
diff changeset
182 } \
kono
parents:
diff changeset
183 JIT_END_STMT
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 #define RETURN_VAL_IF_FAIL_PRINTF5(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4) \
kono
parents:
diff changeset
186 JIT_BEGIN_STMT \
kono
parents:
diff changeset
187 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
188 { \
kono
parents:
diff changeset
189 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
kono
parents:
diff changeset
190 __func__, (A0), (A1), (A2), (A3), (A4)); \
kono
parents:
diff changeset
191 return (RETURN_EXPR); \
kono
parents:
diff changeset
192 } \
kono
parents:
diff changeset
193 JIT_END_STMT
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 #define RETURN_VAL_IF_FAIL_PRINTF6(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4, A5) \
kono
parents:
diff changeset
196 JIT_BEGIN_STMT \
kono
parents:
diff changeset
197 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
198 { \
kono
parents:
diff changeset
199 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
kono
parents:
diff changeset
200 __func__, (A0), (A1), (A2), (A3), (A4), (A5)); \
kono
parents:
diff changeset
201 return (RETURN_EXPR); \
kono
parents:
diff changeset
202 } \
kono
parents:
diff changeset
203 JIT_END_STMT
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 #define RETURN_NULL_IF_FAIL(TEST_EXPR, CTXT, LOC, ERR_MSG) \
kono
parents:
diff changeset
206 RETURN_VAL_IF_FAIL ((TEST_EXPR), NULL, (CTXT), (LOC), (ERR_MSG))
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 #define RETURN_NULL_IF_FAIL_PRINTF1(TEST_EXPR, CTXT, LOC, ERR_FMT, A0) \
kono
parents:
diff changeset
209 RETURN_VAL_IF_FAIL_PRINTF1 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0)
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 #define RETURN_NULL_IF_FAIL_PRINTF2(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1) \
kono
parents:
diff changeset
212 RETURN_VAL_IF_FAIL_PRINTF2 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1)
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 #define RETURN_NULL_IF_FAIL_PRINTF3(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2) \
kono
parents:
diff changeset
215 RETURN_VAL_IF_FAIL_PRINTF3 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2)
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 #define RETURN_NULL_IF_FAIL_PRINTF4(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \
kono
parents:
diff changeset
218 RETURN_VAL_IF_FAIL_PRINTF4 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2, A3)
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 #define RETURN_NULL_IF_FAIL_PRINTF5(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4) \
kono
parents:
diff changeset
221 RETURN_VAL_IF_FAIL_PRINTF5 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4)
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 #define RETURN_NULL_IF_FAIL_PRINTF6(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4, A5) \
kono
parents:
diff changeset
224 RETURN_VAL_IF_FAIL_PRINTF6 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4, A5)
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 #define RETURN_IF_FAIL(TEST_EXPR, CTXT, LOC, ERR_MSG) \
kono
parents:
diff changeset
227 JIT_BEGIN_STMT \
kono
parents:
diff changeset
228 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
229 { \
kono
parents:
diff changeset
230 jit_error ((CTXT), (LOC), "%s: %s", __func__, (ERR_MSG)); \
kono
parents:
diff changeset
231 return; \
kono
parents:
diff changeset
232 } \
kono
parents:
diff changeset
233 JIT_END_STMT
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 #define RETURN_IF_FAIL_PRINTF1(TEST_EXPR, CTXT, LOC, ERR_FMT, A0) \
kono
parents:
diff changeset
236 JIT_BEGIN_STMT \
kono
parents:
diff changeset
237 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
238 { \
kono
parents:
diff changeset
239 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
kono
parents:
diff changeset
240 __func__, (A0)); \
kono
parents:
diff changeset
241 return; \
kono
parents:
diff changeset
242 } \
kono
parents:
diff changeset
243 JIT_END_STMT
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 #define RETURN_IF_FAIL_PRINTF2(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1) \
kono
parents:
diff changeset
246 JIT_BEGIN_STMT \
kono
parents:
diff changeset
247 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
248 { \
kono
parents:
diff changeset
249 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
kono
parents:
diff changeset
250 __func__, (A0), (A1)); \
kono
parents:
diff changeset
251 return; \
kono
parents:
diff changeset
252 } \
kono
parents:
diff changeset
253 JIT_END_STMT
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 #define RETURN_IF_FAIL_PRINTF4(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \
kono
parents:
diff changeset
256 JIT_BEGIN_STMT \
kono
parents:
diff changeset
257 if (!(TEST_EXPR)) \
kono
parents:
diff changeset
258 { \
kono
parents:
diff changeset
259 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
kono
parents:
diff changeset
260 __func__, (A0), (A1), (A2), (A3)); \
kono
parents:
diff changeset
261 return; \
kono
parents:
diff changeset
262 } \
kono
parents:
diff changeset
263 JIT_END_STMT
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 /* Check that BLOCK is non-NULL, and that it's OK to add statements to
kono
parents:
diff changeset
266 it. This will fail if BLOCK has already been terminated by some
kono
parents:
diff changeset
267 kind of jump or a return. */
kono
parents:
diff changeset
268 #define RETURN_IF_NOT_VALID_BLOCK(BLOCK, LOC) \
kono
parents:
diff changeset
269 JIT_BEGIN_STMT \
kono
parents:
diff changeset
270 RETURN_IF_FAIL ((BLOCK), NULL, (LOC), "NULL block"); \
kono
parents:
diff changeset
271 RETURN_IF_FAIL_PRINTF2 ( \
kono
parents:
diff changeset
272 !(BLOCK)->has_been_terminated (), \
kono
parents:
diff changeset
273 (BLOCK)->get_context (), \
kono
parents:
diff changeset
274 (LOC), \
kono
parents:
diff changeset
275 "adding to terminated block: %s (already terminated by: %s)", \
kono
parents:
diff changeset
276 (BLOCK)->get_debug_string (), \
kono
parents:
diff changeset
277 (BLOCK)->get_last_statement ()->get_debug_string ()); \
kono
parents:
diff changeset
278 JIT_END_STMT
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 /* As RETURN_IF_NOT_VALID_BLOCK, but injecting a "return NULL;" if it
kono
parents:
diff changeset
281 fails. */
kono
parents:
diff changeset
282 #define RETURN_NULL_IF_NOT_VALID_BLOCK(BLOCK, LOC) \
kono
parents:
diff changeset
283 JIT_BEGIN_STMT \
kono
parents:
diff changeset
284 RETURN_NULL_IF_FAIL ((BLOCK), NULL, (LOC), "NULL block"); \
kono
parents:
diff changeset
285 RETURN_NULL_IF_FAIL_PRINTF2 ( \
kono
parents:
diff changeset
286 !(BLOCK)->has_been_terminated (), \
kono
parents:
diff changeset
287 (BLOCK)->get_context (), \
kono
parents:
diff changeset
288 (LOC), \
kono
parents:
diff changeset
289 "adding to terminated block: %s (already terminated by: %s)", \
kono
parents:
diff changeset
290 (BLOCK)->get_debug_string (), \
kono
parents:
diff changeset
291 (BLOCK)->get_last_statement ()->get_debug_string ()); \
kono
parents:
diff changeset
292 JIT_END_STMT
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 /* Format the given string, and report it as an error, either on CTXT
kono
parents:
diff changeset
295 if non-NULL, or by printing to stderr if we have a NULL context.
kono
parents:
diff changeset
296 LOC gives the source location where the error occcurred, and can be
kono
parents:
diff changeset
297 NULL. */
kono
parents:
diff changeset
298
kono
parents:
diff changeset
299 static void
kono
parents:
diff changeset
300 jit_error (gcc::jit::recording::context *ctxt,
kono
parents:
diff changeset
301 gcc_jit_location *loc,
kono
parents:
diff changeset
302 const char *fmt, ...)
kono
parents:
diff changeset
303 GNU_PRINTF(3, 4);
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 static void
kono
parents:
diff changeset
306 jit_error (gcc::jit::recording::context *ctxt,
kono
parents:
diff changeset
307 gcc_jit_location *loc,
kono
parents:
diff changeset
308 const char *fmt, ...)
kono
parents:
diff changeset
309 {
kono
parents:
diff changeset
310 va_list ap;
kono
parents:
diff changeset
311 va_start (ap, fmt);
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 if (ctxt)
kono
parents:
diff changeset
314 ctxt->add_error_va (loc, fmt, ap);
kono
parents:
diff changeset
315 else
kono
parents:
diff changeset
316 {
kono
parents:
diff changeset
317 /* No context? Send to stderr. */
kono
parents:
diff changeset
318 vfprintf (stderr, fmt, ap);
kono
parents:
diff changeset
319 fprintf (stderr, "\n");
kono
parents:
diff changeset
320 }
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 va_end (ap);
kono
parents:
diff changeset
323 }
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 /* Determine whether or not we can write to lvalues of type LTYPE from
kono
parents:
diff changeset
326 rvalues of type RTYPE, detecting type errors such as attempting to
kono
parents:
diff changeset
327 write to an int with a string literal (without an explicit cast).
kono
parents:
diff changeset
328
kono
parents:
diff changeset
329 This is implemented by calling the
kono
parents:
diff changeset
330 gcc::jit::recording::type::accepts_writes_from virtual function on
kono
parents:
diff changeset
331 LTYPE. */
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 static bool
kono
parents:
diff changeset
334 compatible_types (gcc::jit::recording::type *ltype,
kono
parents:
diff changeset
335 gcc::jit::recording::type *rtype)
kono
parents:
diff changeset
336 {
kono
parents:
diff changeset
337 return ltype->accepts_writes_from (rtype);
kono
parents:
diff changeset
338 }
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 /* Public entrypoint for acquiring a gcc_jit_context.
kono
parents:
diff changeset
341 Note that this creates a new top-level context; contrast with
kono
parents:
diff changeset
342 gcc_jit_context_new_child_context below.
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 The real work is done in the constructor for
kono
parents:
diff changeset
345 gcc::jit::recording::context in jit-recording.c. */
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 gcc_jit_context *
kono
parents:
diff changeset
348 gcc_jit_context_acquire (void)
kono
parents:
diff changeset
349 {
kono
parents:
diff changeset
350 gcc_jit_context *ctxt = new gcc_jit_context (NULL);
kono
parents:
diff changeset
351 ctxt->log ("new top-level ctxt: %p", (void *)ctxt);
kono
parents:
diff changeset
352 return ctxt;
kono
parents:
diff changeset
353 }
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 /* Public entrypoint for releasing a gcc_jit_context.
kono
parents:
diff changeset
356 The real work is done in the destructor for
kono
parents:
diff changeset
357 gcc::jit::recording::context in jit-recording.c. */
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 void
kono
parents:
diff changeset
360 gcc_jit_context_release (gcc_jit_context *ctxt)
kono
parents:
diff changeset
361 {
kono
parents:
diff changeset
362 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL ctxt");
kono
parents:
diff changeset
363 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
364 ctxt->log ("deleting ctxt: %p", (void *)ctxt);
kono
parents:
diff changeset
365 delete ctxt;
kono
parents:
diff changeset
366 }
kono
parents:
diff changeset
367
kono
parents:
diff changeset
368 /* Public entrypoint for creating a child context within
kono
parents:
diff changeset
369 PARENT_CTXT. See description in libgccjit.h.
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 The real work is done in the constructor for
kono
parents:
diff changeset
372 gcc::jit::recording::context in jit-recording.c. */
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 gcc_jit_context *
kono
parents:
diff changeset
375 gcc_jit_context_new_child_context (gcc_jit_context *parent_ctxt)
kono
parents:
diff changeset
376 {
kono
parents:
diff changeset
377 RETURN_NULL_IF_FAIL (parent_ctxt, NULL, NULL, "NULL parent ctxt");
kono
parents:
diff changeset
378 JIT_LOG_FUNC (parent_ctxt->get_logger ());
kono
parents:
diff changeset
379 parent_ctxt->log ("parent_ctxt: %p", (void *)parent_ctxt);
kono
parents:
diff changeset
380 gcc_jit_context *child_ctxt = new gcc_jit_context (parent_ctxt);
kono
parents:
diff changeset
381 child_ctxt->log ("new child_ctxt: %p", (void *)child_ctxt);
kono
parents:
diff changeset
382 return child_ctxt;
kono
parents:
diff changeset
383 }
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 After error-checking, the real work is done by the
kono
parents:
diff changeset
388 gcc::jit::recording::context::new_location
kono
parents:
diff changeset
389 method in jit-recording.c. */
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 gcc_jit_location *
kono
parents:
diff changeset
392 gcc_jit_context_new_location (gcc_jit_context *ctxt,
kono
parents:
diff changeset
393 const char *filename,
kono
parents:
diff changeset
394 int line,
kono
parents:
diff changeset
395 int column)
kono
parents:
diff changeset
396 {
kono
parents:
diff changeset
397 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
398 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
399 return (gcc_jit_location *)ctxt->new_location (filename, line, column, true);
kono
parents:
diff changeset
400 }
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 After error-checking, this calls the trivial
kono
parents:
diff changeset
405 gcc::jit::recording::memento::as_object method (a location is a
kono
parents:
diff changeset
406 memento), in jit-recording.h. */
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 gcc_jit_object *
kono
parents:
diff changeset
409 gcc_jit_location_as_object (gcc_jit_location *loc)
kono
parents:
diff changeset
410 {
kono
parents:
diff changeset
411 RETURN_NULL_IF_FAIL (loc, NULL, NULL, "NULL location");
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 return static_cast <gcc_jit_object *> (loc->as_object ());
kono
parents:
diff changeset
414 }
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 After error-checking, this calls the trivial
kono
parents:
diff changeset
419 gcc::jit::recording::memento::as_object method (a type is a
kono
parents:
diff changeset
420 memento), in jit-recording.h. */
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 gcc_jit_object *
kono
parents:
diff changeset
423 gcc_jit_type_as_object (gcc_jit_type *type)
kono
parents:
diff changeset
424 {
kono
parents:
diff changeset
425 RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type");
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 return static_cast <gcc_jit_object *> (type->as_object ());
kono
parents:
diff changeset
428 }
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 /* Public entrypoint for getting a specific type from a context.
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 After error-checking, the real work is done by the
kono
parents:
diff changeset
433 gcc::jit::recording::context::get_type method, in
kono
parents:
diff changeset
434 jit-recording.c */
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 gcc_jit_type *
kono
parents:
diff changeset
437 gcc_jit_context_get_type (gcc_jit_context *ctxt,
kono
parents:
diff changeset
438 enum gcc_jit_types type)
kono
parents:
diff changeset
439 {
kono
parents:
diff changeset
440 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
441 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
442 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
443 (type >= GCC_JIT_TYPE_VOID
kono
parents:
diff changeset
444 && type <= GCC_JIT_TYPE_FILE_PTR),
kono
parents:
diff changeset
445 ctxt, NULL,
kono
parents:
diff changeset
446 "unrecognized value for enum gcc_jit_types: %i", type);
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 return (gcc_jit_type *)ctxt->get_type (type);
kono
parents:
diff changeset
449 }
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 /* Public entrypoint for getting the integer type of the given size and
kono
parents:
diff changeset
452 signedness.
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 After error-checking, the real work is done by the
kono
parents:
diff changeset
455 gcc::jit::recording::context::get_int_type method,
kono
parents:
diff changeset
456 in jit-recording.c. */
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 gcc_jit_type *
kono
parents:
diff changeset
459 gcc_jit_context_get_int_type (gcc_jit_context *ctxt,
kono
parents:
diff changeset
460 int num_bytes, int is_signed)
kono
parents:
diff changeset
461 {
kono
parents:
diff changeset
462 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
463 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
464 RETURN_NULL_IF_FAIL (num_bytes >= 0, ctxt, NULL, "negative size");
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 return (gcc_jit_type *)ctxt->get_int_type (num_bytes, is_signed);
kono
parents:
diff changeset
467 }
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 After error-checking, the real work is done by the
kono
parents:
diff changeset
472 gcc::jit::recording::type::get_pointer method, in
kono
parents:
diff changeset
473 jit-recording.c */
kono
parents:
diff changeset
474
kono
parents:
diff changeset
475 gcc_jit_type *
kono
parents:
diff changeset
476 gcc_jit_type_get_pointer (gcc_jit_type *type)
kono
parents:
diff changeset
477 {
kono
parents:
diff changeset
478 RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type");
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 return (gcc_jit_type *)type->get_pointer ();
kono
parents:
diff changeset
481 }
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 After error-checking, the real work is done by the
kono
parents:
diff changeset
486 gcc::jit::recording::type::get_const method, in
kono
parents:
diff changeset
487 jit-recording.c. */
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 gcc_jit_type *
kono
parents:
diff changeset
490 gcc_jit_type_get_const (gcc_jit_type *type)
kono
parents:
diff changeset
491 {
kono
parents:
diff changeset
492 RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type");
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 return (gcc_jit_type *)type->get_const ();
kono
parents:
diff changeset
495 }
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
498
kono
parents:
diff changeset
499 After error-checking, the real work is done by the
kono
parents:
diff changeset
500 gcc::jit::recording::type::get_volatile method, in
kono
parents:
diff changeset
501 jit-recording.c. */
kono
parents:
diff changeset
502
kono
parents:
diff changeset
503 gcc_jit_type *
kono
parents:
diff changeset
504 gcc_jit_type_get_volatile (gcc_jit_type *type)
kono
parents:
diff changeset
505 {
kono
parents:
diff changeset
506 RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type");
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 return (gcc_jit_type *)type->get_volatile ();
kono
parents:
diff changeset
509 }
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 After error-checking, the real work is done by the
kono
parents:
diff changeset
514 gcc::jit::recording::context::new_array_type method, in
kono
parents:
diff changeset
515 jit-recording.c. */
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 gcc_jit_type *
kono
parents:
diff changeset
518 gcc_jit_context_new_array_type (gcc_jit_context *ctxt,
kono
parents:
diff changeset
519 gcc_jit_location *loc,
kono
parents:
diff changeset
520 gcc_jit_type *element_type,
kono
parents:
diff changeset
521 int num_elements)
kono
parents:
diff changeset
522 {
kono
parents:
diff changeset
523 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
524 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
525 /* LOC can be NULL. */
kono
parents:
diff changeset
526 RETURN_NULL_IF_FAIL (element_type, ctxt, loc, "NULL type");
kono
parents:
diff changeset
527 RETURN_NULL_IF_FAIL (num_elements >= 0, ctxt, NULL, "negative size");
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 return (gcc_jit_type *)ctxt->new_array_type (loc,
kono
parents:
diff changeset
530 element_type,
kono
parents:
diff changeset
531 num_elements);
kono
parents:
diff changeset
532 }
kono
parents:
diff changeset
533
kono
parents:
diff changeset
534 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
535
kono
parents:
diff changeset
536 After error-checking, the real work is done by the
kono
parents:
diff changeset
537 gcc::jit::recording::context::new_field method, in
kono
parents:
diff changeset
538 jit-recording.c. */
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 gcc_jit_field *
kono
parents:
diff changeset
541 gcc_jit_context_new_field (gcc_jit_context *ctxt,
kono
parents:
diff changeset
542 gcc_jit_location *loc,
kono
parents:
diff changeset
543 gcc_jit_type *type,
kono
parents:
diff changeset
544 const char *name)
kono
parents:
diff changeset
545 {
kono
parents:
diff changeset
546 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
547 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
548 /* LOC can be NULL. */
kono
parents:
diff changeset
549 RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
kono
parents:
diff changeset
550 RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
kono
parents:
diff changeset
551 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
552 type->has_known_size (),
kono
parents:
diff changeset
553 ctxt, loc,
kono
parents:
diff changeset
554 "unknown size for field \"%s\" (type: %s)",
kono
parents:
diff changeset
555 name,
kono
parents:
diff changeset
556 type->get_debug_string ());
kono
parents:
diff changeset
557
kono
parents:
diff changeset
558 return (gcc_jit_field *)ctxt->new_field (loc, type, name);
kono
parents:
diff changeset
559 }
kono
parents:
diff changeset
560
kono
parents:
diff changeset
561 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
562
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
563 After error-checking, the real work is done by the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
564 gcc::jit::recording::context::new_bitfield method, in
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
565 jit-recording.c. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
566
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
567 gcc_jit_field *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
568 gcc_jit_context_new_bitfield (gcc_jit_context *ctxt,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
569 gcc_jit_location *loc,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
570 gcc_jit_type *type,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
571 int width,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
572 const char *name)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
573 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
574 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
575 JIT_LOG_FUNC (ctxt->get_logger ());
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
576 /* LOC can be NULL. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
577 RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
578 RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
579 RETURN_NULL_IF_FAIL_PRINTF2 (type->is_int () || type->is_bool (),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
580 ctxt, loc,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
581 "bit-field %s has non integral type %s",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
582 name, type->get_debug_string ());
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
583 RETURN_NULL_IF_FAIL_PRINTF2 (
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
584 width > 0, ctxt, loc,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
585 "invalid width %d for bitfield \"%s\" (must be > 0)",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
586 width, name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
587 RETURN_NULL_IF_FAIL_PRINTF2 (
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
588 type->has_known_size (),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
589 ctxt, loc,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
590 "unknown size for field \"%s\" (type: %s)",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
591 name,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
592 type->get_debug_string ());
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
593
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
594 return (gcc_jit_field *)ctxt->new_bitfield (loc, type, width, name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
595 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
596
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
597 /* Public entrypoint. See description in libgccjit.h.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
598
111
kono
parents:
diff changeset
599 After error-checking, this calls the trivial
kono
parents:
diff changeset
600 gcc::jit::recording::memento::as_object method (a field is a
kono
parents:
diff changeset
601 memento), in jit-recording.h. */
kono
parents:
diff changeset
602
kono
parents:
diff changeset
603 gcc_jit_object *
kono
parents:
diff changeset
604 gcc_jit_field_as_object (gcc_jit_field *field)
kono
parents:
diff changeset
605 {
kono
parents:
diff changeset
606 RETURN_NULL_IF_FAIL (field, NULL, NULL, "NULL field");
kono
parents:
diff changeset
607
kono
parents:
diff changeset
608 return static_cast <gcc_jit_object *> (field->as_object ());
kono
parents:
diff changeset
609 }
kono
parents:
diff changeset
610
kono
parents:
diff changeset
611 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 After error-checking, the real work is done by the
kono
parents:
diff changeset
614 gcc::jit::recording::context::new_struct_type method,
kono
parents:
diff changeset
615 immediately followed by a "set_fields" call on the resulting
kono
parents:
diff changeset
616 gcc::jit::recording::compound_type *, both in jit-recording.c */
kono
parents:
diff changeset
617
kono
parents:
diff changeset
618 gcc_jit_struct *
kono
parents:
diff changeset
619 gcc_jit_context_new_struct_type (gcc_jit_context *ctxt,
kono
parents:
diff changeset
620 gcc_jit_location *loc,
kono
parents:
diff changeset
621 const char *name,
kono
parents:
diff changeset
622 int num_fields,
kono
parents:
diff changeset
623 gcc_jit_field **fields)
kono
parents:
diff changeset
624 {
kono
parents:
diff changeset
625 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
626 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
627 /* LOC can be NULL. */
kono
parents:
diff changeset
628 RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
kono
parents:
diff changeset
629 if (num_fields)
kono
parents:
diff changeset
630 RETURN_NULL_IF_FAIL (fields, ctxt, loc, "NULL fields ptr");
kono
parents:
diff changeset
631 for (int i = 0; i < num_fields; i++)
kono
parents:
diff changeset
632 {
kono
parents:
diff changeset
633 RETURN_NULL_IF_FAIL (fields[i], ctxt, loc, "NULL field ptr");
kono
parents:
diff changeset
634 RETURN_NULL_IF_FAIL_PRINTF2 (
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
635 fields[i]->get_container () == NULL,
111
kono
parents:
diff changeset
636 ctxt, loc,
kono
parents:
diff changeset
637 "%s is already a field of %s",
kono
parents:
diff changeset
638 fields[i]->get_debug_string (),
kono
parents:
diff changeset
639 fields[i]->get_container ()->get_debug_string ());
kono
parents:
diff changeset
640 }
kono
parents:
diff changeset
641
kono
parents:
diff changeset
642 gcc::jit::recording::struct_ *result =
kono
parents:
diff changeset
643 ctxt->new_struct_type (loc, name);
kono
parents:
diff changeset
644 result->set_fields (loc,
kono
parents:
diff changeset
645 num_fields,
kono
parents:
diff changeset
646 (gcc::jit::recording::field **)fields);
kono
parents:
diff changeset
647 return static_cast<gcc_jit_struct *> (result);
kono
parents:
diff changeset
648 }
kono
parents:
diff changeset
649
kono
parents:
diff changeset
650 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 After error-checking, the real work is done by the
kono
parents:
diff changeset
653 gcc::jit::recording::context::new_struct_type method in
kono
parents:
diff changeset
654 jit-recording.c. */
kono
parents:
diff changeset
655
kono
parents:
diff changeset
656 gcc_jit_struct *
kono
parents:
diff changeset
657 gcc_jit_context_new_opaque_struct (gcc_jit_context *ctxt,
kono
parents:
diff changeset
658 gcc_jit_location *loc,
kono
parents:
diff changeset
659 const char *name)
kono
parents:
diff changeset
660 {
kono
parents:
diff changeset
661 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
662 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
663 /* LOC can be NULL. */
kono
parents:
diff changeset
664 RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 return (gcc_jit_struct *)ctxt->new_struct_type (loc, name);
kono
parents:
diff changeset
667 }
kono
parents:
diff changeset
668
kono
parents:
diff changeset
669 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
670
kono
parents:
diff changeset
671 After error-checking, this calls the trivial
kono
parents:
diff changeset
672 gcc::jit::recording::struct_::as_object method in
kono
parents:
diff changeset
673 jit-recording.h. */
kono
parents:
diff changeset
674
kono
parents:
diff changeset
675 gcc_jit_type *
kono
parents:
diff changeset
676 gcc_jit_struct_as_type (gcc_jit_struct *struct_type)
kono
parents:
diff changeset
677 {
kono
parents:
diff changeset
678 RETURN_NULL_IF_FAIL (struct_type, NULL, NULL, "NULL struct_type");
kono
parents:
diff changeset
679
kono
parents:
diff changeset
680 return static_cast <gcc_jit_type *> (struct_type->as_type ());
kono
parents:
diff changeset
681 }
kono
parents:
diff changeset
682
kono
parents:
diff changeset
683 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
684
kono
parents:
diff changeset
685 After error-checking, the real work is done by the
kono
parents:
diff changeset
686 gcc::jit::recording::compound_type::set_fields method in
kono
parents:
diff changeset
687 jit-recording.c. */
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 void
kono
parents:
diff changeset
690 gcc_jit_struct_set_fields (gcc_jit_struct *struct_type,
kono
parents:
diff changeset
691 gcc_jit_location *loc,
kono
parents:
diff changeset
692 int num_fields,
kono
parents:
diff changeset
693 gcc_jit_field **fields)
kono
parents:
diff changeset
694 {
kono
parents:
diff changeset
695 RETURN_IF_FAIL (struct_type, NULL, loc, "NULL struct_type");
kono
parents:
diff changeset
696 gcc::jit::recording::context *ctxt = struct_type->m_ctxt;
kono
parents:
diff changeset
697 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
698 /* LOC can be NULL. */
kono
parents:
diff changeset
699 RETURN_IF_FAIL_PRINTF1 (
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
700 struct_type->get_fields () == NULL, ctxt, loc,
111
kono
parents:
diff changeset
701 "%s already has had fields set",
kono
parents:
diff changeset
702 struct_type->get_debug_string ());
kono
parents:
diff changeset
703 if (num_fields)
kono
parents:
diff changeset
704 RETURN_IF_FAIL (fields, ctxt, loc, "NULL fields ptr");
kono
parents:
diff changeset
705 for (int i = 0; i < num_fields; i++)
kono
parents:
diff changeset
706 {
kono
parents:
diff changeset
707 RETURN_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
708 fields[i],
kono
parents:
diff changeset
709 ctxt, loc,
kono
parents:
diff changeset
710 "%s: NULL field ptr at index %i",
kono
parents:
diff changeset
711 struct_type->get_debug_string (),
kono
parents:
diff changeset
712 i);
kono
parents:
diff changeset
713 RETURN_IF_FAIL_PRINTF2 (
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
714 fields[i]->get_container () == NULL,
111
kono
parents:
diff changeset
715 ctxt, loc,
kono
parents:
diff changeset
716 "%s is already a field of %s",
kono
parents:
diff changeset
717 fields[i]->get_debug_string (),
kono
parents:
diff changeset
718 fields[i]->get_container ()->get_debug_string ());
kono
parents:
diff changeset
719 }
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 struct_type->set_fields (loc, num_fields,
kono
parents:
diff changeset
722 (gcc::jit::recording::field **)fields);
kono
parents:
diff changeset
723 }
kono
parents:
diff changeset
724
kono
parents:
diff changeset
725 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 After error-checking, the real work is done by the
kono
parents:
diff changeset
728 gcc::jit::recording::context::new_union_type method,
kono
parents:
diff changeset
729 immediately followed by a "set_fields" call on the resulting
kono
parents:
diff changeset
730 gcc::jit::recording::compound_type *, both in jit-recording.c */
kono
parents:
diff changeset
731
kono
parents:
diff changeset
732 gcc_jit_type *
kono
parents:
diff changeset
733 gcc_jit_context_new_union_type (gcc_jit_context *ctxt,
kono
parents:
diff changeset
734 gcc_jit_location *loc,
kono
parents:
diff changeset
735 const char *name,
kono
parents:
diff changeset
736 int num_fields,
kono
parents:
diff changeset
737 gcc_jit_field **fields)
kono
parents:
diff changeset
738 {
kono
parents:
diff changeset
739 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
740 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
741 /* LOC can be NULL. */
kono
parents:
diff changeset
742 RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
kono
parents:
diff changeset
743 if (num_fields)
kono
parents:
diff changeset
744 RETURN_NULL_IF_FAIL (fields, ctxt, loc, "NULL fields ptr");
kono
parents:
diff changeset
745 for (int i = 0; i < num_fields; i++)
kono
parents:
diff changeset
746 {
kono
parents:
diff changeset
747 RETURN_NULL_IF_FAIL (fields[i], ctxt, loc, "NULL field ptr");
kono
parents:
diff changeset
748 RETURN_NULL_IF_FAIL_PRINTF2 (
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
749 fields[i]->get_container () == NULL,
111
kono
parents:
diff changeset
750 ctxt, loc,
kono
parents:
diff changeset
751 "%s is already a field of %s",
kono
parents:
diff changeset
752 fields[i]->get_debug_string (),
kono
parents:
diff changeset
753 fields[i]->get_container ()->get_debug_string ());
kono
parents:
diff changeset
754 }
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 gcc::jit::recording::union_ *result =
kono
parents:
diff changeset
757 ctxt->new_union_type (loc, name);
kono
parents:
diff changeset
758 result->set_fields (loc,
kono
parents:
diff changeset
759 num_fields,
kono
parents:
diff changeset
760 (gcc::jit::recording::field **)fields);
kono
parents:
diff changeset
761 return (gcc_jit_type *) (result);
kono
parents:
diff changeset
762 }
kono
parents:
diff changeset
763
kono
parents:
diff changeset
764 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
765
kono
parents:
diff changeset
766 After error-checking, the real work is done by the
kono
parents:
diff changeset
767 gcc::jit::recording::context::new_function_ptr_type method,
kono
parents:
diff changeset
768 in jit-recording.c */
kono
parents:
diff changeset
769
kono
parents:
diff changeset
770 gcc_jit_type *
kono
parents:
diff changeset
771 gcc_jit_context_new_function_ptr_type (gcc_jit_context *ctxt,
kono
parents:
diff changeset
772 gcc_jit_location *loc,
kono
parents:
diff changeset
773 gcc_jit_type *return_type,
kono
parents:
diff changeset
774 int num_params,
kono
parents:
diff changeset
775 gcc_jit_type **param_types,
kono
parents:
diff changeset
776 int is_variadic)
kono
parents:
diff changeset
777 {
kono
parents:
diff changeset
778 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
779 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
780 /* LOC can be NULL. */
kono
parents:
diff changeset
781 RETURN_NULL_IF_FAIL (return_type, ctxt, loc, "NULL return_type");
kono
parents:
diff changeset
782 RETURN_NULL_IF_FAIL (
kono
parents:
diff changeset
783 (num_params == 0) || param_types,
kono
parents:
diff changeset
784 ctxt, loc,
kono
parents:
diff changeset
785 "NULL param_types creating function pointer type");
kono
parents:
diff changeset
786 for (int i = 0; i < num_params; i++)
kono
parents:
diff changeset
787 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
788 param_types[i],
kono
parents:
diff changeset
789 ctxt, loc,
kono
parents:
diff changeset
790 "NULL parameter type %i creating function pointer type", i);
kono
parents:
diff changeset
791
kono
parents:
diff changeset
792 return (gcc_jit_type*)
kono
parents:
diff changeset
793 ctxt->new_function_ptr_type (loc, return_type,
kono
parents:
diff changeset
794 num_params,
kono
parents:
diff changeset
795 (gcc::jit::recording::type **)param_types,
kono
parents:
diff changeset
796 is_variadic);
kono
parents:
diff changeset
797 }
kono
parents:
diff changeset
798
kono
parents:
diff changeset
799 /* Constructing functions. */
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
802
kono
parents:
diff changeset
803 After error-checking, the real work is done by the
kono
parents:
diff changeset
804 gcc::jit::recording::context::new_param method, in jit-recording.c */
kono
parents:
diff changeset
805
kono
parents:
diff changeset
806 gcc_jit_param *
kono
parents:
diff changeset
807 gcc_jit_context_new_param (gcc_jit_context *ctxt,
kono
parents:
diff changeset
808 gcc_jit_location *loc,
kono
parents:
diff changeset
809 gcc_jit_type *type,
kono
parents:
diff changeset
810 const char *name)
kono
parents:
diff changeset
811 {
kono
parents:
diff changeset
812 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
813 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
814 /* LOC can be NULL. */
kono
parents:
diff changeset
815 RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
kono
parents:
diff changeset
816 RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
kono
parents:
diff changeset
817
kono
parents:
diff changeset
818 return (gcc_jit_param *)ctxt->new_param (loc, type, name);
kono
parents:
diff changeset
819 }
kono
parents:
diff changeset
820
kono
parents:
diff changeset
821 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 After error-checking, this calls the trivial
kono
parents:
diff changeset
824 gcc::jit::recording::memento::as_object method (a param is a memento),
kono
parents:
diff changeset
825 in jit-recording.h. */
kono
parents:
diff changeset
826
kono
parents:
diff changeset
827 gcc_jit_object *
kono
parents:
diff changeset
828 gcc_jit_param_as_object (gcc_jit_param *param)
kono
parents:
diff changeset
829 {
kono
parents:
diff changeset
830 RETURN_NULL_IF_FAIL (param, NULL, NULL, "NULL param");
kono
parents:
diff changeset
831
kono
parents:
diff changeset
832 return static_cast <gcc_jit_object *> (param->as_object ());
kono
parents:
diff changeset
833 }
kono
parents:
diff changeset
834
kono
parents:
diff changeset
835 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
836
kono
parents:
diff changeset
837 After error-checking, this calls the trivial
kono
parents:
diff changeset
838 gcc::jit::recording::param::as_lvalue method in jit-recording.h. */
kono
parents:
diff changeset
839
kono
parents:
diff changeset
840 gcc_jit_lvalue *
kono
parents:
diff changeset
841 gcc_jit_param_as_lvalue (gcc_jit_param *param)
kono
parents:
diff changeset
842 {
kono
parents:
diff changeset
843 RETURN_NULL_IF_FAIL (param, NULL, NULL, "NULL param");
kono
parents:
diff changeset
844
kono
parents:
diff changeset
845 return (gcc_jit_lvalue *)param->as_lvalue ();
kono
parents:
diff changeset
846 }
kono
parents:
diff changeset
847
kono
parents:
diff changeset
848 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
849
kono
parents:
diff changeset
850 After error-checking, this calls the trivial
kono
parents:
diff changeset
851 gcc::jit::recording::lvalue::as_rvalue method (a param is an rvalue),
kono
parents:
diff changeset
852 in jit-recording.h. */
kono
parents:
diff changeset
853
kono
parents:
diff changeset
854 gcc_jit_rvalue *
kono
parents:
diff changeset
855 gcc_jit_param_as_rvalue (gcc_jit_param *param)
kono
parents:
diff changeset
856 {
kono
parents:
diff changeset
857 RETURN_NULL_IF_FAIL (param, NULL, NULL, "NULL param");
kono
parents:
diff changeset
858
kono
parents:
diff changeset
859 return (gcc_jit_rvalue *)param->as_rvalue ();
kono
parents:
diff changeset
860 }
kono
parents:
diff changeset
861
kono
parents:
diff changeset
862 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
863
kono
parents:
diff changeset
864 After error-checking, the real work is done by the
kono
parents:
diff changeset
865 gcc::jit::recording::context::new_function method, in
kono
parents:
diff changeset
866 jit-recording.c. */
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 gcc_jit_function *
kono
parents:
diff changeset
869 gcc_jit_context_new_function (gcc_jit_context *ctxt,
kono
parents:
diff changeset
870 gcc_jit_location *loc,
kono
parents:
diff changeset
871 enum gcc_jit_function_kind kind,
kono
parents:
diff changeset
872 gcc_jit_type *return_type,
kono
parents:
diff changeset
873 const char *name,
kono
parents:
diff changeset
874 int num_params,
kono
parents:
diff changeset
875 gcc_jit_param **params,
kono
parents:
diff changeset
876 int is_variadic)
kono
parents:
diff changeset
877 {
kono
parents:
diff changeset
878 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
879 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
880 /* LOC can be NULL. */
kono
parents:
diff changeset
881 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
882 ((kind >= GCC_JIT_FUNCTION_EXPORTED)
kono
parents:
diff changeset
883 && (kind <= GCC_JIT_FUNCTION_ALWAYS_INLINE)),
kono
parents:
diff changeset
884 ctxt, loc,
kono
parents:
diff changeset
885 "unrecognized value for enum gcc_jit_function_kind: %i",
kono
parents:
diff changeset
886 kind);
kono
parents:
diff changeset
887 RETURN_NULL_IF_FAIL (return_type, ctxt, loc, "NULL return_type");
kono
parents:
diff changeset
888 RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
kono
parents:
diff changeset
889 /* The assembler can only handle certain names, so for now, enforce
kono
parents:
diff changeset
890 C's rules for identiers upon the name, using ISALPHA and ISALNUM
kono
parents:
diff changeset
891 from safe-ctype.h to ignore the current locale.
kono
parents:
diff changeset
892 Eventually we'll need some way to interact with e.g. C++ name
kono
parents:
diff changeset
893 mangling. */
kono
parents:
diff changeset
894 {
kono
parents:
diff changeset
895 /* Leading char: */
kono
parents:
diff changeset
896 char ch = *name;
kono
parents:
diff changeset
897 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
898 ISALPHA (ch) || ch == '_',
kono
parents:
diff changeset
899 ctxt, loc,
kono
parents:
diff changeset
900 "name \"%s\" contains invalid character: '%c'",
kono
parents:
diff changeset
901 name, ch);
kono
parents:
diff changeset
902 /* Subsequent chars: */
kono
parents:
diff changeset
903 for (const char *ptr = name + 1; (ch = *ptr); ptr++)
kono
parents:
diff changeset
904 {
kono
parents:
diff changeset
905 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
906 ISALNUM (ch) || ch == '_',
kono
parents:
diff changeset
907 ctxt, loc,
kono
parents:
diff changeset
908 "name \"%s\" contains invalid character: '%c'",
kono
parents:
diff changeset
909 name, ch);
kono
parents:
diff changeset
910 }
kono
parents:
diff changeset
911 }
kono
parents:
diff changeset
912 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
913 (num_params == 0) || params,
kono
parents:
diff changeset
914 ctxt, loc,
kono
parents:
diff changeset
915 "NULL params creating function %s", name);
kono
parents:
diff changeset
916 for (int i = 0; i < num_params; i++)
kono
parents:
diff changeset
917 {
kono
parents:
diff changeset
918 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
919 params[i],
kono
parents:
diff changeset
920 ctxt, loc,
kono
parents:
diff changeset
921 "NULL parameter %i creating function %s", i, name);
kono
parents:
diff changeset
922 RETURN_NULL_IF_FAIL_PRINTF5 (
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
923 params[i]->get_scope () == NULL,
111
kono
parents:
diff changeset
924 ctxt, loc,
kono
parents:
diff changeset
925 "parameter %i \"%s\""
kono
parents:
diff changeset
926 " (type: %s)"
kono
parents:
diff changeset
927 " for function %s"
kono
parents:
diff changeset
928 " was already used for function %s",
kono
parents:
diff changeset
929 i, params[i]->get_debug_string (),
kono
parents:
diff changeset
930 params[i]->get_type ()->get_debug_string (),
kono
parents:
diff changeset
931 name,
kono
parents:
diff changeset
932 params[i]->get_scope ()->get_debug_string ());
kono
parents:
diff changeset
933 }
kono
parents:
diff changeset
934
kono
parents:
diff changeset
935 return (gcc_jit_function*)
kono
parents:
diff changeset
936 ctxt->new_function (loc, kind, return_type, name,
kono
parents:
diff changeset
937 num_params,
kono
parents:
diff changeset
938 (gcc::jit::recording::param **)params,
kono
parents:
diff changeset
939 is_variadic,
kono
parents:
diff changeset
940 BUILT_IN_NONE);
kono
parents:
diff changeset
941 }
kono
parents:
diff changeset
942
kono
parents:
diff changeset
943 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
944
kono
parents:
diff changeset
945 After error-checking, the real work is done by the
kono
parents:
diff changeset
946 gcc::jit::recording::context::get_builtin_function method, in
kono
parents:
diff changeset
947 jit-recording.c. */
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 gcc_jit_function *
kono
parents:
diff changeset
950 gcc_jit_context_get_builtin_function (gcc_jit_context *ctxt,
kono
parents:
diff changeset
951 const char *name)
kono
parents:
diff changeset
952 {
kono
parents:
diff changeset
953 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
954 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
955 RETURN_NULL_IF_FAIL (name, ctxt, NULL, "NULL name");
kono
parents:
diff changeset
956
kono
parents:
diff changeset
957 return static_cast <gcc_jit_function *> (ctxt->get_builtin_function (name));
kono
parents:
diff changeset
958 }
kono
parents:
diff changeset
959
kono
parents:
diff changeset
960 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
961
kono
parents:
diff changeset
962 After error-checking, this calls the trivial
kono
parents:
diff changeset
963 gcc::jit::recording::memento::as_object method (a function is a
kono
parents:
diff changeset
964 memento), in jit-recording.h. */
kono
parents:
diff changeset
965
kono
parents:
diff changeset
966 gcc_jit_object *
kono
parents:
diff changeset
967 gcc_jit_function_as_object (gcc_jit_function *func)
kono
parents:
diff changeset
968 {
kono
parents:
diff changeset
969 RETURN_NULL_IF_FAIL (func, NULL, NULL, "NULL function");
kono
parents:
diff changeset
970
kono
parents:
diff changeset
971 return static_cast <gcc_jit_object *> (func->as_object ());
kono
parents:
diff changeset
972 }
kono
parents:
diff changeset
973
kono
parents:
diff changeset
974 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
975
kono
parents:
diff changeset
976 After error-checking, the real work is done by the
kono
parents:
diff changeset
977 gcc::jit::recording::function::get_param method, in
kono
parents:
diff changeset
978 jit-recording.h. */
kono
parents:
diff changeset
979
kono
parents:
diff changeset
980 gcc_jit_param *
kono
parents:
diff changeset
981 gcc_jit_function_get_param (gcc_jit_function *func, int index)
kono
parents:
diff changeset
982 {
kono
parents:
diff changeset
983 RETURN_NULL_IF_FAIL (func, NULL, NULL, "NULL function");
kono
parents:
diff changeset
984 gcc::jit::recording::context *ctxt = func->m_ctxt;
kono
parents:
diff changeset
985 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
986 RETURN_NULL_IF_FAIL (index >= 0, ctxt, NULL, "negative index");
kono
parents:
diff changeset
987 int num_params = func->get_params ().length ();
kono
parents:
diff changeset
988 RETURN_NULL_IF_FAIL_PRINTF3 (index < num_params,
kono
parents:
diff changeset
989 ctxt, NULL,
kono
parents:
diff changeset
990 "index of %d is too large (%s has %d params)",
kono
parents:
diff changeset
991 index,
kono
parents:
diff changeset
992 func->get_debug_string (),
kono
parents:
diff changeset
993 num_params);
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 return static_cast <gcc_jit_param *> (func->get_param (index));
kono
parents:
diff changeset
996 }
kono
parents:
diff changeset
997
kono
parents:
diff changeset
998 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
999
kono
parents:
diff changeset
1000 After error-checking, the real work is done by the
kono
parents:
diff changeset
1001 gcc::jit::recording::function::dump_to_dot method, in
kono
parents:
diff changeset
1002 jit-recording.c. */
kono
parents:
diff changeset
1003
kono
parents:
diff changeset
1004 void
kono
parents:
diff changeset
1005 gcc_jit_function_dump_to_dot (gcc_jit_function *func,
kono
parents:
diff changeset
1006 const char *path)
kono
parents:
diff changeset
1007 {
kono
parents:
diff changeset
1008 RETURN_IF_FAIL (func, NULL, NULL, "NULL function");
kono
parents:
diff changeset
1009 gcc::jit::recording::context *ctxt = func->m_ctxt;
kono
parents:
diff changeset
1010 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1011 RETURN_IF_FAIL (path, ctxt, NULL, "NULL path");
kono
parents:
diff changeset
1012
kono
parents:
diff changeset
1013 func->dump_to_dot (path);
kono
parents:
diff changeset
1014 }
kono
parents:
diff changeset
1015
kono
parents:
diff changeset
1016 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1017
kono
parents:
diff changeset
1018 After error-checking, the real work is done by the
kono
parents:
diff changeset
1019 gcc::jit::recording::function::new_block method, in
kono
parents:
diff changeset
1020 jit-recording.c. */
kono
parents:
diff changeset
1021
kono
parents:
diff changeset
1022 gcc_jit_block*
kono
parents:
diff changeset
1023 gcc_jit_function_new_block (gcc_jit_function *func,
kono
parents:
diff changeset
1024 const char *name)
kono
parents:
diff changeset
1025 {
kono
parents:
diff changeset
1026 RETURN_NULL_IF_FAIL (func, NULL, NULL, "NULL function");
kono
parents:
diff changeset
1027 JIT_LOG_FUNC (func->get_context ()->get_logger ());
kono
parents:
diff changeset
1028 RETURN_NULL_IF_FAIL (func->get_kind () != GCC_JIT_FUNCTION_IMPORTED,
kono
parents:
diff changeset
1029 func->get_context (), NULL,
kono
parents:
diff changeset
1030 "cannot add block to an imported function");
kono
parents:
diff changeset
1031 /* name can be NULL. */
kono
parents:
diff changeset
1032
kono
parents:
diff changeset
1033 return (gcc_jit_block *)func->new_block (name);
kono
parents:
diff changeset
1034 }
kono
parents:
diff changeset
1035
kono
parents:
diff changeset
1036 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1037
kono
parents:
diff changeset
1038 After error-checking, this calls the trivial
kono
parents:
diff changeset
1039 gcc::jit::recording::memento::as_object method (a block is a
kono
parents:
diff changeset
1040 memento), in jit-recording.h. */
kono
parents:
diff changeset
1041
kono
parents:
diff changeset
1042 gcc_jit_object *
kono
parents:
diff changeset
1043 gcc_jit_block_as_object (gcc_jit_block *block)
kono
parents:
diff changeset
1044 {
kono
parents:
diff changeset
1045 RETURN_NULL_IF_FAIL (block, NULL, NULL, "NULL block");
kono
parents:
diff changeset
1046
kono
parents:
diff changeset
1047 return static_cast <gcc_jit_object *> (block->as_object ());
kono
parents:
diff changeset
1048 }
kono
parents:
diff changeset
1049
kono
parents:
diff changeset
1050 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1051
kono
parents:
diff changeset
1052 After error-checking, the real work is done by the
kono
parents:
diff changeset
1053 gcc::jit::recording::block::get_function method, in
kono
parents:
diff changeset
1054 jit-recording.h. */
kono
parents:
diff changeset
1055
kono
parents:
diff changeset
1056 gcc_jit_function *
kono
parents:
diff changeset
1057 gcc_jit_block_get_function (gcc_jit_block *block)
kono
parents:
diff changeset
1058 {
kono
parents:
diff changeset
1059 RETURN_NULL_IF_FAIL (block, NULL, NULL, "NULL block");
kono
parents:
diff changeset
1060
kono
parents:
diff changeset
1061 return static_cast <gcc_jit_function *> (block->get_function ());
kono
parents:
diff changeset
1062 }
kono
parents:
diff changeset
1063
kono
parents:
diff changeset
1064 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1065
kono
parents:
diff changeset
1066 After error-checking, the real work is done by the
kono
parents:
diff changeset
1067 gcc::jit::recording::context::new_global method, in
kono
parents:
diff changeset
1068 jit-recording.c. */
kono
parents:
diff changeset
1069
kono
parents:
diff changeset
1070 gcc_jit_lvalue *
kono
parents:
diff changeset
1071 gcc_jit_context_new_global (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1072 gcc_jit_location *loc,
kono
parents:
diff changeset
1073 enum gcc_jit_global_kind kind,
kono
parents:
diff changeset
1074 gcc_jit_type *type,
kono
parents:
diff changeset
1075 const char *name)
kono
parents:
diff changeset
1076 {
kono
parents:
diff changeset
1077 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
1078 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1079 /* LOC can be NULL. */
kono
parents:
diff changeset
1080 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
1081 ((kind >= GCC_JIT_GLOBAL_EXPORTED)
kono
parents:
diff changeset
1082 && (kind <= GCC_JIT_GLOBAL_IMPORTED)),
kono
parents:
diff changeset
1083 ctxt, loc,
kono
parents:
diff changeset
1084 "unrecognized value for enum gcc_jit_global_kind: %i",
kono
parents:
diff changeset
1085 kind);
kono
parents:
diff changeset
1086 RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
kono
parents:
diff changeset
1087 RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
kono
parents:
diff changeset
1088 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1089 type->has_known_size (),
kono
parents:
diff changeset
1090 ctxt, loc,
kono
parents:
diff changeset
1091 "unknown size for global \"%s\" (type: %s)",
kono
parents:
diff changeset
1092 name,
kono
parents:
diff changeset
1093 type->get_debug_string ());
kono
parents:
diff changeset
1094
kono
parents:
diff changeset
1095 return (gcc_jit_lvalue *)ctxt->new_global (loc, kind, type, name);
kono
parents:
diff changeset
1096 }
kono
parents:
diff changeset
1097
kono
parents:
diff changeset
1098 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1099
kono
parents:
diff changeset
1100 After error-checking, this calls the trivial
kono
parents:
diff changeset
1101 gcc::jit::recording::memento::as_object method (an lvalue is a
kono
parents:
diff changeset
1102 memento), in jit-recording.h. */
kono
parents:
diff changeset
1103
kono
parents:
diff changeset
1104 gcc_jit_object *
kono
parents:
diff changeset
1105 gcc_jit_lvalue_as_object (gcc_jit_lvalue *lvalue)
kono
parents:
diff changeset
1106 {
kono
parents:
diff changeset
1107 RETURN_NULL_IF_FAIL (lvalue, NULL, NULL, "NULL lvalue");
kono
parents:
diff changeset
1108
kono
parents:
diff changeset
1109 return static_cast <gcc_jit_object *> (lvalue->as_object ());
kono
parents:
diff changeset
1110 }
kono
parents:
diff changeset
1111
kono
parents:
diff changeset
1112 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1113
kono
parents:
diff changeset
1114 After error-checking, this calls the trivial
kono
parents:
diff changeset
1115 gcc::jit::recording::lvalue::as_rvalue method in jit-recording.h. */
kono
parents:
diff changeset
1116
kono
parents:
diff changeset
1117 gcc_jit_rvalue *
kono
parents:
diff changeset
1118 gcc_jit_lvalue_as_rvalue (gcc_jit_lvalue *lvalue)
kono
parents:
diff changeset
1119 {
kono
parents:
diff changeset
1120 RETURN_NULL_IF_FAIL (lvalue, NULL, NULL, "NULL lvalue");
kono
parents:
diff changeset
1121
kono
parents:
diff changeset
1122 return (gcc_jit_rvalue *)lvalue->as_rvalue ();
kono
parents:
diff changeset
1123 }
kono
parents:
diff changeset
1124
kono
parents:
diff changeset
1125 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1126
kono
parents:
diff changeset
1127 After error-checking, this calls the trivial
kono
parents:
diff changeset
1128 gcc::jit::recording::memento::as_object method (an rvalue is a
kono
parents:
diff changeset
1129 memento), in jit-recording.h. */
kono
parents:
diff changeset
1130
kono
parents:
diff changeset
1131 gcc_jit_object *
kono
parents:
diff changeset
1132 gcc_jit_rvalue_as_object (gcc_jit_rvalue *rvalue)
kono
parents:
diff changeset
1133 {
kono
parents:
diff changeset
1134 RETURN_NULL_IF_FAIL (rvalue, NULL, NULL, "NULL rvalue");
kono
parents:
diff changeset
1135
kono
parents:
diff changeset
1136 return static_cast <gcc_jit_object *> (rvalue->as_object ());
kono
parents:
diff changeset
1137 }
kono
parents:
diff changeset
1138
kono
parents:
diff changeset
1139 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1140
kono
parents:
diff changeset
1141 After error-checking, the real work is done by the
kono
parents:
diff changeset
1142 gcc::jit::recording::rvalue::get_type method, in
kono
parents:
diff changeset
1143 jit-recording.h. */
kono
parents:
diff changeset
1144
kono
parents:
diff changeset
1145 gcc_jit_type *
kono
parents:
diff changeset
1146 gcc_jit_rvalue_get_type (gcc_jit_rvalue *rvalue)
kono
parents:
diff changeset
1147 {
kono
parents:
diff changeset
1148 RETURN_NULL_IF_FAIL (rvalue, NULL, NULL, "NULL rvalue");
kono
parents:
diff changeset
1149
kono
parents:
diff changeset
1150 return static_cast <gcc_jit_type *> (rvalue->get_type ());
kono
parents:
diff changeset
1151 }
kono
parents:
diff changeset
1152
kono
parents:
diff changeset
1153 /* Verify that NUMERIC_TYPE is non-NULL, and that it is a "numeric"
kono
parents:
diff changeset
1154 type i.e. it satisfies gcc::jit::type::is_numeric (), such as the
kono
parents:
diff changeset
1155 result of gcc_jit_context_get_type (GCC_JIT_TYPE_INT). */
kono
parents:
diff changeset
1156
kono
parents:
diff changeset
1157 #define RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE(CTXT, NUMERIC_TYPE) \
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1158 JIT_BEGIN_STMT \
111
kono
parents:
diff changeset
1159 RETURN_NULL_IF_FAIL (NUMERIC_TYPE, CTXT, NULL, "NULL type"); \
kono
parents:
diff changeset
1160 RETURN_NULL_IF_FAIL_PRINTF1 ( \
kono
parents:
diff changeset
1161 NUMERIC_TYPE->is_numeric (), ctxt, NULL, \
kono
parents:
diff changeset
1162 "not a numeric type: %s", \
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1163 NUMERIC_TYPE->get_debug_string ()); \
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1164 JIT_END_STMT
111
kono
parents:
diff changeset
1165
kono
parents:
diff changeset
1166 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1167
kono
parents:
diff changeset
1168 After error-checking, the real work is done by the
kono
parents:
diff changeset
1169 gcc::jit::recording::context::new_rvalue_from_int method in
kono
parents:
diff changeset
1170 jit-recording.c. */
kono
parents:
diff changeset
1171
kono
parents:
diff changeset
1172 gcc_jit_rvalue *
kono
parents:
diff changeset
1173 gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1174 gcc_jit_type *numeric_type,
kono
parents:
diff changeset
1175 int value)
kono
parents:
diff changeset
1176 {
kono
parents:
diff changeset
1177 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
1178 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1179 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
kono
parents:
diff changeset
1180
kono
parents:
diff changeset
1181 return ((gcc_jit_rvalue *)ctxt
kono
parents:
diff changeset
1182 ->new_rvalue_from_const <int> (numeric_type, value));
kono
parents:
diff changeset
1183 }
kono
parents:
diff changeset
1184
kono
parents:
diff changeset
1185 /* FIXME. */
kono
parents:
diff changeset
1186
kono
parents:
diff changeset
1187 gcc_jit_rvalue *
kono
parents:
diff changeset
1188 gcc_jit_context_new_rvalue_from_long (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1189 gcc_jit_type *numeric_type,
kono
parents:
diff changeset
1190 long value)
kono
parents:
diff changeset
1191 {
kono
parents:
diff changeset
1192 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
1193 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1194 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
kono
parents:
diff changeset
1195
kono
parents:
diff changeset
1196 return ((gcc_jit_rvalue *)ctxt
kono
parents:
diff changeset
1197 ->new_rvalue_from_const <long> (numeric_type, value));
kono
parents:
diff changeset
1198 }
kono
parents:
diff changeset
1199
kono
parents:
diff changeset
1200 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1201
kono
parents:
diff changeset
1202 This is essentially equivalent to:
kono
parents:
diff changeset
1203 gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 0);
kono
parents:
diff changeset
1204 albeit with slightly different error messages if an error occurs. */
kono
parents:
diff changeset
1205
kono
parents:
diff changeset
1206 gcc_jit_rvalue *
kono
parents:
diff changeset
1207 gcc_jit_context_zero (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1208 gcc_jit_type *numeric_type)
kono
parents:
diff changeset
1209 {
kono
parents:
diff changeset
1210 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
1211 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1212 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
kono
parents:
diff changeset
1213
kono
parents:
diff changeset
1214 return gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 0);
kono
parents:
diff changeset
1215 }
kono
parents:
diff changeset
1216
kono
parents:
diff changeset
1217 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1218
kono
parents:
diff changeset
1219 This is essentially equivalent to:
kono
parents:
diff changeset
1220 gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 1);
kono
parents:
diff changeset
1221 albeit with slightly different error messages if an error occurs. */
kono
parents:
diff changeset
1222
kono
parents:
diff changeset
1223 gcc_jit_rvalue *
kono
parents:
diff changeset
1224 gcc_jit_context_one (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1225 gcc_jit_type *numeric_type)
kono
parents:
diff changeset
1226 {
kono
parents:
diff changeset
1227 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
1228 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1229 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
kono
parents:
diff changeset
1230
kono
parents:
diff changeset
1231 return gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 1);
kono
parents:
diff changeset
1232 }
kono
parents:
diff changeset
1233
kono
parents:
diff changeset
1234 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1235
kono
parents:
diff changeset
1236 After error-checking, the real work is done by the
kono
parents:
diff changeset
1237 gcc::jit::recording::context::new_rvalue_from_double method in
kono
parents:
diff changeset
1238 jit-recording.c. */
kono
parents:
diff changeset
1239
kono
parents:
diff changeset
1240 gcc_jit_rvalue *
kono
parents:
diff changeset
1241 gcc_jit_context_new_rvalue_from_double (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1242 gcc_jit_type *numeric_type,
kono
parents:
diff changeset
1243 double value)
kono
parents:
diff changeset
1244 {
kono
parents:
diff changeset
1245 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
1246 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1247 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);
kono
parents:
diff changeset
1248
kono
parents:
diff changeset
1249 return ((gcc_jit_rvalue *)ctxt
kono
parents:
diff changeset
1250 ->new_rvalue_from_const <double> (numeric_type, value));
kono
parents:
diff changeset
1251 }
kono
parents:
diff changeset
1252
kono
parents:
diff changeset
1253 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1254
kono
parents:
diff changeset
1255 After error-checking, the real work is done by the
kono
parents:
diff changeset
1256 gcc::jit::recording::context::new_rvalue_from_ptr method in
kono
parents:
diff changeset
1257 jit-recording.c. */
kono
parents:
diff changeset
1258
kono
parents:
diff changeset
1259 gcc_jit_rvalue *
kono
parents:
diff changeset
1260 gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1261 gcc_jit_type *pointer_type,
kono
parents:
diff changeset
1262 void *value)
kono
parents:
diff changeset
1263 {
kono
parents:
diff changeset
1264 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
1265 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1266 RETURN_NULL_IF_FAIL (pointer_type, ctxt, NULL, "NULL type");
kono
parents:
diff changeset
1267 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
1268 pointer_type->is_pointer (),
kono
parents:
diff changeset
1269 ctxt, NULL,
kono
parents:
diff changeset
1270 "not a pointer type (type: %s)",
kono
parents:
diff changeset
1271 pointer_type->get_debug_string ());
kono
parents:
diff changeset
1272
kono
parents:
diff changeset
1273 return ((gcc_jit_rvalue *)ctxt
kono
parents:
diff changeset
1274 ->new_rvalue_from_const <void *> (pointer_type, value));
kono
parents:
diff changeset
1275 }
kono
parents:
diff changeset
1276
kono
parents:
diff changeset
1277 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1278
kono
parents:
diff changeset
1279 This is essentially equivalent to:
kono
parents:
diff changeset
1280 gcc_jit_context_new_rvalue_from_ptr (ctxt, pointer_type, NULL);
kono
parents:
diff changeset
1281 albeit with slightly different error messages if an error occurs. */
kono
parents:
diff changeset
1282
kono
parents:
diff changeset
1283 gcc_jit_rvalue *
kono
parents:
diff changeset
1284 gcc_jit_context_null (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1285 gcc_jit_type *pointer_type)
kono
parents:
diff changeset
1286 {
kono
parents:
diff changeset
1287 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
1288 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1289 RETURN_NULL_IF_FAIL (pointer_type, ctxt, NULL, "NULL type");
kono
parents:
diff changeset
1290 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
1291 pointer_type->is_pointer (),
kono
parents:
diff changeset
1292 ctxt, NULL,
kono
parents:
diff changeset
1293 "not a pointer type (type: %s)",
kono
parents:
diff changeset
1294 pointer_type->get_debug_string ());
kono
parents:
diff changeset
1295
kono
parents:
diff changeset
1296 return gcc_jit_context_new_rvalue_from_ptr (ctxt, pointer_type, NULL);
kono
parents:
diff changeset
1297 }
kono
parents:
diff changeset
1298
kono
parents:
diff changeset
1299 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1300
kono
parents:
diff changeset
1301 After error-checking, the real work is done by the
kono
parents:
diff changeset
1302 gcc::jit::recording::context::new_string_literal method in
kono
parents:
diff changeset
1303 jit-recording.c. */
kono
parents:
diff changeset
1304
kono
parents:
diff changeset
1305 gcc_jit_rvalue *
kono
parents:
diff changeset
1306 gcc_jit_context_new_string_literal (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1307 const char *value)
kono
parents:
diff changeset
1308 {
kono
parents:
diff changeset
1309 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
1310 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1311 RETURN_NULL_IF_FAIL (value, ctxt, NULL, "NULL value");
kono
parents:
diff changeset
1312
kono
parents:
diff changeset
1313 return (gcc_jit_rvalue *)ctxt->new_string_literal (value);
kono
parents:
diff changeset
1314 }
kono
parents:
diff changeset
1315
kono
parents:
diff changeset
1316 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1317
kono
parents:
diff changeset
1318 After error-checking, the real work is done by the
kono
parents:
diff changeset
1319 gcc::jit::recording::context::new_unary_op method in
kono
parents:
diff changeset
1320 jit-recording.c. */
kono
parents:
diff changeset
1321
kono
parents:
diff changeset
1322 gcc_jit_rvalue *
kono
parents:
diff changeset
1323 gcc_jit_context_new_unary_op (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1324 gcc_jit_location *loc,
kono
parents:
diff changeset
1325 enum gcc_jit_unary_op op,
kono
parents:
diff changeset
1326 gcc_jit_type *result_type,
kono
parents:
diff changeset
1327 gcc_jit_rvalue *rvalue)
kono
parents:
diff changeset
1328 {
kono
parents:
diff changeset
1329 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
1330 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1331 /* LOC can be NULL. */
kono
parents:
diff changeset
1332 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
1333 (op >= GCC_JIT_UNARY_OP_MINUS
kono
parents:
diff changeset
1334 && op <= GCC_JIT_UNARY_OP_ABS),
kono
parents:
diff changeset
1335 ctxt, loc,
kono
parents:
diff changeset
1336 "unrecognized value for enum gcc_jit_unary_op: %i",
kono
parents:
diff changeset
1337 op);
kono
parents:
diff changeset
1338 RETURN_NULL_IF_FAIL (result_type, ctxt, loc, "NULL result_type");
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1339 RETURN_NULL_IF_FAIL_PRINTF3 (
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1340 result_type->is_numeric (), ctxt, loc,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1341 "gcc_jit_unary_op %s with operand %s "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1342 "has non-numeric result_type: %s",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1343 gcc::jit::unary_op_reproducer_strings[op],
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1344 rvalue->get_debug_string (),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1345 result_type->get_debug_string ());
111
kono
parents:
diff changeset
1346 RETURN_NULL_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
kono
parents:
diff changeset
1347
kono
parents:
diff changeset
1348 return (gcc_jit_rvalue *)ctxt->new_unary_op (loc, op, result_type, rvalue);
kono
parents:
diff changeset
1349 }
kono
parents:
diff changeset
1350
kono
parents:
diff changeset
1351 /* Determine if OP is a valid value for enum gcc_jit_binary_op.
kono
parents:
diff changeset
1352 For use by both gcc_jit_context_new_binary_op and
kono
parents:
diff changeset
1353 gcc_jit_block_add_assignment_op. */
kono
parents:
diff changeset
1354
kono
parents:
diff changeset
1355 static bool
kono
parents:
diff changeset
1356 valid_binary_op_p (enum gcc_jit_binary_op op)
kono
parents:
diff changeset
1357 {
kono
parents:
diff changeset
1358 return (op >= GCC_JIT_BINARY_OP_PLUS
kono
parents:
diff changeset
1359 && op <= GCC_JIT_BINARY_OP_RSHIFT);
kono
parents:
diff changeset
1360 }
kono
parents:
diff changeset
1361
kono
parents:
diff changeset
1362 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1363
kono
parents:
diff changeset
1364 After error-checking, the real work is done by the
kono
parents:
diff changeset
1365 gcc::jit::recording::context::new_binary_op method in
kono
parents:
diff changeset
1366 jit-recording.c. */
kono
parents:
diff changeset
1367
kono
parents:
diff changeset
1368 gcc_jit_rvalue *
kono
parents:
diff changeset
1369 gcc_jit_context_new_binary_op (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1370 gcc_jit_location *loc,
kono
parents:
diff changeset
1371 enum gcc_jit_binary_op op,
kono
parents:
diff changeset
1372 gcc_jit_type *result_type,
kono
parents:
diff changeset
1373 gcc_jit_rvalue *a, gcc_jit_rvalue *b)
kono
parents:
diff changeset
1374 {
kono
parents:
diff changeset
1375 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
1376 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1377 /* LOC can be NULL. */
kono
parents:
diff changeset
1378 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
1379 valid_binary_op_p (op),
kono
parents:
diff changeset
1380 ctxt, loc,
kono
parents:
diff changeset
1381 "unrecognized value for enum gcc_jit_binary_op: %i",
kono
parents:
diff changeset
1382 op);
kono
parents:
diff changeset
1383 RETURN_NULL_IF_FAIL (result_type, ctxt, loc, "NULL result_type");
kono
parents:
diff changeset
1384 RETURN_NULL_IF_FAIL (a, ctxt, loc, "NULL a");
kono
parents:
diff changeset
1385 RETURN_NULL_IF_FAIL (b, ctxt, loc, "NULL b");
kono
parents:
diff changeset
1386 RETURN_NULL_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
1387 a->get_type ()->unqualified () == b->get_type ()->unqualified (),
kono
parents:
diff changeset
1388 ctxt, loc,
kono
parents:
diff changeset
1389 "mismatching types for binary op:"
kono
parents:
diff changeset
1390 " a: %s (type: %s) b: %s (type: %s)",
kono
parents:
diff changeset
1391 a->get_debug_string (),
kono
parents:
diff changeset
1392 a->get_type ()->get_debug_string (),
kono
parents:
diff changeset
1393 b->get_debug_string (),
kono
parents:
diff changeset
1394 b->get_type ()->get_debug_string ());
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1395 RETURN_NULL_IF_FAIL_PRINTF4 (
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1396 result_type->is_numeric (), ctxt, loc,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1397 "gcc_jit_binary_op %s with operands a: %s b: %s "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1398 "has non-numeric result_type: %s",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1399 gcc::jit::binary_op_reproducer_strings[op],
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1400 a->get_debug_string (), b->get_debug_string (),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1401 result_type->get_debug_string ());
111
kono
parents:
diff changeset
1402
kono
parents:
diff changeset
1403 return (gcc_jit_rvalue *)ctxt->new_binary_op (loc, op, result_type, a, b);
kono
parents:
diff changeset
1404 }
kono
parents:
diff changeset
1405
kono
parents:
diff changeset
1406 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1407
kono
parents:
diff changeset
1408 After error-checking, the real work is done by the
kono
parents:
diff changeset
1409 gcc::jit::recording::context::new_comparison method in
kono
parents:
diff changeset
1410 jit-recording.c. */
kono
parents:
diff changeset
1411
kono
parents:
diff changeset
1412 gcc_jit_rvalue *
kono
parents:
diff changeset
1413 gcc_jit_context_new_comparison (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1414 gcc_jit_location *loc,
kono
parents:
diff changeset
1415 enum gcc_jit_comparison op,
kono
parents:
diff changeset
1416 gcc_jit_rvalue *a, gcc_jit_rvalue *b)
kono
parents:
diff changeset
1417 {
kono
parents:
diff changeset
1418 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
1419 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1420 /* LOC can be NULL. */
kono
parents:
diff changeset
1421 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
1422 (op >= GCC_JIT_COMPARISON_EQ
kono
parents:
diff changeset
1423 && op <= GCC_JIT_COMPARISON_GE),
kono
parents:
diff changeset
1424 ctxt, loc,
kono
parents:
diff changeset
1425 "unrecognized value for enum gcc_jit_comparison: %i",
kono
parents:
diff changeset
1426 op);
kono
parents:
diff changeset
1427 RETURN_NULL_IF_FAIL (a, ctxt, loc, "NULL a");
kono
parents:
diff changeset
1428 RETURN_NULL_IF_FAIL (b, ctxt, loc, "NULL b");
kono
parents:
diff changeset
1429 RETURN_NULL_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
1430 a->get_type ()->unqualified () == b->get_type ()->unqualified (),
kono
parents:
diff changeset
1431 ctxt, loc,
kono
parents:
diff changeset
1432 "mismatching types for comparison:"
kono
parents:
diff changeset
1433 " a: %s (type: %s) b: %s (type: %s)",
kono
parents:
diff changeset
1434 a->get_debug_string (),
kono
parents:
diff changeset
1435 a->get_type ()->get_debug_string (),
kono
parents:
diff changeset
1436 b->get_debug_string (),
kono
parents:
diff changeset
1437 b->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1438
kono
parents:
diff changeset
1439 return (gcc_jit_rvalue *)ctxt->new_comparison (loc, op, a, b);
kono
parents:
diff changeset
1440 }
kono
parents:
diff changeset
1441
kono
parents:
diff changeset
1442 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1443
kono
parents:
diff changeset
1444 After error-checking, the real work is done by the
kono
parents:
diff changeset
1445 gcc::jit::recording::context::new_call method in
kono
parents:
diff changeset
1446 jit-recording.c. */
kono
parents:
diff changeset
1447
kono
parents:
diff changeset
1448 gcc_jit_rvalue *
kono
parents:
diff changeset
1449 gcc_jit_context_new_call (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1450 gcc_jit_location *loc,
kono
parents:
diff changeset
1451 gcc_jit_function *func,
kono
parents:
diff changeset
1452 int numargs , gcc_jit_rvalue **args)
kono
parents:
diff changeset
1453 {
kono
parents:
diff changeset
1454 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
1455 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1456 /* LOC can be NULL. */
kono
parents:
diff changeset
1457 RETURN_NULL_IF_FAIL (func, ctxt, loc, "NULL function");
kono
parents:
diff changeset
1458 if (numargs)
kono
parents:
diff changeset
1459 RETURN_NULL_IF_FAIL (args, ctxt, loc, "NULL args");
kono
parents:
diff changeset
1460
kono
parents:
diff changeset
1461 int min_num_params = func->get_params ().length ();
kono
parents:
diff changeset
1462 bool is_variadic = func->is_variadic ();
kono
parents:
diff changeset
1463
kono
parents:
diff changeset
1464 RETURN_NULL_IF_FAIL_PRINTF3 (
kono
parents:
diff changeset
1465 numargs >= min_num_params,
kono
parents:
diff changeset
1466 ctxt, loc,
kono
parents:
diff changeset
1467 "not enough arguments to function \"%s\""
kono
parents:
diff changeset
1468 " (got %i args, expected %i)",
kono
parents:
diff changeset
1469 func->get_name ()->c_str (),
kono
parents:
diff changeset
1470 numargs, min_num_params);
kono
parents:
diff changeset
1471
kono
parents:
diff changeset
1472 RETURN_NULL_IF_FAIL_PRINTF3 (
kono
parents:
diff changeset
1473 (numargs == min_num_params || is_variadic),
kono
parents:
diff changeset
1474 ctxt, loc,
kono
parents:
diff changeset
1475 "too many arguments to function \"%s\""
kono
parents:
diff changeset
1476 " (got %i args, expected %i)",
kono
parents:
diff changeset
1477 func->get_name ()->c_str (),
kono
parents:
diff changeset
1478 numargs, min_num_params);
kono
parents:
diff changeset
1479
kono
parents:
diff changeset
1480 for (int i = 0; i < min_num_params; i++)
kono
parents:
diff changeset
1481 {
kono
parents:
diff changeset
1482 gcc::jit::recording::param *param = func->get_param (i);
kono
parents:
diff changeset
1483 gcc_jit_rvalue *arg = args[i];
kono
parents:
diff changeset
1484
kono
parents:
diff changeset
1485 RETURN_NULL_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
1486 arg,
kono
parents:
diff changeset
1487 ctxt, loc,
kono
parents:
diff changeset
1488 "NULL argument %i to function \"%s\":"
kono
parents:
diff changeset
1489 " param %s (type: %s)",
kono
parents:
diff changeset
1490 i + 1,
kono
parents:
diff changeset
1491 func->get_name ()->c_str (),
kono
parents:
diff changeset
1492 param->get_debug_string (),
kono
parents:
diff changeset
1493 param->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1494
kono
parents:
diff changeset
1495 RETURN_NULL_IF_FAIL_PRINTF6 (
kono
parents:
diff changeset
1496 compatible_types (param->get_type (),
kono
parents:
diff changeset
1497 arg->get_type ()),
kono
parents:
diff changeset
1498 ctxt, loc,
kono
parents:
diff changeset
1499 "mismatching types for argument %d of function \"%s\":"
kono
parents:
diff changeset
1500 " assignment to param %s (type: %s) from %s (type: %s)",
kono
parents:
diff changeset
1501 i + 1,
kono
parents:
diff changeset
1502 func->get_name ()->c_str (),
kono
parents:
diff changeset
1503 param->get_debug_string (),
kono
parents:
diff changeset
1504 param->get_type ()->get_debug_string (),
kono
parents:
diff changeset
1505 arg->get_debug_string (),
kono
parents:
diff changeset
1506 arg->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1507 }
kono
parents:
diff changeset
1508
kono
parents:
diff changeset
1509 return (gcc_jit_rvalue *)ctxt->new_call (loc,
kono
parents:
diff changeset
1510 func,
kono
parents:
diff changeset
1511 numargs,
kono
parents:
diff changeset
1512 (gcc::jit::recording::rvalue **)args);
kono
parents:
diff changeset
1513 }
kono
parents:
diff changeset
1514
kono
parents:
diff changeset
1515 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1516
kono
parents:
diff changeset
1517 After error-checking, the real work is done by the
kono
parents:
diff changeset
1518 gcc::jit::recording::context::new_call_through_ptr method in
kono
parents:
diff changeset
1519 jit-recording.c. */
kono
parents:
diff changeset
1520
kono
parents:
diff changeset
1521 gcc_jit_rvalue *
kono
parents:
diff changeset
1522 gcc_jit_context_new_call_through_ptr (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1523 gcc_jit_location *loc,
kono
parents:
diff changeset
1524 gcc_jit_rvalue *fn_ptr,
kono
parents:
diff changeset
1525 int numargs, gcc_jit_rvalue **args)
kono
parents:
diff changeset
1526 {
kono
parents:
diff changeset
1527 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
1528 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1529 /* LOC can be NULL. */
kono
parents:
diff changeset
1530 RETURN_NULL_IF_FAIL (fn_ptr, ctxt, loc, "NULL fn_ptr");
kono
parents:
diff changeset
1531 if (numargs)
kono
parents:
diff changeset
1532 RETURN_NULL_IF_FAIL (args, ctxt, loc, "NULL args");
kono
parents:
diff changeset
1533
kono
parents:
diff changeset
1534 gcc::jit::recording::type *ptr_type = fn_ptr->get_type ()->dereference ();
kono
parents:
diff changeset
1535 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1536 ptr_type, ctxt, loc,
kono
parents:
diff changeset
1537 "fn_ptr is not a ptr: %s"
kono
parents:
diff changeset
1538 " type: %s",
kono
parents:
diff changeset
1539 fn_ptr->get_debug_string (),
kono
parents:
diff changeset
1540 fn_ptr->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1541
kono
parents:
diff changeset
1542 gcc::jit::recording::function_type *fn_type =
kono
parents:
diff changeset
1543 ptr_type->dyn_cast_function_type();
kono
parents:
diff changeset
1544 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1545 fn_type, ctxt, loc,
kono
parents:
diff changeset
1546 "fn_ptr is not a function ptr: %s"
kono
parents:
diff changeset
1547 " type: %s",
kono
parents:
diff changeset
1548 fn_ptr->get_debug_string (),
kono
parents:
diff changeset
1549 fn_ptr->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1550
kono
parents:
diff changeset
1551 int min_num_params = fn_type->get_param_types ().length ();
kono
parents:
diff changeset
1552 bool is_variadic = fn_type->is_variadic ();
kono
parents:
diff changeset
1553
kono
parents:
diff changeset
1554 RETURN_NULL_IF_FAIL_PRINTF3 (
kono
parents:
diff changeset
1555 numargs >= min_num_params,
kono
parents:
diff changeset
1556 ctxt, loc,
kono
parents:
diff changeset
1557 "not enough arguments to fn_ptr: %s"
kono
parents:
diff changeset
1558 " (got %i args, expected %i)",
kono
parents:
diff changeset
1559 fn_ptr->get_debug_string (),
kono
parents:
diff changeset
1560 numargs, min_num_params);
kono
parents:
diff changeset
1561
kono
parents:
diff changeset
1562 RETURN_NULL_IF_FAIL_PRINTF3 (
kono
parents:
diff changeset
1563 (numargs == min_num_params || is_variadic),
kono
parents:
diff changeset
1564 ctxt, loc,
kono
parents:
diff changeset
1565 "too many arguments to fn_ptr: %s"
kono
parents:
diff changeset
1566 " (got %i args, expected %i)",
kono
parents:
diff changeset
1567 fn_ptr->get_debug_string (),
kono
parents:
diff changeset
1568 numargs, min_num_params);
kono
parents:
diff changeset
1569
kono
parents:
diff changeset
1570 for (int i = 0; i < min_num_params; i++)
kono
parents:
diff changeset
1571 {
kono
parents:
diff changeset
1572 gcc::jit::recording::type *param_type = fn_type->get_param_types ()[i];
kono
parents:
diff changeset
1573 gcc_jit_rvalue *arg = args[i];
kono
parents:
diff changeset
1574
kono
parents:
diff changeset
1575 RETURN_NULL_IF_FAIL_PRINTF3 (
kono
parents:
diff changeset
1576 arg,
kono
parents:
diff changeset
1577 ctxt, loc,
kono
parents:
diff changeset
1578 "NULL argument %i to fn_ptr: %s"
kono
parents:
diff changeset
1579 " (type: %s)",
kono
parents:
diff changeset
1580 i + 1,
kono
parents:
diff changeset
1581 fn_ptr->get_debug_string (),
kono
parents:
diff changeset
1582 param_type->get_debug_string ());
kono
parents:
diff changeset
1583
kono
parents:
diff changeset
1584 RETURN_NULL_IF_FAIL_PRINTF6 (
kono
parents:
diff changeset
1585 compatible_types (param_type,
kono
parents:
diff changeset
1586 arg->get_type ()),
kono
parents:
diff changeset
1587 ctxt, loc,
kono
parents:
diff changeset
1588 "mismatching types for argument %d of fn_ptr: %s:"
kono
parents:
diff changeset
1589 " assignment to param %d (type: %s) from %s (type: %s)",
kono
parents:
diff changeset
1590 i + 1,
kono
parents:
diff changeset
1591 fn_ptr->get_debug_string (),
kono
parents:
diff changeset
1592 i + 1,
kono
parents:
diff changeset
1593 param_type->get_debug_string (),
kono
parents:
diff changeset
1594 arg->get_debug_string (),
kono
parents:
diff changeset
1595 arg->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1596 }
kono
parents:
diff changeset
1597
kono
parents:
diff changeset
1598 return (gcc_jit_rvalue *)(
kono
parents:
diff changeset
1599 ctxt->new_call_through_ptr (loc,
kono
parents:
diff changeset
1600 fn_ptr,
kono
parents:
diff changeset
1601 numargs,
kono
parents:
diff changeset
1602 (gcc::jit::recording::rvalue **)args));
kono
parents:
diff changeset
1603 }
kono
parents:
diff changeset
1604
kono
parents:
diff changeset
1605 /* Helper function for determining if we can cast an rvalue from SRC_TYPE
kono
parents:
diff changeset
1606 to DST_TYPE, for use by gcc_jit_context_new_cast.
kono
parents:
diff changeset
1607
kono
parents:
diff changeset
1608 We only permit these kinds of cast:
kono
parents:
diff changeset
1609
kono
parents:
diff changeset
1610 int <-> float
kono
parents:
diff changeset
1611 int <-> bool
kono
parents:
diff changeset
1612 P* <-> Q* for pointer types P and Q. */
kono
parents:
diff changeset
1613
kono
parents:
diff changeset
1614 static bool
kono
parents:
diff changeset
1615 is_valid_cast (gcc::jit::recording::type *src_type,
kono
parents:
diff changeset
1616 gcc_jit_type *dst_type)
kono
parents:
diff changeset
1617 {
kono
parents:
diff changeset
1618 bool src_is_int = src_type->is_int ();
kono
parents:
diff changeset
1619 bool dst_is_int = dst_type->is_int ();
kono
parents:
diff changeset
1620 bool src_is_float = src_type->is_float ();
kono
parents:
diff changeset
1621 bool dst_is_float = dst_type->is_float ();
kono
parents:
diff changeset
1622 bool src_is_bool = src_type->is_bool ();
kono
parents:
diff changeset
1623 bool dst_is_bool = dst_type->is_bool ();
kono
parents:
diff changeset
1624
kono
parents:
diff changeset
1625 if (src_is_int)
kono
parents:
diff changeset
1626 if (dst_is_int || dst_is_float || dst_is_bool)
kono
parents:
diff changeset
1627 return true;
kono
parents:
diff changeset
1628
kono
parents:
diff changeset
1629 if (src_is_float)
kono
parents:
diff changeset
1630 if (dst_is_int || dst_is_float)
kono
parents:
diff changeset
1631 return true;
kono
parents:
diff changeset
1632
kono
parents:
diff changeset
1633 if (src_is_bool)
kono
parents:
diff changeset
1634 if (dst_is_int || dst_is_bool)
kono
parents:
diff changeset
1635 return true;
kono
parents:
diff changeset
1636
kono
parents:
diff changeset
1637 /* Permit casts between pointer types. */
kono
parents:
diff changeset
1638 gcc::jit::recording::type *deref_src_type = src_type->is_pointer ();
kono
parents:
diff changeset
1639 gcc::jit::recording::type *deref_dst_type = dst_type->is_pointer ();
kono
parents:
diff changeset
1640 if (deref_src_type && deref_dst_type)
kono
parents:
diff changeset
1641 return true;
kono
parents:
diff changeset
1642
kono
parents:
diff changeset
1643 return false;
kono
parents:
diff changeset
1644 }
kono
parents:
diff changeset
1645
kono
parents:
diff changeset
1646 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1647
kono
parents:
diff changeset
1648 After error-checking, the real work is done by the
kono
parents:
diff changeset
1649 gcc::jit::recording::context::new_cast method in jit-recording.c. */
kono
parents:
diff changeset
1650
kono
parents:
diff changeset
1651 gcc_jit_rvalue *
kono
parents:
diff changeset
1652 gcc_jit_context_new_cast (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1653 gcc_jit_location *loc,
kono
parents:
diff changeset
1654 gcc_jit_rvalue *rvalue,
kono
parents:
diff changeset
1655 gcc_jit_type *type)
kono
parents:
diff changeset
1656 {
kono
parents:
diff changeset
1657 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
1658 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1659 /* LOC can be NULL. */
kono
parents:
diff changeset
1660 RETURN_NULL_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
kono
parents:
diff changeset
1661 RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
kono
parents:
diff changeset
1662 RETURN_NULL_IF_FAIL_PRINTF3 (
kono
parents:
diff changeset
1663 is_valid_cast (rvalue->get_type (), type),
kono
parents:
diff changeset
1664 ctxt, loc,
kono
parents:
diff changeset
1665 "cannot cast %s from type: %s to type: %s",
kono
parents:
diff changeset
1666 rvalue->get_debug_string (),
kono
parents:
diff changeset
1667 rvalue->get_type ()->get_debug_string (),
kono
parents:
diff changeset
1668 type->get_debug_string ());
kono
parents:
diff changeset
1669
kono
parents:
diff changeset
1670 return static_cast <gcc_jit_rvalue *> (ctxt->new_cast (loc, rvalue, type));
kono
parents:
diff changeset
1671 }
kono
parents:
diff changeset
1672
kono
parents:
diff changeset
1673 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1674
kono
parents:
diff changeset
1675 After error-checking, the real work is done by the
kono
parents:
diff changeset
1676 gcc::jit::recording::context::new_array_access method in
kono
parents:
diff changeset
1677 jit-recording.c. */
kono
parents:
diff changeset
1678
kono
parents:
diff changeset
1679 extern gcc_jit_lvalue *
kono
parents:
diff changeset
1680 gcc_jit_context_new_array_access (gcc_jit_context *ctxt,
kono
parents:
diff changeset
1681 gcc_jit_location *loc,
kono
parents:
diff changeset
1682 gcc_jit_rvalue *ptr,
kono
parents:
diff changeset
1683 gcc_jit_rvalue *index)
kono
parents:
diff changeset
1684 {
kono
parents:
diff changeset
1685 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL context");
kono
parents:
diff changeset
1686 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1687 /* LOC can be NULL. */
kono
parents:
diff changeset
1688 RETURN_NULL_IF_FAIL (ptr, ctxt, loc, "NULL ptr");
kono
parents:
diff changeset
1689 RETURN_NULL_IF_FAIL (index, ctxt, loc, "NULL index");
kono
parents:
diff changeset
1690 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1691 ptr->get_type ()->dereference (),
kono
parents:
diff changeset
1692 ctxt, loc,
kono
parents:
diff changeset
1693 "ptr: %s (type: %s) is not a pointer or array",
kono
parents:
diff changeset
1694 ptr->get_debug_string (),
kono
parents:
diff changeset
1695 ptr->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1696 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1697 index->get_type ()->is_numeric (),
kono
parents:
diff changeset
1698 ctxt, loc,
kono
parents:
diff changeset
1699 "index: %s (type: %s) is not of numeric type",
kono
parents:
diff changeset
1700 index->get_debug_string (),
kono
parents:
diff changeset
1701 index->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1702
kono
parents:
diff changeset
1703 return (gcc_jit_lvalue *)ctxt->new_array_access (loc, ptr, index);
kono
parents:
diff changeset
1704 }
kono
parents:
diff changeset
1705
kono
parents:
diff changeset
1706 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1707
kono
parents:
diff changeset
1708 After error-checking, the real work is done by the
kono
parents:
diff changeset
1709 gcc::jit::recording::memento::get_context method in
kono
parents:
diff changeset
1710 jit-recording.h. */
kono
parents:
diff changeset
1711
kono
parents:
diff changeset
1712 gcc_jit_context *
kono
parents:
diff changeset
1713 gcc_jit_object_get_context (gcc_jit_object *obj)
kono
parents:
diff changeset
1714 {
kono
parents:
diff changeset
1715 RETURN_NULL_IF_FAIL (obj, NULL, NULL, "NULL object");
kono
parents:
diff changeset
1716
kono
parents:
diff changeset
1717 return static_cast <gcc_jit_context *> (obj->get_context ());
kono
parents:
diff changeset
1718 }
kono
parents:
diff changeset
1719
kono
parents:
diff changeset
1720 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1721
kono
parents:
diff changeset
1722 After error-checking, the real work is done by the
kono
parents:
diff changeset
1723 gcc::jit::recording::memento::get_debug_string method in
kono
parents:
diff changeset
1724 jit-recording.c. */
kono
parents:
diff changeset
1725
kono
parents:
diff changeset
1726 const char *
kono
parents:
diff changeset
1727 gcc_jit_object_get_debug_string (gcc_jit_object *obj)
kono
parents:
diff changeset
1728 {
kono
parents:
diff changeset
1729 RETURN_NULL_IF_FAIL (obj, NULL, NULL, "NULL object");
kono
parents:
diff changeset
1730
kono
parents:
diff changeset
1731 return obj->get_debug_string ();
kono
parents:
diff changeset
1732 }
kono
parents:
diff changeset
1733
kono
parents:
diff changeset
1734 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1735
kono
parents:
diff changeset
1736 After error-checking, the real work is done by the
kono
parents:
diff changeset
1737 gcc::jit::recording::lvalue::access_field method in
kono
parents:
diff changeset
1738 jit-recording.c. */
kono
parents:
diff changeset
1739
kono
parents:
diff changeset
1740 gcc_jit_lvalue *
kono
parents:
diff changeset
1741 gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_,
kono
parents:
diff changeset
1742 gcc_jit_location *loc,
kono
parents:
diff changeset
1743 gcc_jit_field *field)
kono
parents:
diff changeset
1744 {
kono
parents:
diff changeset
1745 RETURN_NULL_IF_FAIL (struct_, NULL, loc, "NULL struct");
kono
parents:
diff changeset
1746 gcc::jit::recording::context *ctxt = struct_->m_ctxt;
kono
parents:
diff changeset
1747 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1748 /* LOC can be NULL. */
kono
parents:
diff changeset
1749 RETURN_NULL_IF_FAIL (field, ctxt, loc, "NULL field");
kono
parents:
diff changeset
1750 RETURN_NULL_IF_FAIL_PRINTF1 (field->get_container (), field->m_ctxt, loc,
kono
parents:
diff changeset
1751 "field %s has not been placed in a struct",
kono
parents:
diff changeset
1752 field->get_debug_string ());
kono
parents:
diff changeset
1753 gcc::jit::recording::type *underlying_type =
kono
parents:
diff changeset
1754 struct_->get_type ();
kono
parents:
diff changeset
1755 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1756 (field->get_container ()->unqualified ()
kono
parents:
diff changeset
1757 == underlying_type->unqualified ()),
kono
parents:
diff changeset
1758 struct_->m_ctxt, loc,
kono
parents:
diff changeset
1759 "%s is not a field of %s",
kono
parents:
diff changeset
1760 field->get_debug_string (),
kono
parents:
diff changeset
1761 underlying_type->get_debug_string ());
kono
parents:
diff changeset
1762
kono
parents:
diff changeset
1763 return (gcc_jit_lvalue *)struct_->access_field (loc, field);
kono
parents:
diff changeset
1764 }
kono
parents:
diff changeset
1765
kono
parents:
diff changeset
1766 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1767
kono
parents:
diff changeset
1768 After error-checking, the real work is done by the
kono
parents:
diff changeset
1769 gcc::jit::recording::rvalue::access_field method in
kono
parents:
diff changeset
1770 jit-recording.c. */
kono
parents:
diff changeset
1771
kono
parents:
diff changeset
1772 gcc_jit_rvalue *
kono
parents:
diff changeset
1773 gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_,
kono
parents:
diff changeset
1774 gcc_jit_location *loc,
kono
parents:
diff changeset
1775 gcc_jit_field *field)
kono
parents:
diff changeset
1776 {
kono
parents:
diff changeset
1777 RETURN_NULL_IF_FAIL (struct_, NULL, loc, "NULL struct");
kono
parents:
diff changeset
1778 gcc::jit::recording::context *ctxt = struct_->m_ctxt;
kono
parents:
diff changeset
1779 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1780 /* LOC can be NULL. */
kono
parents:
diff changeset
1781 RETURN_NULL_IF_FAIL (field, ctxt, loc, "NULL field");
kono
parents:
diff changeset
1782 RETURN_NULL_IF_FAIL_PRINTF1 (field->get_container (), field->m_ctxt, loc,
kono
parents:
diff changeset
1783 "field %s has not been placed in a struct",
kono
parents:
diff changeset
1784 field->get_debug_string ());
kono
parents:
diff changeset
1785 gcc::jit::recording::type *underlying_type =
kono
parents:
diff changeset
1786 struct_->get_type ();
kono
parents:
diff changeset
1787 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1788 (field->get_container ()->unqualified ()
kono
parents:
diff changeset
1789 == underlying_type->unqualified ()),
kono
parents:
diff changeset
1790 struct_->m_ctxt, loc,
kono
parents:
diff changeset
1791 "%s is not a field of %s",
kono
parents:
diff changeset
1792 field->get_debug_string (),
kono
parents:
diff changeset
1793 underlying_type->get_debug_string ());
kono
parents:
diff changeset
1794
kono
parents:
diff changeset
1795 return (gcc_jit_rvalue *)struct_->access_field (loc, field);
kono
parents:
diff changeset
1796 }
kono
parents:
diff changeset
1797
kono
parents:
diff changeset
1798 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1799
kono
parents:
diff changeset
1800 After error-checking, the real work is done by the
kono
parents:
diff changeset
1801 gcc::jit::recording::rvalue::deference_field method in
kono
parents:
diff changeset
1802 jit-recording.c. */
kono
parents:
diff changeset
1803
kono
parents:
diff changeset
1804 gcc_jit_lvalue *
kono
parents:
diff changeset
1805 gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr,
kono
parents:
diff changeset
1806 gcc_jit_location *loc,
kono
parents:
diff changeset
1807 gcc_jit_field *field)
kono
parents:
diff changeset
1808 {
kono
parents:
diff changeset
1809 RETURN_NULL_IF_FAIL (ptr, NULL, loc, "NULL ptr");
kono
parents:
diff changeset
1810 JIT_LOG_FUNC (ptr->get_context ()->get_logger ());
kono
parents:
diff changeset
1811 /* LOC can be NULL. */
kono
parents:
diff changeset
1812 RETURN_NULL_IF_FAIL (field, NULL, loc, "NULL field");
kono
parents:
diff changeset
1813 gcc::jit::recording::type *underlying_type =
kono
parents:
diff changeset
1814 ptr->get_type ()->is_pointer ();
kono
parents:
diff changeset
1815 RETURN_NULL_IF_FAIL_PRINTF1 (field->get_container (), field->m_ctxt, loc,
kono
parents:
diff changeset
1816 "field %s has not been placed in a struct",
kono
parents:
diff changeset
1817 field->get_debug_string ());
kono
parents:
diff changeset
1818 RETURN_NULL_IF_FAIL_PRINTF3 (
kono
parents:
diff changeset
1819 underlying_type,
kono
parents:
diff changeset
1820 ptr->m_ctxt, loc,
kono
parents:
diff changeset
1821 "dereference of non-pointer %s (type: %s) when accessing ->%s",
kono
parents:
diff changeset
1822 ptr->get_debug_string (),
kono
parents:
diff changeset
1823 ptr->get_type ()->get_debug_string (),
kono
parents:
diff changeset
1824 field->get_debug_string ());
kono
parents:
diff changeset
1825 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1826 (field->get_container ()->unqualified ()
kono
parents:
diff changeset
1827 == underlying_type->unqualified ()),
kono
parents:
diff changeset
1828 ptr->m_ctxt, loc,
kono
parents:
diff changeset
1829 "%s is not a field of %s",
kono
parents:
diff changeset
1830 field->get_debug_string (),
kono
parents:
diff changeset
1831 underlying_type->get_debug_string ());
kono
parents:
diff changeset
1832
kono
parents:
diff changeset
1833 return (gcc_jit_lvalue *)ptr->dereference_field (loc, field);
kono
parents:
diff changeset
1834 }
kono
parents:
diff changeset
1835
kono
parents:
diff changeset
1836 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1837
kono
parents:
diff changeset
1838 After error-checking, the real work is done by the
kono
parents:
diff changeset
1839 gcc::jit::recording::rvalue::deference method in
kono
parents:
diff changeset
1840 jit-recording.c. */
kono
parents:
diff changeset
1841
kono
parents:
diff changeset
1842 gcc_jit_lvalue *
kono
parents:
diff changeset
1843 gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue,
kono
parents:
diff changeset
1844 gcc_jit_location *loc)
kono
parents:
diff changeset
1845 {
kono
parents:
diff changeset
1846 RETURN_NULL_IF_FAIL (rvalue, NULL, loc, "NULL rvalue");
kono
parents:
diff changeset
1847 JIT_LOG_FUNC (rvalue->get_context ()->get_logger ());
kono
parents:
diff changeset
1848 /* LOC can be NULL. */
kono
parents:
diff changeset
1849
kono
parents:
diff changeset
1850 gcc::jit::recording::type *underlying_type =
kono
parents:
diff changeset
1851 rvalue->get_type ()->is_pointer ();
kono
parents:
diff changeset
1852
kono
parents:
diff changeset
1853 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1854 underlying_type,
kono
parents:
diff changeset
1855 rvalue->m_ctxt, loc,
kono
parents:
diff changeset
1856 "dereference of non-pointer %s (type: %s)",
kono
parents:
diff changeset
1857 rvalue->get_debug_string (),
kono
parents:
diff changeset
1858 rvalue->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1859
kono
parents:
diff changeset
1860 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1861 !underlying_type->is_void (),
kono
parents:
diff changeset
1862 rvalue->m_ctxt, loc,
kono
parents:
diff changeset
1863 "dereference of void pointer %s (type: %s)",
kono
parents:
diff changeset
1864 rvalue->get_debug_string (),
kono
parents:
diff changeset
1865 rvalue->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1866
kono
parents:
diff changeset
1867 return (gcc_jit_lvalue *)rvalue->dereference (loc);
kono
parents:
diff changeset
1868 }
kono
parents:
diff changeset
1869
kono
parents:
diff changeset
1870 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1871
kono
parents:
diff changeset
1872 After error-checking, the real work is done by the
kono
parents:
diff changeset
1873 gcc::jit::recording::lvalue::get_address method in jit-recording.c. */
kono
parents:
diff changeset
1874
kono
parents:
diff changeset
1875 gcc_jit_rvalue *
kono
parents:
diff changeset
1876 gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue,
kono
parents:
diff changeset
1877 gcc_jit_location *loc)
kono
parents:
diff changeset
1878 {
kono
parents:
diff changeset
1879 RETURN_NULL_IF_FAIL (lvalue, NULL, loc, "NULL lvalue");
kono
parents:
diff changeset
1880 JIT_LOG_FUNC (lvalue->get_context ()->get_logger ());
kono
parents:
diff changeset
1881 /* LOC can be NULL. */
kono
parents:
diff changeset
1882
kono
parents:
diff changeset
1883 return (gcc_jit_rvalue *)lvalue->get_address (loc);
kono
parents:
diff changeset
1884 }
kono
parents:
diff changeset
1885
kono
parents:
diff changeset
1886 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1887
kono
parents:
diff changeset
1888 After error-checking, the real work is done by the
kono
parents:
diff changeset
1889 gcc::jit::recording::function::new_local method in jit-recording.c. */
kono
parents:
diff changeset
1890
kono
parents:
diff changeset
1891 gcc_jit_lvalue *
kono
parents:
diff changeset
1892 gcc_jit_function_new_local (gcc_jit_function *func,
kono
parents:
diff changeset
1893 gcc_jit_location *loc,
kono
parents:
diff changeset
1894 gcc_jit_type *type,
kono
parents:
diff changeset
1895 const char *name)
kono
parents:
diff changeset
1896 {
kono
parents:
diff changeset
1897 RETURN_NULL_IF_FAIL (func, NULL, loc, "NULL function");
kono
parents:
diff changeset
1898 gcc::jit::recording::context *ctxt = func->m_ctxt;
kono
parents:
diff changeset
1899 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1900 /* LOC can be NULL. */
kono
parents:
diff changeset
1901 RETURN_NULL_IF_FAIL (func->get_kind () != GCC_JIT_FUNCTION_IMPORTED,
kono
parents:
diff changeset
1902 ctxt, loc,
kono
parents:
diff changeset
1903 "Cannot add locals to an imported function");
kono
parents:
diff changeset
1904 RETURN_NULL_IF_FAIL (type, ctxt, loc, "NULL type");
kono
parents:
diff changeset
1905 RETURN_NULL_IF_FAIL (name, ctxt, loc, "NULL name");
kono
parents:
diff changeset
1906 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
1907 type->has_known_size (),
kono
parents:
diff changeset
1908 ctxt, loc,
kono
parents:
diff changeset
1909 "unknown size for local \"%s\" (type: %s)",
kono
parents:
diff changeset
1910 name,
kono
parents:
diff changeset
1911 type->get_debug_string ());
kono
parents:
diff changeset
1912
kono
parents:
diff changeset
1913 return (gcc_jit_lvalue *)func->new_local (loc, type, name);
kono
parents:
diff changeset
1914 }
kono
parents:
diff changeset
1915
kono
parents:
diff changeset
1916 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1917
kono
parents:
diff changeset
1918 After error-checking, the real work is done by the
kono
parents:
diff changeset
1919 gcc::jit::recording::block::add_eval method in jit-recording.c. */
kono
parents:
diff changeset
1920
kono
parents:
diff changeset
1921 void
kono
parents:
diff changeset
1922 gcc_jit_block_add_eval (gcc_jit_block *block,
kono
parents:
diff changeset
1923 gcc_jit_location *loc,
kono
parents:
diff changeset
1924 gcc_jit_rvalue *rvalue)
kono
parents:
diff changeset
1925 {
kono
parents:
diff changeset
1926 RETURN_IF_NOT_VALID_BLOCK (block, loc);
kono
parents:
diff changeset
1927 gcc::jit::recording::context *ctxt = block->get_context ();
kono
parents:
diff changeset
1928 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1929 /* LOC can be NULL. */
kono
parents:
diff changeset
1930 RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
kono
parents:
diff changeset
1931
kono
parents:
diff changeset
1932 gcc::jit::recording::statement *stmt = block->add_eval (loc, rvalue);
kono
parents:
diff changeset
1933
kono
parents:
diff changeset
1934 /* "stmt" should be good enough to be usable in error-messages,
kono
parents:
diff changeset
1935 but might still not be compilable; perform some more
kono
parents:
diff changeset
1936 error-checking here. We do this here so that the error messages
kono
parents:
diff changeset
1937 can contain a stringified version of "stmt", whilst appearing
kono
parents:
diff changeset
1938 as close as possible to the point of failure. */
kono
parents:
diff changeset
1939 rvalue->verify_valid_within_stmt (__func__, stmt);
kono
parents:
diff changeset
1940 }
kono
parents:
diff changeset
1941
kono
parents:
diff changeset
1942 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1943
kono
parents:
diff changeset
1944 After error-checking, the real work is done by the
kono
parents:
diff changeset
1945 gcc::jit::recording::block::add_assignment method in
kono
parents:
diff changeset
1946 jit-recording.c. */
kono
parents:
diff changeset
1947
kono
parents:
diff changeset
1948 void
kono
parents:
diff changeset
1949 gcc_jit_block_add_assignment (gcc_jit_block *block,
kono
parents:
diff changeset
1950 gcc_jit_location *loc,
kono
parents:
diff changeset
1951 gcc_jit_lvalue *lvalue,
kono
parents:
diff changeset
1952 gcc_jit_rvalue *rvalue)
kono
parents:
diff changeset
1953 {
kono
parents:
diff changeset
1954 RETURN_IF_NOT_VALID_BLOCK (block, loc);
kono
parents:
diff changeset
1955 gcc::jit::recording::context *ctxt = block->get_context ();
kono
parents:
diff changeset
1956 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1957 /* LOC can be NULL. */
kono
parents:
diff changeset
1958 RETURN_IF_FAIL (lvalue, ctxt, loc, "NULL lvalue");
kono
parents:
diff changeset
1959 RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
kono
parents:
diff changeset
1960 RETURN_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
1961 compatible_types (lvalue->get_type (),
kono
parents:
diff changeset
1962 rvalue->get_type ()),
kono
parents:
diff changeset
1963 ctxt, loc,
kono
parents:
diff changeset
1964 "mismatching types:"
kono
parents:
diff changeset
1965 " assignment to %s (type: %s) from %s (type: %s)",
kono
parents:
diff changeset
1966 lvalue->get_debug_string (),
kono
parents:
diff changeset
1967 lvalue->get_type ()->get_debug_string (),
kono
parents:
diff changeset
1968 rvalue->get_debug_string (),
kono
parents:
diff changeset
1969 rvalue->get_type ()->get_debug_string ());
kono
parents:
diff changeset
1970
kono
parents:
diff changeset
1971 gcc::jit::recording::statement *stmt = block->add_assignment (loc, lvalue, rvalue);
kono
parents:
diff changeset
1972
kono
parents:
diff changeset
1973 /* "stmt" should be good enough to be usable in error-messages,
kono
parents:
diff changeset
1974 but might still not be compilable; perform some more
kono
parents:
diff changeset
1975 error-checking here. We do this here so that the error messages
kono
parents:
diff changeset
1976 can contain a stringified version of "stmt", whilst appearing
kono
parents:
diff changeset
1977 as close as possible to the point of failure. */
kono
parents:
diff changeset
1978 lvalue->verify_valid_within_stmt (__func__, stmt);
kono
parents:
diff changeset
1979 rvalue->verify_valid_within_stmt (__func__, stmt);
kono
parents:
diff changeset
1980 }
kono
parents:
diff changeset
1981
kono
parents:
diff changeset
1982 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
1983
kono
parents:
diff changeset
1984 After error-checking, the real work is done by the
kono
parents:
diff changeset
1985 gcc::jit::recording::block::add_assignment_op method in
kono
parents:
diff changeset
1986 jit-recording.c. */
kono
parents:
diff changeset
1987
kono
parents:
diff changeset
1988 void
kono
parents:
diff changeset
1989 gcc_jit_block_add_assignment_op (gcc_jit_block *block,
kono
parents:
diff changeset
1990 gcc_jit_location *loc,
kono
parents:
diff changeset
1991 gcc_jit_lvalue *lvalue,
kono
parents:
diff changeset
1992 enum gcc_jit_binary_op op,
kono
parents:
diff changeset
1993 gcc_jit_rvalue *rvalue)
kono
parents:
diff changeset
1994 {
kono
parents:
diff changeset
1995 RETURN_IF_NOT_VALID_BLOCK (block, loc);
kono
parents:
diff changeset
1996 gcc::jit::recording::context *ctxt = block->get_context ();
kono
parents:
diff changeset
1997 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
1998 /* LOC can be NULL. */
kono
parents:
diff changeset
1999 RETURN_IF_FAIL (lvalue, ctxt, loc, "NULL lvalue");
kono
parents:
diff changeset
2000 RETURN_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
2001 valid_binary_op_p (op),
kono
parents:
diff changeset
2002 ctxt, loc,
kono
parents:
diff changeset
2003 "unrecognized value for enum gcc_jit_binary_op: %i",
kono
parents:
diff changeset
2004 op);
kono
parents:
diff changeset
2005 RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
kono
parents:
diff changeset
2006 RETURN_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
2007 compatible_types (lvalue->get_type (),
kono
parents:
diff changeset
2008 rvalue->get_type ()),
kono
parents:
diff changeset
2009 ctxt, loc,
kono
parents:
diff changeset
2010 "mismatching types:"
kono
parents:
diff changeset
2011 " assignment to %s (type: %s) involving %s (type: %s)",
kono
parents:
diff changeset
2012 lvalue->get_debug_string (),
kono
parents:
diff changeset
2013 lvalue->get_type ()->get_debug_string (),
kono
parents:
diff changeset
2014 rvalue->get_debug_string (),
kono
parents:
diff changeset
2015 rvalue->get_type ()->get_debug_string ());
kono
parents:
diff changeset
2016
kono
parents:
diff changeset
2017 gcc::jit::recording::statement *stmt = block->add_assignment_op (loc, lvalue, op, rvalue);
kono
parents:
diff changeset
2018
kono
parents:
diff changeset
2019 /* "stmt" should be good enough to be usable in error-messages,
kono
parents:
diff changeset
2020 but might still not be compilable; perform some more
kono
parents:
diff changeset
2021 error-checking here. We do this here so that the error messages
kono
parents:
diff changeset
2022 can contain a stringified version of "stmt", whilst appearing
kono
parents:
diff changeset
2023 as close as possible to the point of failure. */
kono
parents:
diff changeset
2024 lvalue->verify_valid_within_stmt (__func__, stmt);
kono
parents:
diff changeset
2025 rvalue->verify_valid_within_stmt (__func__, stmt);
kono
parents:
diff changeset
2026 }
kono
parents:
diff changeset
2027
kono
parents:
diff changeset
2028 /* Internal helper function for determining if rvalue BOOLVAL is of
kono
parents:
diff changeset
2029 boolean type. For use by gcc_jit_block_end_with_conditional. */
kono
parents:
diff changeset
2030
kono
parents:
diff changeset
2031 static bool
kono
parents:
diff changeset
2032 is_bool (gcc_jit_rvalue *boolval)
kono
parents:
diff changeset
2033 {
kono
parents:
diff changeset
2034 gcc::jit::recording::type *actual_type = boolval->get_type ();
kono
parents:
diff changeset
2035 gcc::jit::recording::type *bool_type =
kono
parents:
diff changeset
2036 boolval->m_ctxt->get_type (GCC_JIT_TYPE_BOOL);
kono
parents:
diff changeset
2037 return actual_type == bool_type;
kono
parents:
diff changeset
2038 }
kono
parents:
diff changeset
2039
kono
parents:
diff changeset
2040 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2041
kono
parents:
diff changeset
2042 After error-checking, the real work is done by the
kono
parents:
diff changeset
2043 gcc::jit::recording::block::end_with_conditional method in
kono
parents:
diff changeset
2044 jit-recording.c. */
kono
parents:
diff changeset
2045
kono
parents:
diff changeset
2046 void
kono
parents:
diff changeset
2047 gcc_jit_block_end_with_conditional (gcc_jit_block *block,
kono
parents:
diff changeset
2048 gcc_jit_location *loc,
kono
parents:
diff changeset
2049 gcc_jit_rvalue *boolval,
kono
parents:
diff changeset
2050 gcc_jit_block *on_true,
kono
parents:
diff changeset
2051 gcc_jit_block *on_false)
kono
parents:
diff changeset
2052 {
kono
parents:
diff changeset
2053 RETURN_IF_NOT_VALID_BLOCK (block, loc);
kono
parents:
diff changeset
2054 gcc::jit::recording::context *ctxt = block->get_context ();
kono
parents:
diff changeset
2055 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2056 /* LOC can be NULL. */
kono
parents:
diff changeset
2057 RETURN_IF_FAIL (boolval, ctxt, loc, "NULL boolval");
kono
parents:
diff changeset
2058 RETURN_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
2059 is_bool (boolval), ctxt, loc,
kono
parents:
diff changeset
2060 "%s (type: %s) is not of boolean type ",
kono
parents:
diff changeset
2061 boolval->get_debug_string (),
kono
parents:
diff changeset
2062 boolval->get_type ()->get_debug_string ());
kono
parents:
diff changeset
2063 RETURN_IF_FAIL (on_true, ctxt, loc, "NULL on_true");
kono
parents:
diff changeset
2064 RETURN_IF_FAIL (on_true, ctxt, loc, "NULL on_false");
kono
parents:
diff changeset
2065 RETURN_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
2066 block->get_function () == on_true->get_function (),
kono
parents:
diff changeset
2067 ctxt, loc,
kono
parents:
diff changeset
2068 "\"on_true\" block is not in same function:"
kono
parents:
diff changeset
2069 " source block %s is in function %s"
kono
parents:
diff changeset
2070 " whereas target block %s is in function %s",
kono
parents:
diff changeset
2071 block->get_debug_string (),
kono
parents:
diff changeset
2072 block->get_function ()->get_debug_string (),
kono
parents:
diff changeset
2073 on_true->get_debug_string (),
kono
parents:
diff changeset
2074 on_true->get_function ()->get_debug_string ());
kono
parents:
diff changeset
2075 RETURN_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
2076 block->get_function () == on_false->get_function (),
kono
parents:
diff changeset
2077 ctxt, loc,
kono
parents:
diff changeset
2078 "\"on_false\" block is not in same function:"
kono
parents:
diff changeset
2079 " source block %s is in function %s"
kono
parents:
diff changeset
2080 " whereas target block %s is in function %s",
kono
parents:
diff changeset
2081 block->get_debug_string (),
kono
parents:
diff changeset
2082 block->get_function ()->get_debug_string (),
kono
parents:
diff changeset
2083 on_false->get_debug_string (),
kono
parents:
diff changeset
2084 on_false->get_function ()->get_debug_string ());
kono
parents:
diff changeset
2085
kono
parents:
diff changeset
2086 gcc::jit::recording::statement *stmt = block->end_with_conditional (loc, boolval, on_true, on_false);
kono
parents:
diff changeset
2087
kono
parents:
diff changeset
2088 /* "stmt" should be good enough to be usable in error-messages,
kono
parents:
diff changeset
2089 but might still not be compilable; perform some more
kono
parents:
diff changeset
2090 error-checking here. We do this here so that the error messages
kono
parents:
diff changeset
2091 can contain a stringified version of "stmt", whilst appearing
kono
parents:
diff changeset
2092 as close as possible to the point of failure. */
kono
parents:
diff changeset
2093 boolval->verify_valid_within_stmt (__func__, stmt);
kono
parents:
diff changeset
2094 }
kono
parents:
diff changeset
2095
kono
parents:
diff changeset
2096 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2097
kono
parents:
diff changeset
2098 After error-checking, the real work is done by the
kono
parents:
diff changeset
2099 gcc::jit::recording::block::add_comment method in
kono
parents:
diff changeset
2100 jit-recording.c. */
kono
parents:
diff changeset
2101
kono
parents:
diff changeset
2102 void
kono
parents:
diff changeset
2103 gcc_jit_block_add_comment (gcc_jit_block *block,
kono
parents:
diff changeset
2104 gcc_jit_location *loc,
kono
parents:
diff changeset
2105 const char *text)
kono
parents:
diff changeset
2106 {
kono
parents:
diff changeset
2107 RETURN_IF_NOT_VALID_BLOCK (block, loc);
kono
parents:
diff changeset
2108 gcc::jit::recording::context *ctxt = block->get_context ();
kono
parents:
diff changeset
2109 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2110 /* LOC can be NULL. */
kono
parents:
diff changeset
2111 RETURN_IF_FAIL (text, ctxt, loc, "NULL text");
kono
parents:
diff changeset
2112
kono
parents:
diff changeset
2113 block->add_comment (loc, text);
kono
parents:
diff changeset
2114 }
kono
parents:
diff changeset
2115
kono
parents:
diff changeset
2116 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2117
kono
parents:
diff changeset
2118 After error-checking, the real work is done by the
kono
parents:
diff changeset
2119 gcc::jit::recording::block::end_with_jump method in
kono
parents:
diff changeset
2120 jit-recording.c. */
kono
parents:
diff changeset
2121
kono
parents:
diff changeset
2122 void
kono
parents:
diff changeset
2123 gcc_jit_block_end_with_jump (gcc_jit_block *block,
kono
parents:
diff changeset
2124 gcc_jit_location *loc,
kono
parents:
diff changeset
2125 gcc_jit_block *target)
kono
parents:
diff changeset
2126 {
kono
parents:
diff changeset
2127 RETURN_IF_NOT_VALID_BLOCK (block, loc);
kono
parents:
diff changeset
2128 gcc::jit::recording::context *ctxt = block->get_context ();
kono
parents:
diff changeset
2129 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2130 /* LOC can be NULL. */
kono
parents:
diff changeset
2131 RETURN_IF_FAIL (target, ctxt, loc, "NULL target");
kono
parents:
diff changeset
2132 RETURN_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
2133 block->get_function () == target->get_function (),
kono
parents:
diff changeset
2134 ctxt, loc,
kono
parents:
diff changeset
2135 "target block is not in same function:"
kono
parents:
diff changeset
2136 " source block %s is in function %s"
kono
parents:
diff changeset
2137 " whereas target block %s is in function %s",
kono
parents:
diff changeset
2138 block->get_debug_string (),
kono
parents:
diff changeset
2139 block->get_function ()->get_debug_string (),
kono
parents:
diff changeset
2140 target->get_debug_string (),
kono
parents:
diff changeset
2141 target->get_function ()->get_debug_string ());
kono
parents:
diff changeset
2142
kono
parents:
diff changeset
2143 block->end_with_jump (loc, target);
kono
parents:
diff changeset
2144 }
kono
parents:
diff changeset
2145
kono
parents:
diff changeset
2146 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2147
kono
parents:
diff changeset
2148 After error-checking, the real work is done by the
kono
parents:
diff changeset
2149 gcc::jit::recording::block::end_with_return method in
kono
parents:
diff changeset
2150 jit-recording.c. */
kono
parents:
diff changeset
2151
kono
parents:
diff changeset
2152 void
kono
parents:
diff changeset
2153 gcc_jit_block_end_with_return (gcc_jit_block *block,
kono
parents:
diff changeset
2154 gcc_jit_location *loc,
kono
parents:
diff changeset
2155 gcc_jit_rvalue *rvalue)
kono
parents:
diff changeset
2156 {
kono
parents:
diff changeset
2157 RETURN_IF_NOT_VALID_BLOCK (block, loc);
kono
parents:
diff changeset
2158 gcc::jit::recording::context *ctxt = block->get_context ();
kono
parents:
diff changeset
2159 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2160 /* LOC can be NULL. */
kono
parents:
diff changeset
2161 gcc::jit::recording::function *func = block->get_function ();
kono
parents:
diff changeset
2162 RETURN_IF_FAIL (rvalue, ctxt, loc, "NULL rvalue");
kono
parents:
diff changeset
2163 RETURN_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
2164 compatible_types (
kono
parents:
diff changeset
2165 func->get_return_type (),
kono
parents:
diff changeset
2166 rvalue->get_type ()),
kono
parents:
diff changeset
2167 ctxt, loc,
kono
parents:
diff changeset
2168 "mismatching types:"
kono
parents:
diff changeset
2169 " return of %s (type: %s) in function %s (return type: %s)",
kono
parents:
diff changeset
2170 rvalue->get_debug_string (),
kono
parents:
diff changeset
2171 rvalue->get_type ()->get_debug_string (),
kono
parents:
diff changeset
2172 func->get_debug_string (),
kono
parents:
diff changeset
2173 func->get_return_type ()->get_debug_string ());
kono
parents:
diff changeset
2174
kono
parents:
diff changeset
2175 gcc::jit::recording::statement *stmt = block->end_with_return (loc, rvalue);
kono
parents:
diff changeset
2176
kono
parents:
diff changeset
2177 /* "stmt" should be good enough to be usable in error-messages,
kono
parents:
diff changeset
2178 but might still not be compilable; perform some more
kono
parents:
diff changeset
2179 error-checking here. We do this here so that the error messages
kono
parents:
diff changeset
2180 can contain a stringified version of "stmt", whilst appearing
kono
parents:
diff changeset
2181 as close as possible to the point of failure. */
kono
parents:
diff changeset
2182 rvalue->verify_valid_within_stmt (__func__, stmt);
kono
parents:
diff changeset
2183 }
kono
parents:
diff changeset
2184
kono
parents:
diff changeset
2185 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2186
kono
parents:
diff changeset
2187 After error-checking, the real work is done by the
kono
parents:
diff changeset
2188 gcc::jit::recording::block::end_with_return method in
kono
parents:
diff changeset
2189 jit-recording.c. */
kono
parents:
diff changeset
2190
kono
parents:
diff changeset
2191 void
kono
parents:
diff changeset
2192 gcc_jit_block_end_with_void_return (gcc_jit_block *block,
kono
parents:
diff changeset
2193 gcc_jit_location *loc)
kono
parents:
diff changeset
2194 {
kono
parents:
diff changeset
2195 RETURN_IF_NOT_VALID_BLOCK (block, loc);
kono
parents:
diff changeset
2196 gcc::jit::recording::context *ctxt = block->get_context ();
kono
parents:
diff changeset
2197 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2198 /* LOC can be NULL. */
kono
parents:
diff changeset
2199 gcc::jit::recording::function *func = block->get_function ();
kono
parents:
diff changeset
2200 RETURN_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
2201 func->get_return_type () == ctxt->get_type (GCC_JIT_TYPE_VOID),
kono
parents:
diff changeset
2202 ctxt, loc,
kono
parents:
diff changeset
2203 "mismatching types:"
kono
parents:
diff changeset
2204 " void return in function %s (return type: %s)",
kono
parents:
diff changeset
2205 func->get_debug_string (),
kono
parents:
diff changeset
2206 func->get_return_type ()->get_debug_string ());
kono
parents:
diff changeset
2207
kono
parents:
diff changeset
2208 block->end_with_return (loc, NULL);
kono
parents:
diff changeset
2209 }
kono
parents:
diff changeset
2210
kono
parents:
diff changeset
2211 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2212
kono
parents:
diff changeset
2213 After error-checking, the real work is done by the
kono
parents:
diff changeset
2214 gcc::jit::recording::context::new_case method in
kono
parents:
diff changeset
2215 jit-recording.c. */
kono
parents:
diff changeset
2216
kono
parents:
diff changeset
2217 gcc_jit_case *
kono
parents:
diff changeset
2218 gcc_jit_context_new_case (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2219 gcc_jit_rvalue *min_value,
kono
parents:
diff changeset
2220 gcc_jit_rvalue *max_value,
kono
parents:
diff changeset
2221 gcc_jit_block *block)
kono
parents:
diff changeset
2222 {
kono
parents:
diff changeset
2223 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2224 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2225 RETURN_NULL_IF_FAIL (min_value, ctxt, NULL, "NULL min_value");
kono
parents:
diff changeset
2226 RETURN_NULL_IF_FAIL (max_value, ctxt, NULL, "NULL max_value");
kono
parents:
diff changeset
2227 RETURN_NULL_IF_FAIL (block, ctxt, NULL, "NULL block");
kono
parents:
diff changeset
2228
kono
parents:
diff changeset
2229 RETURN_NULL_IF_FAIL_PRINTF1 (min_value->is_constant (), ctxt, NULL,
kono
parents:
diff changeset
2230 "min_value is not a constant: %s",
kono
parents:
diff changeset
2231 min_value->get_debug_string ());
kono
parents:
diff changeset
2232 RETURN_NULL_IF_FAIL_PRINTF1 (max_value->is_constant (), ctxt, NULL,
kono
parents:
diff changeset
2233 "max_value is not a constant: %s",
kono
parents:
diff changeset
2234 max_value->get_debug_string ());
kono
parents:
diff changeset
2235 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
2236 min_value->get_type ()->is_int (),
kono
parents:
diff changeset
2237 ctxt, NULL,
kono
parents:
diff changeset
2238 "min_value: %s (type: %s) is not of integer type",
kono
parents:
diff changeset
2239 min_value->get_debug_string (),
kono
parents:
diff changeset
2240 min_value->get_type ()->get_debug_string ());
kono
parents:
diff changeset
2241 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
2242 max_value->get_type ()->is_int (),
kono
parents:
diff changeset
2243 ctxt, NULL,
kono
parents:
diff changeset
2244 "max_value: %s (type: %s) is not of integer type",
kono
parents:
diff changeset
2245 max_value->get_debug_string (),
kono
parents:
diff changeset
2246 max_value->get_type ()->get_debug_string ());
kono
parents:
diff changeset
2247
kono
parents:
diff changeset
2248 wide_int wi_min, wi_max;
kono
parents:
diff changeset
2249 if (!min_value->get_wide_int (&wi_min))
kono
parents:
diff changeset
2250 gcc_unreachable ();
kono
parents:
diff changeset
2251 if (!max_value->get_wide_int (&wi_max))
kono
parents:
diff changeset
2252 gcc_unreachable ();
kono
parents:
diff changeset
2253 RETURN_NULL_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
2254 wi::les_p (wi_min, wi_max),
kono
parents:
diff changeset
2255 ctxt, NULL,
kono
parents:
diff changeset
2256 "min_value: %s > max_value: %s",
kono
parents:
diff changeset
2257 min_value->get_debug_string (),
kono
parents:
diff changeset
2258 max_value->get_debug_string ());
kono
parents:
diff changeset
2259 return (gcc_jit_case *)ctxt->new_case (min_value,
kono
parents:
diff changeset
2260 max_value,
kono
parents:
diff changeset
2261 block);
kono
parents:
diff changeset
2262 }
kono
parents:
diff changeset
2263
kono
parents:
diff changeset
2264 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2265
kono
parents:
diff changeset
2266 After error-checking, this calls the trivial
kono
parents:
diff changeset
2267 gcc::jit::recording::memento::as_object method (a case is a
kono
parents:
diff changeset
2268 memento), in jit-recording.h. */
kono
parents:
diff changeset
2269
kono
parents:
diff changeset
2270 gcc_jit_object *
kono
parents:
diff changeset
2271 gcc_jit_case_as_object (gcc_jit_case *case_)
kono
parents:
diff changeset
2272 {
kono
parents:
diff changeset
2273 RETURN_NULL_IF_FAIL (case_, NULL, NULL, "NULL case");
kono
parents:
diff changeset
2274
kono
parents:
diff changeset
2275 return static_cast <gcc_jit_object *> (case_->as_object ());
kono
parents:
diff changeset
2276 }
kono
parents:
diff changeset
2277
kono
parents:
diff changeset
2278 /* Helper function for gcc_jit_block_end_with_switch and
kono
parents:
diff changeset
2279 valid_case_for_switch. */
kono
parents:
diff changeset
2280
kono
parents:
diff changeset
2281 static bool
kono
parents:
diff changeset
2282 valid_dest_for_switch (gcc::jit::recording::context *ctxt,
kono
parents:
diff changeset
2283 gcc_jit_location *loc,
kono
parents:
diff changeset
2284 const char *api_funcname,
kono
parents:
diff changeset
2285 gcc::jit::recording::block *switch_block,
kono
parents:
diff changeset
2286 gcc::jit::recording::block *dest_block,
kono
parents:
diff changeset
2287 const char *dest_block_desc)
kono
parents:
diff changeset
2288 {
kono
parents:
diff changeset
2289 if (!dest_block)
kono
parents:
diff changeset
2290 {
kono
parents:
diff changeset
2291 jit_error (ctxt, loc, "%s: NULL %s", api_funcname, dest_block_desc);
kono
parents:
diff changeset
2292 return false;
kono
parents:
diff changeset
2293 }
kono
parents:
diff changeset
2294 gcc::jit::recording::function *switch_fn = switch_block->get_function ();
kono
parents:
diff changeset
2295 gcc::jit::recording::function *dest_fn = dest_block->get_function ();
kono
parents:
diff changeset
2296 if (switch_fn != dest_fn)
kono
parents:
diff changeset
2297 {
kono
parents:
diff changeset
2298 jit_error (ctxt, loc,
kono
parents:
diff changeset
2299 "%s: %s is not in same function:"
kono
parents:
diff changeset
2300 " switch block %s is in function %s"
kono
parents:
diff changeset
2301 " whereas %s %s is in function %s",
kono
parents:
diff changeset
2302 api_funcname,
kono
parents:
diff changeset
2303 dest_block_desc,
kono
parents:
diff changeset
2304 switch_block->get_debug_string (),
kono
parents:
diff changeset
2305 switch_fn->get_debug_string (),
kono
parents:
diff changeset
2306 dest_block_desc,
kono
parents:
diff changeset
2307 dest_block->get_debug_string (),
kono
parents:
diff changeset
2308 dest_fn->get_debug_string ());
kono
parents:
diff changeset
2309 return false;
kono
parents:
diff changeset
2310 }
kono
parents:
diff changeset
2311 return true;
kono
parents:
diff changeset
2312 }
kono
parents:
diff changeset
2313
kono
parents:
diff changeset
2314 /* Helper function for gcc_jit_block_end_with_switch. */
kono
parents:
diff changeset
2315
kono
parents:
diff changeset
2316 static bool
kono
parents:
diff changeset
2317 valid_case_for_switch (gcc::jit::recording::context *ctxt,
kono
parents:
diff changeset
2318 gcc_jit_location *loc,
kono
parents:
diff changeset
2319 const char *api_funcname,
kono
parents:
diff changeset
2320 gcc_jit_block *switch_block,
kono
parents:
diff changeset
2321 gcc_jit_rvalue *expr,
kono
parents:
diff changeset
2322 gcc_jit_case *case_,
kono
parents:
diff changeset
2323 const char *case_desc,
kono
parents:
diff changeset
2324 int case_idx)
kono
parents:
diff changeset
2325 {
kono
parents:
diff changeset
2326 if (!case_)
kono
parents:
diff changeset
2327 {
kono
parents:
diff changeset
2328 jit_error (ctxt, loc,
kono
parents:
diff changeset
2329 "%s:"
kono
parents:
diff changeset
2330 " NULL case %i",
kono
parents:
diff changeset
2331 api_funcname,
kono
parents:
diff changeset
2332 case_idx);
kono
parents:
diff changeset
2333 return false;
kono
parents:
diff changeset
2334 }
kono
parents:
diff changeset
2335 if (!valid_dest_for_switch (ctxt, loc,
kono
parents:
diff changeset
2336 api_funcname,
kono
parents:
diff changeset
2337 switch_block,
kono
parents:
diff changeset
2338 case_->get_dest_block (),
kono
parents:
diff changeset
2339 case_desc))
kono
parents:
diff changeset
2340 return false;
kono
parents:
diff changeset
2341 gcc::jit::recording::type *expr_type = expr->get_type ();
kono
parents:
diff changeset
2342 if (expr_type != case_->get_min_value ()->get_type ())
kono
parents:
diff changeset
2343 {
kono
parents:
diff changeset
2344 jit_error (ctxt, loc,
kono
parents:
diff changeset
2345 "%s:"
kono
parents:
diff changeset
2346 " mismatching types between case and expression:"
kono
parents:
diff changeset
2347 " cases[%i]->min_value: %s (type: %s)"
kono
parents:
diff changeset
2348 " expr: %s (type: %s)",
kono
parents:
diff changeset
2349 api_funcname,
kono
parents:
diff changeset
2350 case_idx,
kono
parents:
diff changeset
2351 case_->get_min_value ()->get_debug_string (),
kono
parents:
diff changeset
2352 case_->get_min_value ()->get_type ()->get_debug_string (),
kono
parents:
diff changeset
2353 expr->get_debug_string (),
kono
parents:
diff changeset
2354 expr_type->get_debug_string ());
kono
parents:
diff changeset
2355 return false;
kono
parents:
diff changeset
2356 }
kono
parents:
diff changeset
2357 if (expr_type != case_->get_max_value ()->get_type ())
kono
parents:
diff changeset
2358 {
kono
parents:
diff changeset
2359 jit_error (ctxt, loc,
kono
parents:
diff changeset
2360 "%s:"
kono
parents:
diff changeset
2361 " mismatching types between case and expression:"
kono
parents:
diff changeset
2362 " cases[%i]->max_value: %s (type: %s)"
kono
parents:
diff changeset
2363 " expr: %s (type: %s)",
kono
parents:
diff changeset
2364 api_funcname,
kono
parents:
diff changeset
2365 case_idx,
kono
parents:
diff changeset
2366 case_->get_max_value ()->get_debug_string (),
kono
parents:
diff changeset
2367 case_->get_max_value ()->get_type ()->get_debug_string (),
kono
parents:
diff changeset
2368 expr->get_debug_string (),
kono
parents:
diff changeset
2369 expr_type->get_debug_string ());
kono
parents:
diff changeset
2370 return false;
kono
parents:
diff changeset
2371 }
kono
parents:
diff changeset
2372 return true;
kono
parents:
diff changeset
2373 }
kono
parents:
diff changeset
2374
kono
parents:
diff changeset
2375 /* A class for holding the data we need to perform error-checking
kono
parents:
diff changeset
2376 on a libgccjit API call. */
kono
parents:
diff changeset
2377
kono
parents:
diff changeset
2378 class api_call_validator
kono
parents:
diff changeset
2379 {
kono
parents:
diff changeset
2380 public:
kono
parents:
diff changeset
2381 api_call_validator (gcc::jit::recording::context *ctxt,
kono
parents:
diff changeset
2382 gcc_jit_location *loc,
kono
parents:
diff changeset
2383 const char *funcname)
kono
parents:
diff changeset
2384 : m_ctxt (ctxt),
kono
parents:
diff changeset
2385 m_loc (loc),
kono
parents:
diff changeset
2386 m_funcname (funcname)
kono
parents:
diff changeset
2387 {}
kono
parents:
diff changeset
2388
kono
parents:
diff changeset
2389 protected:
kono
parents:
diff changeset
2390 gcc::jit::recording::context *m_ctxt;
kono
parents:
diff changeset
2391 gcc_jit_location *m_loc;
kono
parents:
diff changeset
2392 const char *m_funcname;
kono
parents:
diff changeset
2393 };
kono
parents:
diff changeset
2394
kono
parents:
diff changeset
2395 /* A class for verifying that the ranges of cases within
kono
parents:
diff changeset
2396 gcc_jit_block_end_with_switch don't overlap. */
kono
parents:
diff changeset
2397
kono
parents:
diff changeset
2398 class case_range_validator : public api_call_validator
kono
parents:
diff changeset
2399 {
kono
parents:
diff changeset
2400 public:
kono
parents:
diff changeset
2401 case_range_validator (gcc::jit::recording::context *ctxt,
kono
parents:
diff changeset
2402 gcc_jit_location *loc,
kono
parents:
diff changeset
2403 const char *funcname);
kono
parents:
diff changeset
2404
kono
parents:
diff changeset
2405 bool
kono
parents:
diff changeset
2406 validate (gcc_jit_case *case_, int idx);
kono
parents:
diff changeset
2407
kono
parents:
diff changeset
2408 private:
kono
parents:
diff changeset
2409 static int
kono
parents:
diff changeset
2410 case_compare (gcc::jit::recording::rvalue *k1,
kono
parents:
diff changeset
2411 gcc::jit::recording::rvalue *k2);
kono
parents:
diff changeset
2412
kono
parents:
diff changeset
2413 static wide_int
kono
parents:
diff changeset
2414 get_wide_int (gcc::jit::recording::rvalue *k);
kono
parents:
diff changeset
2415
kono
parents:
diff changeset
2416 private:
kono
parents:
diff changeset
2417 typed_splay_tree <gcc::jit::recording::rvalue *, gcc_jit_case *> m_cases;
kono
parents:
diff changeset
2418 };
kono
parents:
diff changeset
2419
kono
parents:
diff changeset
2420 /* case_range_validator's ctor. */
kono
parents:
diff changeset
2421
kono
parents:
diff changeset
2422 case_range_validator::case_range_validator (gcc::jit::recording::context *ctxt,
kono
parents:
diff changeset
2423 gcc_jit_location *loc,
kono
parents:
diff changeset
2424 const char *funcname)
kono
parents:
diff changeset
2425 : api_call_validator (ctxt, loc, funcname),
kono
parents:
diff changeset
2426 m_cases (case_compare, NULL, NULL)
kono
parents:
diff changeset
2427 {
kono
parents:
diff changeset
2428 }
kono
parents:
diff changeset
2429
kono
parents:
diff changeset
2430 /* Ensure that the range of CASE_ does not overlap with any of the
kono
parents:
diff changeset
2431 ranges of cases we've already seen.
kono
parents:
diff changeset
2432 Return true if everything is OK.
kono
parents:
diff changeset
2433 Return false and emit an error if there is an overlap.
kono
parents:
diff changeset
2434 Compare with c-family/c-common.c:c_add_case_label. */
kono
parents:
diff changeset
2435
kono
parents:
diff changeset
2436 bool
kono
parents:
diff changeset
2437 case_range_validator::validate (gcc_jit_case *case_,
kono
parents:
diff changeset
2438 int case_idx)
kono
parents:
diff changeset
2439 {
kono
parents:
diff changeset
2440 /* Look up the LOW_VALUE in the table of case labels we already
kono
parents:
diff changeset
2441 have. */
kono
parents:
diff changeset
2442 gcc_jit_case *other = m_cases.lookup (case_->get_min_value ());
kono
parents:
diff changeset
2443
kono
parents:
diff changeset
2444 /* If there was not an exact match, check for overlapping ranges. */
kono
parents:
diff changeset
2445 if (!other)
kono
parents:
diff changeset
2446 {
kono
parents:
diff changeset
2447 gcc_jit_case *pred;
kono
parents:
diff changeset
2448 gcc_jit_case *succ;
kono
parents:
diff changeset
2449
kono
parents:
diff changeset
2450 /* Even though there wasn't an exact match, there might be an
kono
parents:
diff changeset
2451 overlap between this case range and another case range.
kono
parents:
diff changeset
2452 Since we've (inductively) not allowed any overlapping case
kono
parents:
diff changeset
2453 ranges, we simply need to find the greatest low case label
kono
parents:
diff changeset
2454 that is smaller that CASE_MIN_VALUE, and the smallest low case
kono
parents:
diff changeset
2455 label that is greater than CASE_MAX_VALUE. If there is an overlap
kono
parents:
diff changeset
2456 it will occur in one of these two ranges. */
kono
parents:
diff changeset
2457 pred = m_cases.predecessor (case_->get_min_value ());
kono
parents:
diff changeset
2458 succ = m_cases.successor (case_->get_max_value ());
kono
parents:
diff changeset
2459
kono
parents:
diff changeset
2460 /* Check to see if the PRED overlaps. It is smaller than
kono
parents:
diff changeset
2461 the LOW_VALUE, so we only need to check its max value. */
kono
parents:
diff changeset
2462 if (pred)
kono
parents:
diff changeset
2463 {
kono
parents:
diff changeset
2464 wide_int wi_case_min = get_wide_int (case_->get_min_value ());
kono
parents:
diff changeset
2465 wide_int wi_pred_max = get_wide_int (pred->get_max_value ());
kono
parents:
diff changeset
2466 if (wi::ges_p (wi_pred_max, wi_case_min))
kono
parents:
diff changeset
2467 other = pred;
kono
parents:
diff changeset
2468 }
kono
parents:
diff changeset
2469
kono
parents:
diff changeset
2470 if (!other && succ)
kono
parents:
diff changeset
2471 {
kono
parents:
diff changeset
2472 /* Check to see if the SUCC overlaps. The low end of that
kono
parents:
diff changeset
2473 range is bigger than the low end of the current range. */
kono
parents:
diff changeset
2474 wide_int wi_case_max = get_wide_int (case_->get_max_value ());
kono
parents:
diff changeset
2475 wide_int wi_succ_min = get_wide_int (succ->get_min_value ());
kono
parents:
diff changeset
2476 if (wi::les_p (wi_succ_min, wi_case_max))
kono
parents:
diff changeset
2477 other = succ;
kono
parents:
diff changeset
2478 }
kono
parents:
diff changeset
2479 }
kono
parents:
diff changeset
2480
kono
parents:
diff changeset
2481 /* If there was an overlap, issue an error. */
kono
parents:
diff changeset
2482 if (other)
kono
parents:
diff changeset
2483 {
kono
parents:
diff changeset
2484 jit_error (m_ctxt, m_loc,
kono
parents:
diff changeset
2485 "%s: duplicate (or overlapping) cases values:"
kono
parents:
diff changeset
2486 " case %i: %s overlaps %s",
kono
parents:
diff changeset
2487 m_funcname,
kono
parents:
diff changeset
2488 case_idx,
kono
parents:
diff changeset
2489 case_->get_debug_string (),
kono
parents:
diff changeset
2490 other->get_debug_string ());
kono
parents:
diff changeset
2491 return false;
kono
parents:
diff changeset
2492 }
kono
parents:
diff changeset
2493
kono
parents:
diff changeset
2494 /* Register this case label in the splay tree. */
kono
parents:
diff changeset
2495 m_cases.insert (case_->get_min_value (),
kono
parents:
diff changeset
2496 case_);
kono
parents:
diff changeset
2497 return true;
kono
parents:
diff changeset
2498 }
kono
parents:
diff changeset
2499
kono
parents:
diff changeset
2500 /* Compare with c-family/c-common.c:case_compare, which acts on tree
kono
parents:
diff changeset
2501 nodes, rather than rvalue *.
kono
parents:
diff changeset
2502
kono
parents:
diff changeset
2503 Comparator for case label values. K1 and K2 must be constant integer
kono
parents:
diff changeset
2504 values (anything else should have been rejected by
kono
parents:
diff changeset
2505 gcc_jit_context_new_case.
kono
parents:
diff changeset
2506
kono
parents:
diff changeset
2507 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
kono
parents:
diff changeset
2508 K2, and 0 if K1 and K2 are equal. */
kono
parents:
diff changeset
2509
kono
parents:
diff changeset
2510 int
kono
parents:
diff changeset
2511 case_range_validator::case_compare (gcc::jit::recording::rvalue * k1,
kono
parents:
diff changeset
2512 gcc::jit::recording::rvalue * k2)
kono
parents:
diff changeset
2513 {
kono
parents:
diff changeset
2514 wide_int wi1 = get_wide_int (k1);
kono
parents:
diff changeset
2515 wide_int wi2 = get_wide_int (k2);
kono
parents:
diff changeset
2516 return wi::cmps(wi1, wi2);
kono
parents:
diff changeset
2517 }
kono
parents:
diff changeset
2518
kono
parents:
diff changeset
2519 /* Given a const int rvalue K, get the underlying value as a wide_int. */
kono
parents:
diff changeset
2520
kono
parents:
diff changeset
2521 wide_int
kono
parents:
diff changeset
2522 case_range_validator::get_wide_int (gcc::jit::recording::rvalue *k)
kono
parents:
diff changeset
2523 {
kono
parents:
diff changeset
2524 wide_int wi;
kono
parents:
diff changeset
2525 bool got_wi = k->get_wide_int (&wi);
kono
parents:
diff changeset
2526 gcc_assert (got_wi);
kono
parents:
diff changeset
2527 return wi;
kono
parents:
diff changeset
2528 }
kono
parents:
diff changeset
2529
kono
parents:
diff changeset
2530 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2531
kono
parents:
diff changeset
2532 After error-checking, the real work is done by the
kono
parents:
diff changeset
2533 gcc::jit::recording::block::end_with_switch method in
kono
parents:
diff changeset
2534 jit-recording.c. */
kono
parents:
diff changeset
2535
kono
parents:
diff changeset
2536 void
kono
parents:
diff changeset
2537 gcc_jit_block_end_with_switch (gcc_jit_block *block,
kono
parents:
diff changeset
2538 gcc_jit_location *loc,
kono
parents:
diff changeset
2539 gcc_jit_rvalue *expr,
kono
parents:
diff changeset
2540 gcc_jit_block *default_block,
kono
parents:
diff changeset
2541 int num_cases,
kono
parents:
diff changeset
2542 gcc_jit_case **cases)
kono
parents:
diff changeset
2543 {
kono
parents:
diff changeset
2544 RETURN_IF_NOT_VALID_BLOCK (block, loc);
kono
parents:
diff changeset
2545 gcc::jit::recording::context *ctxt = block->get_context ();
kono
parents:
diff changeset
2546 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2547 /* LOC can be NULL. */
kono
parents:
diff changeset
2548 RETURN_IF_FAIL (expr, ctxt, loc,
kono
parents:
diff changeset
2549 "NULL expr");
kono
parents:
diff changeset
2550 gcc::jit::recording::type *expr_type = expr->get_type ();
kono
parents:
diff changeset
2551 RETURN_IF_FAIL_PRINTF2 (
kono
parents:
diff changeset
2552 expr_type->is_int (),
kono
parents:
diff changeset
2553 ctxt, loc,
kono
parents:
diff changeset
2554 "expr: %s (type: %s) is not of integer type",
kono
parents:
diff changeset
2555 expr->get_debug_string (),
kono
parents:
diff changeset
2556 expr_type->get_debug_string ());
kono
parents:
diff changeset
2557 if (!valid_dest_for_switch (ctxt, loc,
kono
parents:
diff changeset
2558 __func__,
kono
parents:
diff changeset
2559 block,
kono
parents:
diff changeset
2560 default_block,
kono
parents:
diff changeset
2561 "default_block"))
kono
parents:
diff changeset
2562 return;
kono
parents:
diff changeset
2563 RETURN_IF_FAIL (num_cases >= 0, ctxt, loc, "num_cases < 0");
kono
parents:
diff changeset
2564 case_range_validator crv (ctxt, loc, __func__);
kono
parents:
diff changeset
2565 for (int i = 0; i < num_cases; i++)
kono
parents:
diff changeset
2566 {
kono
parents:
diff changeset
2567 char case_desc[32];
kono
parents:
diff changeset
2568 snprintf (case_desc, sizeof (case_desc),
kono
parents:
diff changeset
2569 "cases[%i]", i);
kono
parents:
diff changeset
2570 if (!valid_case_for_switch (ctxt, loc,
kono
parents:
diff changeset
2571 __func__,
kono
parents:
diff changeset
2572 block,
kono
parents:
diff changeset
2573 expr,
kono
parents:
diff changeset
2574 cases[i],
kono
parents:
diff changeset
2575 case_desc,
kono
parents:
diff changeset
2576 i))
kono
parents:
diff changeset
2577 return;
kono
parents:
diff changeset
2578 if (!crv.validate (cases[i], i))
kono
parents:
diff changeset
2579 return;
kono
parents:
diff changeset
2580 }
kono
parents:
diff changeset
2581
kono
parents:
diff changeset
2582 block->end_with_switch (loc, expr, default_block,
kono
parents:
diff changeset
2583 num_cases,
kono
parents:
diff changeset
2584 (gcc::jit::recording::case_ **)cases);
kono
parents:
diff changeset
2585 }
kono
parents:
diff changeset
2586
kono
parents:
diff changeset
2587 /**********************************************************************
kono
parents:
diff changeset
2588 Option-management
kono
parents:
diff changeset
2589 **********************************************************************/
kono
parents:
diff changeset
2590
kono
parents:
diff changeset
2591 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2592
kono
parents:
diff changeset
2593 After error-checking, the real work is done by the
kono
parents:
diff changeset
2594 gcc::jit::recording::context::set_str_option method in
kono
parents:
diff changeset
2595 jit-recording.c. */
kono
parents:
diff changeset
2596
kono
parents:
diff changeset
2597 void
kono
parents:
diff changeset
2598 gcc_jit_context_set_str_option (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2599 enum gcc_jit_str_option opt,
kono
parents:
diff changeset
2600 const char *value)
kono
parents:
diff changeset
2601 {
kono
parents:
diff changeset
2602 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2603 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2604 /* opt is checked by the inner function.
kono
parents:
diff changeset
2605 value can be NULL. */
kono
parents:
diff changeset
2606
kono
parents:
diff changeset
2607 ctxt->set_str_option (opt, value);
kono
parents:
diff changeset
2608 }
kono
parents:
diff changeset
2609
kono
parents:
diff changeset
2610 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2611
kono
parents:
diff changeset
2612 After error-checking, the real work is done by the
kono
parents:
diff changeset
2613 gcc::jit::recording::context::set_int_option method in
kono
parents:
diff changeset
2614 jit-recording.c. */
kono
parents:
diff changeset
2615
kono
parents:
diff changeset
2616 void
kono
parents:
diff changeset
2617 gcc_jit_context_set_int_option (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2618 enum gcc_jit_int_option opt,
kono
parents:
diff changeset
2619 int value)
kono
parents:
diff changeset
2620 {
kono
parents:
diff changeset
2621 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2622 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2623 /* opt is checked by the inner function. */
kono
parents:
diff changeset
2624
kono
parents:
diff changeset
2625 ctxt->set_int_option (opt, value);
kono
parents:
diff changeset
2626 }
kono
parents:
diff changeset
2627
kono
parents:
diff changeset
2628 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2629
kono
parents:
diff changeset
2630 After error-checking, the real work is done by the
kono
parents:
diff changeset
2631 gcc::jit::recording::context::set_bool_option method in
kono
parents:
diff changeset
2632 jit-recording.c. */
kono
parents:
diff changeset
2633
kono
parents:
diff changeset
2634 void
kono
parents:
diff changeset
2635 gcc_jit_context_set_bool_option (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2636 enum gcc_jit_bool_option opt,
kono
parents:
diff changeset
2637 int value)
kono
parents:
diff changeset
2638 {
kono
parents:
diff changeset
2639 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2640 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2641 /* opt is checked by the inner function. */
kono
parents:
diff changeset
2642
kono
parents:
diff changeset
2643 ctxt->set_bool_option (opt, value);
kono
parents:
diff changeset
2644 }
kono
parents:
diff changeset
2645
kono
parents:
diff changeset
2646 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2647
kono
parents:
diff changeset
2648 After error-checking, the real work is done by the
kono
parents:
diff changeset
2649 gcc::jit::recording::context::set_inner_bool_option method in
kono
parents:
diff changeset
2650 jit-recording.c. */
kono
parents:
diff changeset
2651
kono
parents:
diff changeset
2652 void
kono
parents:
diff changeset
2653 gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2654 int bool_value)
kono
parents:
diff changeset
2655 {
kono
parents:
diff changeset
2656 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2657 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2658 ctxt->set_inner_bool_option (
kono
parents:
diff changeset
2659 gcc::jit::INNER_BOOL_OPTION_ALLOW_UNREACHABLE_BLOCKS,
kono
parents:
diff changeset
2660 bool_value);
kono
parents:
diff changeset
2661 }
kono
parents:
diff changeset
2662
kono
parents:
diff changeset
2663 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2664
kono
parents:
diff changeset
2665 After error-checking, the real work is done by the
kono
parents:
diff changeset
2666 gcc::jit::recording::context::set_inner_bool_option method in
kono
parents:
diff changeset
2667 jit-recording.c. */
kono
parents:
diff changeset
2668
kono
parents:
diff changeset
2669 extern void
kono
parents:
diff changeset
2670 gcc_jit_context_set_bool_use_external_driver (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2671 int bool_value)
kono
parents:
diff changeset
2672 {
kono
parents:
diff changeset
2673 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2674 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2675 ctxt->set_inner_bool_option (
kono
parents:
diff changeset
2676 gcc::jit::INNER_BOOL_OPTION_USE_EXTERNAL_DRIVER,
kono
parents:
diff changeset
2677 bool_value);
kono
parents:
diff changeset
2678 }
kono
parents:
diff changeset
2679
kono
parents:
diff changeset
2680 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2681
kono
parents:
diff changeset
2682 After error-checking, the real work is done by the
kono
parents:
diff changeset
2683 gcc::jit::recording::context::add_command_line_option method in
kono
parents:
diff changeset
2684 jit-recording.c. */
kono
parents:
diff changeset
2685
kono
parents:
diff changeset
2686 void
kono
parents:
diff changeset
2687 gcc_jit_context_add_command_line_option (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2688 const char *optname)
kono
parents:
diff changeset
2689 {
kono
parents:
diff changeset
2690 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2691 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2692 RETURN_IF_FAIL (optname, ctxt, NULL, "NULL optname");
kono
parents:
diff changeset
2693 if (ctxt->get_logger ())
kono
parents:
diff changeset
2694 ctxt->get_logger ()->log ("optname: %s", optname);
kono
parents:
diff changeset
2695
kono
parents:
diff changeset
2696 ctxt->add_command_line_option (optname);
kono
parents:
diff changeset
2697 }
kono
parents:
diff changeset
2698
kono
parents:
diff changeset
2699 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2700
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2701 The real work is done by the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2702 gcc::jit::recording::context::add_driver_option method in
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2703 jit-recording.c. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2704
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2705 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2706 gcc_jit_context_add_driver_option (gcc_jit_context *ctxt,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2707 const char *optname)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2708 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2709 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2710 JIT_LOG_FUNC (ctxt->get_logger ());
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2711 RETURN_IF_FAIL (optname, ctxt, NULL, "NULL optname");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2712 if (ctxt->get_logger ())
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2713 ctxt->get_logger ()->log ("optname: %s", optname);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2714
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2715 ctxt->add_driver_option (optname);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2716 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2717
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2718 /* Public entrypoint. See description in libgccjit.h.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2719
111
kono
parents:
diff changeset
2720 After error-checking, the real work is done by the
kono
parents:
diff changeset
2721 gcc::jit::recording::context::enable_dump method in
kono
parents:
diff changeset
2722 jit-recording.c. */
kono
parents:
diff changeset
2723
kono
parents:
diff changeset
2724 void
kono
parents:
diff changeset
2725 gcc_jit_context_enable_dump (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2726 const char *dumpname,
kono
parents:
diff changeset
2727 char **out_ptr)
kono
parents:
diff changeset
2728 {
kono
parents:
diff changeset
2729 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2730 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2731 RETURN_IF_FAIL (dumpname, ctxt, NULL, "NULL dumpname");
kono
parents:
diff changeset
2732 RETURN_IF_FAIL (out_ptr, ctxt, NULL, "NULL out_ptr");
kono
parents:
diff changeset
2733
kono
parents:
diff changeset
2734 ctxt->enable_dump (dumpname, out_ptr);
kono
parents:
diff changeset
2735 }
kono
parents:
diff changeset
2736
kono
parents:
diff changeset
2737 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2738
kono
parents:
diff changeset
2739 After error-checking, the real work is done by the
kono
parents:
diff changeset
2740 gcc::jit::recording::context::compile method in
kono
parents:
diff changeset
2741 jit-recording.c. */
kono
parents:
diff changeset
2742
kono
parents:
diff changeset
2743 gcc_jit_result *
kono
parents:
diff changeset
2744 gcc_jit_context_compile (gcc_jit_context *ctxt)
kono
parents:
diff changeset
2745 {
kono
parents:
diff changeset
2746 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2747
kono
parents:
diff changeset
2748 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2749
kono
parents:
diff changeset
2750 ctxt->log ("in-memory compile of ctxt: %p", (void *)ctxt);
kono
parents:
diff changeset
2751
kono
parents:
diff changeset
2752 gcc_jit_result *result = (gcc_jit_result *)ctxt->compile ();
kono
parents:
diff changeset
2753
kono
parents:
diff changeset
2754 ctxt->log ("%s: returning (gcc_jit_result *)%p",
kono
parents:
diff changeset
2755 __func__, (void *)result);
kono
parents:
diff changeset
2756
kono
parents:
diff changeset
2757 return result;
kono
parents:
diff changeset
2758 }
kono
parents:
diff changeset
2759
kono
parents:
diff changeset
2760 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2761
kono
parents:
diff changeset
2762 After error-checking, the real work is done by the
kono
parents:
diff changeset
2763 gcc::jit::recording::context::compile_to_file method in
kono
parents:
diff changeset
2764 jit-recording.c. */
kono
parents:
diff changeset
2765
kono
parents:
diff changeset
2766 void
kono
parents:
diff changeset
2767 gcc_jit_context_compile_to_file (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2768 enum gcc_jit_output_kind output_kind,
kono
parents:
diff changeset
2769 const char *output_path)
kono
parents:
diff changeset
2770 {
kono
parents:
diff changeset
2771 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2772 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2773 RETURN_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
2774 ((output_kind >= GCC_JIT_OUTPUT_KIND_ASSEMBLER)
kono
parents:
diff changeset
2775 && (output_kind <= GCC_JIT_OUTPUT_KIND_EXECUTABLE)),
kono
parents:
diff changeset
2776 ctxt, NULL,
kono
parents:
diff changeset
2777 "unrecognized output_kind: %i",
kono
parents:
diff changeset
2778 output_kind);
kono
parents:
diff changeset
2779 RETURN_IF_FAIL (output_path, ctxt, NULL, "NULL output_path");
kono
parents:
diff changeset
2780
kono
parents:
diff changeset
2781 ctxt->log ("compile_to_file of ctxt: %p", (void *)ctxt);
kono
parents:
diff changeset
2782 ctxt->log ("output_kind: %i", output_kind);
kono
parents:
diff changeset
2783 ctxt->log ("output_path: %s", output_path);
kono
parents:
diff changeset
2784
kono
parents:
diff changeset
2785 ctxt->compile_to_file (output_kind, output_path);
kono
parents:
diff changeset
2786 }
kono
parents:
diff changeset
2787
kono
parents:
diff changeset
2788
kono
parents:
diff changeset
2789 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2790
kono
parents:
diff changeset
2791 After error-checking, the real work is done by the
kono
parents:
diff changeset
2792 gcc::jit::recording::context::dump_to_file method in
kono
parents:
diff changeset
2793 jit-recording.c. */
kono
parents:
diff changeset
2794
kono
parents:
diff changeset
2795 void
kono
parents:
diff changeset
2796 gcc_jit_context_dump_to_file (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2797 const char *path,
kono
parents:
diff changeset
2798 int update_locations)
kono
parents:
diff changeset
2799 {
kono
parents:
diff changeset
2800 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2801 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2802 RETURN_IF_FAIL (path, ctxt, NULL, "NULL path");
kono
parents:
diff changeset
2803 ctxt->dump_to_file (path, update_locations);
kono
parents:
diff changeset
2804 }
kono
parents:
diff changeset
2805
kono
parents:
diff changeset
2806 /* Public entrypoint. See description in libgccjit.h. */
kono
parents:
diff changeset
2807
kono
parents:
diff changeset
2808 void
kono
parents:
diff changeset
2809 gcc_jit_context_set_logfile (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2810 FILE *logfile,
kono
parents:
diff changeset
2811 int flags,
kono
parents:
diff changeset
2812 int verbosity)
kono
parents:
diff changeset
2813 {
kono
parents:
diff changeset
2814 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2815 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2816 RETURN_IF_FAIL ((flags == 0), ctxt, NULL, "flags must be 0 for now");
kono
parents:
diff changeset
2817 RETURN_IF_FAIL ((verbosity == 0), ctxt, NULL, "verbosity must be 0 for now");
kono
parents:
diff changeset
2818
kono
parents:
diff changeset
2819 gcc::jit::logger *logger;
kono
parents:
diff changeset
2820 if (logfile)
kono
parents:
diff changeset
2821 logger = new gcc::jit::logger (logfile, flags, verbosity);
kono
parents:
diff changeset
2822 else
kono
parents:
diff changeset
2823 logger = NULL;
kono
parents:
diff changeset
2824 ctxt->set_logger (logger);
kono
parents:
diff changeset
2825 }
kono
parents:
diff changeset
2826
kono
parents:
diff changeset
2827 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2828
kono
parents:
diff changeset
2829 After error-checking, the real work is done by the
kono
parents:
diff changeset
2830 gcc::jit::recording::context::dump_reproducer_to_file method in
kono
parents:
diff changeset
2831 jit-recording.c. */
kono
parents:
diff changeset
2832
kono
parents:
diff changeset
2833 void
kono
parents:
diff changeset
2834 gcc_jit_context_dump_reproducer_to_file (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2835 const char *path)
kono
parents:
diff changeset
2836 {
kono
parents:
diff changeset
2837 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2838 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2839 RETURN_IF_FAIL (path, ctxt, NULL, "NULL path");
kono
parents:
diff changeset
2840 ctxt->dump_reproducer_to_file (path);
kono
parents:
diff changeset
2841 }
kono
parents:
diff changeset
2842
kono
parents:
diff changeset
2843 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2844
kono
parents:
diff changeset
2845 After error-checking, the real work is done by the
kono
parents:
diff changeset
2846 gcc::jit::recording::context::get_first_error method in
kono
parents:
diff changeset
2847 jit-recording.c. */
kono
parents:
diff changeset
2848
kono
parents:
diff changeset
2849 const char *
kono
parents:
diff changeset
2850 gcc_jit_context_get_first_error (gcc_jit_context *ctxt)
kono
parents:
diff changeset
2851 {
kono
parents:
diff changeset
2852 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2853 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
2854
kono
parents:
diff changeset
2855 return ctxt->get_first_error ();
kono
parents:
diff changeset
2856 }
kono
parents:
diff changeset
2857
kono
parents:
diff changeset
2858 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2859
kono
parents:
diff changeset
2860 After error-checking, the real work is done by the
kono
parents:
diff changeset
2861 gcc::jit::recording::context::get_last_error method in
kono
parents:
diff changeset
2862 jit-recording.c. */
kono
parents:
diff changeset
2863
kono
parents:
diff changeset
2864 const char *
kono
parents:
diff changeset
2865 gcc_jit_context_get_last_error (gcc_jit_context *ctxt)
kono
parents:
diff changeset
2866 {
kono
parents:
diff changeset
2867 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
kono
parents:
diff changeset
2868
kono
parents:
diff changeset
2869 return ctxt->get_last_error ();
kono
parents:
diff changeset
2870 }
kono
parents:
diff changeset
2871
kono
parents:
diff changeset
2872 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2873
kono
parents:
diff changeset
2874 After error-checking, the real work is done by the
kono
parents:
diff changeset
2875 gcc::jit::result::get_code method in jit-result.c. */
kono
parents:
diff changeset
2876
kono
parents:
diff changeset
2877 void *
kono
parents:
diff changeset
2878 gcc_jit_result_get_code (gcc_jit_result *result,
kono
parents:
diff changeset
2879 const char *fnname)
kono
parents:
diff changeset
2880 {
kono
parents:
diff changeset
2881 RETURN_NULL_IF_FAIL (result, NULL, NULL, "NULL result");
kono
parents:
diff changeset
2882 JIT_LOG_FUNC (result->get_logger ());
kono
parents:
diff changeset
2883 RETURN_NULL_IF_FAIL (fnname, NULL, NULL, "NULL fnname");
kono
parents:
diff changeset
2884
kono
parents:
diff changeset
2885 result->log ("locating fnname: %s", fnname);
kono
parents:
diff changeset
2886 void *code = result->get_code (fnname);
kono
parents:
diff changeset
2887 result->log ("%s: returning (void *)%p", __func__, code);
kono
parents:
diff changeset
2888
kono
parents:
diff changeset
2889 return code;
kono
parents:
diff changeset
2890 }
kono
parents:
diff changeset
2891
kono
parents:
diff changeset
2892 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2893
kono
parents:
diff changeset
2894 After error-checking, the real work is done by the
kono
parents:
diff changeset
2895 gcc::jit::result::get_global method in jit-result.c. */
kono
parents:
diff changeset
2896
kono
parents:
diff changeset
2897 void *
kono
parents:
diff changeset
2898 gcc_jit_result_get_global (gcc_jit_result *result,
kono
parents:
diff changeset
2899 const char *name)
kono
parents:
diff changeset
2900 {
kono
parents:
diff changeset
2901 RETURN_NULL_IF_FAIL (result, NULL, NULL, "NULL result");
kono
parents:
diff changeset
2902 JIT_LOG_FUNC (result->get_logger ());
kono
parents:
diff changeset
2903 RETURN_NULL_IF_FAIL (name, NULL, NULL, "NULL name");
kono
parents:
diff changeset
2904
kono
parents:
diff changeset
2905 void *global = result->get_global (name);
kono
parents:
diff changeset
2906 result->log ("%s: returning (void *)%p", __func__, global);
kono
parents:
diff changeset
2907
kono
parents:
diff changeset
2908 return global;
kono
parents:
diff changeset
2909 }
kono
parents:
diff changeset
2910
kono
parents:
diff changeset
2911 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
2912
kono
parents:
diff changeset
2913 After error-checking, this is essentially a wrapper around the
kono
parents:
diff changeset
2914 destructor for gcc::jit::result in jit-result.c. */
kono
parents:
diff changeset
2915
kono
parents:
diff changeset
2916 void
kono
parents:
diff changeset
2917 gcc_jit_result_release (gcc_jit_result *result)
kono
parents:
diff changeset
2918 {
kono
parents:
diff changeset
2919 RETURN_IF_FAIL (result, NULL, NULL, "NULL result");
kono
parents:
diff changeset
2920 JIT_LOG_FUNC (result->get_logger ());
kono
parents:
diff changeset
2921 result->log ("deleting result: %p", (void *)result);
kono
parents:
diff changeset
2922 delete result;
kono
parents:
diff changeset
2923 }
kono
parents:
diff changeset
2924
kono
parents:
diff changeset
2925 /**********************************************************************
kono
parents:
diff changeset
2926 Timing support.
kono
parents:
diff changeset
2927 **********************************************************************/
kono
parents:
diff changeset
2928
kono
parents:
diff changeset
2929 /* Create a gcc_jit_timer instance, and start timing. */
kono
parents:
diff changeset
2930
kono
parents:
diff changeset
2931 gcc_jit_timer *
kono
parents:
diff changeset
2932 gcc_jit_timer_new (void)
kono
parents:
diff changeset
2933 {
kono
parents:
diff changeset
2934 gcc_jit_timer *timer = new gcc_jit_timer ();
kono
parents:
diff changeset
2935 timer->start (TV_TOTAL);
kono
parents:
diff changeset
2936 timer->push (TV_JIT_CLIENT_CODE);
kono
parents:
diff changeset
2937 return timer;
kono
parents:
diff changeset
2938 }
kono
parents:
diff changeset
2939
kono
parents:
diff changeset
2940 /* Release a gcc_jit_timer instance. */
kono
parents:
diff changeset
2941
kono
parents:
diff changeset
2942 void
kono
parents:
diff changeset
2943 gcc_jit_timer_release (gcc_jit_timer *timer)
kono
parents:
diff changeset
2944 {
kono
parents:
diff changeset
2945 RETURN_IF_FAIL (timer, NULL, NULL, "NULL timer");
kono
parents:
diff changeset
2946
kono
parents:
diff changeset
2947 delete timer;
kono
parents:
diff changeset
2948 }
kono
parents:
diff changeset
2949
kono
parents:
diff changeset
2950 /* Associate a gcc_jit_timer instance with a context. */
kono
parents:
diff changeset
2951
kono
parents:
diff changeset
2952 void
kono
parents:
diff changeset
2953 gcc_jit_context_set_timer (gcc_jit_context *ctxt,
kono
parents:
diff changeset
2954 gcc_jit_timer *timer)
kono
parents:
diff changeset
2955 {
kono
parents:
diff changeset
2956 RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL ctxt");
kono
parents:
diff changeset
2957 RETURN_IF_FAIL (timer, ctxt, NULL, "NULL timer");
kono
parents:
diff changeset
2958
kono
parents:
diff changeset
2959 ctxt->set_timer (timer);
kono
parents:
diff changeset
2960 }
kono
parents:
diff changeset
2961
kono
parents:
diff changeset
2962 /* Get the timer associated with a context (if any). */
kono
parents:
diff changeset
2963
kono
parents:
diff changeset
2964 gcc_jit_timer *
kono
parents:
diff changeset
2965 gcc_jit_context_get_timer (gcc_jit_context *ctxt)
kono
parents:
diff changeset
2966 {
kono
parents:
diff changeset
2967 RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL ctxt");
kono
parents:
diff changeset
2968
kono
parents:
diff changeset
2969 return (gcc_jit_timer *)ctxt->get_timer ();
kono
parents:
diff changeset
2970 }
kono
parents:
diff changeset
2971
kono
parents:
diff changeset
2972 /* Push the given item onto the timing stack. */
kono
parents:
diff changeset
2973
kono
parents:
diff changeset
2974 void
kono
parents:
diff changeset
2975 gcc_jit_timer_push (gcc_jit_timer *timer,
kono
parents:
diff changeset
2976 const char *item_name)
kono
parents:
diff changeset
2977 {
kono
parents:
diff changeset
2978 RETURN_IF_FAIL (timer, NULL, NULL, "NULL timer");
kono
parents:
diff changeset
2979 RETURN_IF_FAIL (item_name, NULL, NULL, "NULL item_name");
kono
parents:
diff changeset
2980 timer->push_client_item (item_name);
kono
parents:
diff changeset
2981 }
kono
parents:
diff changeset
2982
kono
parents:
diff changeset
2983 /* Pop the top item from the timing stack. */
kono
parents:
diff changeset
2984
kono
parents:
diff changeset
2985 void
kono
parents:
diff changeset
2986 gcc_jit_timer_pop (gcc_jit_timer *timer,
kono
parents:
diff changeset
2987 const char *item_name)
kono
parents:
diff changeset
2988 {
kono
parents:
diff changeset
2989 RETURN_IF_FAIL (timer, NULL, NULL, "NULL timer");
kono
parents:
diff changeset
2990
kono
parents:
diff changeset
2991 if (item_name)
kono
parents:
diff changeset
2992 {
kono
parents:
diff changeset
2993 const char *top_item_name = timer->get_topmost_item_name ();
kono
parents:
diff changeset
2994
kono
parents:
diff changeset
2995 RETURN_IF_FAIL_PRINTF1
kono
parents:
diff changeset
2996 (top_item_name, NULL, NULL,
kono
parents:
diff changeset
2997 "pop of empty timing stack (attempting to pop: \"%s\")",
kono
parents:
diff changeset
2998 item_name);
kono
parents:
diff changeset
2999
kono
parents:
diff changeset
3000 RETURN_IF_FAIL_PRINTF2
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3001 (strcmp (item_name, top_item_name) == 0, NULL, NULL,
111
kono
parents:
diff changeset
3002 "mismatching item_name:"
kono
parents:
diff changeset
3003 " top of timing stack: \"%s\","
kono
parents:
diff changeset
3004 " attempting to pop: \"%s\"",
kono
parents:
diff changeset
3005 top_item_name,
kono
parents:
diff changeset
3006 item_name);
kono
parents:
diff changeset
3007 }
kono
parents:
diff changeset
3008
kono
parents:
diff changeset
3009 timer->pop_client_item ();
kono
parents:
diff changeset
3010 }
kono
parents:
diff changeset
3011
kono
parents:
diff changeset
3012 /* Print timing information to the given stream about activity since
kono
parents:
diff changeset
3013 the timer was started. */
kono
parents:
diff changeset
3014
kono
parents:
diff changeset
3015 void
kono
parents:
diff changeset
3016 gcc_jit_timer_print (gcc_jit_timer *timer,
kono
parents:
diff changeset
3017 FILE *f_out)
kono
parents:
diff changeset
3018 {
kono
parents:
diff changeset
3019 RETURN_IF_FAIL (timer, NULL, NULL, "NULL timer");
kono
parents:
diff changeset
3020 RETURN_IF_FAIL (f_out, NULL, NULL, "NULL f_out");
kono
parents:
diff changeset
3021
kono
parents:
diff changeset
3022 timer->pop (TV_JIT_CLIENT_CODE);
kono
parents:
diff changeset
3023 timer->stop (TV_TOTAL);
kono
parents:
diff changeset
3024 timer->print (f_out);
kono
parents:
diff changeset
3025 timer->start (TV_TOTAL);
kono
parents:
diff changeset
3026 timer->push (TV_JIT_CLIENT_CODE);
kono
parents:
diff changeset
3027 }
kono
parents:
diff changeset
3028
kono
parents:
diff changeset
3029 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
3030
kono
parents:
diff changeset
3031 After error-checking, the real work is effectively done by the
kono
parents:
diff changeset
3032 gcc::jit::base_call::set_require_tail_call setter in jit-recording.h. */
kono
parents:
diff changeset
3033
kono
parents:
diff changeset
3034 void
kono
parents:
diff changeset
3035 gcc_jit_rvalue_set_bool_require_tail_call (gcc_jit_rvalue *rvalue,
kono
parents:
diff changeset
3036 int require_tail_call)
kono
parents:
diff changeset
3037 {
kono
parents:
diff changeset
3038 RETURN_IF_FAIL (rvalue, NULL, NULL, "NULL call");
kono
parents:
diff changeset
3039 JIT_LOG_FUNC (rvalue->get_context ()->get_logger ());
kono
parents:
diff changeset
3040
kono
parents:
diff changeset
3041 /* Verify that it's a call. */
kono
parents:
diff changeset
3042 gcc::jit::recording::base_call *call = rvalue->dyn_cast_base_call ();
kono
parents:
diff changeset
3043 RETURN_IF_FAIL_PRINTF1 (call, NULL, NULL, "not a call: %s",
kono
parents:
diff changeset
3044 rvalue->get_debug_string ());
kono
parents:
diff changeset
3045
kono
parents:
diff changeset
3046 call->set_require_tail_call (require_tail_call);
kono
parents:
diff changeset
3047 }
kono
parents:
diff changeset
3048
kono
parents:
diff changeset
3049 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
3050
kono
parents:
diff changeset
3051 After error-checking, the real work is done by the
kono
parents:
diff changeset
3052 gcc::jit::recording::type::get_aligned method, in
kono
parents:
diff changeset
3053 jit-recording.c. */
kono
parents:
diff changeset
3054
kono
parents:
diff changeset
3055 gcc_jit_type *
kono
parents:
diff changeset
3056 gcc_jit_type_get_aligned (gcc_jit_type *type,
kono
parents:
diff changeset
3057 size_t alignment_in_bytes)
kono
parents:
diff changeset
3058 {
kono
parents:
diff changeset
3059 RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type");
kono
parents:
diff changeset
3060
kono
parents:
diff changeset
3061 gcc::jit::recording::context *ctxt = type->m_ctxt;
kono
parents:
diff changeset
3062
kono
parents:
diff changeset
3063 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
3064
kono
parents:
diff changeset
3065 RETURN_NULL_IF_FAIL_PRINTF1
kono
parents:
diff changeset
3066 (pow2_or_zerop (alignment_in_bytes), ctxt, NULL,
kono
parents:
diff changeset
3067 "alignment not a power of two: %zi",
kono
parents:
diff changeset
3068 alignment_in_bytes);
kono
parents:
diff changeset
3069
kono
parents:
diff changeset
3070 return (gcc_jit_type *)type->get_aligned (alignment_in_bytes);
kono
parents:
diff changeset
3071 }
kono
parents:
diff changeset
3072
kono
parents:
diff changeset
3073 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
3074
kono
parents:
diff changeset
3075 After error-checking, the real work is done by the
kono
parents:
diff changeset
3076 gcc::jit::recording::type::get_vector method, in
kono
parents:
diff changeset
3077 jit-recording.c. */
kono
parents:
diff changeset
3078
kono
parents:
diff changeset
3079 gcc_jit_type *
kono
parents:
diff changeset
3080 gcc_jit_type_get_vector (gcc_jit_type *type, size_t num_units)
kono
parents:
diff changeset
3081 {
kono
parents:
diff changeset
3082 RETURN_NULL_IF_FAIL (type, NULL, NULL, "NULL type");
kono
parents:
diff changeset
3083
kono
parents:
diff changeset
3084 gcc::jit::recording::context *ctxt = type->m_ctxt;
kono
parents:
diff changeset
3085
kono
parents:
diff changeset
3086 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
3087
kono
parents:
diff changeset
3088 RETURN_NULL_IF_FAIL_PRINTF1
kono
parents:
diff changeset
3089 (type->is_int () || type->is_float (), ctxt, NULL,
kono
parents:
diff changeset
3090 "type is not integral or floating point: %s",
kono
parents:
diff changeset
3091 type->get_debug_string ());
kono
parents:
diff changeset
3092
kono
parents:
diff changeset
3093 RETURN_NULL_IF_FAIL_PRINTF1
kono
parents:
diff changeset
3094 (pow2_or_zerop (num_units), ctxt, NULL,
kono
parents:
diff changeset
3095 "num_units not a power of two: %zi",
kono
parents:
diff changeset
3096 num_units);
kono
parents:
diff changeset
3097
kono
parents:
diff changeset
3098 return (gcc_jit_type *)type->get_vector (num_units);
kono
parents:
diff changeset
3099 }
kono
parents:
diff changeset
3100
kono
parents:
diff changeset
3101 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
3102
kono
parents:
diff changeset
3103 After error-checking, the real work is done by the
kono
parents:
diff changeset
3104 gcc::jit::recording::function::get_address method, in
kono
parents:
diff changeset
3105 jit-recording.c. */
kono
parents:
diff changeset
3106
kono
parents:
diff changeset
3107 gcc_jit_rvalue *
kono
parents:
diff changeset
3108 gcc_jit_function_get_address (gcc_jit_function *fn,
kono
parents:
diff changeset
3109 gcc_jit_location *loc)
kono
parents:
diff changeset
3110 {
kono
parents:
diff changeset
3111 RETURN_NULL_IF_FAIL (fn, NULL, NULL, "NULL function");
kono
parents:
diff changeset
3112
kono
parents:
diff changeset
3113 gcc::jit::recording::context *ctxt = fn->m_ctxt;
kono
parents:
diff changeset
3114
kono
parents:
diff changeset
3115 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
3116 /* LOC can be NULL. */
kono
parents:
diff changeset
3117
kono
parents:
diff changeset
3118 return (gcc_jit_rvalue *)fn->get_address (loc);
kono
parents:
diff changeset
3119 }
kono
parents:
diff changeset
3120
kono
parents:
diff changeset
3121 /* Public entrypoint. See description in libgccjit.h.
kono
parents:
diff changeset
3122
kono
parents:
diff changeset
3123 After error-checking, the real work is done by the
kono
parents:
diff changeset
3124 gcc::jit::recording::context::new_rvalue_from_vector method, in
kono
parents:
diff changeset
3125 jit-recording.c. */
kono
parents:
diff changeset
3126
kono
parents:
diff changeset
3127 extern gcc_jit_rvalue *
kono
parents:
diff changeset
3128 gcc_jit_context_new_rvalue_from_vector (gcc_jit_context *ctxt,
kono
parents:
diff changeset
3129 gcc_jit_location *loc,
kono
parents:
diff changeset
3130 gcc_jit_type *vec_type,
kono
parents:
diff changeset
3131 size_t num_elements,
kono
parents:
diff changeset
3132 gcc_jit_rvalue **elements)
kono
parents:
diff changeset
3133 {
kono
parents:
diff changeset
3134 RETURN_NULL_IF_FAIL (ctxt, NULL, loc, "NULL ctxt");
kono
parents:
diff changeset
3135 JIT_LOG_FUNC (ctxt->get_logger ());
kono
parents:
diff changeset
3136
kono
parents:
diff changeset
3137 /* LOC can be NULL. */
kono
parents:
diff changeset
3138 RETURN_NULL_IF_FAIL (vec_type, ctxt, loc, "NULL vec_type");
kono
parents:
diff changeset
3139
kono
parents:
diff changeset
3140 /* "vec_type" must be a vector type. */
kono
parents:
diff changeset
3141 gcc::jit::recording::vector_type *as_vec_type
kono
parents:
diff changeset
3142 = vec_type->dyn_cast_vector_type ();
kono
parents:
diff changeset
3143 RETURN_NULL_IF_FAIL_PRINTF1 (as_vec_type, ctxt, loc,
kono
parents:
diff changeset
3144 "%s is not a vector type",
kono
parents:
diff changeset
3145 vec_type->get_debug_string ());
kono
parents:
diff changeset
3146
kono
parents:
diff changeset
3147 /* "num_elements" must match. */
kono
parents:
diff changeset
3148 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
3149 num_elements == as_vec_type->get_num_units (), ctxt, loc,
kono
parents:
diff changeset
3150 "num_elements != %zi", as_vec_type->get_num_units ());
kono
parents:
diff changeset
3151
kono
parents:
diff changeset
3152 /* "elements must be non-NULL. */
kono
parents:
diff changeset
3153 RETURN_NULL_IF_FAIL (elements, ctxt, loc, "NULL elements");
kono
parents:
diff changeset
3154
kono
parents:
diff changeset
3155 /* Each of "elements" must be non-NULL and of the correct type. */
kono
parents:
diff changeset
3156 gcc::jit::recording::type *element_type
kono
parents:
diff changeset
3157 = as_vec_type->get_element_type ();
kono
parents:
diff changeset
3158 for (size_t i = 0; i < num_elements; i++)
kono
parents:
diff changeset
3159 {
kono
parents:
diff changeset
3160 RETURN_NULL_IF_FAIL_PRINTF1 (
kono
parents:
diff changeset
3161 elements[i], ctxt, loc, "NULL elements[%zi]", i);
kono
parents:
diff changeset
3162 RETURN_NULL_IF_FAIL_PRINTF4 (
kono
parents:
diff changeset
3163 compatible_types (element_type,
kono
parents:
diff changeset
3164 elements[i]->get_type ()),
kono
parents:
diff changeset
3165 ctxt, loc,
kono
parents:
diff changeset
3166 "mismatching type for element[%zi] (expected type: %s): %s (type: %s)",
kono
parents:
diff changeset
3167 i,
kono
parents:
diff changeset
3168 element_type->get_debug_string (),
kono
parents:
diff changeset
3169 elements[i]->get_debug_string (),
kono
parents:
diff changeset
3170 elements[i]->get_type ()->get_debug_string ());
kono
parents:
diff changeset
3171 }
kono
parents:
diff changeset
3172
kono
parents:
diff changeset
3173 return (gcc_jit_rvalue *)ctxt->new_rvalue_from_vector
kono
parents:
diff changeset
3174 (loc,
kono
parents:
diff changeset
3175 as_vec_type,
kono
parents:
diff changeset
3176 (gcc::jit::recording::rvalue **)elements);
kono
parents:
diff changeset
3177 }