1 /* Implementation of the C API; all wrappers into the internal C++ API
2 Copyright (C) 2013-2023 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
26 #include "typed-splay-tree.h"
27 #include "cppbuiltin.h"
29 #include "libgccjit.h"
30 #include "jit-recording.h"
31 #include "jit-result.h"
33 /* The opaque types used by the public API are actually subclasses
34 of the gcc::jit::recording classes. */
36 struct gcc_jit_context
: public gcc::jit::recording::context
38 gcc_jit_context (gcc_jit_context
*parent_ctxt
) :
43 struct gcc_jit_result
: public gcc::jit::result
47 struct gcc_jit_object
: public gcc::jit::recording::memento
51 struct gcc_jit_location
: public gcc::jit::recording::location
55 struct gcc_jit_type
: public gcc::jit::recording::type
59 struct gcc_jit_struct
: public gcc::jit::recording::struct_
63 struct gcc_jit_function_type
: public gcc::jit::recording::function_type
67 struct gcc_jit_vector_type
: public gcc::jit::recording::vector_type
71 struct gcc_jit_field
: public gcc::jit::recording::field
75 struct gcc_jit_bitfield
: public gcc::jit::recording::bitfield
79 struct gcc_jit_function
: public gcc::jit::recording::function
83 struct gcc_jit_block
: public gcc::jit::recording::block
87 struct gcc_jit_rvalue
: public gcc::jit::recording::rvalue
91 struct gcc_jit_lvalue
: public gcc::jit::recording::lvalue
95 struct gcc_jit_param
: public gcc::jit::recording::param
99 struct gcc_jit_case
: public gcc::jit::recording::case_
103 struct gcc_jit_timer
: public timer
107 struct gcc_jit_extended_asm
: public gcc::jit::recording::extended_asm
112 /**********************************************************************
115 We try to gracefully handle API usage errors by being defensive
117 **********************************************************************/
119 #define JIT_BEGIN_STMT do {
120 #define JIT_END_STMT } while(0)
122 /* Each of these error-handling macros determines if TEST_EXPR holds.
124 If TEXT_EXPR fails to hold we return from the enclosing function and
125 print an error, either via adding an error on the given context CTXT
126 if CTXT is non-NULL, falling back to simply printing to stderr if CTXT
129 They have to be macros since they inject their "return" into the
130 function they are placed in.
132 The variant macros express:
134 (A) whether or not we need to return a value:
135 RETURN_VAL_IF_FAIL* vs
137 with the former returning RETURN_EXPR, and
139 for the common case where a NULL value is to be returned on
142 (B) whether the error message is to be directly printed:
144 or is a format string with some number of arguments:
145 RETURN_*IF_FAIL_PRINTF*
147 They all use JIT_BEGIN_STMT/JIT_END_STMT so they can be written with
151 #define RETURN_VAL_IF_FAIL(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_MSG) \
155 jit_error ((CTXT), (LOC), "%s: %s", __func__, (ERR_MSG)); \
156 return (RETURN_EXPR); \
160 #define RETURN_VAL_IF_FAIL_PRINTF1(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0) \
164 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
166 return (RETURN_EXPR); \
170 #define RETURN_VAL_IF_FAIL_PRINTF2(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1) \
174 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
175 __func__, (A0), (A1)); \
176 return (RETURN_EXPR); \
180 #define RETURN_VAL_IF_FAIL_PRINTF3(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2) \
184 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
185 __func__, (A0), (A1), (A2)); \
186 return (RETURN_EXPR); \
190 #define RETURN_VAL_IF_FAIL_PRINTF4(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \
194 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
195 __func__, (A0), (A1), (A2), (A3)); \
196 return (RETURN_EXPR); \
200 #define RETURN_VAL_IF_FAIL_PRINTF5(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4) \
204 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
205 __func__, (A0), (A1), (A2), (A3), (A4)); \
206 return (RETURN_EXPR); \
210 #define RETURN_VAL_IF_FAIL_PRINTF6(TEST_EXPR, RETURN_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4, A5) \
214 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
215 __func__, (A0), (A1), (A2), (A3), (A4), (A5)); \
216 return (RETURN_EXPR); \
220 #define RETURN_NULL_IF_FAIL(TEST_EXPR, CTXT, LOC, ERR_MSG) \
221 RETURN_VAL_IF_FAIL ((TEST_EXPR), NULL, (CTXT), (LOC), (ERR_MSG))
223 #define RETURN_NULL_IF_FAIL_PRINTF1(TEST_EXPR, CTXT, LOC, ERR_FMT, A0) \
224 RETURN_VAL_IF_FAIL_PRINTF1 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0)
226 #define RETURN_NULL_IF_FAIL_PRINTF2(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1) \
227 RETURN_VAL_IF_FAIL_PRINTF2 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1)
229 #define RETURN_NULL_IF_FAIL_PRINTF3(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2) \
230 RETURN_VAL_IF_FAIL_PRINTF3 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2)
232 #define RETURN_NULL_IF_FAIL_PRINTF4(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \
233 RETURN_VAL_IF_FAIL_PRINTF4 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2, A3)
235 #define RETURN_NULL_IF_FAIL_PRINTF5(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4) \
236 RETURN_VAL_IF_FAIL_PRINTF5 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4)
238 #define RETURN_NULL_IF_FAIL_PRINTF6(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4, A5) \
239 RETURN_VAL_IF_FAIL_PRINTF6 (TEST_EXPR, NULL, CTXT, LOC, ERR_FMT, A0, A1, A2, A3, A4, A5)
241 #define RETURN_IF_FAIL(TEST_EXPR, CTXT, LOC, ERR_MSG) \
245 jit_error ((CTXT), (LOC), "%s: %s", __func__, (ERR_MSG)); \
250 #define RETURN_IF_FAIL_PRINTF1(TEST_EXPR, CTXT, LOC, ERR_FMT, A0) \
254 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
260 #define RETURN_IF_FAIL_PRINTF2(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1) \
264 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
265 __func__, (A0), (A1)); \
270 #define RETURN_IF_FAIL_PRINTF4(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \
274 jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
275 __func__, (A0), (A1), (A2), (A3)); \
280 /* Check that BLOCK is non-NULL, and that it's OK to add statements to
281 it. This will fail if BLOCK has already been terminated by some
282 kind of jump or a return. */
283 #define RETURN_IF_NOT_VALID_BLOCK(BLOCK, LOC) \
285 RETURN_IF_FAIL ((BLOCK), NULL, (LOC), "NULL block"); \
286 RETURN_IF_FAIL_PRINTF2 ( \
287 !(BLOCK)->has_been_terminated (), \
288 (BLOCK)->get_context (), \
290 "adding to terminated block: %s (already terminated by: %s)", \
291 (BLOCK)->get_debug_string (), \
292 (BLOCK)->get_last_statement ()->get_debug_string ()); \
295 /* As RETURN_IF_NOT_VALID_BLOCK, but injecting a "return NULL;" if it
297 #define RETURN_NULL_IF_NOT_VALID_BLOCK(BLOCK, LOC) \
299 RETURN_NULL_IF_FAIL ((BLOCK), NULL, (LOC), "NULL block"); \
300 RETURN_NULL_IF_FAIL_PRINTF2 ( \
301 !(BLOCK)->has_been_terminated (), \
302 (BLOCK)->get_context (), \
304 "adding to terminated block: %s (already terminated by: %s)", \
305 (BLOCK)->get_debug_string (), \
306 (BLOCK)->get_last_statement ()->get_debug_string ()); \
309 /* Format the given string, and report it as an error, either on CTXT
310 if non-NULL, or by printing to stderr if we have a NULL context.
311 LOC gives the source location where the error occcurred, and can be
315 jit_error (gcc::jit::recording::context
*ctxt
,
316 gcc::jit::recording::location
*loc
,
317 const char *fmt
, ...)
321 jit_error (gcc::jit::recording::context
*ctxt
,
322 gcc::jit::recording::location
*loc
,
323 const char *fmt
, ...)
329 ctxt
->add_error_va (loc
, fmt
, ap
);
332 /* No context? Send to stderr. */
333 vfprintf (stderr
, fmt
, ap
);
334 fprintf (stderr
, "\n");
340 /* Determine whether or not we can write to lvalues of type LTYPE from
341 rvalues of type RTYPE, detecting type errors such as attempting to
342 write to an int with a string literal (without an explicit cast).
344 This is implemented by calling the
345 gcc::jit::recording::type::accepts_writes_from virtual function on
349 compatible_types (gcc::jit::recording::type
*ltype
,
350 gcc::jit::recording::type
*rtype
)
352 return ltype
->accepts_writes_from (rtype
);
355 /* Public entrypoint wrapping compatible_types. */
358 gcc_jit_compatible_types (gcc_jit_type
*ltype
,
361 RETURN_VAL_IF_FAIL (ltype
, 0, NULL
, NULL
, "NULL ltype");
362 RETURN_VAL_IF_FAIL (rtype
, 0, NULL
, NULL
, "NULL rtype");
363 return compatible_types (ltype
, rtype
);
366 /* Public entrypoint for acquiring a gcc_jit_context.
367 Note that this creates a new top-level context; contrast with
368 gcc_jit_context_new_child_context below.
370 The real work is done in the constructor for
371 gcc::jit::recording::context in jit-recording.cc. */
374 gcc_jit_context_acquire (void)
376 gcc_jit_context
*ctxt
= new gcc_jit_context (NULL
);
377 ctxt
->log ("new top-level ctxt: %p", (void *)ctxt
);
381 /* Public entrypoint for releasing a gcc_jit_context.
382 The real work is done in the destructor for
383 gcc::jit::recording::context in jit-recording.cc. */
386 gcc_jit_context_release (gcc_jit_context
*ctxt
)
388 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL ctxt");
389 JIT_LOG_FUNC (ctxt
->get_logger ());
390 ctxt
->log ("deleting ctxt: %p", (void *)ctxt
);
394 /* Public entrypoint for creating a child context within
395 PARENT_CTXT. See description in libgccjit.h.
397 The real work is done in the constructor for
398 gcc::jit::recording::context in jit-recording.cc. */
401 gcc_jit_context_new_child_context (gcc_jit_context
*parent_ctxt
)
403 RETURN_NULL_IF_FAIL (parent_ctxt
, NULL
, NULL
, "NULL parent ctxt");
404 JIT_LOG_FUNC (parent_ctxt
->get_logger ());
405 parent_ctxt
->log ("parent_ctxt: %p", (void *)parent_ctxt
);
406 gcc_jit_context
*child_ctxt
= new gcc_jit_context (parent_ctxt
);
407 child_ctxt
->log ("new child_ctxt: %p", (void *)child_ctxt
);
411 /* Public entrypoint. See description in libgccjit.h.
413 After error-checking, the real work is done by the
414 gcc::jit::recording::context::new_location
415 method in jit-recording.cc. */
418 gcc_jit_context_new_location (gcc_jit_context
*ctxt
,
419 const char *filename
,
423 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
424 JIT_LOG_FUNC (ctxt
->get_logger ());
425 return (gcc_jit_location
*)ctxt
->new_location (filename
, line
, column
, true);
428 /* Public entrypoint. See description in libgccjit.h.
430 After error-checking, this calls the trivial
431 gcc::jit::recording::memento::as_object method (a location is a
432 memento), in jit-recording.h. */
435 gcc_jit_location_as_object (gcc_jit_location
*loc
)
437 RETURN_NULL_IF_FAIL (loc
, NULL
, NULL
, "NULL location");
439 return static_cast <gcc_jit_object
*> (loc
->as_object ());
442 /* Public entrypoint. See description in libgccjit.h.
444 After error-checking, this calls the trivial
445 gcc::jit::recording::memento::as_object method (a type is a
446 memento), in jit-recording.h. */
449 gcc_jit_type_as_object (gcc_jit_type
*type
)
451 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
453 return static_cast <gcc_jit_object
*> (type
->as_object ());
456 /* Public entrypoint for getting a specific type from a context.
458 After error-checking, the real work is done by the
459 gcc::jit::recording::context::get_type method, in
463 gcc_jit_context_get_type (gcc_jit_context
*ctxt
,
464 enum gcc_jit_types type
)
466 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
467 JIT_LOG_FUNC (ctxt
->get_logger ());
468 RETURN_NULL_IF_FAIL_PRINTF1 (
469 (type
>= GCC_JIT_TYPE_VOID
470 && type
< NUM_GCC_JIT_TYPES
),
472 "unrecognized value for enum gcc_jit_types: %i", type
);
474 return (gcc_jit_type
*)ctxt
->get_type (type
);
477 /* Public entrypoint for getting the integer type of the given size and
480 After error-checking, the real work is done by the
481 gcc::jit::recording::context::get_int_type method,
482 in jit-recording.cc. */
485 gcc_jit_context_get_int_type (gcc_jit_context
*ctxt
,
486 int num_bytes
, int is_signed
)
488 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
489 JIT_LOG_FUNC (ctxt
->get_logger ());
490 RETURN_NULL_IF_FAIL (num_bytes
>= 0, ctxt
, NULL
, "negative size");
492 return (gcc_jit_type
*)ctxt
->get_int_type (num_bytes
, is_signed
);
495 /* Public entrypoint. See description in libgccjit.h.
497 After error-checking, the real work is done by the
498 gcc::jit::recording::type::get_pointer method, in
502 gcc_jit_type_get_pointer (gcc_jit_type
*type
)
504 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
506 return (gcc_jit_type
*)type
->get_pointer ();
509 /* Public entrypoint. See description in libgccjit.h.
511 After error-checking, the real work is done by the
512 gcc::jit::recording::type::get_const method, in
516 gcc_jit_type_get_const (gcc_jit_type
*type
)
518 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
520 return (gcc_jit_type
*)type
->get_const ();
523 /* Public entrypoint. See description in libgccjit.h.
525 After error-checking, the real work is done by the
526 gcc::jit::recording::type::get_volatile method, in
530 gcc_jit_type_get_volatile (gcc_jit_type
*type
)
532 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
534 return (gcc_jit_type
*)type
->get_volatile ();
537 /* Public entrypoint. See description in libgccjit.h.
539 After error-checking, the real work is done by the
540 gcc::jit::recording::type::get_size method, in
544 gcc_jit_type_get_size (gcc_jit_type
*type
)
546 RETURN_VAL_IF_FAIL (type
, -1, NULL
, NULL
, "NULL type");
548 (type
->is_int () || type
->is_float (), -1, NULL
, NULL
,
549 "only getting the size of integer or floating-point types is supported for now");
550 return type
->get_size ();
553 /* Public entrypoint. See description in libgccjit.h.
555 After error-checking, the real work is done by the
556 gcc::jit::recording::type::is_array method, in
560 gcc_jit_type_dyncast_array (gcc_jit_type
*type
)
562 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
564 return (gcc_jit_type
*)type
->is_array ();
567 /* Public entrypoint. See description in libgccjit.h.
569 After error-checking, the real work is done by the
570 gcc::jit::recording::type::is_bool method, in
574 gcc_jit_type_is_bool (gcc_jit_type
*type
)
576 RETURN_VAL_IF_FAIL (type
, FALSE
, NULL
, NULL
, "NULL type");
578 return type
->is_bool ();
581 /* Public entrypoint. See description in libgccjit.h.
583 After error-checking, the real work is done by the
584 gcc::jit::recording::type::is_pointer method, in
588 gcc_jit_type_is_pointer (gcc_jit_type
*type
)
590 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
592 return (gcc_jit_type
*)type
->is_pointer ();
595 /* Public entrypoint. See description in libgccjit.h.
597 After error-checking, the real work is done by the
598 gcc::jit::recording::type::is_int method, in
602 gcc_jit_type_is_integral (gcc_jit_type
*type
)
604 RETURN_VAL_IF_FAIL (type
, FALSE
, NULL
, NULL
, "NULL type");
606 return type
->is_int ();
609 /* Public entrypoint. See description in libgccjit.h.
611 After error-checking, the real work is done by the
612 gcc::jit::recording::type::is_vector method, in
615 gcc_jit_vector_type
*
616 gcc_jit_type_dyncast_vector (gcc_jit_type
*type
)
618 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
619 gcc::jit::recording::vector_type
*vector_type
= type
->is_vector ();
620 return (gcc_jit_vector_type
*)vector_type
;
623 /* Public entrypoint. See description in libgccjit.h.
625 After error-checking, the real work is done by the
626 gcc::jit::recording::type::is_struct method, in
630 gcc_jit_type_is_struct (gcc_jit_type
*type
)
632 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
633 gcc::jit::recording::struct_
*struct_type
= type
->is_struct ();
634 return (gcc_jit_struct
*)struct_type
;
637 /* Public entrypoint. See description in libgccjit.h.
639 After error-checking, the real work is done by the
640 gcc::jit::recording::vector_type::get_num_units method, in
644 gcc_jit_vector_type_get_num_units (gcc_jit_vector_type
*vector_type
)
646 RETURN_VAL_IF_FAIL (vector_type
, 0, NULL
, NULL
, "NULL vector_type");
647 return vector_type
->get_num_units ();
650 /* Public entrypoint. See description in libgccjit.h.
652 After error-checking, the real work is done by the
653 gcc::jit::recording::vector_type::get_element_type method, in
657 gcc_jit_vector_type_get_element_type (gcc_jit_vector_type
*vector_type
)
659 RETURN_NULL_IF_FAIL (vector_type
, NULL
, NULL
, "NULL vector_type");
660 return (gcc_jit_type
*)vector_type
->get_element_type ();
663 /* Public entrypoint. See description in libgccjit.h.
665 After error-checking, the real work is done by the
666 gcc::jit::recording::type::unqualified method, in
670 gcc_jit_type_unqualified (gcc_jit_type
*type
)
672 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
674 return (gcc_jit_type
*)type
->unqualified ();
677 /* Public entrypoint. See description in libgccjit.h.
679 After error-checking, the real work is done by the
680 gcc::jit::recording::type::dyn_cast_function_type method, in
683 gcc_jit_function_type
*
684 gcc_jit_type_dyncast_function_ptr_type (gcc_jit_type
*type
)
686 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
687 gcc::jit::recording::type
*func_ptr_type
= type
->dereference ();
693 return (gcc_jit_function_type
*)func_ptr_type
->dyn_cast_function_type ();
696 /* Public entrypoint. See description in libgccjit.h.
698 After error-checking, the real work is done by the
699 gcc::jit::recording::function_type::get_return_type method, in
703 gcc_jit_function_type_get_return_type (gcc_jit_function_type
*function_type
)
705 RETURN_NULL_IF_FAIL (function_type
, NULL
, NULL
, "NULL function_type");
706 return (gcc_jit_type
*)function_type
->get_return_type ();
709 /* Public entrypoint. See description in libgccjit.h.
711 After error-checking, the real work is done by the
712 gcc::jit::recording::function_type::get_param_types method, in
716 gcc_jit_function_type_get_param_count (gcc_jit_function_type
*function_type
)
718 RETURN_VAL_IF_FAIL (function_type
, 0, NULL
, NULL
, "NULL function_type");
719 return function_type
->get_param_types ().length ();
722 /* Public entrypoint. See description in libgccjit.h.
724 After error-checking, the real work is done by the
725 gcc::jit::recording::function_type::get_param_types method, in
729 gcc_jit_function_type_get_param_type (gcc_jit_function_type
*function_type
,
732 RETURN_NULL_IF_FAIL (function_type
, NULL
, NULL
, "NULL function_type");
733 size_t num_params
= function_type
->get_param_types ().length ();
734 gcc::jit::recording::context
*ctxt
= function_type
->m_ctxt
;
735 RETURN_NULL_IF_FAIL_PRINTF3 (index
< num_params
,
737 "index of %zu is too large (%s has %zu params)",
739 function_type
->get_debug_string (),
741 return (gcc_jit_type
*)function_type
->get_param_types ()[index
];
744 /* Public entrypoint. See description in libgccjit.h.
746 After error-checking, the real work is done by the
747 gcc::jit::recording::context::new_array_type method, in
751 gcc_jit_context_new_array_type (gcc_jit_context
*ctxt
,
752 gcc_jit_location
*loc
,
753 gcc_jit_type
*element_type
,
756 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
757 JIT_LOG_FUNC (ctxt
->get_logger ());
758 /* LOC can be NULL. */
759 RETURN_NULL_IF_FAIL (element_type
, ctxt
, loc
, "NULL type");
760 RETURN_NULL_IF_FAIL (num_elements
>= 0, ctxt
, NULL
, "negative size");
761 RETURN_NULL_IF_FAIL (!element_type
->is_void (), ctxt
, loc
,
762 "void type for elements");
764 return (gcc_jit_type
*)ctxt
->new_array_type (loc
,
769 /* Public entrypoint. See description in libgccjit.h.
771 After error-checking, the real work is done by the
772 gcc::jit::recording::context::new_field method, in
776 gcc_jit_context_new_field (gcc_jit_context
*ctxt
,
777 gcc_jit_location
*loc
,
781 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
782 JIT_LOG_FUNC (ctxt
->get_logger ());
783 /* LOC can be NULL. */
784 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
785 RETURN_NULL_IF_FAIL (name
, ctxt
, loc
, "NULL name");
786 RETURN_NULL_IF_FAIL_PRINTF2 (
787 type
->has_known_size (),
789 "unknown size for field \"%s\" (type: %s)",
791 type
->get_debug_string ());
792 RETURN_NULL_IF_FAIL_PRINTF1 (
795 "void type for field \"%s\"",
798 return (gcc_jit_field
*)ctxt
->new_field (loc
, type
, name
);
801 /* Public entrypoint. See description in libgccjit.h.
803 After error-checking, the real work is done by the
804 gcc::jit::recording::context::new_bitfield method, in
808 gcc_jit_context_new_bitfield (gcc_jit_context
*ctxt
,
809 gcc_jit_location
*loc
,
814 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
815 JIT_LOG_FUNC (ctxt
->get_logger ());
816 /* LOC can be NULL. */
817 RETURN_NULL_IF_FAIL (name
, ctxt
, loc
, "NULL name");
818 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
819 RETURN_NULL_IF_FAIL_PRINTF2 (type
->is_int () || type
->is_bool (),
821 "bit-field %s has non integral type %s",
822 name
, type
->get_debug_string ());
823 RETURN_NULL_IF_FAIL_PRINTF2 (
824 width
> 0, ctxt
, loc
,
825 "invalid width %d for bitfield \"%s\" (must be > 0)",
827 RETURN_NULL_IF_FAIL_PRINTF2 (
828 type
->has_known_size (),
830 "unknown size for field \"%s\" (type: %s)",
832 type
->get_debug_string ());
834 return (gcc_jit_field
*)ctxt
->new_bitfield (loc
, type
, width
, name
);
837 /* Public entrypoint. See description in libgccjit.h.
839 After error-checking, this calls the trivial
840 gcc::jit::recording::memento::as_object method (a field is a
841 memento), in jit-recording.h. */
844 gcc_jit_field_as_object (gcc_jit_field
*field
)
846 RETURN_NULL_IF_FAIL (field
, NULL
, NULL
, "NULL field");
848 return static_cast <gcc_jit_object
*> (field
->as_object ());
851 /* Public entrypoint. See description in libgccjit.h.
853 After error-checking, the real work is done by the
854 gcc::jit::recording::context::new_struct_type method,
855 immediately followed by a "set_fields" call on the resulting
856 gcc::jit::recording::compound_type *, both in jit-recording.cc */
859 gcc_jit_context_new_struct_type (gcc_jit_context
*ctxt
,
860 gcc_jit_location
*loc
,
863 gcc_jit_field
**fields
)
865 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
866 JIT_LOG_FUNC (ctxt
->get_logger ());
867 /* LOC can be NULL. */
868 RETURN_NULL_IF_FAIL (name
, ctxt
, loc
, "NULL name");
870 RETURN_NULL_IF_FAIL (fields
, ctxt
, loc
, "NULL fields ptr");
871 for (int i
= 0; i
< num_fields
; i
++)
873 RETURN_NULL_IF_FAIL (fields
[i
], ctxt
, loc
, "NULL field ptr");
874 RETURN_NULL_IF_FAIL_PRINTF2 (
875 fields
[i
]->get_container () == NULL
,
877 "%s is already a field of %s",
878 fields
[i
]->get_debug_string (),
879 fields
[i
]->get_container ()->get_debug_string ());
882 gcc::jit::recording::struct_
*result
=
883 ctxt
->new_struct_type (loc
, name
);
884 result
->set_fields (loc
,
886 (gcc::jit::recording::field
**)fields
);
887 return static_cast<gcc_jit_struct
*> (result
);
890 /* Public entrypoint. See description in libgccjit.h.
892 After error-checking, the real work is done by the
893 gcc::jit::recording::context::new_struct_type method in
897 gcc_jit_context_new_opaque_struct (gcc_jit_context
*ctxt
,
898 gcc_jit_location
*loc
,
901 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
902 JIT_LOG_FUNC (ctxt
->get_logger ());
903 /* LOC can be NULL. */
904 RETURN_NULL_IF_FAIL (name
, ctxt
, loc
, "NULL name");
906 return (gcc_jit_struct
*)ctxt
->new_struct_type (loc
, name
);
909 /* Public entrypoint. See description in libgccjit.h.
911 After error-checking, this calls the trivial
912 gcc::jit::recording::struct_::as_object method in
916 gcc_jit_struct_as_type (gcc_jit_struct
*struct_type
)
918 RETURN_NULL_IF_FAIL (struct_type
, NULL
, NULL
, "NULL struct_type");
920 return static_cast <gcc_jit_type
*> (struct_type
->as_type ());
923 /* Public entrypoint. See description in libgccjit.h.
925 After error-checking, the real work is done by the
926 gcc::jit::recording::compound_type::set_fields method in
930 gcc_jit_struct_set_fields (gcc_jit_struct
*struct_type
,
931 gcc_jit_location
*loc
,
933 gcc_jit_field
**fields
)
935 RETURN_IF_FAIL (struct_type
, NULL
, loc
, "NULL struct_type");
936 gcc::jit::recording::context
*ctxt
= struct_type
->m_ctxt
;
937 JIT_LOG_FUNC (ctxt
->get_logger ());
938 /* LOC can be NULL. */
939 RETURN_IF_FAIL_PRINTF1 (
940 struct_type
->get_fields () == NULL
, ctxt
, loc
,
941 "%s already has had fields set",
942 struct_type
->get_debug_string ());
944 RETURN_IF_FAIL (fields
, ctxt
, loc
, "NULL fields ptr");
945 for (int i
= 0; i
< num_fields
; i
++)
947 RETURN_IF_FAIL_PRINTF2 (
950 "%s: NULL field ptr at index %i",
951 struct_type
->get_debug_string (),
953 RETURN_IF_FAIL_PRINTF2 (
954 fields
[i
]->get_container () == NULL
,
956 "%s is already a field of %s",
957 fields
[i
]->get_debug_string (),
958 fields
[i
]->get_container ()->get_debug_string ());
961 struct_type
->set_fields (loc
, num_fields
,
962 (gcc::jit::recording::field
**)fields
);
966 /* Public entrypoint. See description in libgccjit.h.
968 After error-checking, the real work is done by the
969 gcc::jit::recording::fields::get_field method in
971 extern gcc_jit_field
*
972 gcc_jit_struct_get_field (gcc_jit_struct
*struct_type
,
975 RETURN_NULL_IF_FAIL (struct_type
, NULL
, NULL
, "NULL struct type");
976 RETURN_NULL_IF_FAIL (struct_type
->get_fields (), NULL
, NULL
,
977 "NULL struct fields");
978 size_t num_fields
= struct_type
->get_fields ()->length ();
979 RETURN_NULL_IF_FAIL_PRINTF3 (index
< num_fields
,
981 "index of %zu is too large (%s has %zu fields)",
983 struct_type
->get_debug_string (),
985 return (gcc_jit_field
*)struct_type
->get_fields ()->get_field (index
);
988 /* Public entrypoint. See description in libgccjit.h.
990 After error-checking, this calls the trivial
991 gcc::jit::recording::struct_::get_fields method in
995 gcc_jit_struct_get_field_count (gcc_jit_struct
*struct_type
)
997 RETURN_VAL_IF_FAIL (struct_type
, 0, NULL
, NULL
, "NULL struct type");
998 return struct_type
->get_fields ()->length ();
1001 /* Public entrypoint. See description in libgccjit.h.
1003 After error-checking, the real work is done by the
1004 gcc::jit::recording::context::new_union_type method,
1005 immediately followed by a "set_fields" call on the resulting
1006 gcc::jit::recording::compound_type *, both in jit-recording.cc */
1009 gcc_jit_context_new_union_type (gcc_jit_context
*ctxt
,
1010 gcc_jit_location
*loc
,
1013 gcc_jit_field
**fields
)
1015 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
1016 JIT_LOG_FUNC (ctxt
->get_logger ());
1017 /* LOC can be NULL. */
1018 RETURN_NULL_IF_FAIL (name
, ctxt
, loc
, "NULL name");
1020 RETURN_NULL_IF_FAIL (fields
, ctxt
, loc
, "NULL fields ptr");
1021 for (int i
= 0; i
< num_fields
; i
++)
1023 RETURN_NULL_IF_FAIL (fields
[i
], ctxt
, loc
, "NULL field ptr");
1024 RETURN_NULL_IF_FAIL_PRINTF2 (
1025 fields
[i
]->get_container () == NULL
,
1027 "%s is already a field of %s",
1028 fields
[i
]->get_debug_string (),
1029 fields
[i
]->get_container ()->get_debug_string ());
1032 gcc::jit::recording::union_
*result
=
1033 ctxt
->new_union_type (loc
, name
);
1034 result
->set_fields (loc
,
1036 (gcc::jit::recording::field
**)fields
);
1037 return (gcc_jit_type
*) (result
);
1040 /* Public entrypoint. See description in libgccjit.h.
1042 After error-checking, the real work is done by the
1043 gcc::jit::recording::context::new_function_ptr_type method,
1044 in jit-recording.cc */
1047 gcc_jit_context_new_function_ptr_type (gcc_jit_context
*ctxt
,
1048 gcc_jit_location
*loc
,
1049 gcc_jit_type
*return_type
,
1051 gcc_jit_type
**param_types
,
1054 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
1055 JIT_LOG_FUNC (ctxt
->get_logger ());
1056 /* LOC can be NULL. */
1057 RETURN_NULL_IF_FAIL (return_type
, ctxt
, loc
, "NULL return_type");
1058 RETURN_NULL_IF_FAIL (
1059 (num_params
== 0) || param_types
,
1061 "NULL param_types creating function pointer type");
1062 for (int i
= 0; i
< num_params
; i
++)
1064 RETURN_NULL_IF_FAIL_PRINTF1 (param_types
[i
],
1066 "NULL parameter type %i"
1067 " creating function pointer type", i
);
1068 RETURN_NULL_IF_FAIL_PRINTF1 (!param_types
[i
]->is_void (),
1070 "void type for param %i", i
);
1073 return (gcc_jit_type
*)
1074 ctxt
->new_function_ptr_type (loc
, return_type
,
1076 (gcc::jit::recording::type
**)param_types
,
1080 /* Constructing functions. */
1082 /* Public entrypoint. See description in libgccjit.h.
1084 After error-checking, the real work is done by the
1085 gcc::jit::recording::context::new_param method, in jit-recording.cc */
1088 gcc_jit_context_new_param (gcc_jit_context
*ctxt
,
1089 gcc_jit_location
*loc
,
1093 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
1094 JIT_LOG_FUNC (ctxt
->get_logger ());
1095 /* LOC can be NULL. */
1096 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
1097 RETURN_NULL_IF_FAIL (name
, ctxt
, loc
, "NULL name");
1098 RETURN_NULL_IF_FAIL_PRINTF1 (!type
->is_void (),
1100 "void type for param \"%s\"", name
);
1102 return (gcc_jit_param
*)ctxt
->new_param (loc
, type
, name
);
1105 /* Public entrypoint. See description in libgccjit.h.
1107 After error-checking, this calls the trivial
1108 gcc::jit::recording::memento::as_object method (a param is a memento),
1109 in jit-recording.h. */
1112 gcc_jit_param_as_object (gcc_jit_param
*param
)
1114 RETURN_NULL_IF_FAIL (param
, NULL
, NULL
, "NULL param");
1116 return static_cast <gcc_jit_object
*> (param
->as_object ());
1119 /* Public entrypoint. See description in libgccjit.h.
1121 After error-checking, this calls the trivial
1122 gcc::jit::recording::param::as_lvalue method in jit-recording.h. */
1125 gcc_jit_param_as_lvalue (gcc_jit_param
*param
)
1127 RETURN_NULL_IF_FAIL (param
, NULL
, NULL
, "NULL param");
1129 return (gcc_jit_lvalue
*)param
->as_lvalue ();
1132 /* Public entrypoint. See description in libgccjit.h.
1134 After error-checking, this calls the trivial
1135 gcc::jit::recording::lvalue::as_rvalue method (a param is an rvalue),
1136 in jit-recording.h. */
1139 gcc_jit_param_as_rvalue (gcc_jit_param
*param
)
1141 RETURN_NULL_IF_FAIL (param
, NULL
, NULL
, "NULL param");
1143 return (gcc_jit_rvalue
*)param
->as_rvalue ();
1146 /* Public entrypoint. See description in libgccjit.h.
1148 After error-checking, the real work is done by the
1149 gcc::jit::recording::context::new_function method, in
1150 jit-recording.cc. */
1153 gcc_jit_context_new_function (gcc_jit_context
*ctxt
,
1154 gcc_jit_location
*loc
,
1155 enum gcc_jit_function_kind kind
,
1156 gcc_jit_type
*return_type
,
1159 gcc_jit_param
**params
,
1162 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
1163 JIT_LOG_FUNC (ctxt
->get_logger ());
1164 /* LOC can be NULL. */
1165 RETURN_NULL_IF_FAIL_PRINTF1 (
1166 ((kind
>= GCC_JIT_FUNCTION_EXPORTED
)
1167 && (kind
<= GCC_JIT_FUNCTION_ALWAYS_INLINE
)),
1169 "unrecognized value for enum gcc_jit_function_kind: %i",
1171 RETURN_NULL_IF_FAIL (return_type
, ctxt
, loc
, "NULL return_type");
1172 RETURN_NULL_IF_FAIL (name
, ctxt
, loc
, "NULL name");
1173 /* The assembler can only handle certain names, so for now, enforce
1174 C's rules for identifiers upon the name, using ISALPHA and ISALNUM
1175 from safe-ctype.h to ignore the current locale.
1176 Eventually we'll need some way to interact with e.g. C++ name
1181 RETURN_NULL_IF_FAIL_PRINTF2 (
1182 ISALPHA (ch
) || ch
== '_',
1184 "name \"%s\" contains invalid character: '%c'",
1186 /* Subsequent chars: */
1187 for (const char *ptr
= name
+ 1; (ch
= *ptr
); ptr
++)
1189 RETURN_NULL_IF_FAIL_PRINTF2 (
1190 ISALNUM (ch
) || ch
== '_',
1192 "name \"%s\" contains invalid character: '%c'",
1196 RETURN_NULL_IF_FAIL_PRINTF1 (
1197 (num_params
== 0) || params
,
1199 "NULL params creating function %s", name
);
1200 for (int i
= 0; i
< num_params
; i
++)
1202 RETURN_NULL_IF_FAIL_PRINTF2 (
1205 "NULL parameter %i creating function %s", i
, name
);
1206 RETURN_NULL_IF_FAIL_PRINTF5 (
1207 params
[i
]->get_scope () == NULL
,
1209 "parameter %i \"%s\""
1212 " was already used for function %s",
1213 i
, params
[i
]->get_debug_string (),
1214 params
[i
]->get_type ()->get_debug_string (),
1216 params
[i
]->get_scope ()->get_debug_string ());
1219 return (gcc_jit_function
*)
1220 ctxt
->new_function (loc
, kind
, return_type
, name
,
1222 (gcc::jit::recording::param
**)params
,
1227 /* Public entrypoint. See description in libgccjit.h.
1229 After error-checking, the real work is done by the
1230 gcc::jit::recording::context::get_builtin_function method, in
1231 jit-recording.cc. */
1234 gcc_jit_context_get_builtin_function (gcc_jit_context
*ctxt
,
1237 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
1238 JIT_LOG_FUNC (ctxt
->get_logger ());
1239 RETURN_NULL_IF_FAIL (name
, ctxt
, NULL
, "NULL name");
1241 return static_cast <gcc_jit_function
*> (ctxt
->get_builtin_function (name
));
1244 /* Public entrypoint. See description in libgccjit.h.
1246 After error-checking, this calls the trivial
1247 gcc::jit::recording::memento::as_object method (a function is a
1248 memento), in jit-recording.h. */
1251 gcc_jit_function_as_object (gcc_jit_function
*func
)
1253 RETURN_NULL_IF_FAIL (func
, NULL
, NULL
, "NULL function");
1255 return static_cast <gcc_jit_object
*> (func
->as_object ());
1258 /* Public entrypoint. See description in libgccjit.h.
1260 After error-checking, the real work is done by the
1261 gcc::jit::recording::function::get_param method, in
1265 gcc_jit_function_get_param (gcc_jit_function
*func
, int index
)
1267 RETURN_NULL_IF_FAIL (func
, NULL
, NULL
, "NULL function");
1268 gcc::jit::recording::context
*ctxt
= func
->m_ctxt
;
1269 JIT_LOG_FUNC (ctxt
->get_logger ());
1270 RETURN_NULL_IF_FAIL (index
>= 0, ctxt
, NULL
, "negative index");
1271 int num_params
= func
->get_params ().length ();
1272 RETURN_NULL_IF_FAIL_PRINTF3 (index
< num_params
,
1274 "index of %d is too large (%s has %d params)",
1276 func
->get_debug_string (),
1279 return static_cast <gcc_jit_param
*> (func
->get_param (index
));
1282 /* Public entrypoint. See description in libgccjit.h.
1284 After error-checking, the real work is done by the
1285 gcc::jit::recording::function::get_params method, in
1290 gcc_jit_function_get_param_count (gcc_jit_function
*func
)
1292 RETURN_VAL_IF_FAIL (func
, 0, NULL
, NULL
, "NULL function");
1293 gcc::jit::recording::context
*ctxt
= func
->m_ctxt
;
1294 JIT_LOG_FUNC (ctxt
->get_logger ());
1295 return func
->get_params ().length ();
1298 /* Public entrypoint. See description in libgccjit.h.
1300 After error-checking, the real work is done by the
1301 gcc::jit::recording::function::get_return_type method, in
1305 gcc_jit_function_get_return_type (gcc_jit_function
*func
)
1307 RETURN_NULL_IF_FAIL (func
, NULL
, NULL
, "NULL function_type");
1308 return (gcc_jit_type
*)func
->get_return_type ();
1311 /* Public entrypoint. See description in libgccjit.h.
1313 After error-checking, the real work is done by the
1314 gcc::jit::recording::function::dump_to_dot method, in
1315 jit-recording.cc. */
1318 gcc_jit_function_dump_to_dot (gcc_jit_function
*func
,
1321 RETURN_IF_FAIL (func
, NULL
, NULL
, "NULL function");
1322 gcc::jit::recording::context
*ctxt
= func
->m_ctxt
;
1323 JIT_LOG_FUNC (ctxt
->get_logger ());
1324 RETURN_IF_FAIL (path
, ctxt
, NULL
, "NULL path");
1326 func
->dump_to_dot (path
);
1329 /* Public entrypoint. See description in libgccjit.h.
1331 After error-checking, the real work is done by the
1332 gcc::jit::recording::function::new_block method, in
1333 jit-recording.cc. */
1336 gcc_jit_function_new_block (gcc_jit_function
*func
,
1339 RETURN_NULL_IF_FAIL (func
, NULL
, NULL
, "NULL function");
1340 JIT_LOG_FUNC (func
->get_context ()->get_logger ());
1341 RETURN_NULL_IF_FAIL (func
->get_kind () != GCC_JIT_FUNCTION_IMPORTED
,
1342 func
->get_context (), NULL
,
1343 "cannot add block to an imported function");
1344 /* name can be NULL. */
1346 return (gcc_jit_block
*)func
->new_block (name
);
1349 /* Public entrypoint. See description in libgccjit.h.
1351 After error-checking, this calls the trivial
1352 gcc::jit::recording::memento::as_object method (a block is a
1353 memento), in jit-recording.h. */
1356 gcc_jit_block_as_object (gcc_jit_block
*block
)
1358 RETURN_NULL_IF_FAIL (block
, NULL
, NULL
, "NULL block");
1360 return static_cast <gcc_jit_object
*> (block
->as_object ());
1363 /* Public entrypoint. See description in libgccjit.h.
1365 After error-checking, the real work is done by the
1366 gcc::jit::recording::block::get_function method, in
1370 gcc_jit_block_get_function (gcc_jit_block
*block
)
1372 RETURN_NULL_IF_FAIL (block
, NULL
, NULL
, "NULL block");
1374 return static_cast <gcc_jit_function
*> (block
->get_function ());
1377 /* Public entrypoint. See description in libgccjit.h.
1379 After error-checking, the real work is done by the
1380 gcc::jit::recording::context::new_global method, in
1381 jit-recording.cc. */
1384 gcc_jit_context_new_global (gcc_jit_context
*ctxt
,
1385 gcc_jit_location
*loc
,
1386 enum gcc_jit_global_kind kind
,
1390 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
1391 JIT_LOG_FUNC (ctxt
->get_logger ());
1392 /* LOC can be NULL. */
1393 RETURN_NULL_IF_FAIL_PRINTF1 (
1394 ((kind
>= GCC_JIT_GLOBAL_EXPORTED
)
1395 && (kind
<= GCC_JIT_GLOBAL_IMPORTED
)),
1397 "unrecognized value for enum gcc_jit_global_kind: %i",
1399 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
1400 RETURN_NULL_IF_FAIL (name
, ctxt
, loc
, "NULL name");
1401 RETURN_NULL_IF_FAIL_PRINTF2 (
1402 type
->has_known_size (),
1404 "unknown size for global \"%s\" (type: %s)",
1406 type
->get_debug_string ());
1407 RETURN_NULL_IF_FAIL_PRINTF1 (
1410 "void type for global \"%s\"",
1413 return (gcc_jit_lvalue
*)ctxt
->new_global (loc
, kind
, type
, name
);
1416 extern gcc_jit_rvalue
*
1417 gcc_jit_context_new_struct_constructor (gcc_jit_context
*ctxt
,
1418 gcc_jit_location
*loc
,
1421 gcc_jit_field
**fields
,
1422 gcc_jit_rvalue
**values
)
1424 using namespace gcc::jit::recording
;
1426 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
1427 JIT_LOG_FUNC (ctxt
->get_logger ());
1428 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
1430 RETURN_NULL_IF_FAIL_PRINTF1 (type
->is_struct (),
1432 "constructor type is not a struct: %s",
1433 type
->get_debug_string ());
1435 compound_type
*ct
= reinterpret_cast<compound_type
*>(type
);
1436 gcc::jit::recording::fields
*fields_struct
= ct
->get_fields ();
1437 size_t n_fields
= fields_struct
->length ();
1439 RETURN_NULL_IF_FAIL_PRINTF1 (ct
->has_known_size (),
1441 "struct can't be opaque: %s",
1442 type
->get_debug_string ());
1443 RETURN_NULL_IF_FAIL_PRINTF1 (n_fields
,
1445 "no fields in struct: %s",
1446 type
->get_debug_string ());
1448 /* If there is no array input we just short circuit to zero the struct. */
1450 return (gcc_jit_rvalue
*)ctxt
->new_ctor (loc
, type
, 0, NULL
, NULL
);
1452 RETURN_NULL_IF_FAIL_PRINTF3 (n_fields
>= num_values
,
1454 "more values in constructor (n=%zu) than fields"
1455 " in target %s (n=%zu)",
1457 type
->get_debug_string (),
1460 /* It is OK if fields are null here, indicating definiton order,
1461 but there has to be a values array. */
1462 RETURN_NULL_IF_FAIL (values
,
1464 "'values' NULL with non-zero 'num_values'");
1466 size_t idx
= 0; /* Runner index for fields in the type object. */
1468 for (size_t i
= 0; i
< num_values
; i
++)
1470 gcc::jit::recording::rvalue
*rv
= values
[i
];
1472 /* rv kan be NULL, which would indicate zero init for the field. */
1473 gcc::jit::recording::type
*rv_type
= rv
? rv
->get_type () : nullptr;
1475 /* If fields are specified we need to check that they are in
1476 definition order. */
1479 gcc::jit::recording::field
*f
= fields
[i
];
1481 RETURN_NULL_IF_FAIL_PRINTF1 (
1484 "NULL field in 'fields', at index %zu", i
);
1486 RETURN_NULL_IF_FAIL_PRINTF3 (
1487 f
->get_container () ==
1488 static_cast<gcc::jit::recording::type
*>(type
),
1490 "field object at index %zu (%s), was not used when creating "
1493 f
->get_debug_string (),
1494 type
->get_debug_string ());
1496 /* Fields in the constructor need to be in struct definition
1497 order, but there can be gaps. */
1499 for (j
= idx
; j
< n_fields
; j
++)
1501 field
*fs
= fields_struct
->get_field (j
);
1504 idx
= j
; /* Advance runner index for next iteration. */
1509 RETURN_NULL_IF_FAIL_PRINTF3 (
1512 "field at index %zu in 'fields' is not in definition order "
1513 "(struct: %s) (ctor field: %s)",
1515 type
->get_debug_string (),
1516 f
->get_debug_string ());
1518 /* Check that the specified field has the same type as the
1519 value, unless the value is null (a zero value init). */
1520 RETURN_NULL_IF_FAIL_PRINTF5 (
1521 !rv
|| gcc::jit::types_kinda_same (rv_type
,
1524 "value and field not the same unqualified type, at index %zu"
1525 " (%s.%s: %s)(value type: %s)",
1527 type
->get_debug_string (),
1528 f
->get_debug_string (),
1529 f
->get_type ()->get_debug_string (),
1530 rv_type
->get_debug_string ());
1533 /* If no fields are specified, check that the value has the same type
1534 as the field in the definition of the struct. */
1537 RETURN_NULL_IF_FAIL_PRINTF5 (
1538 gcc::jit::types_kinda_same (rv_type
,
1540 get_field (i
)->get_type ()),
1542 "value and field not the same unqualified type, at index %zu"
1543 " (%s.%s: %s)(value type: %s)",
1545 type
->get_debug_string (),
1546 fields_struct
->get_field (i
)->get_debug_string (),
1547 fields_struct
->get_field (i
)->get_type ()->get_debug_string (),
1548 rv_type
->get_debug_string ());
1553 RETURN_NULL_IF_FAIL_PRINTF1 (
1554 !rv_type
->is_void (),
1556 "can't construct the void type, at index %zu", i
);
1560 return (gcc_jit_rvalue
*)ctxt
->new_ctor (
1564 reinterpret_cast<gcc::jit::recording::field
**>(fields
),
1565 reinterpret_cast<gcc::jit::recording::rvalue
**>(values
));
1568 extern gcc_jit_rvalue
*
1569 gcc_jit_context_new_union_constructor (gcc_jit_context
*ctxt
,
1570 gcc_jit_location
*loc
,
1572 gcc_jit_field
*field
,
1573 gcc_jit_rvalue
*value
)
1575 using namespace gcc::jit::recording
;
1577 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
1578 JIT_LOG_FUNC (ctxt
->get_logger ());
1579 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
1581 RETURN_NULL_IF_FAIL_PRINTF1 (type
->is_union (),
1583 "constructor type is not an union: %s",
1584 type
->get_debug_string ());
1586 compound_type
*ct
= reinterpret_cast<compound_type
*>(type
);
1587 gcc::jit::recording::fields
*fields_union
= ct
->get_fields ();
1588 size_t n_fields
= fields_union
->length ();
1590 RETURN_NULL_IF_FAIL_PRINTF1 (ct
->has_known_size (),
1592 "union can't be opaque: %s",
1593 type
->get_debug_string ());
1594 RETURN_NULL_IF_FAIL_PRINTF1 (n_fields
,
1596 "no fields in union: %s",
1597 type
->get_debug_string ());
1599 /* If value is NULL we are just supposed to zero the whole union. */
1601 return (gcc_jit_rvalue
*)ctxt
->new_ctor (loc
, type
, 0, NULL
, NULL
);
1603 gcc::jit::recording::type
*rv_type
= value
->get_type ();
1605 RETURN_NULL_IF_FAIL (
1606 !rv_type
->is_void (),
1608 "can't construct the void type");
1612 RETURN_NULL_IF_FAIL_PRINTF2 (
1613 field
->get_container () ==
1614 static_cast<gcc::jit::recording::type
*>(type
),
1616 "field object (%s) was not used when creating "
1618 field
->get_debug_string (),
1619 type
->get_debug_string ());
1621 RETURN_NULL_IF_FAIL_PRINTF4 (
1622 gcc::jit::types_kinda_same (rv_type
,
1623 field
->get_type ()),
1625 "value and field are not the same unqualified type"
1626 " (%s.%s: %s)(value type: %s)",
1627 type
->get_debug_string (),
1628 field
->get_debug_string (),
1629 field
->get_type ()->get_debug_string (),
1630 rv_type
->get_debug_string ());
1632 /* If no field is specified, check that the value has the same type
1633 as the first field in the definition of the union. */
1635 RETURN_NULL_IF_FAIL_PRINTF2 (
1636 gcc::jit::types_kinda_same (rv_type
,
1638 get_field (0)->get_type ()),
1640 "value and first union field not the same unqualified type"
1641 " (field type: %s)(value type: %s)",
1642 fields_union
->get_field (0)->get_type ()->get_debug_string (),
1643 rv_type
->get_debug_string ());
1646 return (gcc_jit_rvalue
*)ctxt
->new_ctor (
1650 /* A NULL fields array tells new_ctor to take fields from the type obj. */
1651 reinterpret_cast<gcc::jit::recording::field
**>(field
? &field
: NULL
),
1652 reinterpret_cast<gcc::jit::recording::rvalue
**>(&value
));
1655 extern gcc_jit_rvalue
*
1656 gcc_jit_context_new_array_constructor (gcc_jit_context
*ctxt
,
1657 gcc_jit_location
*loc
,
1660 gcc_jit_rvalue
**values
)
1662 using namespace gcc::jit::recording
;
1664 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
1665 JIT_LOG_FUNC (ctxt
->get_logger ());
1666 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
1668 RETURN_NULL_IF_FAIL (type
->is_array () != NULL
,
1670 "constructor type not an array");
1677 RETURN_NULL_IF_FAIL (
1680 "'values' NULL with non-zero 'num_values'");
1682 gcc::jit::recording::array_type
*arr_type
=
1683 reinterpret_cast<gcc::jit::recording::array_type
*>(type
);
1684 size_t n_el
= arr_type
->num_elements ();
1686 RETURN_NULL_IF_FAIL_PRINTF2 (
1689 "array constructor has more values than the array type's length"
1690 " (array type length: %zu, constructor length: %zu)",
1694 /* For arrays, all values need to be the same base type. */
1695 gcc::jit::recording::type
*type0
= NULL
;
1697 /* Find first non-null value. */
1698 for (;i
< num_values
; i
++)
1704 if (i
< num_values
) /* All values might be null and i == num_values. */
1705 type0
= values
[i
]->get_type ();
1707 /* If we got a type0, check that all other values have
1709 for (; i
< num_values
; i
++)
1712 RETURN_NULL_IF_FAIL_PRINTF3 (
1713 gcc::jit::types_kinda_same (type0
,
1714 values
[i
]->get_type ()),
1716 "value type at index %zu differ from first value type"
1717 " (first type: %s)(different type: %s)",
1719 type0
->get_debug_string (),
1720 values
[i
]->get_type ()->get_debug_string ());
1723 /* Compare type0 with the element type specified in the
1724 type of the array. */
1727 gcc::jit::recording::type
*el_type
=
1730 RETURN_NULL_IF_FAIL_PRINTF2 (
1731 gcc::jit::types_kinda_same (type0
, el_type
),
1733 "array element value types differ from types in 'values'"
1734 " (element type: %s)('values' type: %s)",
1735 el_type
->get_debug_string (),
1736 type0
->get_debug_string ());
1740 return (gcc_jit_rvalue
*)ctxt
->new_ctor (
1745 reinterpret_cast<gcc::jit::recording::rvalue
**>(values
));
1748 /* Public entrypoint. See description in libgccjit.h. */
1750 extern gcc_jit_lvalue
*
1751 gcc_jit_global_set_initializer_rvalue (gcc_jit_lvalue
*global
,
1752 gcc_jit_rvalue
*init_rvalue
)
1754 RETURN_NULL_IF_FAIL (global
, NULL
, NULL
,"NULL global");
1756 gcc::jit::recording::context
*ctxt
= global
->get_context ();
1757 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
,"NULL context");
1758 JIT_LOG_FUNC (ctxt
->get_logger ());
1759 RETURN_NULL_IF_FAIL (init_rvalue
, ctxt
, NULL
,"NULL init_rvalue");
1761 RETURN_NULL_IF_FAIL_PRINTF1 (global
->is_global (),
1763 "lvalue \"%s\" not a global",
1764 global
->get_debug_string ());
1766 gcc::jit::recording::global
*gbl
=
1767 reinterpret_cast<gcc::jit::recording::global
*> (global
);
1769 RETURN_NULL_IF_FAIL_PRINTF1 (gbl
->get_kind () !=
1770 GCC_JIT_GLOBAL_IMPORTED
,
1772 "can't initialize \"%s\", it is imported",
1773 global
->get_debug_string ());
1775 RETURN_NULL_IF_FAIL_PRINTF4 (gcc::jit::types_kinda_same (
1776 global
->get_type (),
1777 init_rvalue
->get_type ()),
1779 "mismatching types:"
1780 " initializing %s (type: %s) with %s (type: %s)",
1781 global
->get_debug_string (),
1782 global
->get_type ()->get_debug_string (),
1783 init_rvalue
->get_debug_string (),
1784 init_rvalue
->get_type ()->get_debug_string ());
1786 /* Check that there are no initializers set for the global yet. */
1787 RETURN_NULL_IF_FAIL_PRINTF1 (!gbl
->test_flags_anyof (
1788 gcc::jit::GLOBAL_VAR_FLAGS_WILL_BE_RVAL_INIT
|
1789 gcc::jit::GLOBAL_VAR_FLAGS_WILL_BE_BLOB_INIT
),
1791 "global variable already initialized: %s",
1792 global
->get_debug_string ());
1794 /* The global need to know during playback that it will be
1796 gbl
->set_flags (gcc::jit::GLOBAL_VAR_FLAGS_WILL_BE_RVAL_INIT
);
1798 ctxt
->new_global_init_rvalue (global
, init_rvalue
);
1803 /* Public entrypoint. See description in libgccjit.h.
1805 After error-checking, the real work is done by the
1806 gcc::jit::recording::global::set_initializer method, in
1807 jit-recording.cc. */
1809 extern gcc_jit_lvalue
*
1810 gcc_jit_global_set_initializer (gcc_jit_lvalue
*global
,
1814 RETURN_NULL_IF_FAIL (global
, NULL
, NULL
, "NULL global");
1815 RETURN_NULL_IF_FAIL (blob
, NULL
, NULL
, "NULL blob");
1816 RETURN_NULL_IF_FAIL_PRINTF1 (global
->is_global (), NULL
, NULL
,
1817 "lvalue \"%s\" not a global",
1818 global
->get_debug_string ());
1820 gcc::jit::recording::type
*lval_type
= global
->get_type ();
1821 RETURN_NULL_IF_FAIL_PRINTF1 (lval_type
->is_array (), NULL
, NULL
,
1822 "global \"%s\" is not an array",
1823 global
->get_debug_string ());
1824 RETURN_NULL_IF_FAIL_PRINTF1 (lval_type
->dereference ()->is_int (), NULL
, NULL
,
1825 "global \"%s\" is not an array of integral type",
1826 global
->get_debug_string ());
1827 size_t lvalue_size
=
1828 lval_type
->dereference ()->get_size ()
1829 * static_cast <gcc::jit::recording::array_type
*> (lval_type
)->num_elements ();
1830 RETURN_NULL_IF_FAIL_PRINTF3 (
1831 lvalue_size
== num_bytes
, NULL
, NULL
,
1832 "mismatching sizes:"
1833 " global \"%s\" has size %zu whereas initializer has size %zu",
1834 global
->get_debug_string (), lvalue_size
, num_bytes
);
1836 /* Check that the rvalue initializer is not set for this global.
1837 Note that we do not check if this blob type initializer is
1838 already set, since that check was not present when the entrypoint
1839 was initially written. */
1840 gcc::jit::recording::global
*gbl
=
1841 reinterpret_cast<gcc::jit::recording::global
*> (global
);
1842 RETURN_NULL_IF_FAIL_PRINTF1 (!gbl
->test_flags_anyof (
1843 gcc::jit::GLOBAL_VAR_FLAGS_WILL_BE_RVAL_INIT
),
1845 "global variable already initialized: %s",
1846 global
->get_debug_string ());
1848 gbl
->set_initializer (blob
, num_bytes
);
1849 /* The global need to know during playback that it will be
1851 gbl
->set_flags (gcc::jit::GLOBAL_VAR_FLAGS_WILL_BE_BLOB_INIT
);
1856 /* Public entrypoint. See description in libgccjit.h.
1858 After error-checking, this calls the trivial
1859 gcc::jit::recording::memento::as_object method (an lvalue is a
1860 memento), in jit-recording.h. */
1863 gcc_jit_lvalue_as_object (gcc_jit_lvalue
*lvalue
)
1865 RETURN_NULL_IF_FAIL (lvalue
, NULL
, NULL
, "NULL lvalue");
1867 return static_cast <gcc_jit_object
*> (lvalue
->as_object ());
1870 /* Public entrypoint. See description in libgccjit.h.
1872 After error-checking, this calls the trivial
1873 gcc::jit::recording::lvalue::as_rvalue method in jit-recording.h. */
1876 gcc_jit_lvalue_as_rvalue (gcc_jit_lvalue
*lvalue
)
1878 RETURN_NULL_IF_FAIL (lvalue
, NULL
, NULL
, "NULL lvalue");
1880 return (gcc_jit_rvalue
*)lvalue
->as_rvalue ();
1883 /* Public entrypoint. See description in libgccjit.h.
1885 After error-checking, this calls the trivial
1886 gcc::jit::recording::memento::as_object method (an rvalue is a
1887 memento), in jit-recording.h. */
1890 gcc_jit_rvalue_as_object (gcc_jit_rvalue
*rvalue
)
1892 RETURN_NULL_IF_FAIL (rvalue
, NULL
, NULL
, "NULL rvalue");
1894 return static_cast <gcc_jit_object
*> (rvalue
->as_object ());
1897 /* Public entrypoint. See description in libgccjit.h.
1899 After error-checking, the real work is done by the
1900 gcc::jit::recording::rvalue::get_type method, in
1904 gcc_jit_rvalue_get_type (gcc_jit_rvalue
*rvalue
)
1906 RETURN_NULL_IF_FAIL (rvalue
, NULL
, NULL
, "NULL rvalue");
1908 return static_cast <gcc_jit_type
*> (rvalue
->get_type ());
1911 /* Verify that NUMERIC_TYPE is non-NULL, and that it is a "numeric"
1912 type i.e. it satisfies gcc::jit::type::is_numeric (), such as the
1913 result of gcc_jit_context_get_type (GCC_JIT_TYPE_INT). */
1915 #define RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE(CTXT, NUMERIC_TYPE) \
1917 RETURN_NULL_IF_FAIL (NUMERIC_TYPE, CTXT, NULL, "NULL type"); \
1918 RETURN_NULL_IF_FAIL_PRINTF1 ( \
1919 NUMERIC_TYPE->is_numeric (), ctxt, NULL, \
1920 "not a numeric type: %s", \
1921 NUMERIC_TYPE->get_debug_string ()); \
1924 /* Public entrypoint. See description in libgccjit.h.
1926 After error-checking, the real work is done by the
1927 gcc::jit::recording::context::new_rvalue_from_const <int> method in
1928 jit-recording.cc. */
1931 gcc_jit_context_new_rvalue_from_int (gcc_jit_context
*ctxt
,
1932 gcc_jit_type
*numeric_type
,
1935 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
1936 JIT_LOG_FUNC (ctxt
->get_logger ());
1937 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt
, numeric_type
);
1939 return ((gcc_jit_rvalue
*)ctxt
1940 ->new_rvalue_from_const
<int> (numeric_type
, value
));
1943 /* Public entrypoint. See description in libgccjit.h.
1945 After error-checking, the real work is done by the
1946 gcc::jit::recording::context::new_rvalue_from_const <long> method
1947 in jit-recording.cc. */
1950 gcc_jit_context_new_rvalue_from_long (gcc_jit_context
*ctxt
,
1951 gcc_jit_type
*numeric_type
,
1954 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
1955 JIT_LOG_FUNC (ctxt
->get_logger ());
1956 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt
, numeric_type
);
1958 return ((gcc_jit_rvalue
*)ctxt
1959 ->new_rvalue_from_const
<long> (numeric_type
, value
));
1962 /* Public entrypoint. See description in libgccjit.h.
1964 This is essentially equivalent to:
1965 gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 0);
1966 albeit with slightly different error messages if an error occurs. */
1969 gcc_jit_context_zero (gcc_jit_context
*ctxt
,
1970 gcc_jit_type
*numeric_type
)
1972 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
1973 JIT_LOG_FUNC (ctxt
->get_logger ());
1974 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt
, numeric_type
);
1976 return gcc_jit_context_new_rvalue_from_int (ctxt
, numeric_type
, 0);
1979 /* Public entrypoint. See description in libgccjit.h.
1981 This is essentially equivalent to:
1982 gcc_jit_context_new_rvalue_from_int (ctxt, numeric_type, 1);
1983 albeit with slightly different error messages if an error occurs. */
1986 gcc_jit_context_one (gcc_jit_context
*ctxt
,
1987 gcc_jit_type
*numeric_type
)
1989 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
1990 JIT_LOG_FUNC (ctxt
->get_logger ());
1991 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt
, numeric_type
);
1993 return gcc_jit_context_new_rvalue_from_int (ctxt
, numeric_type
, 1);
1996 /* Public entrypoint. See description in libgccjit.h.
1998 After error-checking, the real work is done by the
1999 gcc::jit::recording::context::new_rvalue_from_const <double> method in
2000 jit-recording.cc. */
2003 gcc_jit_context_new_rvalue_from_double (gcc_jit_context
*ctxt
,
2004 gcc_jit_type
*numeric_type
,
2007 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
2008 JIT_LOG_FUNC (ctxt
->get_logger ());
2009 RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt
, numeric_type
);
2011 return ((gcc_jit_rvalue
*)ctxt
2012 ->new_rvalue_from_const
<double> (numeric_type
, value
));
2015 /* Public entrypoint. See description in libgccjit.h.
2017 After error-checking, the real work is done by the
2018 gcc::jit::recording::context::new_rvalue_from_const <void *> method
2019 in jit-recording.cc. */
2022 gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context
*ctxt
,
2023 gcc_jit_type
*pointer_type
,
2026 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
2027 JIT_LOG_FUNC (ctxt
->get_logger ());
2028 RETURN_NULL_IF_FAIL (pointer_type
, ctxt
, NULL
, "NULL type");
2029 RETURN_NULL_IF_FAIL_PRINTF1 (
2030 pointer_type
->is_pointer (),
2032 "not a pointer type (type: %s)",
2033 pointer_type
->get_debug_string ());
2035 return ((gcc_jit_rvalue
*)ctxt
2036 ->new_rvalue_from_const
<void *> (pointer_type
, value
));
2039 /* Public entrypoint. See description in libgccjit.h.
2041 This is essentially equivalent to:
2042 gcc_jit_context_new_rvalue_from_ptr (ctxt, pointer_type, NULL);
2043 albeit with slightly different error messages if an error occurs. */
2046 gcc_jit_context_null (gcc_jit_context
*ctxt
,
2047 gcc_jit_type
*pointer_type
)
2049 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
2050 JIT_LOG_FUNC (ctxt
->get_logger ());
2051 RETURN_NULL_IF_FAIL (pointer_type
, ctxt
, NULL
, "NULL type");
2052 RETURN_NULL_IF_FAIL_PRINTF1 (
2053 pointer_type
->is_pointer (),
2055 "not a pointer type (type: %s)",
2056 pointer_type
->get_debug_string ());
2058 return gcc_jit_context_new_rvalue_from_ptr (ctxt
, pointer_type
, NULL
);
2061 /* Public entrypoint. See description in libgccjit.h.
2063 After error-checking, the real work is done by the
2064 gcc::jit::recording::context::new_string_literal method in
2065 jit-recording.cc. */
2068 gcc_jit_context_new_string_literal (gcc_jit_context
*ctxt
,
2071 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
2072 JIT_LOG_FUNC (ctxt
->get_logger ());
2073 RETURN_NULL_IF_FAIL (value
, ctxt
, NULL
, "NULL value");
2075 return (gcc_jit_rvalue
*)ctxt
->new_string_literal (value
);
2078 /* Public entrypoint. See description in libgccjit.h.
2080 After error-checking, the real work is done by the
2081 gcc::jit::recording::context::new_unary_op method in
2082 jit-recording.cc. */
2085 gcc_jit_context_new_unary_op (gcc_jit_context
*ctxt
,
2086 gcc_jit_location
*loc
,
2087 enum gcc_jit_unary_op op
,
2088 gcc_jit_type
*result_type
,
2089 gcc_jit_rvalue
*rvalue
)
2091 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
2092 JIT_LOG_FUNC (ctxt
->get_logger ());
2093 /* LOC can be NULL. */
2094 RETURN_NULL_IF_FAIL_PRINTF1 (
2095 (op
>= GCC_JIT_UNARY_OP_MINUS
2096 && op
<= GCC_JIT_UNARY_OP_ABS
),
2098 "unrecognized value for enum gcc_jit_unary_op: %i",
2100 RETURN_NULL_IF_FAIL (result_type
, ctxt
, loc
, "NULL result_type");
2101 RETURN_NULL_IF_FAIL_PRINTF3 (
2102 result_type
->is_numeric (), ctxt
, loc
,
2103 "gcc_jit_unary_op %s with operand %s "
2104 "has non-numeric result_type: %s",
2105 gcc::jit::unary_op_reproducer_strings
[op
],
2106 rvalue
->get_debug_string (),
2107 result_type
->get_debug_string ());
2108 RETURN_NULL_IF_FAIL (rvalue
, ctxt
, loc
, "NULL rvalue");
2110 return (gcc_jit_rvalue
*)ctxt
->new_unary_op (loc
, op
, result_type
, rvalue
);
2113 /* Determine if OP is a valid value for enum gcc_jit_binary_op.
2114 For use by both gcc_jit_context_new_binary_op and
2115 gcc_jit_block_add_assignment_op. */
2118 valid_binary_op_p (enum gcc_jit_binary_op op
)
2120 return (op
>= GCC_JIT_BINARY_OP_PLUS
2121 && op
<= GCC_JIT_BINARY_OP_RSHIFT
);
2124 /* Public entrypoint. See description in libgccjit.h.
2126 After error-checking, the real work is done by the
2127 gcc::jit::recording::context::new_binary_op method in
2128 jit-recording.cc. */
2131 gcc_jit_context_new_binary_op (gcc_jit_context
*ctxt
,
2132 gcc_jit_location
*loc
,
2133 enum gcc_jit_binary_op op
,
2134 gcc_jit_type
*result_type
,
2135 gcc_jit_rvalue
*a
, gcc_jit_rvalue
*b
)
2137 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
2138 JIT_LOG_FUNC (ctxt
->get_logger ());
2139 /* LOC can be NULL. */
2140 RETURN_NULL_IF_FAIL_PRINTF1 (
2141 valid_binary_op_p (op
),
2143 "unrecognized value for enum gcc_jit_binary_op: %i",
2145 RETURN_NULL_IF_FAIL (result_type
, ctxt
, loc
, "NULL result_type");
2146 RETURN_NULL_IF_FAIL (a
, ctxt
, loc
, "NULL a");
2147 RETURN_NULL_IF_FAIL (b
, ctxt
, loc
, "NULL b");
2148 RETURN_NULL_IF_FAIL_PRINTF4 (
2149 compatible_types (a
->get_type ()->unqualified (),
2150 b
->get_type ()->unqualified ()),
2152 "mismatching types for binary op:"
2153 " a: %s (type: %s) b: %s (type: %s)",
2154 a
->get_debug_string (),
2155 a
->get_type ()->get_debug_string (),
2156 b
->get_debug_string (),
2157 b
->get_type ()->get_debug_string ());
2158 RETURN_NULL_IF_FAIL_PRINTF4 (
2159 result_type
->is_numeric (), ctxt
, loc
,
2160 "gcc_jit_binary_op %s with operands a: %s b: %s "
2161 "has non-numeric result_type: %s",
2162 gcc::jit::binary_op_reproducer_strings
[op
],
2163 a
->get_debug_string (), b
->get_debug_string (),
2164 result_type
->get_debug_string ());
2166 return (gcc_jit_rvalue
*)ctxt
->new_binary_op (loc
, op
, result_type
, a
, b
);
2169 /* Public entrypoint. See description in libgccjit.h.
2171 After error-checking, the real work is done by the
2172 gcc::jit::recording::context::new_comparison method in
2173 jit-recording.cc. */
2176 gcc_jit_context_new_comparison (gcc_jit_context
*ctxt
,
2177 gcc_jit_location
*loc
,
2178 enum gcc_jit_comparison op
,
2179 gcc_jit_rvalue
*a
, gcc_jit_rvalue
*b
)
2181 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
2182 JIT_LOG_FUNC (ctxt
->get_logger ());
2183 /* LOC can be NULL. */
2184 RETURN_NULL_IF_FAIL_PRINTF1 (
2185 (op
>= GCC_JIT_COMPARISON_EQ
2186 && op
<= GCC_JIT_COMPARISON_GE
),
2188 "unrecognized value for enum gcc_jit_comparison: %i",
2190 RETURN_NULL_IF_FAIL (a
, ctxt
, loc
, "NULL a");
2191 RETURN_NULL_IF_FAIL (b
, ctxt
, loc
, "NULL b");
2192 RETURN_NULL_IF_FAIL_PRINTF4 (
2193 a
->get_type ()->unqualified () == b
->get_type ()->unqualified (),
2195 "mismatching types for comparison:"
2196 " a: %s (type: %s) b: %s (type: %s)",
2197 a
->get_debug_string (),
2198 a
->get_type ()->get_debug_string (),
2199 b
->get_debug_string (),
2200 b
->get_type ()->get_debug_string ());
2202 return (gcc_jit_rvalue
*)ctxt
->new_comparison (loc
, op
, a
, b
);
2205 /* Public entrypoint. See description in libgccjit.h.
2207 After error-checking, the real work is done by the
2208 gcc::jit::recording::context::new_call method in
2209 jit-recording.cc. */
2212 gcc_jit_context_new_call (gcc_jit_context
*ctxt
,
2213 gcc_jit_location
*loc
,
2214 gcc_jit_function
*func
,
2215 int numargs
, gcc_jit_rvalue
**args
)
2217 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
2218 JIT_LOG_FUNC (ctxt
->get_logger ());
2219 /* LOC can be NULL. */
2220 RETURN_NULL_IF_FAIL (func
, ctxt
, loc
, "NULL function");
2222 RETURN_NULL_IF_FAIL (args
, ctxt
, loc
, "NULL args");
2224 int min_num_params
= func
->get_params ().length ();
2225 bool is_variadic
= func
->is_variadic ();
2227 RETURN_NULL_IF_FAIL_PRINTF3 (
2228 numargs
>= min_num_params
,
2230 "not enough arguments to function \"%s\""
2231 " (got %i args, expected %i)",
2232 func
->get_name ()->c_str (),
2233 numargs
, min_num_params
);
2235 RETURN_NULL_IF_FAIL_PRINTF3 (
2236 (numargs
== min_num_params
|| is_variadic
),
2238 "too many arguments to function \"%s\""
2239 " (got %i args, expected %i)",
2240 func
->get_name ()->c_str (),
2241 numargs
, min_num_params
);
2243 for (int i
= 0; i
< min_num_params
; i
++)
2245 gcc::jit::recording::param
*param
= func
->get_param (i
);
2246 gcc_jit_rvalue
*arg
= args
[i
];
2248 RETURN_NULL_IF_FAIL_PRINTF4 (
2251 "NULL argument %i to function \"%s\":"
2252 " param %s (type: %s)",
2254 func
->get_name ()->c_str (),
2255 param
->get_debug_string (),
2256 param
->get_type ()->get_debug_string ());
2258 RETURN_NULL_IF_FAIL_PRINTF6 (
2259 compatible_types (param
->get_type (),
2262 "mismatching types for argument %d of function \"%s\":"
2263 " assignment to param %s (type: %s) from %s (type: %s)",
2265 func
->get_name ()->c_str (),
2266 param
->get_debug_string (),
2267 param
->get_type ()->get_debug_string (),
2268 arg
->get_debug_string (),
2269 arg
->get_type ()->get_debug_string ());
2272 return (gcc_jit_rvalue
*)ctxt
->new_call (loc
,
2275 (gcc::jit::recording::rvalue
**)args
);
2278 /* Public entrypoint. See description in libgccjit.h.
2280 After error-checking, the real work is done by the
2281 gcc::jit::recording::context::new_call_through_ptr method in
2282 jit-recording.cc. */
2285 gcc_jit_context_new_call_through_ptr (gcc_jit_context
*ctxt
,
2286 gcc_jit_location
*loc
,
2287 gcc_jit_rvalue
*fn_ptr
,
2288 int numargs
, gcc_jit_rvalue
**args
)
2290 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
2291 JIT_LOG_FUNC (ctxt
->get_logger ());
2292 /* LOC can be NULL. */
2293 RETURN_NULL_IF_FAIL (fn_ptr
, ctxt
, loc
, "NULL fn_ptr");
2295 RETURN_NULL_IF_FAIL (args
, ctxt
, loc
, "NULL args");
2297 gcc::jit::recording::type
*ptr_type
= fn_ptr
->get_type ()->dereference ();
2298 RETURN_NULL_IF_FAIL_PRINTF2 (
2299 ptr_type
, ctxt
, loc
,
2300 "fn_ptr is not a ptr: %s"
2302 fn_ptr
->get_debug_string (),
2303 fn_ptr
->get_type ()->get_debug_string ());
2305 gcc::jit::recording::function_type
*fn_type
=
2306 ptr_type
->dyn_cast_function_type();
2307 RETURN_NULL_IF_FAIL_PRINTF2 (
2309 "fn_ptr is not a function ptr: %s"
2311 fn_ptr
->get_debug_string (),
2312 fn_ptr
->get_type ()->get_debug_string ());
2314 int min_num_params
= fn_type
->get_param_types ().length ();
2315 bool is_variadic
= fn_type
->is_variadic ();
2317 RETURN_NULL_IF_FAIL_PRINTF3 (
2318 numargs
>= min_num_params
,
2320 "not enough arguments to fn_ptr: %s"
2321 " (got %i args, expected %i)",
2322 fn_ptr
->get_debug_string (),
2323 numargs
, min_num_params
);
2325 RETURN_NULL_IF_FAIL_PRINTF3 (
2326 (numargs
== min_num_params
|| is_variadic
),
2328 "too many arguments to fn_ptr: %s"
2329 " (got %i args, expected %i)",
2330 fn_ptr
->get_debug_string (),
2331 numargs
, min_num_params
);
2333 for (int i
= 0; i
< min_num_params
; i
++)
2335 gcc::jit::recording::type
*param_type
= fn_type
->get_param_types ()[i
];
2336 gcc_jit_rvalue
*arg
= args
[i
];
2338 RETURN_NULL_IF_FAIL_PRINTF3 (
2341 "NULL argument %i to fn_ptr: %s"
2344 fn_ptr
->get_debug_string (),
2345 param_type
->get_debug_string ());
2347 RETURN_NULL_IF_FAIL_PRINTF6 (
2348 compatible_types (param_type
,
2351 "mismatching types for argument %d of fn_ptr: %s:"
2352 " assignment to param %d (type: %s) from %s (type: %s)",
2354 fn_ptr
->get_debug_string (),
2356 param_type
->get_debug_string (),
2357 arg
->get_debug_string (),
2358 arg
->get_type ()->get_debug_string ());
2361 return (gcc_jit_rvalue
*)(
2362 ctxt
->new_call_through_ptr (loc
,
2365 (gcc::jit::recording::rvalue
**)args
));
2368 /* Helper function for determining if we can cast an rvalue from SRC_TYPE
2369 to DST_TYPE, for use by gcc_jit_context_new_cast.
2371 We only permit these kinds of cast:
2375 P* <-> Q* for pointer types P and Q. */
2378 is_valid_cast (gcc::jit::recording::type
*src_type
,
2379 gcc_jit_type
*dst_type
)
2381 bool src_is_int
= src_type
->is_int ();
2382 bool dst_is_int
= dst_type
->is_int ();
2383 bool src_is_float
= src_type
->is_float ();
2384 bool dst_is_float
= dst_type
->is_float ();
2385 bool src_is_bool
= src_type
->is_bool ();
2386 bool dst_is_bool
= dst_type
->is_bool ();
2389 if (dst_is_int
|| dst_is_float
|| dst_is_bool
)
2393 if (dst_is_int
|| dst_is_float
)
2397 if (dst_is_int
|| dst_is_bool
)
2400 /* Permit casts between pointer types. */
2401 gcc::jit::recording::type
*deref_src_type
= src_type
->is_pointer ();
2402 gcc::jit::recording::type
*deref_dst_type
= dst_type
->is_pointer ();
2403 if (deref_src_type
&& deref_dst_type
)
2409 /* Public entrypoint. See description in libgccjit.h.
2411 After error-checking, the real work is done by the
2412 gcc::jit::recording::context::new_cast method in jit-recording.cc. */
2415 gcc_jit_context_new_cast (gcc_jit_context
*ctxt
,
2416 gcc_jit_location
*loc
,
2417 gcc_jit_rvalue
*rvalue
,
2420 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
2421 JIT_LOG_FUNC (ctxt
->get_logger ());
2422 /* LOC can be NULL. */
2423 RETURN_NULL_IF_FAIL (rvalue
, ctxt
, loc
, "NULL rvalue");
2424 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
2425 RETURN_NULL_IF_FAIL_PRINTF3 (
2426 is_valid_cast (rvalue
->get_type (), type
),
2428 "cannot cast %s from type: %s to type: %s",
2429 rvalue
->get_debug_string (),
2430 rvalue
->get_type ()->get_debug_string (),
2431 type
->get_debug_string ());
2433 return static_cast <gcc_jit_rvalue
*> (ctxt
->new_cast (loc
, rvalue
, type
));
2436 /* Public entrypoint. See description in libgccjit.h.
2438 After error-checking, the real work is done by the
2439 gcc::jit::recording::context::new_bitcast method in jit-recording.c. */
2442 gcc_jit_context_new_bitcast (gcc_jit_context
*ctxt
,
2443 gcc_jit_location
*loc
,
2444 gcc_jit_rvalue
*rvalue
,
2447 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
2448 JIT_LOG_FUNC (ctxt
->get_logger ());
2449 /* LOC can be NULL. */
2450 RETURN_NULL_IF_FAIL (rvalue
, ctxt
, loc
, "NULL rvalue");
2451 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
2452 /* We cannot check if the size of rvalue matches the size of type here, so
2453 we'll do it at playback. */
2455 return static_cast <gcc_jit_rvalue
*> (ctxt
->new_bitcast (loc
, rvalue
, type
));
2458 /* Public entrypoint. See description in libgccjit.h.
2460 After error-checking, the real work is done by the
2461 gcc::jit::recording::context::new_array_access method in
2462 jit-recording.cc. */
2464 extern gcc_jit_lvalue
*
2465 gcc_jit_context_new_array_access (gcc_jit_context
*ctxt
,
2466 gcc_jit_location
*loc
,
2467 gcc_jit_rvalue
*ptr
,
2468 gcc_jit_rvalue
*index
)
2470 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL context");
2471 JIT_LOG_FUNC (ctxt
->get_logger ());
2472 /* LOC can be NULL. */
2473 RETURN_NULL_IF_FAIL (ptr
, ctxt
, loc
, "NULL ptr");
2474 RETURN_NULL_IF_FAIL (index
, ctxt
, loc
, "NULL index");
2475 RETURN_NULL_IF_FAIL_PRINTF2 (
2476 ptr
->get_type ()->dereference (),
2478 "ptr: %s (type: %s) is not a pointer or array",
2479 ptr
->get_debug_string (),
2480 ptr
->get_type ()->get_debug_string ());
2481 RETURN_NULL_IF_FAIL_PRINTF2 (
2482 index
->get_type ()->is_numeric (),
2484 "index: %s (type: %s) is not of numeric type",
2485 index
->get_debug_string (),
2486 index
->get_type ()->get_debug_string ());
2488 return (gcc_jit_lvalue
*)ctxt
->new_array_access (loc
, ptr
, index
);
2491 /* Public entrypoint. See description in libgccjit.h.
2493 After error-checking, the real work is done by the
2494 gcc::jit::recording::memento::get_context method in
2498 gcc_jit_object_get_context (gcc_jit_object
*obj
)
2500 RETURN_NULL_IF_FAIL (obj
, NULL
, NULL
, "NULL object");
2502 return static_cast <gcc_jit_context
*> (obj
->get_context ());
2505 /* Public entrypoint. See description in libgccjit.h.
2507 After error-checking, the real work is done by the
2508 gcc::jit::recording::memento::get_debug_string method in
2509 jit-recording.cc. */
2512 gcc_jit_object_get_debug_string (gcc_jit_object
*obj
)
2514 RETURN_NULL_IF_FAIL (obj
, NULL
, NULL
, "NULL object");
2516 return obj
->get_debug_string ();
2519 /* Public entrypoint. See description in libgccjit.h.
2521 After error-checking, the real work is done by the
2522 gcc::jit::recording::lvalue::access_field method in
2523 jit-recording.cc. */
2526 gcc_jit_lvalue_access_field (gcc_jit_lvalue
*struct_
,
2527 gcc_jit_location
*loc
,
2528 gcc_jit_field
*field
)
2530 RETURN_NULL_IF_FAIL (struct_
, NULL
, loc
, "NULL struct");
2531 gcc::jit::recording::context
*ctxt
= struct_
->m_ctxt
;
2532 JIT_LOG_FUNC (ctxt
->get_logger ());
2533 /* LOC can be NULL. */
2534 RETURN_NULL_IF_FAIL (field
, ctxt
, loc
, "NULL field");
2535 RETURN_NULL_IF_FAIL_PRINTF1 (field
->get_container (), field
->m_ctxt
, loc
,
2536 "field %s has not been placed in a struct",
2537 field
->get_debug_string ());
2538 gcc::jit::recording::type
*underlying_type
=
2539 struct_
->get_type ();
2540 RETURN_NULL_IF_FAIL_PRINTF2 (
2541 (field
->get_container ()->unqualified ()
2542 == underlying_type
->unqualified ()),
2543 struct_
->m_ctxt
, loc
,
2544 "%s is not a field of %s",
2545 field
->get_debug_string (),
2546 underlying_type
->get_debug_string ());
2548 return (gcc_jit_lvalue
*)struct_
->access_field (loc
, field
);
2551 /* Public entrypoint. See description in libgccjit.h.
2553 After error-checking, the real work is done by the
2554 gcc::jit::recording::rvalue::access_field method in
2555 jit-recording.cc. */
2558 gcc_jit_rvalue_access_field (gcc_jit_rvalue
*struct_
,
2559 gcc_jit_location
*loc
,
2560 gcc_jit_field
*field
)
2562 RETURN_NULL_IF_FAIL (struct_
, NULL
, loc
, "NULL struct");
2563 gcc::jit::recording::context
*ctxt
= struct_
->m_ctxt
;
2564 JIT_LOG_FUNC (ctxt
->get_logger ());
2565 /* LOC can be NULL. */
2566 RETURN_NULL_IF_FAIL (field
, ctxt
, loc
, "NULL field");
2567 RETURN_NULL_IF_FAIL_PRINTF1 (field
->get_container (), field
->m_ctxt
, loc
,
2568 "field %s has not been placed in a struct",
2569 field
->get_debug_string ());
2570 gcc::jit::recording::type
*underlying_type
=
2571 struct_
->get_type ();
2572 RETURN_NULL_IF_FAIL_PRINTF2 (
2573 (field
->get_container ()->unqualified ()
2574 == underlying_type
->unqualified ()),
2575 struct_
->m_ctxt
, loc
,
2576 "%s is not a field of %s",
2577 field
->get_debug_string (),
2578 underlying_type
->get_debug_string ());
2580 return (gcc_jit_rvalue
*)struct_
->access_field (loc
, field
);
2583 /* Public entrypoint. See description in libgccjit.h.
2585 After error-checking, the real work is done by the
2586 gcc::jit::recording::rvalue::deference_field method in
2587 jit-recording.cc. */
2590 gcc_jit_rvalue_dereference_field (gcc_jit_rvalue
*ptr
,
2591 gcc_jit_location
*loc
,
2592 gcc_jit_field
*field
)
2594 RETURN_NULL_IF_FAIL (ptr
, NULL
, loc
, "NULL ptr");
2595 JIT_LOG_FUNC (ptr
->get_context ()->get_logger ());
2596 /* LOC can be NULL. */
2597 RETURN_NULL_IF_FAIL (field
, NULL
, loc
, "NULL field");
2598 gcc::jit::recording::type
*underlying_type
=
2599 ptr
->get_type ()->is_pointer ();
2600 RETURN_NULL_IF_FAIL_PRINTF1 (field
->get_container (), field
->m_ctxt
, loc
,
2601 "field %s has not been placed in a struct",
2602 field
->get_debug_string ());
2603 RETURN_NULL_IF_FAIL_PRINTF3 (
2606 "dereference of non-pointer %s (type: %s) when accessing ->%s",
2607 ptr
->get_debug_string (),
2608 ptr
->get_type ()->get_debug_string (),
2609 field
->get_debug_string ());
2610 RETURN_NULL_IF_FAIL_PRINTF2 (
2611 (field
->get_container ()->unqualified ()
2612 == underlying_type
->unqualified ()),
2614 "%s is not a field of %s",
2615 field
->get_debug_string (),
2616 underlying_type
->get_debug_string ());
2618 return (gcc_jit_lvalue
*)ptr
->dereference_field (loc
, field
);
2621 /* Public entrypoint. See description in libgccjit.h.
2623 After error-checking, the real work is done by the
2624 gcc::jit::recording::rvalue::deference method in
2625 jit-recording.cc. */
2628 gcc_jit_rvalue_dereference (gcc_jit_rvalue
*rvalue
,
2629 gcc_jit_location
*loc
)
2631 RETURN_NULL_IF_FAIL (rvalue
, NULL
, loc
, "NULL rvalue");
2632 JIT_LOG_FUNC (rvalue
->get_context ()->get_logger ());
2633 /* LOC can be NULL. */
2635 gcc::jit::recording::type
*underlying_type
=
2636 rvalue
->get_type ()->is_pointer ();
2638 RETURN_NULL_IF_FAIL_PRINTF2 (
2640 rvalue
->m_ctxt
, loc
,
2641 "dereference of non-pointer %s (type: %s)",
2642 rvalue
->get_debug_string (),
2643 rvalue
->get_type ()->get_debug_string ());
2645 RETURN_NULL_IF_FAIL_PRINTF2 (
2646 !underlying_type
->is_void (),
2647 rvalue
->m_ctxt
, loc
,
2648 "dereference of void pointer %s (type: %s)",
2649 rvalue
->get_debug_string (),
2650 rvalue
->get_type ()->get_debug_string ());
2652 return (gcc_jit_lvalue
*)rvalue
->dereference (loc
);
2655 /* Public entrypoint. See description in libgccjit.h.
2657 After error-checking, the real work is done by the
2658 gcc::jit::recording::lvalue::get_address method in jit-recording.cc. */
2661 gcc_jit_lvalue_get_address (gcc_jit_lvalue
*lvalue
,
2662 gcc_jit_location
*loc
)
2664 RETURN_NULL_IF_FAIL (lvalue
, NULL
, loc
, "NULL lvalue");
2665 JIT_LOG_FUNC (lvalue
->get_context ()->get_logger ());
2666 /* LOC can be NULL. */
2668 return (gcc_jit_rvalue
*)lvalue
->get_address (loc
);
2671 /* Public entrypoint. See description in libgccjit.h.
2673 After error-checking, the real work is done by the
2674 gcc::jit::recording::lvalue::set_tls_model method in jit-recording.cc. */
2677 gcc_jit_lvalue_set_tls_model (gcc_jit_lvalue
*lvalue
,
2678 enum gcc_jit_tls_model model
)
2680 RETURN_IF_FAIL (lvalue
, NULL
, NULL
, "NULL lvalue");
2681 JIT_LOG_FUNC (lvalue
->get_context ()->get_logger ());
2682 RETURN_IF_FAIL_PRINTF1 (lvalue
->is_global (), lvalue
->get_context (), NULL
,
2683 "lvalue \"%s\" not a global",
2684 lvalue
->get_debug_string ());
2686 lvalue
->set_tls_model (model
);
2689 /* Public entrypoint. See description in libgccjit.h.
2691 After error-checking, the real work is done by the
2692 gcc::jit::recording::lvalue::set_link_section method in jit-recording.cc. */
2695 gcc_jit_lvalue_set_link_section (gcc_jit_lvalue
*lvalue
,
2696 const char *section_name
)
2698 RETURN_IF_FAIL (section_name
, NULL
, NULL
, "NULL section_name");
2699 lvalue
->set_link_section (section_name
);
2702 /* Public entrypoint. See description in libgccjit.h.
2704 After error-checking, the real work is done by the
2705 gcc::jit::recording::lvalue::get_alignment method in jit-recording.cc. */
2708 gcc_jit_lvalue_get_alignment (gcc_jit_lvalue
*lvalue
)
2710 RETURN_VAL_IF_FAIL (lvalue
, 0, NULL
, NULL
, "NULL lvalue");
2711 return lvalue
->get_alignment ();
2714 /* Public entrypoint. See description in libgccjit.h.
2716 After error-checking, the real work is done by the
2717 gcc::jit::recording::lvalue::set_alignment method in jit-recording.cc. */
2720 gcc_jit_lvalue_set_alignment (gcc_jit_lvalue
*lvalue
,
2723 RETURN_IF_FAIL (lvalue
, NULL
, NULL
, "NULL lvalue");
2724 RETURN_IF_FAIL ((bytes
& (bytes
- 1)) == 0, NULL
, NULL
,
2725 "alignment is not a power of 2");
2726 lvalue
->set_alignment (bytes
);
2729 /* Public entrypoint. See description in libgccjit.h.
2731 After error-checking, the real work is done by the
2732 gcc::jit::recording::lvalue::set_register_name method in jit-recording.cc. */
2735 gcc_jit_lvalue_set_register_name (gcc_jit_lvalue
*lvalue
,
2736 const char *reg_name
)
2738 RETURN_IF_FAIL (lvalue
, NULL
, NULL
, "NULL lvalue");
2739 RETURN_IF_FAIL (reg_name
, NULL
, NULL
, "NULL reg_name");
2740 lvalue
->set_register_name (reg_name
);
2743 /* Public entrypoint. See description in libgccjit.h.
2745 After error-checking, the real work is done by the
2746 gcc::jit::recording::function::new_local method in jit-recording.cc. */
2749 gcc_jit_function_new_local (gcc_jit_function
*func
,
2750 gcc_jit_location
*loc
,
2754 RETURN_NULL_IF_FAIL (func
, NULL
, loc
, "NULL function");
2755 gcc::jit::recording::context
*ctxt
= func
->m_ctxt
;
2756 JIT_LOG_FUNC (ctxt
->get_logger ());
2757 /* LOC can be NULL. */
2758 RETURN_NULL_IF_FAIL (func
->get_kind () != GCC_JIT_FUNCTION_IMPORTED
,
2760 "Cannot add locals to an imported function");
2761 RETURN_NULL_IF_FAIL (type
, ctxt
, loc
, "NULL type");
2762 RETURN_NULL_IF_FAIL (name
, ctxt
, loc
, "NULL name");
2763 RETURN_NULL_IF_FAIL_PRINTF2 (
2764 type
->has_known_size (),
2766 "unknown size for local \"%s\" (type: %s)",
2768 type
->get_debug_string ());
2769 RETURN_NULL_IF_FAIL_PRINTF1 (
2772 "void type for local \"%s\"",
2775 return (gcc_jit_lvalue
*)func
->new_local (loc
, type
, name
);
2778 /* Public entrypoint. See description in libgccjit.h.
2780 After error-checking, the real work is done by the
2781 gcc::jit::recording::block::add_eval method in jit-recording.cc. */
2784 gcc_jit_block_add_eval (gcc_jit_block
*block
,
2785 gcc_jit_location
*loc
,
2786 gcc_jit_rvalue
*rvalue
)
2788 RETURN_IF_NOT_VALID_BLOCK (block
, loc
);
2789 gcc::jit::recording::context
*ctxt
= block
->get_context ();
2790 JIT_LOG_FUNC (ctxt
->get_logger ());
2791 /* LOC can be NULL. */
2792 RETURN_IF_FAIL (rvalue
, ctxt
, loc
, "NULL rvalue");
2794 gcc::jit::recording::statement
*stmt
= block
->add_eval (loc
, rvalue
);
2796 /* "stmt" should be good enough to be usable in error-messages,
2797 but might still not be compilable; perform some more
2798 error-checking here. We do this here so that the error messages
2799 can contain a stringified version of "stmt", whilst appearing
2800 as close as possible to the point of failure. */
2801 rvalue
->verify_valid_within_stmt (__func__
, stmt
);
2804 /* Public entrypoint. See description in libgccjit.h.
2806 After error-checking, the real work is done by the
2807 gcc::jit::recording::block::add_assignment method in
2808 jit-recording.cc. */
2811 gcc_jit_block_add_assignment (gcc_jit_block
*block
,
2812 gcc_jit_location
*loc
,
2813 gcc_jit_lvalue
*lvalue
,
2814 gcc_jit_rvalue
*rvalue
)
2816 RETURN_IF_NOT_VALID_BLOCK (block
, loc
);
2817 gcc::jit::recording::context
*ctxt
= block
->get_context ();
2818 JIT_LOG_FUNC (ctxt
->get_logger ());
2819 /* LOC can be NULL. */
2820 RETURN_IF_FAIL (lvalue
, ctxt
, loc
, "NULL lvalue");
2821 RETURN_IF_FAIL (rvalue
, ctxt
, loc
, "NULL rvalue");
2822 RETURN_IF_FAIL_PRINTF4 (
2823 compatible_types (lvalue
->get_type (),
2824 rvalue
->get_type ()),
2826 "mismatching types:"
2827 " assignment to %s (type: %s) from %s (type: %s)",
2828 lvalue
->get_debug_string (),
2829 lvalue
->get_type ()->get_debug_string (),
2830 rvalue
->get_debug_string (),
2831 rvalue
->get_type ()->get_debug_string ());
2833 gcc::jit::recording::statement
*stmt
= block
->add_assignment (loc
, lvalue
, rvalue
);
2835 /* "stmt" should be good enough to be usable in error-messages,
2836 but might still not be compilable; perform some more
2837 error-checking here. We do this here so that the error messages
2838 can contain a stringified version of "stmt", whilst appearing
2839 as close as possible to the point of failure. */
2840 lvalue
->verify_valid_within_stmt (__func__
, stmt
);
2841 rvalue
->verify_valid_within_stmt (__func__
, stmt
);
2844 /* Public entrypoint. See description in libgccjit.h.
2846 After error-checking, the real work is done by the
2847 gcc::jit::recording::block::add_assignment_op method in
2848 jit-recording.cc. */
2851 gcc_jit_block_add_assignment_op (gcc_jit_block
*block
,
2852 gcc_jit_location
*loc
,
2853 gcc_jit_lvalue
*lvalue
,
2854 enum gcc_jit_binary_op op
,
2855 gcc_jit_rvalue
*rvalue
)
2857 RETURN_IF_NOT_VALID_BLOCK (block
, loc
);
2858 gcc::jit::recording::context
*ctxt
= block
->get_context ();
2859 JIT_LOG_FUNC (ctxt
->get_logger ());
2860 /* LOC can be NULL. */
2861 RETURN_IF_FAIL (lvalue
, ctxt
, loc
, "NULL lvalue");
2862 RETURN_IF_FAIL_PRINTF1 (
2863 valid_binary_op_p (op
),
2865 "unrecognized value for enum gcc_jit_binary_op: %i",
2867 RETURN_IF_FAIL (rvalue
, ctxt
, loc
, "NULL rvalue");
2868 RETURN_IF_FAIL_PRINTF4 (
2869 compatible_types (lvalue
->get_type (),
2870 rvalue
->get_type ()),
2872 "mismatching types:"
2873 " assignment to %s (type: %s) involving %s (type: %s)",
2874 lvalue
->get_debug_string (),
2875 lvalue
->get_type ()->get_debug_string (),
2876 rvalue
->get_debug_string (),
2877 rvalue
->get_type ()->get_debug_string ());
2879 gcc::jit::recording::statement
*stmt
= block
->add_assignment_op (loc
, lvalue
, op
, rvalue
);
2881 /* "stmt" should be good enough to be usable in error-messages,
2882 but might still not be compilable; perform some more
2883 error-checking here. We do this here so that the error messages
2884 can contain a stringified version of "stmt", whilst appearing
2885 as close as possible to the point of failure. */
2886 lvalue
->verify_valid_within_stmt (__func__
, stmt
);
2887 rvalue
->verify_valid_within_stmt (__func__
, stmt
);
2890 /* Internal helper function for determining if rvalue BOOLVAL is of
2891 boolean type. For use by gcc_jit_block_end_with_conditional. */
2894 is_bool (gcc_jit_rvalue
*boolval
)
2896 gcc::jit::recording::type
*actual_type
= boolval
->get_type ();
2897 gcc::jit::recording::type
*bool_type
=
2898 boolval
->m_ctxt
->get_type (GCC_JIT_TYPE_BOOL
);
2899 return actual_type
== bool_type
;
2902 /* Public entrypoint. See description in libgccjit.h.
2904 After error-checking, the real work is done by the
2905 gcc::jit::recording::block::end_with_conditional method in
2906 jit-recording.cc. */
2909 gcc_jit_block_end_with_conditional (gcc_jit_block
*block
,
2910 gcc_jit_location
*loc
,
2911 gcc_jit_rvalue
*boolval
,
2912 gcc_jit_block
*on_true
,
2913 gcc_jit_block
*on_false
)
2915 RETURN_IF_NOT_VALID_BLOCK (block
, loc
);
2916 gcc::jit::recording::context
*ctxt
= block
->get_context ();
2917 JIT_LOG_FUNC (ctxt
->get_logger ());
2918 /* LOC can be NULL. */
2919 RETURN_IF_FAIL (boolval
, ctxt
, loc
, "NULL boolval");
2920 RETURN_IF_FAIL_PRINTF2 (
2921 is_bool (boolval
), ctxt
, loc
,
2922 "%s (type: %s) is not of boolean type ",
2923 boolval
->get_debug_string (),
2924 boolval
->get_type ()->get_debug_string ());
2925 RETURN_IF_FAIL (on_true
, ctxt
, loc
, "NULL on_true");
2926 RETURN_IF_FAIL (on_true
, ctxt
, loc
, "NULL on_false");
2927 RETURN_IF_FAIL_PRINTF4 (
2928 block
->get_function () == on_true
->get_function (),
2930 "\"on_true\" block is not in same function:"
2931 " source block %s is in function %s"
2932 " whereas target block %s is in function %s",
2933 block
->get_debug_string (),
2934 block
->get_function ()->get_debug_string (),
2935 on_true
->get_debug_string (),
2936 on_true
->get_function ()->get_debug_string ());
2937 RETURN_IF_FAIL_PRINTF4 (
2938 block
->get_function () == on_false
->get_function (),
2940 "\"on_false\" block is not in same function:"
2941 " source block %s is in function %s"
2942 " whereas target block %s is in function %s",
2943 block
->get_debug_string (),
2944 block
->get_function ()->get_debug_string (),
2945 on_false
->get_debug_string (),
2946 on_false
->get_function ()->get_debug_string ());
2948 gcc::jit::recording::statement
*stmt
= block
->end_with_conditional (loc
, boolval
, on_true
, on_false
);
2950 /* "stmt" should be good enough to be usable in error-messages,
2951 but might still not be compilable; perform some more
2952 error-checking here. We do this here so that the error messages
2953 can contain a stringified version of "stmt", whilst appearing
2954 as close as possible to the point of failure. */
2955 boolval
->verify_valid_within_stmt (__func__
, stmt
);
2958 /* Public entrypoint. See description in libgccjit.h.
2960 After error-checking, the real work is done by the
2961 gcc::jit::recording::block::add_comment method in
2962 jit-recording.cc. */
2965 gcc_jit_block_add_comment (gcc_jit_block
*block
,
2966 gcc_jit_location
*loc
,
2969 RETURN_IF_NOT_VALID_BLOCK (block
, loc
);
2970 gcc::jit::recording::context
*ctxt
= block
->get_context ();
2971 JIT_LOG_FUNC (ctxt
->get_logger ());
2972 /* LOC can be NULL. */
2973 RETURN_IF_FAIL (text
, ctxt
, loc
, "NULL text");
2975 block
->add_comment (loc
, text
);
2978 /* Public entrypoint. See description in libgccjit.h.
2980 After error-checking, the real work is done by the
2981 gcc::jit::recording::block::end_with_jump method in
2982 jit-recording.cc. */
2985 gcc_jit_block_end_with_jump (gcc_jit_block
*block
,
2986 gcc_jit_location
*loc
,
2987 gcc_jit_block
*target
)
2989 RETURN_IF_NOT_VALID_BLOCK (block
, loc
);
2990 gcc::jit::recording::context
*ctxt
= block
->get_context ();
2991 JIT_LOG_FUNC (ctxt
->get_logger ());
2992 /* LOC can be NULL. */
2993 RETURN_IF_FAIL (target
, ctxt
, loc
, "NULL target");
2994 RETURN_IF_FAIL_PRINTF4 (
2995 block
->get_function () == target
->get_function (),
2997 "target block is not in same function:"
2998 " source block %s is in function %s"
2999 " whereas target block %s is in function %s",
3000 block
->get_debug_string (),
3001 block
->get_function ()->get_debug_string (),
3002 target
->get_debug_string (),
3003 target
->get_function ()->get_debug_string ());
3005 block
->end_with_jump (loc
, target
);
3008 /* Public entrypoint. See description in libgccjit.h.
3010 After error-checking, the real work is done by the
3011 gcc::jit::recording::block::end_with_return method in
3012 jit-recording.cc. */
3015 gcc_jit_block_end_with_return (gcc_jit_block
*block
,
3016 gcc_jit_location
*loc
,
3017 gcc_jit_rvalue
*rvalue
)
3019 RETURN_IF_NOT_VALID_BLOCK (block
, loc
);
3020 gcc::jit::recording::context
*ctxt
= block
->get_context ();
3021 JIT_LOG_FUNC (ctxt
->get_logger ());
3022 /* LOC can be NULL. */
3023 gcc::jit::recording::function
*func
= block
->get_function ();
3024 RETURN_IF_FAIL (rvalue
, ctxt
, loc
, "NULL rvalue");
3025 RETURN_IF_FAIL_PRINTF4 (
3027 func
->get_return_type (),
3028 rvalue
->get_type ()),
3030 "mismatching types:"
3031 " return of %s (type: %s) in function %s (return type: %s)",
3032 rvalue
->get_debug_string (),
3033 rvalue
->get_type ()->get_debug_string (),
3034 func
->get_debug_string (),
3035 func
->get_return_type ()->get_debug_string ());
3037 gcc::jit::recording::statement
*stmt
= block
->end_with_return (loc
, rvalue
);
3039 /* "stmt" should be good enough to be usable in error-messages,
3040 but might still not be compilable; perform some more
3041 error-checking here. We do this here so that the error messages
3042 can contain a stringified version of "stmt", whilst appearing
3043 as close as possible to the point of failure. */
3044 rvalue
->verify_valid_within_stmt (__func__
, stmt
);
3047 /* Public entrypoint. See description in libgccjit.h.
3049 After error-checking, the real work is done by the
3050 gcc::jit::recording::block::end_with_return method in
3051 jit-recording.cc. */
3054 gcc_jit_block_end_with_void_return (gcc_jit_block
*block
,
3055 gcc_jit_location
*loc
)
3057 RETURN_IF_NOT_VALID_BLOCK (block
, loc
);
3058 gcc::jit::recording::context
*ctxt
= block
->get_context ();
3059 JIT_LOG_FUNC (ctxt
->get_logger ());
3060 /* LOC can be NULL. */
3061 gcc::jit::recording::function
*func
= block
->get_function ();
3062 RETURN_IF_FAIL_PRINTF2 (
3063 func
->get_return_type () == ctxt
->get_type (GCC_JIT_TYPE_VOID
),
3065 "mismatching types:"
3066 " void return in function %s (return type: %s)",
3067 func
->get_debug_string (),
3068 func
->get_return_type ()->get_debug_string ());
3070 block
->end_with_return (loc
, NULL
);
3073 /* Public entrypoint. See description in libgccjit.h.
3075 After error-checking, the real work is done by the
3076 gcc::jit::recording::context::new_case method in
3077 jit-recording.cc. */
3080 gcc_jit_context_new_case (gcc_jit_context
*ctxt
,
3081 gcc_jit_rvalue
*min_value
,
3082 gcc_jit_rvalue
*max_value
,
3083 gcc_jit_block
*block
)
3085 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3086 JIT_LOG_FUNC (ctxt
->get_logger ());
3087 RETURN_NULL_IF_FAIL (min_value
, ctxt
, NULL
, "NULL min_value");
3088 RETURN_NULL_IF_FAIL (max_value
, ctxt
, NULL
, "NULL max_value");
3089 RETURN_NULL_IF_FAIL (block
, ctxt
, NULL
, "NULL block");
3091 RETURN_NULL_IF_FAIL_PRINTF1 (min_value
->is_constant (), ctxt
, NULL
,
3092 "min_value is not a constant: %s",
3093 min_value
->get_debug_string ());
3094 RETURN_NULL_IF_FAIL_PRINTF1 (max_value
->is_constant (), ctxt
, NULL
,
3095 "max_value is not a constant: %s",
3096 max_value
->get_debug_string ());
3097 RETURN_NULL_IF_FAIL_PRINTF2 (
3098 min_value
->get_type ()->is_int (),
3100 "min_value: %s (type: %s) is not of integer type",
3101 min_value
->get_debug_string (),
3102 min_value
->get_type ()->get_debug_string ());
3103 RETURN_NULL_IF_FAIL_PRINTF2 (
3104 max_value
->get_type ()->is_int (),
3106 "max_value: %s (type: %s) is not of integer type",
3107 max_value
->get_debug_string (),
3108 max_value
->get_type ()->get_debug_string ());
3110 wide_int wi_min
, wi_max
;
3111 if (!min_value
->get_wide_int (&wi_min
))
3113 if (!max_value
->get_wide_int (&wi_max
))
3115 RETURN_NULL_IF_FAIL_PRINTF2 (
3116 wi::les_p (wi_min
, wi_max
),
3118 "min_value: %s > max_value: %s",
3119 min_value
->get_debug_string (),
3120 max_value
->get_debug_string ());
3121 return (gcc_jit_case
*)ctxt
->new_case (min_value
,
3126 /* Public entrypoint. See description in libgccjit.h.
3128 After error-checking, this calls the trivial
3129 gcc::jit::recording::memento::as_object method (a case is a
3130 memento), in jit-recording.h. */
3133 gcc_jit_case_as_object (gcc_jit_case
*case_
)
3135 RETURN_NULL_IF_FAIL (case_
, NULL
, NULL
, "NULL case");
3137 return static_cast <gcc_jit_object
*> (case_
->as_object ());
3140 /* Helper function for gcc_jit_block_end_with_switch and
3141 valid_case_for_switch. */
3144 valid_dest_for_switch (gcc::jit::recording::context
*ctxt
,
3145 gcc_jit_location
*loc
,
3146 const char *api_funcname
,
3147 gcc::jit::recording::block
*switch_block
,
3148 gcc::jit::recording::block
*dest_block
,
3149 const char *dest_block_desc
)
3153 jit_error (ctxt
, loc
, "%s: NULL %s", api_funcname
, dest_block_desc
);
3156 gcc::jit::recording::function
*switch_fn
= switch_block
->get_function ();
3157 gcc::jit::recording::function
*dest_fn
= dest_block
->get_function ();
3158 if (switch_fn
!= dest_fn
)
3160 jit_error (ctxt
, loc
,
3161 "%s: %s is not in same function:"
3162 " switch block %s is in function %s"
3163 " whereas %s %s is in function %s",
3166 switch_block
->get_debug_string (),
3167 switch_fn
->get_debug_string (),
3169 dest_block
->get_debug_string (),
3170 dest_fn
->get_debug_string ());
3176 /* Helper function for gcc_jit_block_end_with_switch. */
3179 valid_case_for_switch (gcc::jit::recording::context
*ctxt
,
3180 gcc_jit_location
*loc
,
3181 const char *api_funcname
,
3182 gcc_jit_block
*switch_block
,
3183 gcc_jit_rvalue
*expr
,
3184 gcc_jit_case
*case_
,
3185 const char *case_desc
,
3190 jit_error (ctxt
, loc
,
3197 if (!valid_dest_for_switch (ctxt
, loc
,
3200 case_
->get_dest_block (),
3203 gcc::jit::recording::type
*expr_type
= expr
->get_type ();
3204 if (expr_type
!= case_
->get_min_value ()->get_type ())
3206 jit_error (ctxt
, loc
,
3208 " mismatching types between case and expression:"
3209 " cases[%i]->min_value: %s (type: %s)"
3210 " expr: %s (type: %s)",
3213 case_
->get_min_value ()->get_debug_string (),
3214 case_
->get_min_value ()->get_type ()->get_debug_string (),
3215 expr
->get_debug_string (),
3216 expr_type
->get_debug_string ());
3219 if (expr_type
!= case_
->get_max_value ()->get_type ())
3221 jit_error (ctxt
, loc
,
3223 " mismatching types between case and expression:"
3224 " cases[%i]->max_value: %s (type: %s)"
3225 " expr: %s (type: %s)",
3228 case_
->get_max_value ()->get_debug_string (),
3229 case_
->get_max_value ()->get_type ()->get_debug_string (),
3230 expr
->get_debug_string (),
3231 expr_type
->get_debug_string ());
3237 /* A class for holding the data we need to perform error-checking
3238 on a libgccjit API call. */
3240 class api_call_validator
3243 api_call_validator (gcc::jit::recording::context
*ctxt
,
3244 gcc_jit_location
*loc
,
3245 const char *funcname
)
3248 m_funcname (funcname
)
3252 gcc::jit::recording::context
*m_ctxt
;
3253 gcc_jit_location
*m_loc
;
3254 const char *m_funcname
;
3257 /* A class for verifying that the ranges of cases within
3258 gcc_jit_block_end_with_switch don't overlap. */
3260 class case_range_validator
: public api_call_validator
3263 case_range_validator (gcc::jit::recording::context
*ctxt
,
3264 gcc_jit_location
*loc
,
3265 const char *funcname
);
3268 validate (gcc_jit_case
*case_
, int idx
);
3272 case_compare (gcc::jit::recording::rvalue
*k1
,
3273 gcc::jit::recording::rvalue
*k2
);
3276 get_wide_int (gcc::jit::recording::rvalue
*k
);
3279 typed_splay_tree
<gcc::jit::recording::rvalue
*, gcc_jit_case
*> m_cases
;
3282 /* case_range_validator's ctor. */
3284 case_range_validator::case_range_validator (gcc::jit::recording::context
*ctxt
,
3285 gcc_jit_location
*loc
,
3286 const char *funcname
)
3287 : api_call_validator (ctxt
, loc
, funcname
),
3288 m_cases (case_compare
, NULL
, NULL
)
3292 /* Ensure that the range of CASE_ does not overlap with any of the
3293 ranges of cases we've already seen.
3294 Return true if everything is OK.
3295 Return false and emit an error if there is an overlap.
3296 Compare with c-family/c-common.cc:c_add_case_label. */
3299 case_range_validator::validate (gcc_jit_case
*case_
,
3302 /* Look up the LOW_VALUE in the table of case labels we already
3304 gcc_jit_case
*other
= m_cases
.lookup (case_
->get_min_value ());
3306 /* If there was not an exact match, check for overlapping ranges. */
3312 /* Even though there wasn't an exact match, there might be an
3313 overlap between this case range and another case range.
3314 Since we've (inductively) not allowed any overlapping case
3315 ranges, we simply need to find the greatest low case label
3316 that is smaller that CASE_MIN_VALUE, and the smallest low case
3317 label that is greater than CASE_MAX_VALUE. If there is an overlap
3318 it will occur in one of these two ranges. */
3319 pred
= m_cases
.predecessor (case_
->get_min_value ());
3320 succ
= m_cases
.successor (case_
->get_max_value ());
3322 /* Check to see if the PRED overlaps. It is smaller than
3323 the LOW_VALUE, so we only need to check its max value. */
3326 wide_int wi_case_min
= get_wide_int (case_
->get_min_value ());
3327 wide_int wi_pred_max
= get_wide_int (pred
->get_max_value ());
3328 if (wi::ges_p (wi_pred_max
, wi_case_min
))
3334 /* Check to see if the SUCC overlaps. The low end of that
3335 range is bigger than the low end of the current range. */
3336 wide_int wi_case_max
= get_wide_int (case_
->get_max_value ());
3337 wide_int wi_succ_min
= get_wide_int (succ
->get_min_value ());
3338 if (wi::les_p (wi_succ_min
, wi_case_max
))
3343 /* If there was an overlap, issue an error. */
3346 jit_error (m_ctxt
, m_loc
,
3347 "%s: duplicate (or overlapping) cases values:"
3348 " case %i: %s overlaps %s",
3351 case_
->get_debug_string (),
3352 other
->get_debug_string ());
3356 /* Register this case label in the splay tree. */
3357 m_cases
.insert (case_
->get_min_value (),
3362 /* Compare with c-family/c-common.cc:case_compare, which acts on tree
3363 nodes, rather than rvalue *.
3365 Comparator for case label values. K1 and K2 must be constant integer
3366 values (anything else should have been rejected by
3367 gcc_jit_context_new_case.
3369 Returns -1 if K1 is ordered before K2, -1 if K1 is ordered after
3370 K2, and 0 if K1 and K2 are equal. */
3373 case_range_validator::case_compare (gcc::jit::recording::rvalue
* k1
,
3374 gcc::jit::recording::rvalue
* k2
)
3376 wide_int wi1
= get_wide_int (k1
);
3377 wide_int wi2
= get_wide_int (k2
);
3378 return wi::cmps(wi1
, wi2
);
3381 /* Given a const int rvalue K, get the underlying value as a wide_int. */
3384 case_range_validator::get_wide_int (gcc::jit::recording::rvalue
*k
)
3387 bool got_wi
= k
->get_wide_int (&wi
);
3388 gcc_assert (got_wi
);
3392 /* Public entrypoint. See description in libgccjit.h.
3394 After error-checking, the real work is done by the
3395 gcc::jit::recording::block::end_with_switch method in
3396 jit-recording.cc. */
3399 gcc_jit_block_end_with_switch (gcc_jit_block
*block
,
3400 gcc_jit_location
*loc
,
3401 gcc_jit_rvalue
*expr
,
3402 gcc_jit_block
*default_block
,
3404 gcc_jit_case
**cases
)
3406 RETURN_IF_NOT_VALID_BLOCK (block
, loc
);
3407 gcc::jit::recording::context
*ctxt
= block
->get_context ();
3408 JIT_LOG_FUNC (ctxt
->get_logger ());
3409 /* LOC can be NULL. */
3410 RETURN_IF_FAIL (expr
, ctxt
, loc
,
3412 gcc::jit::recording::type
*expr_type
= expr
->get_type ();
3413 RETURN_IF_FAIL_PRINTF2 (
3414 expr_type
->is_int (),
3416 "expr: %s (type: %s) is not of integer type",
3417 expr
->get_debug_string (),
3418 expr_type
->get_debug_string ());
3419 if (!valid_dest_for_switch (ctxt
, loc
,
3425 RETURN_IF_FAIL (num_cases
>= 0, ctxt
, loc
, "num_cases < 0");
3426 case_range_validator
crv (ctxt
, loc
, __func__
);
3427 for (int i
= 0; i
< num_cases
; i
++)
3430 snprintf (case_desc
, sizeof (case_desc
),
3432 if (!valid_case_for_switch (ctxt
, loc
,
3440 if (!crv
.validate (cases
[i
], i
))
3444 block
->end_with_switch (loc
, expr
, default_block
,
3446 (gcc::jit::recording::case_
**)cases
);
3449 /**********************************************************************
3451 **********************************************************************/
3453 /* Public entrypoint. See description in libgccjit.h.
3455 After error-checking, the real work is done by the
3456 gcc::jit::recording::context::set_str_option method in
3457 jit-recording.cc. */
3460 gcc_jit_context_set_str_option (gcc_jit_context
*ctxt
,
3461 enum gcc_jit_str_option opt
,
3464 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3465 JIT_LOG_FUNC (ctxt
->get_logger ());
3466 /* opt is checked by the inner function.
3467 value can be NULL. */
3469 ctxt
->set_str_option (opt
, value
);
3472 /* Public entrypoint. See description in libgccjit.h.
3474 After error-checking, the real work is done by the
3475 gcc::jit::recording::context::set_int_option method in
3476 jit-recording.cc. */
3479 gcc_jit_context_set_int_option (gcc_jit_context
*ctxt
,
3480 enum gcc_jit_int_option opt
,
3483 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3484 JIT_LOG_FUNC (ctxt
->get_logger ());
3485 /* opt is checked by the inner function. */
3487 ctxt
->set_int_option (opt
, value
);
3490 /* Public entrypoint. See description in libgccjit.h.
3492 After error-checking, the real work is done by the
3493 gcc::jit::recording::context::set_bool_option method in
3494 jit-recording.cc. */
3497 gcc_jit_context_set_bool_option (gcc_jit_context
*ctxt
,
3498 enum gcc_jit_bool_option opt
,
3501 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3502 JIT_LOG_FUNC (ctxt
->get_logger ());
3503 /* opt is checked by the inner function. */
3505 ctxt
->set_bool_option (opt
, value
);
3508 /* Public entrypoint. See description in libgccjit.h.
3510 After error-checking, the real work is done by the
3511 gcc::jit::recording::context::set_inner_bool_option method in
3512 jit-recording.cc. */
3515 gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context
*ctxt
,
3518 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3519 JIT_LOG_FUNC (ctxt
->get_logger ());
3520 ctxt
->set_inner_bool_option (
3521 gcc::jit::INNER_BOOL_OPTION_ALLOW_UNREACHABLE_BLOCKS
,
3525 /* Public entrypoint. See description in libgccjit.h.
3527 After error-checking, the real work is done by the
3528 gcc::jit::recording::context::set_inner_bool_option method in
3529 jit-recording.cc. */
3532 gcc_jit_context_set_bool_print_errors_to_stderr (gcc_jit_context
*ctxt
,
3535 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3536 JIT_LOG_FUNC (ctxt
->get_logger ());
3537 ctxt
->set_inner_bool_option (
3538 gcc::jit::INNER_BOOL_OPTION_PRINT_ERRORS_TO_STDERR
,
3542 /* Public entrypoint. See description in libgccjit.h.
3544 After error-checking, the real work is done by the
3545 gcc::jit::recording::context::set_inner_bool_option method in
3546 jit-recording.cc. */
3549 gcc_jit_context_set_bool_use_external_driver (gcc_jit_context
*ctxt
,
3552 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3553 JIT_LOG_FUNC (ctxt
->get_logger ());
3554 ctxt
->set_inner_bool_option (
3555 gcc::jit::INNER_BOOL_OPTION_USE_EXTERNAL_DRIVER
,
3559 /* Public entrypoint. See description in libgccjit.h.
3561 After error-checking, the real work is done by the
3562 gcc::jit::recording::context::add_command_line_option method in
3563 jit-recording.cc. */
3566 gcc_jit_context_add_command_line_option (gcc_jit_context
*ctxt
,
3567 const char *optname
)
3569 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3570 JIT_LOG_FUNC (ctxt
->get_logger ());
3571 RETURN_IF_FAIL (optname
, ctxt
, NULL
, "NULL optname");
3572 if (ctxt
->get_logger ())
3573 ctxt
->get_logger ()->log ("optname: %s", optname
);
3575 ctxt
->add_command_line_option (optname
);
3578 /* Public entrypoint. See description in libgccjit.h.
3580 The real work is done by the
3581 gcc::jit::recording::context::add_driver_option method in
3582 jit-recording.cc. */
3585 gcc_jit_context_add_driver_option (gcc_jit_context
*ctxt
,
3586 const char *optname
)
3588 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3589 JIT_LOG_FUNC (ctxt
->get_logger ());
3590 RETURN_IF_FAIL (optname
, ctxt
, NULL
, "NULL optname");
3591 if (ctxt
->get_logger ())
3592 ctxt
->get_logger ()->log ("optname: %s", optname
);
3594 ctxt
->add_driver_option (optname
);
3597 /* Public entrypoint. See description in libgccjit.h.
3599 After error-checking, the real work is done by the
3600 gcc::jit::recording::context::enable_dump method in
3601 jit-recording.cc. */
3604 gcc_jit_context_enable_dump (gcc_jit_context
*ctxt
,
3605 const char *dumpname
,
3608 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3609 JIT_LOG_FUNC (ctxt
->get_logger ());
3610 RETURN_IF_FAIL (dumpname
, ctxt
, NULL
, "NULL dumpname");
3611 RETURN_IF_FAIL (out_ptr
, ctxt
, NULL
, "NULL out_ptr");
3613 ctxt
->enable_dump (dumpname
, out_ptr
);
3616 /* Public entrypoint. See description in libgccjit.h.
3618 After error-checking, the real work is done by the
3619 gcc::jit::recording::context::compile method in
3620 jit-recording.cc. */
3623 gcc_jit_context_compile (gcc_jit_context
*ctxt
)
3625 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3627 JIT_LOG_FUNC (ctxt
->get_logger ());
3629 ctxt
->log ("in-memory compile of ctxt: %p", (void *)ctxt
);
3631 gcc_jit_result
*result
= (gcc_jit_result
*)ctxt
->compile ();
3633 ctxt
->log ("%s: returning (gcc_jit_result *)%p",
3634 __func__
, (void *)result
);
3639 /* Public entrypoint. See description in libgccjit.h.
3641 After error-checking, the real work is done by the
3642 gcc::jit::recording::context::compile_to_file method in
3643 jit-recording.cc. */
3646 gcc_jit_context_compile_to_file (gcc_jit_context
*ctxt
,
3647 enum gcc_jit_output_kind output_kind
,
3648 const char *output_path
)
3650 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3651 JIT_LOG_FUNC (ctxt
->get_logger ());
3652 RETURN_IF_FAIL_PRINTF1 (
3653 ((output_kind
>= GCC_JIT_OUTPUT_KIND_ASSEMBLER
)
3654 && (output_kind
<= GCC_JIT_OUTPUT_KIND_EXECUTABLE
)),
3656 "unrecognized output_kind: %i",
3658 RETURN_IF_FAIL (output_path
, ctxt
, NULL
, "NULL output_path");
3660 ctxt
->log ("compile_to_file of ctxt: %p", (void *)ctxt
);
3661 ctxt
->log ("output_kind: %i", output_kind
);
3662 ctxt
->log ("output_path: %s", output_path
);
3664 ctxt
->compile_to_file (output_kind
, output_path
);
3668 /* Public entrypoint. See description in libgccjit.h.
3670 After error-checking, the real work is done by the
3671 gcc::jit::recording::context::dump_to_file method in
3672 jit-recording.cc. */
3675 gcc_jit_context_dump_to_file (gcc_jit_context
*ctxt
,
3677 int update_locations
)
3679 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3680 JIT_LOG_FUNC (ctxt
->get_logger ());
3681 RETURN_IF_FAIL (path
, ctxt
, NULL
, "NULL path");
3682 ctxt
->dump_to_file (path
, update_locations
);
3685 /* Public entrypoint. See description in libgccjit.h. */
3688 gcc_jit_context_set_logfile (gcc_jit_context
*ctxt
,
3693 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3694 JIT_LOG_FUNC (ctxt
->get_logger ());
3695 RETURN_IF_FAIL ((flags
== 0), ctxt
, NULL
, "flags must be 0 for now");
3696 RETURN_IF_FAIL ((verbosity
== 0), ctxt
, NULL
, "verbosity must be 0 for now");
3698 gcc::jit::logger
*logger
;
3700 logger
= new gcc::jit::logger (logfile
, flags
, verbosity
);
3703 ctxt
->set_logger (logger
);
3706 /* Public entrypoint. See description in libgccjit.h.
3708 After error-checking, the real work is done by the
3709 gcc::jit::recording::context::dump_reproducer_to_file method in
3710 jit-recording.cc. */
3713 gcc_jit_context_dump_reproducer_to_file (gcc_jit_context
*ctxt
,
3716 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3717 JIT_LOG_FUNC (ctxt
->get_logger ());
3718 RETURN_IF_FAIL (path
, ctxt
, NULL
, "NULL path");
3719 ctxt
->dump_reproducer_to_file (path
);
3722 /* Public entrypoint. See description in libgccjit.h.
3724 After error-checking, the real work is done by the
3725 gcc::jit::recording::context::get_first_error method in
3726 jit-recording.cc. */
3729 gcc_jit_context_get_first_error (gcc_jit_context
*ctxt
)
3731 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3732 JIT_LOG_FUNC (ctxt
->get_logger ());
3734 return ctxt
->get_first_error ();
3737 /* Public entrypoint. See description in libgccjit.h.
3739 After error-checking, the real work is done by the
3740 gcc::jit::recording::context::get_last_error method in
3741 jit-recording.cc. */
3744 gcc_jit_context_get_last_error (gcc_jit_context
*ctxt
)
3746 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL context");
3748 return ctxt
->get_last_error ();
3751 /* Public entrypoint. See description in libgccjit.h.
3753 After error-checking, the real work is done by the
3754 gcc::jit::result::get_code method in jit-result.cc. */
3757 gcc_jit_result_get_code (gcc_jit_result
*result
,
3760 RETURN_NULL_IF_FAIL (result
, NULL
, NULL
, "NULL result");
3761 JIT_LOG_FUNC (result
->get_logger ());
3762 RETURN_NULL_IF_FAIL (fnname
, NULL
, NULL
, "NULL fnname");
3764 result
->log ("locating fnname: %s", fnname
);
3765 void *code
= result
->get_code (fnname
);
3766 result
->log ("%s: returning (void *)%p", __func__
, code
);
3771 /* Public entrypoint. See description in libgccjit.h.
3773 After error-checking, the real work is done by the
3774 gcc::jit::result::get_global method in jit-result.cc. */
3777 gcc_jit_result_get_global (gcc_jit_result
*result
,
3780 RETURN_NULL_IF_FAIL (result
, NULL
, NULL
, "NULL result");
3781 JIT_LOG_FUNC (result
->get_logger ());
3782 RETURN_NULL_IF_FAIL (name
, NULL
, NULL
, "NULL name");
3784 void *global
= result
->get_global (name
);
3785 result
->log ("%s: returning (void *)%p", __func__
, global
);
3790 /* Public entrypoint. See description in libgccjit.h.
3792 After error-checking, this is essentially a wrapper around the
3793 destructor for gcc::jit::result in jit-result.cc. */
3796 gcc_jit_result_release (gcc_jit_result
*result
)
3798 RETURN_IF_FAIL (result
, NULL
, NULL
, "NULL result");
3799 JIT_LOG_FUNC (result
->get_logger ());
3800 result
->log ("deleting result: %p", (void *)result
);
3804 /**********************************************************************
3806 **********************************************************************/
3808 /* Create a gcc_jit_timer instance, and start timing. */
3811 gcc_jit_timer_new (void)
3813 gcc_jit_timer
*timer
= new gcc_jit_timer ();
3814 timer
->start (TV_TOTAL
);
3815 timer
->push (TV_JIT_CLIENT_CODE
);
3819 /* Release a gcc_jit_timer instance. */
3822 gcc_jit_timer_release (gcc_jit_timer
*timer
)
3824 RETURN_IF_FAIL (timer
, NULL
, NULL
, "NULL timer");
3829 /* Associate a gcc_jit_timer instance with a context. */
3832 gcc_jit_context_set_timer (gcc_jit_context
*ctxt
,
3833 gcc_jit_timer
*timer
)
3835 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL ctxt");
3836 RETURN_IF_FAIL (timer
, ctxt
, NULL
, "NULL timer");
3838 ctxt
->set_timer (timer
);
3841 /* Get the timer associated with a context (if any). */
3844 gcc_jit_context_get_timer (gcc_jit_context
*ctxt
)
3846 RETURN_NULL_IF_FAIL (ctxt
, NULL
, NULL
, "NULL ctxt");
3848 return (gcc_jit_timer
*)ctxt
->get_timer ();
3851 /* Push the given item onto the timing stack. */
3854 gcc_jit_timer_push (gcc_jit_timer
*timer
,
3855 const char *item_name
)
3857 RETURN_IF_FAIL (timer
, NULL
, NULL
, "NULL timer");
3858 RETURN_IF_FAIL (item_name
, NULL
, NULL
, "NULL item_name");
3859 timer
->push_client_item (item_name
);
3862 /* Pop the top item from the timing stack. */
3865 gcc_jit_timer_pop (gcc_jit_timer
*timer
,
3866 const char *item_name
)
3868 RETURN_IF_FAIL (timer
, NULL
, NULL
, "NULL timer");
3872 const char *top_item_name
= timer
->get_topmost_item_name ();
3874 RETURN_IF_FAIL_PRINTF1
3875 (top_item_name
, NULL
, NULL
,
3876 "pop of empty timing stack (attempting to pop: \"%s\")",
3879 RETURN_IF_FAIL_PRINTF2
3880 (strcmp (item_name
, top_item_name
) == 0, NULL
, NULL
,
3881 "mismatching item_name:"
3882 " top of timing stack: \"%s\","
3883 " attempting to pop: \"%s\"",
3888 timer
->pop_client_item ();
3891 /* Print timing information to the given stream about activity since
3892 the timer was started. */
3895 gcc_jit_timer_print (gcc_jit_timer
*timer
,
3898 RETURN_IF_FAIL (timer
, NULL
, NULL
, "NULL timer");
3899 RETURN_IF_FAIL (f_out
, NULL
, NULL
, "NULL f_out");
3901 timer
->pop (TV_JIT_CLIENT_CODE
);
3902 timer
->stop (TV_TOTAL
);
3903 timer
->print (f_out
);
3904 timer
->start (TV_TOTAL
);
3905 timer
->push (TV_JIT_CLIENT_CODE
);
3908 /* Public entrypoint. See description in libgccjit.h.
3910 After error-checking, the real work is effectively done by the
3911 gcc::jit::base_call::set_require_tail_call setter in jit-recording.h. */
3914 gcc_jit_rvalue_set_bool_require_tail_call (gcc_jit_rvalue
*rvalue
,
3915 int require_tail_call
)
3917 RETURN_IF_FAIL (rvalue
, NULL
, NULL
, "NULL call");
3918 JIT_LOG_FUNC (rvalue
->get_context ()->get_logger ());
3920 /* Verify that it's a call. */
3921 gcc::jit::recording::base_call
*call
= rvalue
->dyn_cast_base_call ();
3922 RETURN_IF_FAIL_PRINTF1 (call
, NULL
, NULL
, "not a call: %s",
3923 rvalue
->get_debug_string ());
3925 call
->set_require_tail_call (require_tail_call
);
3928 /* Public entrypoint. See description in libgccjit.h.
3930 After error-checking, the real work is done by the
3931 gcc::jit::recording::type::get_aligned method, in
3932 jit-recording.cc. */
3935 gcc_jit_type_get_aligned (gcc_jit_type
*type
,
3936 size_t alignment_in_bytes
)
3938 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
3940 gcc::jit::recording::context
*ctxt
= type
->m_ctxt
;
3942 JIT_LOG_FUNC (ctxt
->get_logger ());
3944 RETURN_NULL_IF_FAIL_PRINTF1
3945 (pow2_or_zerop (alignment_in_bytes
), ctxt
, NULL
,
3946 "alignment not a power of two: %zi",
3947 alignment_in_bytes
);
3948 RETURN_NULL_IF_FAIL (!type
->is_void (), ctxt
, NULL
, "void type");
3950 return (gcc_jit_type
*)type
->get_aligned (alignment_in_bytes
);
3953 /* Public entrypoint. See description in libgccjit.h.
3955 After error-checking, the real work is done by the
3956 gcc::jit::recording::type::get_vector method, in
3957 jit-recording.cc. */
3960 gcc_jit_type_get_vector (gcc_jit_type
*type
, size_t num_units
)
3962 RETURN_NULL_IF_FAIL (type
, NULL
, NULL
, "NULL type");
3964 gcc::jit::recording::context
*ctxt
= type
->m_ctxt
;
3966 JIT_LOG_FUNC (ctxt
->get_logger ());
3968 RETURN_NULL_IF_FAIL_PRINTF1
3969 (type
->is_int () || type
->is_float (), ctxt
, NULL
,
3970 "type is not integral or floating point: %s",
3971 type
->get_debug_string ());
3973 RETURN_NULL_IF_FAIL_PRINTF1
3974 (pow2_or_zerop (num_units
), ctxt
, NULL
,
3975 "num_units not a power of two: %zi",
3978 return (gcc_jit_type
*)type
->get_vector (num_units
);
3981 /* Public entrypoint. See description in libgccjit.h.
3983 After error-checking, the real work is done by the
3984 gcc::jit::recording::function::get_address method, in
3985 jit-recording.cc. */
3988 gcc_jit_function_get_address (gcc_jit_function
*fn
,
3989 gcc_jit_location
*loc
)
3991 RETURN_NULL_IF_FAIL (fn
, NULL
, NULL
, "NULL function");
3993 gcc::jit::recording::context
*ctxt
= fn
->m_ctxt
;
3995 JIT_LOG_FUNC (ctxt
->get_logger ());
3996 /* LOC can be NULL. */
3998 return (gcc_jit_rvalue
*)fn
->get_address (loc
);
4001 /* Public entrypoint. See description in libgccjit.h.
4003 After error-checking, the real work is done by the
4004 gcc::jit::recording::context::new_rvalue_from_vector method, in
4005 jit-recording.cc. */
4007 extern gcc_jit_rvalue
*
4008 gcc_jit_context_new_rvalue_from_vector (gcc_jit_context
*ctxt
,
4009 gcc_jit_location
*loc
,
4010 gcc_jit_type
*vec_type
,
4011 size_t num_elements
,
4012 gcc_jit_rvalue
**elements
)
4014 RETURN_NULL_IF_FAIL (ctxt
, NULL
, loc
, "NULL ctxt");
4015 JIT_LOG_FUNC (ctxt
->get_logger ());
4017 /* LOC can be NULL. */
4018 RETURN_NULL_IF_FAIL (vec_type
, ctxt
, loc
, "NULL vec_type");
4020 /* "vec_type" must be a vector type. */
4021 gcc::jit::recording::vector_type
*as_vec_type
4022 = vec_type
->dyn_cast_vector_type ();
4023 RETURN_NULL_IF_FAIL_PRINTF1 (as_vec_type
, ctxt
, loc
,
4024 "%s is not a vector type",
4025 vec_type
->get_debug_string ());
4027 /* "num_elements" must match. */
4028 RETURN_NULL_IF_FAIL_PRINTF1 (
4029 num_elements
== as_vec_type
->get_num_units (), ctxt
, loc
,
4030 "num_elements != %zi", as_vec_type
->get_num_units ());
4032 /* "elements must be non-NULL. */
4033 RETURN_NULL_IF_FAIL (elements
, ctxt
, loc
, "NULL elements");
4035 /* Each of "elements" must be non-NULL and of the correct type. */
4036 gcc::jit::recording::type
*element_type
4037 = as_vec_type
->get_element_type ();
4038 for (size_t i
= 0; i
< num_elements
; i
++)
4040 RETURN_NULL_IF_FAIL_PRINTF1 (
4041 elements
[i
], ctxt
, loc
, "NULL elements[%zi]", i
);
4042 RETURN_NULL_IF_FAIL_PRINTF4 (
4043 compatible_types (element_type
,
4044 elements
[i
]->get_type ()),
4046 "mismatching type for element[%zi] (expected type: %s): %s (type: %s)",
4048 element_type
->get_debug_string (),
4049 elements
[i
]->get_debug_string (),
4050 elements
[i
]->get_type ()->get_debug_string ());
4053 return (gcc_jit_rvalue
*)ctxt
->new_rvalue_from_vector
4056 (gcc::jit::recording::rvalue
**)elements
);
4059 /* A mutex around the cached state in parse_basever.
4060 Ideally this would be within parse_basever, but the mutex is only needed
4063 static std::mutex version_mutex
;
4065 struct jit_version_info
4067 /* Default constructor. Populate via parse_basever,
4068 guarded by version_mutex. */
4071 std::lock_guard
<std::mutex
> g (version_mutex
);
4072 parse_basever (&major
, &minor
, &patchlevel
);
4082 gcc_jit_version_major (void)
4084 jit_version_info vi
;
4089 gcc_jit_version_minor (void)
4091 jit_version_info vi
;
4096 gcc_jit_version_patchlevel (void)
4098 jit_version_info vi
;
4099 return vi
.patchlevel
;
4102 /**********************************************************************
4104 **********************************************************************/
4106 /* Public entrypoint. See description in libgccjit.h.
4108 After error-checking, the real work is done by the
4109 gcc::jit::recording::block::add_extended_asm, in
4110 jit-recording.cc. */
4112 gcc_jit_extended_asm
*
4113 gcc_jit_block_add_extended_asm (gcc_jit_block
*block
,
4114 gcc_jit_location
*loc
,
4115 const char *asm_template
)
4117 RETURN_NULL_IF_NOT_VALID_BLOCK (block
, loc
);
4118 gcc::jit::recording::context
*ctxt
= block
->get_context ();
4119 JIT_LOG_FUNC (ctxt
->get_logger ());
4120 /* LOC can be NULL. */
4121 RETURN_NULL_IF_FAIL (asm_template
, ctxt
, loc
, "NULL asm_template");
4123 return (gcc_jit_extended_asm
*)block
->add_extended_asm (loc
, asm_template
);
4126 /* Public entrypoint. See description in libgccjit.h.
4128 After error-checking, the real work is done by the
4129 gcc::jit::recording::block::end_with_extended_asm_goto, in
4130 jit-recording.cc. */
4132 gcc_jit_extended_asm
*
4133 gcc_jit_block_end_with_extended_asm_goto (gcc_jit_block
*block
,
4134 gcc_jit_location
*loc
,
4135 const char *asm_template
,
4136 int num_goto_blocks
,
4137 gcc_jit_block
**goto_blocks
,
4138 gcc_jit_block
*fallthrough_block
)
4140 RETURN_NULL_IF_NOT_VALID_BLOCK (block
, loc
);
4141 gcc::jit::recording::context
*ctxt
= block
->get_context ();
4142 JIT_LOG_FUNC (ctxt
->get_logger ());
4143 /* LOC can be NULL. */
4144 RETURN_NULL_IF_FAIL (asm_template
, ctxt
, loc
, "NULL asm_template");
4145 RETURN_NULL_IF_FAIL (num_goto_blocks
>= 0, ctxt
, loc
, "num_goto_blocks < 0");
4146 for (int i
= 0; i
< num_goto_blocks
; i
++)
4147 RETURN_NULL_IF_FAIL_PRINTF1 (goto_blocks
[i
],
4149 "NULL goto_blocks[%i]", i
);
4150 /* fallthrough_block can be NULL. */
4151 return (gcc_jit_extended_asm
*)block
->end_with_extended_asm_goto
4153 num_goto_blocks
, (gcc::jit::recording::block
**)goto_blocks
,
4157 /* Public entrypoint. See description in libgccjit.h.
4159 After error-checking, this calls the trivial
4160 gcc::jit::recording::memento::as_object method (an extended_asm is a
4161 memento), in jit-recording.h. */
4164 gcc_jit_extended_asm_as_object (gcc_jit_extended_asm
*ext_asm
)
4166 RETURN_NULL_IF_FAIL (ext_asm
, NULL
, NULL
, "NULL ext_asm");
4168 return static_cast <gcc_jit_object
*> (ext_asm
->as_object ());
4171 /* Public entrypoint. See description in libgccjit.h.
4173 After error-checking, the real work is done by the
4174 gcc::jit::recording::extended_asm::set_volatile_flag, in
4175 jit-recording.cc. */
4178 gcc_jit_extended_asm_set_volatile_flag (gcc_jit_extended_asm
*ext_asm
,
4181 RETURN_IF_FAIL (ext_asm
, NULL
, NULL
, "NULL ext_asm");
4182 ext_asm
->set_volatile_flag (flag
);
4185 /* Public entrypoint. See description in libgccjit.h.
4187 After error-checking, the real work is done by the
4188 gcc::jit::recording::extended_asm::set_inline_flag, in
4189 jit-recording.cc. */
4192 gcc_jit_extended_asm_set_inline_flag (gcc_jit_extended_asm
*ext_asm
,
4195 RETURN_IF_FAIL (ext_asm
, NULL
, NULL
, "NULL ext_asm");
4196 ext_asm
->set_inline_flag (flag
);
4199 /* Public entrypoint. See description in libgccjit.h.
4201 After error-checking, the real work is done by the
4202 gcc::jit::recording::extended_asm::add_output_operand, in
4203 jit-recording.cc. */
4206 gcc_jit_extended_asm_add_output_operand (gcc_jit_extended_asm
*ext_asm
,
4207 const char *asm_symbolic_name
,
4208 const char *constraint
,
4209 gcc_jit_lvalue
*dest
)
4211 RETURN_IF_FAIL (ext_asm
, NULL
, NULL
, "NULL ext_asm");
4212 gcc::jit::recording::context
*ctxt
= ext_asm
->get_context ();
4213 JIT_LOG_FUNC (ctxt
->get_logger ());
4214 gcc::jit::recording::location
*loc
= ext_asm
->get_loc ();
4215 /* asm_symbolic_name can be NULL. */
4216 RETURN_IF_FAIL (constraint
, ctxt
, loc
, "NULL constraint");
4217 RETURN_IF_FAIL (dest
, ctxt
, loc
, "NULL dest");
4218 RETURN_IF_FAIL (!ext_asm
->is_goto (), ctxt
, loc
,
4219 "cannot add output operand to asm goto");
4220 ext_asm
->add_output_operand (asm_symbolic_name
, constraint
, dest
);
4223 /* Public entrypoint. See description in libgccjit.h.
4225 After error-checking, the real work is done by the
4226 gcc::jit::recording::extended_asm::add_input_operand, in
4227 jit-recording.cc. */
4230 gcc_jit_extended_asm_add_input_operand (gcc_jit_extended_asm
*ext_asm
,
4231 const char *asm_symbolic_name
,
4232 const char *constraint
,
4233 gcc_jit_rvalue
*src
)
4235 RETURN_IF_FAIL (ext_asm
, NULL
, NULL
, "NULL ext_asm");
4236 gcc::jit::recording::context
*ctxt
= ext_asm
->get_context ();
4237 JIT_LOG_FUNC (ctxt
->get_logger ());
4238 gcc::jit::recording::location
*loc
= ext_asm
->get_loc ();
4239 /* asm_symbolic_name can be NULL. */
4240 RETURN_IF_FAIL (constraint
, ctxt
, loc
, "NULL constraint");
4241 RETURN_IF_FAIL (src
, ctxt
, loc
, "NULL src");
4242 ext_asm
->add_input_operand (asm_symbolic_name
, constraint
, src
);
4245 /* Public entrypoint. See description in libgccjit.h.
4247 After error-checking, the real work is done by the
4248 gcc::jit::recording::extended_asm::add_clobber, in
4249 jit-recording.cc. */
4252 gcc_jit_extended_asm_add_clobber (gcc_jit_extended_asm
*ext_asm
,
4255 RETURN_IF_FAIL (ext_asm
, NULL
, NULL
, "NULL ext_asm");
4256 gcc::jit::recording::context
*ctxt
= ext_asm
->get_context ();
4257 JIT_LOG_FUNC (ctxt
->get_logger ());
4258 gcc::jit::recording::location
*loc
= ext_asm
->get_loc ();
4259 RETURN_IF_FAIL (victim
, ctxt
, loc
, "NULL victim");
4260 ext_asm
->add_clobber (victim
);
4263 /* Public entrypoint. See description in libgccjit.h.
4265 After error-checking, the real work is done by the
4266 gcc::jit::recording::context::add_top_level_asm, in
4267 jit-recording.cc. */
4270 gcc_jit_context_add_top_level_asm (gcc_jit_context
*ctxt
,
4271 gcc_jit_location
*loc
,
4272 const char *asm_stmts
)
4274 RETURN_IF_FAIL (ctxt
, NULL
, NULL
, "NULL ctxt");
4275 JIT_LOG_FUNC (ctxt
->get_logger ());
4276 /* LOC can be NULL. */
4277 RETURN_IF_FAIL (asm_stmts
, ctxt
, NULL
, "NULL asm_stmts");
4278 ctxt
->add_top_level_asm (loc
, asm_stmts
);