1 /* A C++ API for libgccjit, purely as inline wrapper functions.
2 Copyright (C) 2014-2023 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef LIBGCCJIT_PLUS_PLUS_H
21 #define LIBGCCJIT_PLUS_PLUS_H
23 #include "libgccjit.h"
29 /****************************************************************************
31 ****************************************************************************/
35 /* Indentation indicates inheritance. */
55 /* Errors within the API become C++ exceptions of this class. */
63 context
get_context () const;
65 std::string
get_debug_string () const;
69 object (gcc_jit_object
*obj
);
71 gcc_jit_object
*get_inner_object () const;
74 gcc_jit_object
*m_inner_obj
;
77 inline std::ostream
& operator << (std::ostream
& stream
, const object
&obj
);
79 /* Some client code will want to supply source code locations, others
80 won't. To avoid doubling the number of entrypoints, everything
81 accepting a location also has a default argument. To do this, the
82 other classes need to see that "location" has a default constructor,
83 hence we need to declare it first. */
84 class location
: public object
88 location (gcc_jit_location
*loc
);
90 gcc_jit_location
*get_inner_location () const;
96 static context
acquire ();
98 context (gcc_jit_context
*ctxt
);
100 gccjit::context
new_child_context ();
102 gcc_jit_context
*get_inner_context () { return m_inner_ctxt
; }
106 gcc_jit_result
*compile ();
108 void compile_to_file (enum gcc_jit_output_kind output_kind
,
109 const char *output_path
);
111 void dump_to_file (const std::string
&path
,
112 bool update_locations
);
114 void set_logfile (FILE *logfile
,
118 void dump_reproducer_to_file (const char *path
);
120 void set_str_option (enum gcc_jit_str_option opt
,
123 void set_int_option (enum gcc_jit_int_option opt
,
126 void set_bool_option (enum gcc_jit_bool_option opt
,
129 void set_bool_allow_unreachable_blocks (int bool_value
);
130 void set_bool_use_external_driver (int bool_value
);
132 void add_command_line_option (const char *optname
);
133 void add_driver_option (const char *optname
);
135 void set_timer (gccjit::timer t
);
136 gccjit::timer
get_timer () const;
139 new_location (const std::string
&filename
,
143 type
get_type (enum gcc_jit_types kind
);
144 type
get_int_type (size_t num_bytes
, int is_signed
);
146 /* A way to map a specific int type, using the compiler to
147 get the details automatically e.g.:
148 gccjit::type type = get_int_type <my_int_type_t> (); */
149 template <typename T
>
150 type
get_int_type ();
152 type
new_array_type (type element_type
, int num_elements
,
153 location loc
= location ());
155 field
new_field (type type_
, const std::string
&name
,
156 location loc
= location ());
158 field
new_bitfield (type type_
, int width
, const std::string
&name
,
159 location loc
= location ());
161 struct_
new_struct_type (const std::string
&name
,
162 std::vector
<field
> &fields
,
163 location loc
= location ());
165 struct_
new_opaque_struct_type (const std::string
&name
,
166 location loc
= location ());
168 param
new_param (type type_
,
169 const std::string
&name
,
170 location loc
= location ());
172 function
new_function (enum gcc_jit_function_kind kind
,
174 const std::string
&name
,
175 std::vector
<param
> ¶ms
,
177 location loc
= location ());
179 function
get_builtin_function (const std::string
&name
);
181 lvalue
new_global (enum gcc_jit_global_kind kind
,
183 const std::string
&name
,
184 location loc
= location ());
186 rvalue
new_rvalue (type numeric_type
,
188 rvalue
new_rvalue (type numeric_type
,
190 rvalue
zero (type numeric_type
) const;
191 rvalue
one (type numeric_type
) const;
192 rvalue
new_rvalue (type numeric_type
,
194 rvalue
new_rvalue (type pointer_type
,
196 rvalue
new_rvalue (const std::string
&value
) const;
197 rvalue
new_rvalue (type vector_type
,
198 std::vector
<rvalue
> elements
) const;
200 rvalue
new_struct_ctor (type type_
,
201 std::vector
<field
> &fields
,
202 std::vector
<rvalue
> &values
,
203 location loc
= location ());
205 rvalue
new_array_ctor (type type_
,
206 std::vector
<rvalue
> &values
,
207 location loc
= location ());
209 rvalue
new_union_ctor (type type_
,
212 location loc
= location ());
214 /* Generic unary operations... */
215 rvalue
new_unary_op (enum gcc_jit_unary_op op
,
218 location loc
= location ());
220 /* ...and shorter ways to spell the various specific kinds of
222 rvalue
new_minus (type result_type
,
224 location loc
= location ());
225 rvalue
new_bitwise_negate (type result_type
,
227 location loc
= location ());
228 rvalue
new_logical_negate (type result_type
,
230 location loc
= location ());
232 /* Generic binary operations... */
233 rvalue
new_binary_op (enum gcc_jit_binary_op op
,
236 location loc
= location ());
238 /* ...and shorter ways to spell the various specific kinds of
240 rvalue
new_plus (type result_type
,
242 location loc
= location ());
243 rvalue
new_minus (type result_type
,
245 location loc
= location ());
246 rvalue
new_mult (type result_type
,
248 location loc
= location ());
249 rvalue
new_divide (type result_type
,
251 location loc
= location ());
252 rvalue
new_modulo (type result_type
,
254 location loc
= location ());
255 rvalue
new_bitwise_and (type result_type
,
257 location loc
= location ());
258 rvalue
new_bitwise_xor (type result_type
,
260 location loc
= location ());
261 rvalue
new_bitwise_or (type result_type
,
263 location loc
= location ());
264 rvalue
new_logical_and (type result_type
,
266 location loc
= location ());
267 rvalue
new_logical_or (type result_type
,
269 location loc
= location ());
271 /* Generic comparisons... */
272 rvalue
new_comparison (enum gcc_jit_comparison op
,
274 location loc
= location ());
275 /* ...and shorter ways to spell the various specific kinds of
277 rvalue
new_eq (rvalue a
, rvalue b
,
278 location loc
= location ());
279 rvalue
new_ne (rvalue a
, rvalue b
,
280 location loc
= location ());
281 rvalue
new_lt (rvalue a
, rvalue b
,
282 location loc
= location ());
283 rvalue
new_le (rvalue a
, rvalue b
,
284 location loc
= location ());
285 rvalue
new_gt (rvalue a
, rvalue b
,
286 location loc
= location ());
287 rvalue
new_ge (rvalue a
, rvalue b
,
288 location loc
= location ());
290 /* The most general way of creating a function call. */
291 rvalue
new_call (function func
,
292 std::vector
<rvalue
> &args
,
293 location loc
= location ());
295 /* In addition, we provide a series of overloaded "new_call" methods
296 for specific numbers of args (from 0 - 6), to avoid the need for
297 client code to manually build a vector. */
298 rvalue
new_call (function func
,
299 location loc
= location ());
300 rvalue
new_call (function func
,
302 location loc
= location ());
303 rvalue
new_call (function func
,
304 rvalue arg0
, rvalue arg1
,
305 location loc
= location ());
306 rvalue
new_call (function func
,
307 rvalue arg0
, rvalue arg1
, rvalue arg2
,
308 location loc
= location ());
309 rvalue
new_call (function func
,
310 rvalue arg0
, rvalue arg1
, rvalue arg2
,
312 location loc
= location ());
313 rvalue
new_call (function func
,
314 rvalue arg0
, rvalue arg1
, rvalue arg2
,
315 rvalue arg3
, rvalue arg4
,
316 location loc
= location ());
317 rvalue
new_call (function func
,
318 rvalue arg0
, rvalue arg1
, rvalue arg2
,
319 rvalue arg3
, rvalue arg4
, rvalue arg5
,
320 location loc
= location ());
322 rvalue
new_cast (rvalue expr
,
324 location loc
= location ());
326 lvalue
new_array_access (rvalue ptr
,
328 location loc
= location ());
330 case_
new_case (rvalue min_value
,
334 void add_top_level_asm (const char *asm_stmts
,
335 location loc
= location ());
338 gcc_jit_context
*m_inner_ctxt
;
341 class field
: public object
345 field (gcc_jit_field
*inner
);
347 gcc_jit_field
*get_inner_field () const;
350 class type
: public object
354 type (gcc_jit_type
*inner
);
356 gcc_jit_type
*get_inner_type () const;
360 type
get_volatile ();
361 type
get_aligned (size_t alignment_in_bytes
);
362 type
get_vector (size_t num_units
);
364 // Shortcuts for getting values of numeric types:
369 class struct_
: public type
373 struct_ (gcc_jit_struct
*inner
);
375 gcc_jit_struct
*get_inner_struct () const;
378 class function
: public object
382 function (gcc_jit_function
*func
);
384 gcc_jit_function
*get_inner_function () const;
386 void dump_to_dot (const std::string
&path
);
388 param
get_param (int index
) const;
391 block
new_block (const std::string
&name
);
393 lvalue
new_local (type type_
,
394 const std::string
&name
,
395 location loc
= location ());
397 rvalue
get_address (location loc
= location ());
399 /* A series of overloaded operator () with various numbers of arguments
400 for a very terse way of creating a call to this function. The call
401 is created within the same context as the function itself, which may
402 not be what you want. */
403 rvalue
operator() (location loc
= location ());
404 rvalue
operator() (rvalue arg0
,
405 location loc
= location ());
406 rvalue
operator() (rvalue arg0
, rvalue arg1
,
407 location loc
= location ());
408 rvalue
operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
409 location loc
= location ());
412 class block
: public object
416 block (gcc_jit_block
*inner
);
418 gcc_jit_block
*get_inner_block () const;
420 function
get_function () const;
422 void add_eval (rvalue rvalue
,
423 location loc
= location ());
425 void add_assignment (lvalue lvalue
,
427 location loc
= location ());
429 void add_assignment_op (lvalue lvalue
,
430 enum gcc_jit_binary_op op
,
432 location loc
= location ());
434 /* A way to add a function call to the body of a function being
435 defined, with various numbers of args. */
436 rvalue
add_call (function other
,
437 location loc
= location ());
438 rvalue
add_call (function other
,
440 location loc
= location ());
441 rvalue
add_call (function other
,
442 rvalue arg0
, rvalue arg1
,
443 location loc
= location ());
444 rvalue
add_call (function other
,
445 rvalue arg0
, rvalue arg1
, rvalue arg2
,
446 location loc
= location ());
447 rvalue
add_call (function other
,
448 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
449 location loc
= location ());
451 void add_comment (const std::string
&text
,
452 location loc
= location ());
454 void end_with_conditional (rvalue boolval
,
457 location loc
= location ());
459 void end_with_jump (block target
,
460 location loc
= location ());
462 void end_with_return (rvalue rvalue
,
463 location loc
= location ());
464 void end_with_return (location loc
= location ());
466 void end_with_switch (rvalue expr
,
468 std::vector
<case_
> cases
,
469 location loc
= location ());
471 extended_asm
add_extended_asm (const std::string
&asm_template
,
472 location loc
= location ());
473 extended_asm
end_with_extended_asm_goto (const std::string
&asm_template
,
474 std::vector
<block
> goto_blocks
,
475 block
*fallthrough_block
,
476 location loc
= location ());
479 class rvalue
: public object
483 rvalue (gcc_jit_rvalue
*inner
);
484 gcc_jit_rvalue
*get_inner_rvalue () const;
488 rvalue
access_field (field field
,
489 location loc
= location ());
491 lvalue
dereference_field (field field
,
492 location loc
= location ());
494 lvalue
dereference (location loc
= location ());
496 rvalue
cast_to (type type_
,
497 location loc
= location ());
500 lvalue
operator[] (rvalue index
);
501 lvalue
operator[] (int index
);
504 class lvalue
: public rvalue
508 lvalue (gcc_jit_lvalue
*inner
);
510 gcc_jit_lvalue
*get_inner_lvalue () const;
512 lvalue
access_field (field field
,
513 location loc
= location ());
515 rvalue
get_address (location loc
= location ());
516 lvalue
set_initializer (const void *blob
, size_t num_bytes
);
517 lvalue
set_initializer_rvalue (rvalue init_value
);
520 class param
: public lvalue
524 param (gcc_jit_param
*inner
);
526 gcc_jit_param
*get_inner_param () const;
529 class case_
: public object
533 case_ (gcc_jit_case
*inner
);
535 gcc_jit_case
*get_inner_case () const;
538 class extended_asm
: public object
542 extended_asm (gcc_jit_extended_asm
*inner
);
545 set_volatile_flag (bool flag
);
548 set_inline_flag (bool flag
);
551 add_output_operand (const std::string
&asm_symbolic_name
,
552 const std::string
&constraint
,
553 gccjit::lvalue dest
);
555 add_output_operand (const std::string
&constraint
,
556 gccjit::lvalue dest
);
559 add_input_operand (const std::string
&asm_symbolic_name
,
560 const std::string
&constraint
,
563 add_input_operand (const std::string
&constraint
,
567 add_clobber (const std::string
&victim
);
569 gcc_jit_extended_asm
*get_inner_extended_asm () const;
572 /* Overloaded operators, for those who want the most terse API
573 (at the possible risk of being a little too magical).
575 In each case, the first parameter is used to determine which context
576 owns the resulting expression, and, where appropriate, what the
579 /* Unary operators. */
580 rvalue
operator- (rvalue a
); // unary minus
581 rvalue
operator~ (rvalue a
); // unary bitwise negate
582 rvalue
operator! (rvalue a
); // unary logical negate
584 /* Binary operators. */
585 rvalue
operator+ (rvalue a
, rvalue b
);
586 rvalue
operator- (rvalue a
, rvalue b
);
587 rvalue
operator* (rvalue a
, rvalue b
);
588 rvalue
operator/ (rvalue a
, rvalue b
);
589 rvalue
operator% (rvalue a
, rvalue b
);
590 rvalue
operator& (rvalue a
, rvalue b
); // bitwise and
591 rvalue
operator^ (rvalue a
, rvalue b
); // bitwise_xor
592 rvalue
operator| (rvalue a
, rvalue b
); // bitwise_or
593 rvalue
operator&& (rvalue a
, rvalue b
); // logical_and
594 rvalue
operator|| (rvalue a
, rvalue b
); // logical_or
597 rvalue
operator== (rvalue a
, rvalue b
);
598 rvalue
operator!= (rvalue a
, rvalue b
);
599 rvalue
operator< (rvalue a
, rvalue b
);
600 rvalue
operator<= (rvalue a
, rvalue b
);
601 rvalue
operator> (rvalue a
, rvalue b
);
602 rvalue
operator>= (rvalue a
, rvalue b
);
605 lvalue
operator* (rvalue ptr
);
611 timer (gcc_jit_timer
*inner_timer
);
613 void push (const char *item_name
);
614 void pop (const char *item_name
);
615 void print (FILE *f_out
) const;
619 gcc_jit_timer
*get_inner_timer () const;
622 gcc_jit_timer
*m_inner_timer
;
628 auto_time (timer t
, const char *item_name
);
629 auto_time (context ctxt
, const char *item_name
);
634 const char *m_item_name
;
638 /****************************************************************************
639 Implementation of the API
640 ****************************************************************************/
644 inline context
context::acquire ()
646 return context (gcc_jit_context_acquire ());
648 inline context::context () : m_inner_ctxt (NULL
) {}
649 inline context::context (gcc_jit_context
*inner
) : m_inner_ctxt (inner
)
655 inline gccjit::context
656 context::new_child_context ()
658 return context (gcc_jit_context_new_child_context (m_inner_ctxt
));
664 gcc_jit_context_release (m_inner_ctxt
);
668 inline gcc_jit_result
*
671 gcc_jit_result
*result
= gcc_jit_context_compile (m_inner_ctxt
);
678 context::compile_to_file (enum gcc_jit_output_kind output_kind
,
679 const char *output_path
)
681 gcc_jit_context_compile_to_file (m_inner_ctxt
,
687 context::dump_to_file (const std::string
&path
,
688 bool update_locations
)
690 gcc_jit_context_dump_to_file (m_inner_ctxt
,
696 context::set_logfile (FILE *logfile
,
700 gcc_jit_context_set_logfile (m_inner_ctxt
,
707 context::dump_reproducer_to_file (const char *path
)
709 gcc_jit_context_dump_reproducer_to_file (m_inner_ctxt
,
714 context::set_str_option (enum gcc_jit_str_option opt
,
717 gcc_jit_context_set_str_option (m_inner_ctxt
, opt
, value
);
722 context::set_int_option (enum gcc_jit_int_option opt
,
725 gcc_jit_context_set_int_option (m_inner_ctxt
, opt
, value
);
730 context::set_bool_option (enum gcc_jit_bool_option opt
,
733 gcc_jit_context_set_bool_option (m_inner_ctxt
, opt
, value
);
737 context::set_bool_allow_unreachable_blocks (int bool_value
)
739 gcc_jit_context_set_bool_allow_unreachable_blocks (m_inner_ctxt
,
744 context::set_bool_use_external_driver (int bool_value
)
746 gcc_jit_context_set_bool_use_external_driver (m_inner_ctxt
,
751 context::add_command_line_option (const char *optname
)
753 gcc_jit_context_add_command_line_option (m_inner_ctxt
, optname
);
757 context::add_driver_option (const char *optname
)
759 gcc_jit_context_add_driver_option (m_inner_ctxt
, optname
);
763 context::set_timer (gccjit::timer t
)
765 gcc_jit_context_set_timer (m_inner_ctxt
, t
.get_inner_timer ());
769 context::get_timer () const
771 return gccjit::timer (gcc_jit_context_get_timer (m_inner_ctxt
));
776 context::new_location (const std::string
&filename
,
780 return location (gcc_jit_context_new_location (m_inner_ctxt
,
787 context::get_type (enum gcc_jit_types kind
)
789 return type (gcc_jit_context_get_type (m_inner_ctxt
, kind
));
793 context::get_int_type (size_t num_bytes
, int is_signed
)
795 return type (gcc_jit_context_get_int_type (m_inner_ctxt
,
800 template <typename T
>
802 context::get_int_type ()
804 return get_int_type (sizeof (T
), std::numeric_limits
<T
>::is_signed
);
808 context::new_array_type (type element_type
, int num_elements
, location loc
)
810 return type (gcc_jit_context_new_array_type (
812 loc
.get_inner_location (),
813 element_type
.get_inner_type (),
818 context::new_field (type type_
, const std::string
&name
, location loc
)
820 return field (gcc_jit_context_new_field (m_inner_ctxt
,
821 loc
.get_inner_location (),
822 type_
.get_inner_type (),
827 context::new_bitfield (type type_
, int width
, const std::string
&name
,
830 return field (gcc_jit_context_new_bitfield (m_inner_ctxt
,
831 loc
.get_inner_location (),
832 type_
.get_inner_type (),
838 context::new_struct_type (const std::string
&name
,
839 std::vector
<field
> &fields
,
842 /* Treat std::vector as an array, relying on it not being resized: */
843 field
*as_array_of_wrappers
= &fields
[0];
845 /* Treat the array as being of the underlying pointers, relying on
846 the wrapper type being such a pointer internally. */
847 gcc_jit_field
**as_array_of_ptrs
=
848 reinterpret_cast<gcc_jit_field
**> (as_array_of_wrappers
);
850 return struct_ (gcc_jit_context_new_struct_type (m_inner_ctxt
,
851 loc
.get_inner_location (),
858 context::new_opaque_struct_type (const std::string
&name
,
861 return struct_ (gcc_jit_context_new_opaque_struct (
863 loc
.get_inner_location (),
868 context::new_param (type type_
,
869 const std::string
&name
,
872 return param (gcc_jit_context_new_param (m_inner_ctxt
,
873 loc
.get_inner_location (),
874 type_
.get_inner_type (),
879 context::new_function (enum gcc_jit_function_kind kind
,
881 const std::string
&name
,
882 std::vector
<param
> ¶ms
,
886 /* Treat std::vector as an array, relying on it not being resized: */
887 param
*as_array_of_wrappers
= ¶ms
[0];
889 /* Treat the array as being of the underlying pointers, relying on
890 the wrapper type being such a pointer internally. */
891 gcc_jit_param
**as_array_of_ptrs
=
892 reinterpret_cast<gcc_jit_param
**> (as_array_of_wrappers
);
894 return function (gcc_jit_context_new_function (m_inner_ctxt
,
895 loc
.get_inner_location (),
897 return_type
.get_inner_type (),
905 context::get_builtin_function (const std::string
&name
)
907 return function (gcc_jit_context_get_builtin_function (m_inner_ctxt
,
912 context::new_global (enum gcc_jit_global_kind kind
,
914 const std::string
&name
,
917 return lvalue (gcc_jit_context_new_global (m_inner_ctxt
,
918 loc
.get_inner_location (),
920 type_
.get_inner_type (),
925 context::new_rvalue (type numeric_type
,
929 gcc_jit_context_new_rvalue_from_int (m_inner_ctxt
,
930 numeric_type
.get_inner_type (),
935 context::new_rvalue (type numeric_type
,
939 gcc_jit_context_new_rvalue_from_long (m_inner_ctxt
,
940 numeric_type
.get_inner_type (),
945 context::zero (type numeric_type
) const
947 return rvalue (gcc_jit_context_zero (m_inner_ctxt
,
948 numeric_type
.get_inner_type ()));
952 context::one (type numeric_type
) const
954 return rvalue (gcc_jit_context_one (m_inner_ctxt
,
955 numeric_type
.get_inner_type ()));
959 context::new_rvalue (type numeric_type
,
963 gcc_jit_context_new_rvalue_from_double (m_inner_ctxt
,
964 numeric_type
.get_inner_type (),
969 context::new_rvalue (type pointer_type
,
973 gcc_jit_context_new_rvalue_from_ptr (m_inner_ctxt
,
974 pointer_type
.get_inner_type (),
979 context::new_rvalue (const std::string
&value
) const
982 gcc_jit_context_new_string_literal (m_inner_ctxt
, value
.c_str ()));
986 context::new_rvalue (type vector_type
,
987 std::vector
<rvalue
> elements
) const
989 /* Treat std::vector as an array, relying on it not being resized: */
990 rvalue
*as_array_of_wrappers
= &elements
[0];
992 /* Treat the array as being of the underlying pointers, relying on
993 the wrapper type being such a pointer internally. */
994 gcc_jit_rvalue
**as_array_of_ptrs
=
995 reinterpret_cast<gcc_jit_rvalue
**> (as_array_of_wrappers
);
998 gcc_jit_context_new_rvalue_from_vector (m_inner_ctxt
,
1000 vector_type
.get_inner_type (),
1006 context::new_unary_op (enum gcc_jit_unary_op op
,
1011 return rvalue (gcc_jit_context_new_unary_op (m_inner_ctxt
,
1012 loc
.get_inner_location (),
1014 result_type
.get_inner_type (),
1015 a
.get_inner_rvalue ()));
1018 context::new_minus (type result_type
,
1022 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_MINUS
,
1023 result_type
, a
, loc
));
1026 context::new_bitwise_negate (type result_type
,
1030 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_BITWISE_NEGATE
,
1031 result_type
, a
, loc
));
1034 context::new_logical_negate (type result_type
,
1038 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_LOGICAL_NEGATE
,
1039 result_type
, a
, loc
));
1043 context::new_binary_op (enum gcc_jit_binary_op op
,
1048 return rvalue (gcc_jit_context_new_binary_op (m_inner_ctxt
,
1049 loc
.get_inner_location (),
1051 result_type
.get_inner_type (),
1052 a
.get_inner_rvalue (),
1053 b
.get_inner_rvalue ()));
1056 context::new_plus (type result_type
,
1060 return new_binary_op (GCC_JIT_BINARY_OP_PLUS
,
1061 result_type
, a
, b
, loc
);
1064 context::new_minus (type result_type
,
1068 return new_binary_op (GCC_JIT_BINARY_OP_MINUS
,
1069 result_type
, a
, b
, loc
);
1072 context::new_mult (type result_type
,
1076 return new_binary_op (GCC_JIT_BINARY_OP_MULT
,
1077 result_type
, a
, b
, loc
);
1080 context::new_divide (type result_type
,
1084 return new_binary_op (GCC_JIT_BINARY_OP_DIVIDE
,
1085 result_type
, a
, b
, loc
);
1088 context::new_modulo (type result_type
,
1092 return new_binary_op (GCC_JIT_BINARY_OP_MODULO
,
1093 result_type
, a
, b
, loc
);
1096 context::new_bitwise_and (type result_type
,
1100 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_AND
,
1101 result_type
, a
, b
, loc
);
1104 context::new_bitwise_xor (type result_type
,
1108 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_XOR
,
1109 result_type
, a
, b
, loc
);
1112 context::new_bitwise_or (type result_type
,
1116 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_OR
,
1117 result_type
, a
, b
, loc
);
1120 context::new_logical_and (type result_type
,
1124 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_AND
,
1125 result_type
, a
, b
, loc
);
1128 context::new_logical_or (type result_type
,
1132 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_OR
,
1133 result_type
, a
, b
, loc
);
1137 context::new_comparison (enum gcc_jit_comparison op
,
1141 return rvalue (gcc_jit_context_new_comparison (m_inner_ctxt
,
1142 loc
.get_inner_location (),
1144 a
.get_inner_rvalue (),
1145 b
.get_inner_rvalue ()));
1148 context::new_eq (rvalue a
, rvalue b
,
1151 return new_comparison (GCC_JIT_COMPARISON_EQ
,
1155 context::new_ne (rvalue a
, rvalue b
,
1158 return new_comparison (GCC_JIT_COMPARISON_NE
,
1162 context::new_lt (rvalue a
, rvalue b
,
1165 return new_comparison (GCC_JIT_COMPARISON_LT
,
1169 context::new_le (rvalue a
, rvalue b
,
1172 return new_comparison (GCC_JIT_COMPARISON_LE
,
1176 context::new_gt (rvalue a
, rvalue b
,
1179 return new_comparison (GCC_JIT_COMPARISON_GT
,
1183 context::new_ge (rvalue a
, rvalue b
,
1186 return new_comparison (GCC_JIT_COMPARISON_GE
,
1191 context::new_call (function func
,
1192 std::vector
<rvalue
> &args
,
1195 /* Treat std::vector as an array, relying on it not being resized: */
1196 rvalue
*as_array_of_wrappers
= &args
[0];
1198 /* Treat the array as being of the underlying pointers, relying on
1199 the wrapper type being such a pointer internally. */
1200 gcc_jit_rvalue
**as_array_of_ptrs
=
1201 reinterpret_cast<gcc_jit_rvalue
**> (as_array_of_wrappers
);
1202 return gcc_jit_context_new_call (m_inner_ctxt
,
1203 loc
.get_inner_location (),
1204 func
.get_inner_function (),
1209 context::new_call (function func
,
1212 std::vector
<rvalue
> args
;
1213 return new_call (func
, args
, loc
);
1217 context::new_call (function func
,
1221 std::vector
<rvalue
> args(1);
1223 return new_call (func
, args
, loc
);
1226 context::new_call (function func
,
1227 rvalue arg0
, rvalue arg1
,
1230 std::vector
<rvalue
> args(2);
1233 return new_call (func
, args
, loc
);
1236 context::new_call (function func
,
1237 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1240 std::vector
<rvalue
> args(3);
1244 return new_call (func
, args
, loc
);
1247 context::new_call (function func
,
1248 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1252 std::vector
<rvalue
> args(4);
1257 return new_call (func
, args
, loc
);
1260 context::new_call (function func
,
1261 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1262 rvalue arg3
, rvalue arg4
,
1265 std::vector
<rvalue
> args(5);
1271 return new_call (func
, args
, loc
);
1274 context::new_call (function func
,
1275 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1276 rvalue arg3
, rvalue arg4
, rvalue arg5
,
1279 std::vector
<rvalue
> args(6);
1286 return new_call (func
, args
, loc
);
1290 context::new_cast (rvalue expr
,
1294 return rvalue (gcc_jit_context_new_cast (m_inner_ctxt
,
1295 loc
.get_inner_location (),
1296 expr
.get_inner_rvalue (),
1297 type_
.get_inner_type ()));
1301 context::new_array_access (rvalue ptr
,
1305 return lvalue (gcc_jit_context_new_array_access (m_inner_ctxt
,
1306 loc
.get_inner_location (),
1307 ptr
.get_inner_rvalue (),
1308 index
.get_inner_rvalue ()));
1312 context::new_case (rvalue min_value
,
1316 return case_ (gcc_jit_context_new_case (m_inner_ctxt
,
1317 min_value
.get_inner_rvalue (),
1318 max_value
.get_inner_rvalue (),
1319 dest_block
.get_inner_block ()));
1323 context::add_top_level_asm (const char *asm_stmts
, location loc
)
1325 gcc_jit_context_add_top_level_asm (m_inner_ctxt
,
1326 loc
.get_inner_location (),
1332 object::get_context () const
1334 return context (gcc_jit_object_get_context (m_inner_obj
));
1338 object::get_debug_string () const
1340 return gcc_jit_object_get_debug_string (m_inner_obj
);
1343 inline object::object () : m_inner_obj (NULL
) {}
1344 inline object::object (gcc_jit_object
*obj
) : m_inner_obj (obj
)
1350 inline gcc_jit_object
*
1351 object::get_inner_object () const
1356 inline std::ostream
&
1357 operator << (std::ostream
& stream
, const object
&obj
)
1359 return stream
<< obj
.get_debug_string ();
1363 inline location::location () : object () {}
1364 inline location::location (gcc_jit_location
*loc
)
1365 : object (gcc_jit_location_as_object (loc
))
1368 inline gcc_jit_location
*
1369 location::get_inner_location () const
1371 /* Manual downcast: */
1372 return reinterpret_cast<gcc_jit_location
*> (get_inner_object ());
1376 inline field::field () : object () {}
1377 inline field::field (gcc_jit_field
*inner
)
1378 : object (gcc_jit_field_as_object (inner
))
1381 inline gcc_jit_field
*
1382 field::get_inner_field () const
1384 /* Manual downcast: */
1385 return reinterpret_cast<gcc_jit_field
*> (get_inner_object ());
1389 inline type::type () : object () {}
1390 inline type::type (gcc_jit_type
*inner
)
1391 : object (gcc_jit_type_as_object (inner
))
1394 inline gcc_jit_type
*
1395 type::get_inner_type () const
1397 /* Manual downcast: */
1398 return reinterpret_cast<gcc_jit_type
*> (get_inner_object ());
1402 type::get_pointer ()
1404 return type (gcc_jit_type_get_pointer (get_inner_type ()));
1410 return type (gcc_jit_type_get_const (get_inner_type ()));
1414 type::get_volatile ()
1416 return type (gcc_jit_type_get_volatile (get_inner_type ()));
1420 type::get_aligned (size_t alignment_in_bytes
)
1422 return type (gcc_jit_type_get_aligned (get_inner_type (),
1423 alignment_in_bytes
));
1427 type::get_vector (size_t num_units
)
1429 return type (gcc_jit_type_get_vector (get_inner_type (),
1436 return get_context ().new_rvalue (*this, 0);
1442 return get_context ().new_rvalue (*this, 1);
1446 inline struct_::struct_ () : type (NULL
) {}
1447 inline struct_::struct_ (gcc_jit_struct
*inner
) :
1448 type (gcc_jit_struct_as_type (inner
))
1452 inline gcc_jit_struct
*
1453 struct_::get_inner_struct () const
1455 /* Manual downcast: */
1456 return reinterpret_cast<gcc_jit_struct
*> (get_inner_object ());
1460 inline function::function () : object () {}
1461 inline function::function (gcc_jit_function
*inner
)
1462 : object (gcc_jit_function_as_object (inner
))
1465 inline gcc_jit_function
*
1466 function::get_inner_function () const
1468 /* Manual downcast: */
1469 return reinterpret_cast<gcc_jit_function
*> (get_inner_object ());
1473 function::dump_to_dot (const std::string
&path
)
1475 gcc_jit_function_dump_to_dot (get_inner_function (),
1480 function::get_param (int index
) const
1482 return param (gcc_jit_function_get_param (get_inner_function (),
1487 function::new_block ()
1489 return block (gcc_jit_function_new_block (get_inner_function (),
1494 function::new_block (const std::string
&name
)
1496 return block (gcc_jit_function_new_block (get_inner_function (),
1501 function::new_local (type type_
,
1502 const std::string
&name
,
1505 return lvalue (gcc_jit_function_new_local (get_inner_function (),
1506 loc
.get_inner_location (),
1507 type_
.get_inner_type (),
1512 function::get_address (location loc
)
1514 return rvalue (gcc_jit_function_get_address (get_inner_function (),
1515 loc
.get_inner_location ()));
1519 block::get_function () const
1521 return function (gcc_jit_block_get_function ( get_inner_block ()));
1525 block::add_eval (rvalue rvalue
,
1528 gcc_jit_block_add_eval (get_inner_block (),
1529 loc
.get_inner_location (),
1530 rvalue
.get_inner_rvalue ());
1534 block::add_assignment (lvalue lvalue
,
1538 gcc_jit_block_add_assignment (get_inner_block (),
1539 loc
.get_inner_location (),
1540 lvalue
.get_inner_lvalue (),
1541 rvalue
.get_inner_rvalue ());
1545 block::add_assignment_op (lvalue lvalue
,
1546 enum gcc_jit_binary_op op
,
1550 gcc_jit_block_add_assignment_op (get_inner_block (),
1551 loc
.get_inner_location (),
1552 lvalue
.get_inner_lvalue (),
1554 rvalue
.get_inner_rvalue ());
1558 block::add_comment (const std::string
&text
,
1561 gcc_jit_block_add_comment (get_inner_block (),
1562 loc
.get_inner_location (),
1567 block::end_with_conditional (rvalue boolval
,
1572 gcc_jit_block_end_with_conditional (get_inner_block (),
1573 loc
.get_inner_location (),
1574 boolval
.get_inner_rvalue (),
1575 on_true
.get_inner_block (),
1576 on_false
.get_inner_block ());
1580 block::end_with_jump (block target
,
1583 gcc_jit_block_end_with_jump (get_inner_block (),
1584 loc
.get_inner_location (),
1585 target
.get_inner_block ());
1589 block::end_with_return (rvalue rvalue
,
1592 gcc_jit_block_end_with_return (get_inner_block (),
1593 loc
.get_inner_location (),
1594 rvalue
.get_inner_rvalue ());
1598 block::end_with_return (location loc
)
1600 gcc_jit_block_end_with_void_return (get_inner_block (),
1601 loc
.get_inner_location ());
1605 block::end_with_switch (rvalue expr
,
1606 block default_block
,
1607 std::vector
<case_
> cases
,
1610 /* Treat std::vector as an array, relying on it not being resized: */
1611 case_
*as_array_of_wrappers
= &cases
[0];
1613 /* Treat the array as being of the underlying pointers, relying on
1614 the wrapper type being such a pointer internally. */
1615 gcc_jit_case
**as_array_of_ptrs
=
1616 reinterpret_cast<gcc_jit_case
**> (as_array_of_wrappers
);
1617 gcc_jit_block_end_with_switch (get_inner_block (),
1618 loc
.get_inner_location (),
1619 expr
.get_inner_rvalue (),
1620 default_block
.get_inner_block (),
1626 block::add_extended_asm (const std::string
&asm_template
,
1629 return gcc_jit_block_add_extended_asm (get_inner_block (),
1630 loc
.get_inner_location (),
1631 asm_template
.c_str ());
1635 block::end_with_extended_asm_goto (const std::string
&asm_template
,
1636 std::vector
<block
> goto_blocks
,
1637 block
*fallthrough_block
,
1640 /* Treat std::vector as an array, relying on it not being resized: */
1641 block
*as_array_of_wrappers
= &goto_blocks
[0];
1643 /* Treat the array as being of the underlying pointers, relying on
1644 the wrapper type being such a pointer internally. */
1645 gcc_jit_block
**as_array_of_ptrs
=
1646 reinterpret_cast<gcc_jit_block
**> (as_array_of_wrappers
);
1647 return gcc_jit_block_end_with_extended_asm_goto
1648 (get_inner_block (),
1649 loc
.get_inner_location (),
1650 asm_template
.c_str (),
1651 goto_blocks
.size (),
1653 fallthrough_block
? fallthrough_block
->get_inner_block () : NULL
);
1657 block::add_call (function other
,
1660 rvalue c
= get_context ().new_call (other
, loc
);
1665 block::add_call (function other
,
1669 rvalue c
= get_context ().new_call (other
, arg0
, loc
);
1674 block::add_call (function other
,
1675 rvalue arg0
, rvalue arg1
,
1678 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, loc
);
1683 block::add_call (function other
,
1684 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1687 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, loc
);
1693 block::add_call (function other
,
1694 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
1697 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, arg3
, loc
);
1703 function::operator() (location loc
)
1705 return get_context ().new_call (*this, loc
);
1708 function::operator() (rvalue arg0
,
1711 return get_context ().new_call (*this,
1716 function::operator() (rvalue arg0
, rvalue arg1
,
1719 return get_context ().new_call (*this,
1724 function::operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
1727 return get_context ().new_call (*this,
1733 inline block::block () : object () {}
1734 inline block::block (gcc_jit_block
*inner
)
1735 : object (gcc_jit_block_as_object (inner
))
1738 inline gcc_jit_block
*
1739 block::get_inner_block () const
1741 /* Manual downcast: */
1742 return reinterpret_cast<gcc_jit_block
*> (get_inner_object ());
1746 inline rvalue::rvalue () : object () {}
1747 inline rvalue::rvalue (gcc_jit_rvalue
*inner
)
1748 : object (gcc_jit_rvalue_as_object (inner
))
1751 inline gcc_jit_rvalue
*
1752 rvalue::get_inner_rvalue () const
1754 /* Manual downcast: */
1755 return reinterpret_cast<gcc_jit_rvalue
*> (get_inner_object ());
1761 return type (gcc_jit_rvalue_get_type (get_inner_rvalue ()));
1765 rvalue::access_field (field field
,
1768 return rvalue (gcc_jit_rvalue_access_field (get_inner_rvalue (),
1769 loc
.get_inner_location (),
1770 field
.get_inner_field ()));
1774 rvalue::dereference_field (field field
,
1777 return lvalue (gcc_jit_rvalue_dereference_field (get_inner_rvalue (),
1778 loc
.get_inner_location (),
1779 field
.get_inner_field ()));
1783 rvalue::dereference (location loc
)
1785 return lvalue (gcc_jit_rvalue_dereference (get_inner_rvalue (),
1786 loc
.get_inner_location ()));
1790 rvalue::cast_to (type type_
,
1793 return get_context ().new_cast (*this, type_
, loc
);
1797 rvalue::operator[] (rvalue index
)
1799 return get_context ().new_array_access (*this, index
);
1803 rvalue::operator[] (int index
)
1805 context ctxt
= get_context ();
1806 type int_t
= ctxt
.get_int_type
<int> ();
1807 return ctxt
.new_array_access (*this,
1808 ctxt
.new_rvalue (int_t
,
1812 // class lvalue : public rvalue
1813 inline lvalue::lvalue () : rvalue () {}
1814 inline lvalue::lvalue (gcc_jit_lvalue
*inner
)
1815 : rvalue (gcc_jit_lvalue_as_rvalue (inner
))
1818 inline gcc_jit_lvalue
*
1819 lvalue::get_inner_lvalue () const
1821 /* Manual downcast: */
1822 return reinterpret_cast<gcc_jit_lvalue
*> (get_inner_object ());
1826 lvalue::access_field (field field
, location loc
)
1828 return lvalue (gcc_jit_lvalue_access_field (get_inner_lvalue (),
1829 loc
.get_inner_location (),
1830 field
.get_inner_field ()));
1834 lvalue::get_address (location loc
)
1836 return rvalue (gcc_jit_lvalue_get_address (get_inner_lvalue (),
1837 loc
.get_inner_location ()));
1841 lvalue::set_initializer (const void *blob
, size_t num_bytes
)
1843 gcc_jit_global_set_initializer (get_inner_lvalue (),
1850 lvalue::set_initializer_rvalue (rvalue init_value
)
1852 return lvalue (gcc_jit_global_set_initializer_rvalue (
1853 get_inner_lvalue (),
1854 init_value
.get_inner_rvalue ()));
1858 context::new_struct_ctor (type type_
,
1859 std::vector
<field
> &fields
,
1860 std::vector
<rvalue
> &values
,
1863 field
*pfields
= nullptr;
1865 pfields
= &fields
[0];
1867 gcc_jit_field
**fields_arr
=
1868 reinterpret_cast<gcc_jit_field
**> (pfields
);
1870 rvalue
*pvalues
= nullptr;
1872 pvalues
= &values
[0];
1874 gcc_jit_rvalue
**values_arr
=
1875 reinterpret_cast<gcc_jit_rvalue
**> (pvalues
);
1878 gcc_jit_context_new_struct_constructor (
1880 loc
.get_inner_location (),
1881 type_
.get_inner_type (),
1882 (int)values
.size (),
1888 context::new_array_ctor (type type_
,
1889 std::vector
<rvalue
> &values
,
1892 rvalue
*pvalues
= nullptr;
1894 pvalues
= &values
[0];
1896 gcc_jit_rvalue
**values_arr
=
1897 reinterpret_cast<gcc_jit_rvalue
**> (pvalues
);
1900 gcc_jit_context_new_array_constructor (
1902 loc
.get_inner_location (),
1903 type_
.get_inner_type (),
1904 (int)values
.size (),
1909 context::new_union_ctor (type type_
,
1915 gcc_jit_context_new_union_constructor (
1917 loc
.get_inner_location (),
1918 type_
.get_inner_type (),
1919 field
.get_inner_field (),
1920 value
.get_inner_rvalue ()));
1924 // class param : public lvalue
1925 inline param::param () : lvalue () {}
1926 inline param::param (gcc_jit_param
*inner
)
1927 : lvalue (gcc_jit_param_as_lvalue (inner
))
1930 // class case_ : public object
1931 inline case_::case_ () : object () {}
1932 inline case_::case_ (gcc_jit_case
*inner
)
1933 : object (gcc_jit_case_as_object (inner
))
1937 inline gcc_jit_case
*
1938 case_::get_inner_case () const
1940 /* Manual downcast: */
1941 return reinterpret_cast<gcc_jit_case
*> (get_inner_object ());
1944 // class extended_asm : public object
1945 inline extended_asm::extended_asm () : object () {}
1946 inline extended_asm::extended_asm (gcc_jit_extended_asm
*inner
)
1947 : object (gcc_jit_extended_asm_as_object (inner
))
1951 inline extended_asm
&
1952 extended_asm::set_volatile_flag (bool flag
)
1954 gcc_jit_extended_asm_set_volatile_flag (get_inner_extended_asm (), flag
);
1958 inline extended_asm
&
1959 extended_asm::set_inline_flag (bool flag
)
1961 gcc_jit_extended_asm_set_inline_flag (get_inner_extended_asm (), flag
);
1965 inline extended_asm
&
1966 extended_asm::add_output_operand (const std::string
&asm_symbolic_name
,
1967 const std::string
&constraint
,
1968 gccjit::lvalue dest
)
1970 gcc_jit_extended_asm_add_output_operand
1971 (get_inner_extended_asm (),
1972 asm_symbolic_name
.c_str (),
1973 constraint
.c_str (),
1974 dest
.get_inner_lvalue ());
1978 inline extended_asm
&
1979 extended_asm::add_output_operand (const std::string
&constraint
,
1980 gccjit::lvalue dest
)
1982 gcc_jit_extended_asm_add_output_operand
1983 (get_inner_extended_asm (),
1984 NULL
, /* asm_symbolic_name */
1985 constraint
.c_str (),
1986 dest
.get_inner_lvalue ());
1990 inline extended_asm
&
1991 extended_asm::add_input_operand (const std::string
&asm_symbolic_name
,
1992 const std::string
&constraint
,
1995 gcc_jit_extended_asm_add_input_operand
1996 (get_inner_extended_asm (),
1997 asm_symbolic_name
.c_str (),
1998 constraint
.c_str (),
1999 src
.get_inner_rvalue ());
2003 inline extended_asm
&
2004 extended_asm::add_input_operand (const std::string
&constraint
,
2007 gcc_jit_extended_asm_add_input_operand
2008 (get_inner_extended_asm (),
2009 NULL
, /* asm_symbolic_name */
2010 constraint
.c_str (),
2011 src
.get_inner_rvalue ());
2015 inline extended_asm
&
2016 extended_asm::add_clobber (const std::string
&victim
)
2018 gcc_jit_extended_asm_add_clobber (get_inner_extended_asm (),
2023 inline gcc_jit_extended_asm
*
2024 extended_asm::get_inner_extended_asm () const
2026 /* Manual downcast: */
2027 return reinterpret_cast<gcc_jit_extended_asm
*> (get_inner_object ());
2030 /* Overloaded operators. */
2032 inline rvalue
operator- (rvalue a
)
2034 return a
.get_context ().new_minus (a
.get_type (), a
);
2036 inline rvalue
operator~ (rvalue a
)
2038 return a
.get_context ().new_bitwise_negate (a
.get_type (), a
);
2040 inline rvalue
operator! (rvalue a
)
2042 return a
.get_context ().new_logical_negate (a
.get_type (), a
);
2046 inline rvalue
operator+ (rvalue a
, rvalue b
)
2048 return a
.get_context ().new_plus (a
.get_type (), a
, b
);
2050 inline rvalue
operator- (rvalue a
, rvalue b
)
2052 return a
.get_context ().new_minus (a
.get_type (), a
, b
);
2054 inline rvalue
operator* (rvalue a
, rvalue b
)
2056 return a
.get_context ().new_mult (a
.get_type (), a
, b
);
2058 inline rvalue
operator/ (rvalue a
, rvalue b
)
2060 return a
.get_context ().new_divide (a
.get_type (), a
, b
);
2062 inline rvalue
operator% (rvalue a
, rvalue b
)
2064 return a
.get_context ().new_modulo (a
.get_type (), a
, b
);
2066 inline rvalue
operator& (rvalue a
, rvalue b
)
2068 return a
.get_context ().new_bitwise_and (a
.get_type (), a
, b
);
2070 inline rvalue
operator^ (rvalue a
, rvalue b
)
2072 return a
.get_context ().new_bitwise_xor (a
.get_type (), a
, b
);
2074 inline rvalue
operator| (rvalue a
, rvalue b
)
2076 return a
.get_context ().new_bitwise_or (a
.get_type (), a
, b
);
2078 inline rvalue
operator&& (rvalue a
, rvalue b
)
2080 return a
.get_context ().new_logical_and (a
.get_type (), a
, b
);
2082 inline rvalue
operator|| (rvalue a
, rvalue b
)
2084 return a
.get_context ().new_logical_or (a
.get_type (), a
, b
);
2088 inline rvalue
operator== (rvalue a
, rvalue b
)
2090 return a
.get_context ().new_eq (a
, b
);
2092 inline rvalue
operator!= (rvalue a
, rvalue b
)
2094 return a
.get_context ().new_ne (a
, b
);
2096 inline rvalue
operator< (rvalue a
, rvalue b
)
2098 return a
.get_context ().new_lt (a
, b
);
2100 inline rvalue
operator<= (rvalue a
, rvalue b
)
2102 return a
.get_context ().new_le (a
, b
);
2104 inline rvalue
operator> (rvalue a
, rvalue b
)
2106 return a
.get_context ().new_gt (a
, b
);
2108 inline rvalue
operator>= (rvalue a
, rvalue b
)
2110 return a
.get_context ().new_ge (a
, b
);
2113 /* Dereferencing. */
2114 inline lvalue
operator* (rvalue ptr
)
2116 return ptr
.dereference ();
2123 m_inner_timer
= gcc_jit_timer_new ();
2127 timer::timer (gcc_jit_timer
*inner_timer
)
2129 m_inner_timer
= inner_timer
;
2133 timer::push (const char *item_name
)
2135 gcc_jit_timer_push (m_inner_timer
, item_name
);
2140 timer::pop (const char *item_name
)
2142 gcc_jit_timer_pop (m_inner_timer
, item_name
);
2146 timer::print (FILE *f_out
) const
2148 gcc_jit_timer_print (m_inner_timer
, f_out
);
2151 inline gcc_jit_timer
*
2152 timer::get_inner_timer () const
2154 return m_inner_timer
;
2160 gcc_jit_timer_release (m_inner_timer
);
2161 m_inner_timer
= NULL
;
2167 auto_time::auto_time (timer t
, const char *item_name
)
2169 m_item_name (item_name
)
2175 auto_time::auto_time (context ctxt
, const char *item_name
)
2176 : m_timer (ctxt
.get_timer ()),
2177 m_item_name (item_name
)
2179 m_timer
.push (item_name
);
2183 auto_time::~auto_time ()
2185 m_timer
.pop (m_item_name
);
2193 return gcc_jit_version_major ();
2199 return gcc_jit_version_minor ();
2205 return gcc_jit_version_patchlevel ();
2207 } // namespace version
2208 } // namespace gccjit
2210 #endif /* #ifndef LIBGCCJIT_PLUS_PLUS_H */