1 /* A C++ API for libgccjit, purely as inline wrapper functions.
2 Copyright (C) 2014 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. */
49 /* Errors within the API become C++ exceptions of this class. */
57 context
get_context () const;
59 std::string
get_debug_string () const;
63 object (gcc_jit_object
*obj
);
65 gcc_jit_object
*get_inner_object () const;
68 gcc_jit_object
*m_inner_obj
;
71 inline std::ostream
& operator << (std::ostream
& stream
, const object
&obj
);
73 /* Some client code will want to supply source code locations, others
74 won't. To avoid doubling the number of entrypoints, everything
75 accepting a location also has a default argument. To do this, the
76 other classes need to see that "location" has a default constructor,
77 hence we need to declare it first. */
78 class location
: public object
82 location (gcc_jit_location
*loc
);
84 gcc_jit_location
*get_inner_location () const;
90 static context
acquire ();
92 context (gcc_jit_context
*ctxt
);
94 gccjit::context
new_child_context ();
96 gcc_jit_context
*get_inner_context () { return m_inner_ctxt
; }
100 gcc_jit_result
*compile ();
102 void dump_to_file (const std::string
&path
,
103 bool update_locations
);
105 void set_int_option (enum gcc_jit_int_option opt
,
108 void set_bool_option (enum gcc_jit_bool_option opt
,
112 new_location (const std::string
&filename
,
116 type
get_type (enum gcc_jit_types kind
);
117 type
get_int_type (size_t num_bytes
, int is_signed
);
119 /* A way to map a specific int type, using the compiler to
120 get the details automatically e.g.:
121 gccjit::type type = get_int_type <my_int_type_t> (); */
122 template <typename T
>
123 type
get_int_type ();
125 type
new_array_type (type element_type
, int num_elements
,
126 location loc
= location ());
128 field
new_field (type type_
, const std::string
&name
,
129 location loc
= location ());
131 struct_
new_struct_type (const std::string
&name
,
132 std::vector
<field
> &fields
,
133 location loc
= location ());
135 struct_
new_opaque_struct_type (const std::string
&name
,
136 location loc
= location ());
138 param
new_param (type type_
,
139 const std::string
&name
,
140 location loc
= location ());
142 function
new_function (enum gcc_jit_function_kind kind
,
144 const std::string
&name
,
145 std::vector
<param
> ¶ms
,
147 location loc
= location ());
149 function
get_builtin_function (const std::string
&name
);
151 lvalue
new_global (type type_
,
152 const std::string
&name
,
153 location loc
= location ());
155 rvalue
new_rvalue (type numeric_type
,
157 rvalue
zero (type numeric_type
) const;
158 rvalue
one (type numeric_type
) const;
159 rvalue
new_rvalue (type numeric_type
,
161 rvalue
new_rvalue (type pointer_type
,
163 rvalue
new_rvalue (const std::string
&value
) const;
165 /* Generic unary operations... */
166 rvalue
new_unary_op (enum gcc_jit_unary_op op
,
169 location loc
= location ());
171 /* ...and shorter ways to spell the various specific kinds of
173 rvalue
new_minus (type result_type
,
175 location loc
= location ());
176 rvalue
new_bitwise_negate (type result_type
,
178 location loc
= location ());
179 rvalue
new_logical_negate (type result_type
,
181 location loc
= location ());
183 /* Generic binary operations... */
184 rvalue
new_binary_op (enum gcc_jit_binary_op op
,
187 location loc
= location ());
189 /* ...and shorter ways to spell the various specific kinds of
191 rvalue
new_plus (type result_type
,
193 location loc
= location ());
194 rvalue
new_minus (type result_type
,
196 location loc
= location ());
197 rvalue
new_mult (type result_type
,
199 location loc
= location ());
200 rvalue
new_divide (type result_type
,
202 location loc
= location ());
203 rvalue
new_modulo (type result_type
,
205 location loc
= location ());
206 rvalue
new_bitwise_and (type result_type
,
208 location loc
= location ());
209 rvalue
new_bitwise_xor (type result_type
,
211 location loc
= location ());
212 rvalue
new_bitwise_or (type result_type
,
214 location loc
= location ());
215 rvalue
new_logical_and (type result_type
,
217 location loc
= location ());
218 rvalue
new_logical_or (type result_type
,
220 location loc
= location ());
222 /* Generic comparisons... */
223 rvalue
new_comparison (enum gcc_jit_comparison op
,
225 location loc
= location ());
226 /* ...and shorter ways to spell the various specific kinds of
228 rvalue
new_eq (rvalue a
, rvalue b
,
229 location loc
= location ());
230 rvalue
new_ne (rvalue a
, rvalue b
,
231 location loc
= location ());
232 rvalue
new_lt (rvalue a
, rvalue b
,
233 location loc
= location ());
234 rvalue
new_le (rvalue a
, rvalue b
,
235 location loc
= location ());
236 rvalue
new_gt (rvalue a
, rvalue b
,
237 location loc
= location ());
238 rvalue
new_ge (rvalue a
, rvalue b
,
239 location loc
= location ());
241 /* The most general way of creating a function call. */
242 rvalue
new_call (function func
,
243 std::vector
<rvalue
> &args
,
244 location loc
= location ());
246 /* In addition, we provide a series of overloaded "new_call" methods
247 for specific numbers of args (from 0 - 6), to avoid the need for
248 client code to manually build a vector. */
249 rvalue
new_call (function func
,
250 location loc
= location ());
251 rvalue
new_call (function func
,
253 location loc
= location ());
254 rvalue
new_call (function func
,
255 rvalue arg0
, rvalue arg1
,
256 location loc
= location ());
257 rvalue
new_call (function func
,
258 rvalue arg0
, rvalue arg1
, rvalue arg2
,
259 location loc
= location ());
260 rvalue
new_call (function func
,
261 rvalue arg0
, rvalue arg1
, rvalue arg2
,
263 location loc
= location ());
264 rvalue
new_call (function func
,
265 rvalue arg0
, rvalue arg1
, rvalue arg2
,
266 rvalue arg3
, rvalue arg4
,
267 location loc
= location ());
268 rvalue
new_call (function func
,
269 rvalue arg0
, rvalue arg1
, rvalue arg2
,
270 rvalue arg3
, rvalue arg4
, rvalue arg5
,
271 location loc
= location ());
273 rvalue
new_cast (rvalue expr
,
275 location loc
= location ());
277 lvalue
new_array_access (rvalue ptr
,
279 location loc
= location ());
282 gcc_jit_context
*m_inner_ctxt
;
285 class field
: public object
289 field (gcc_jit_field
*inner
);
291 gcc_jit_field
*get_inner_field () const;
294 class type
: public object
298 type (gcc_jit_type
*inner
);
300 gcc_jit_type
*get_inner_type () const;
303 type
get_volatile ();
305 // Shortcuts for getting values of numeric types:
310 class struct_
: public type
314 struct_ (gcc_jit_struct
*inner
);
316 gcc_jit_struct
*get_inner_struct () const;
319 class function
: public object
323 function (gcc_jit_function
*func
);
325 gcc_jit_function
*get_inner_function () const;
327 void dump_to_dot (const std::string
&path
);
329 param
get_param (int index
) const;
332 block
new_block (const std::string
&name
);
334 lvalue
new_local (type type_
,
335 const std::string
&name
,
336 location loc
= location ());
338 /* A series of overloaded operator () with various numbers of arguments
339 for a very terse way of creating a call to this function. The call
340 is created within the same context as the function itself, which may
341 not be what you want. */
342 rvalue
operator() (location loc
= location ());
343 rvalue
operator() (rvalue arg0
,
344 location loc
= location ());
345 rvalue
operator() (rvalue arg0
, rvalue arg1
,
346 location loc
= location ());
347 rvalue
operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
348 location loc
= location ());
351 class block
: public object
355 block (gcc_jit_block
*inner
);
357 gcc_jit_block
*get_inner_block () const;
359 function
get_function () const;
361 void add_eval (rvalue rvalue
,
362 location loc
= location ());
364 void add_assignment (lvalue lvalue
,
366 location loc
= location ());
368 void add_assignment_op (lvalue lvalue
,
369 enum gcc_jit_binary_op op
,
371 location loc
= location ());
373 /* A way to add a function call to the body of a function being
374 defined, with various numbers of args. */
375 rvalue
add_call (function other
,
376 location loc
= location ());
377 rvalue
add_call (function other
,
379 location loc
= location ());
380 rvalue
add_call (function other
,
381 rvalue arg0
, rvalue arg1
,
382 location loc
= location ());
383 rvalue
add_call (function other
,
384 rvalue arg0
, rvalue arg1
, rvalue arg2
,
385 location loc
= location ());
386 rvalue
add_call (function other
,
387 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
388 location loc
= location ());
390 void add_comment (const std::string
&text
,
391 location loc
= location ());
393 void end_with_conditional (rvalue boolval
,
396 location loc
= location ());
398 void end_with_jump (block target
,
399 location loc
= location ());
401 void end_with_return (rvalue rvalue
,
402 location loc
= location ());
403 void end_with_return (location loc
= location ());
407 class rvalue
: public object
411 rvalue (gcc_jit_rvalue
*inner
);
412 gcc_jit_rvalue
*get_inner_rvalue () const;
416 rvalue
access_field (field field
,
417 location loc
= location ());
419 lvalue
dereference_field (field field
,
420 location loc
= location ());
422 lvalue
dereference (location loc
= location ());
424 rvalue
cast_to (type type_
,
425 location loc
= location ());
428 lvalue
operator[] (rvalue index
);
429 lvalue
operator[] (int index
);
432 class lvalue
: public rvalue
436 lvalue (gcc_jit_lvalue
*inner
);
438 gcc_jit_lvalue
*get_inner_lvalue () const;
440 lvalue
access_field (field field
,
441 location loc
= location ());
443 rvalue
get_address (location loc
= location ());
446 class param
: public lvalue
450 param (gcc_jit_param
*inner
);
452 gcc_jit_param
*get_inner_param () const;
456 /* Overloaded operators, for those who want the most terse API
457 (at the possible risk of being a little too magical).
459 In each case, the first parameter is used to determine which context
460 owns the resulting expression, and, where appropriate, what the
463 /* Unary operators. */
464 rvalue
operator- (rvalue a
); // unary minus
465 rvalue
operator~ (rvalue a
); // unary bitwise negate
466 rvalue
operator! (rvalue a
); // unary logical negate
468 /* Binary operators. */
469 rvalue
operator+ (rvalue a
, rvalue b
);
470 rvalue
operator- (rvalue a
, rvalue b
);
471 rvalue
operator* (rvalue a
, rvalue b
);
472 rvalue
operator/ (rvalue a
, rvalue b
);
473 rvalue
operator% (rvalue a
, rvalue b
);
474 rvalue
operator& (rvalue a
, rvalue b
); // bitwise and
475 rvalue
operator^ (rvalue a
, rvalue b
); // bitwise_xor
476 rvalue
operator| (rvalue a
, rvalue b
); // bitwise_or
477 rvalue
operator&& (rvalue a
, rvalue b
); // logical_and
478 rvalue
operator|| (rvalue a
, rvalue b
); // logical_or
481 rvalue
operator== (rvalue a
, rvalue b
);
482 rvalue
operator!= (rvalue a
, rvalue b
);
483 rvalue
operator< (rvalue a
, rvalue b
);
484 rvalue
operator<= (rvalue a
, rvalue b
);
485 rvalue
operator> (rvalue a
, rvalue b
);
486 rvalue
operator>= (rvalue a
, rvalue b
);
489 lvalue
operator* (rvalue ptr
);
492 /****************************************************************************
493 Implementation of the API
494 ****************************************************************************/
498 inline context
context::acquire ()
500 return context (gcc_jit_context_acquire ());
502 inline context::context () : m_inner_ctxt (NULL
) {}
503 inline context::context (gcc_jit_context
*inner
) : m_inner_ctxt (inner
)
509 inline gccjit::context
510 context::new_child_context ()
512 return context (gcc_jit_context_new_child_context (m_inner_ctxt
));
518 gcc_jit_context_release (m_inner_ctxt
);
522 inline gcc_jit_result
*
525 gcc_jit_result
*result
= gcc_jit_context_compile (m_inner_ctxt
);
532 context::dump_to_file (const std::string
&path
,
533 bool update_locations
)
535 gcc_jit_context_dump_to_file (m_inner_ctxt
,
541 context::set_int_option (enum gcc_jit_int_option opt
,
544 gcc_jit_context_set_int_option (m_inner_ctxt
, opt
, value
);
549 context::set_bool_option (enum gcc_jit_bool_option opt
,
552 gcc_jit_context_set_bool_option (m_inner_ctxt
, opt
, value
);
557 context::new_location (const std::string
&filename
,
561 return location (gcc_jit_context_new_location (m_inner_ctxt
,
568 context::get_type (enum gcc_jit_types kind
)
570 return type (gcc_jit_context_get_type (m_inner_ctxt
, kind
));
574 context::get_int_type (size_t num_bytes
, int is_signed
)
576 return type (gcc_jit_context_get_int_type (m_inner_ctxt
,
581 template <typename T
>
583 context::get_int_type ()
585 return get_int_type (sizeof (T
), std::numeric_limits
<T
>::is_signed
);
589 context::new_array_type (type element_type
, int num_elements
, location loc
)
591 return type (gcc_jit_context_new_array_type (
593 loc
.get_inner_location (),
594 element_type
.get_inner_type (),
599 context::new_field (type type_
, const std::string
&name
, location loc
)
601 return field (gcc_jit_context_new_field (m_inner_ctxt
,
602 loc
.get_inner_location (),
603 type_
.get_inner_type (),
608 context::new_struct_type (const std::string
&name
,
609 std::vector
<field
> &fields
,
612 /* Treat std::vector as an array, relying on it not being resized: */
613 field
*as_array_of_wrappers
= &fields
[0];
615 /* Treat the array as being of the underlying pointers, relying on
616 the wrapper type being such a pointer internally. */
617 gcc_jit_field
**as_array_of_ptrs
=
618 reinterpret_cast<gcc_jit_field
**> (as_array_of_wrappers
);
620 return struct_ (gcc_jit_context_new_struct_type (m_inner_ctxt
,
621 loc
.get_inner_location (),
628 context::new_opaque_struct_type (const std::string
&name
,
631 return struct_ (gcc_jit_context_new_opaque_struct (
633 loc
.get_inner_location (),
638 context::new_param (type type_
,
639 const std::string
&name
,
642 return param (gcc_jit_context_new_param (m_inner_ctxt
,
643 loc
.get_inner_location (),
644 type_
.get_inner_type (),
649 context::new_function (enum gcc_jit_function_kind kind
,
651 const std::string
&name
,
652 std::vector
<param
> ¶ms
,
656 /* Treat std::vector as an array, relying on it not being resized: */
657 param
*as_array_of_wrappers
= ¶ms
[0];
659 /* Treat the array as being of the underlying pointers, relying on
660 the wrapper type being such a pointer internally. */
661 gcc_jit_param
**as_array_of_ptrs
=
662 reinterpret_cast<gcc_jit_param
**> (as_array_of_wrappers
);
664 return function (gcc_jit_context_new_function (m_inner_ctxt
,
665 loc
.get_inner_location (),
667 return_type
.get_inner_type (),
675 context::get_builtin_function (const std::string
&name
)
677 return function (gcc_jit_context_get_builtin_function (m_inner_ctxt
,
682 context::new_global (type type_
,
683 const std::string
&name
,
686 return lvalue (gcc_jit_context_new_global (m_inner_ctxt
,
687 loc
.get_inner_location (),
688 type_
.get_inner_type (),
693 context::new_rvalue (type numeric_type
,
697 gcc_jit_context_new_rvalue_from_int (m_inner_ctxt
,
698 numeric_type
.get_inner_type (),
703 context::zero (type numeric_type
) const
705 return rvalue (gcc_jit_context_zero (m_inner_ctxt
,
706 numeric_type
.get_inner_type ()));
710 context::one (type numeric_type
) const
712 return rvalue (gcc_jit_context_one (m_inner_ctxt
,
713 numeric_type
.get_inner_type ()));
717 context::new_rvalue (type numeric_type
,
721 gcc_jit_context_new_rvalue_from_double (m_inner_ctxt
,
722 numeric_type
.get_inner_type (),
727 context::new_rvalue (type pointer_type
,
731 gcc_jit_context_new_rvalue_from_ptr (m_inner_ctxt
,
732 pointer_type
.get_inner_type (),
737 context::new_rvalue (const std::string
&value
) const
740 gcc_jit_context_new_string_literal (m_inner_ctxt
, value
.c_str ()));
744 context::new_unary_op (enum gcc_jit_unary_op op
,
749 return rvalue (gcc_jit_context_new_unary_op (m_inner_ctxt
,
750 loc
.get_inner_location (),
752 result_type
.get_inner_type (),
753 a
.get_inner_rvalue ()));
756 context::new_minus (type result_type
,
760 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_MINUS
,
761 result_type
, a
, loc
));
764 context::new_bitwise_negate (type result_type
,
768 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_BITWISE_NEGATE
,
769 result_type
, a
, loc
));
772 context::new_logical_negate (type result_type
,
776 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_LOGICAL_NEGATE
,
777 result_type
, a
, loc
));
781 context::new_binary_op (enum gcc_jit_binary_op op
,
786 return rvalue (gcc_jit_context_new_binary_op (m_inner_ctxt
,
787 loc
.get_inner_location (),
789 result_type
.get_inner_type (),
790 a
.get_inner_rvalue (),
791 b
.get_inner_rvalue ()));
794 context::new_plus (type result_type
,
798 return new_binary_op (GCC_JIT_BINARY_OP_PLUS
,
799 result_type
, a
, b
, loc
);
802 context::new_minus (type result_type
,
806 return new_binary_op (GCC_JIT_BINARY_OP_MINUS
,
807 result_type
, a
, b
, loc
);
810 context::new_mult (type result_type
,
814 return new_binary_op (GCC_JIT_BINARY_OP_MULT
,
815 result_type
, a
, b
, loc
);
818 context::new_divide (type result_type
,
822 return new_binary_op (GCC_JIT_BINARY_OP_DIVIDE
,
823 result_type
, a
, b
, loc
);
826 context::new_modulo (type result_type
,
830 return new_binary_op (GCC_JIT_BINARY_OP_MODULO
,
831 result_type
, a
, b
, loc
);
834 context::new_bitwise_and (type result_type
,
838 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_AND
,
839 result_type
, a
, b
, loc
);
842 context::new_bitwise_xor (type result_type
,
846 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_XOR
,
847 result_type
, a
, b
, loc
);
850 context::new_bitwise_or (type result_type
,
854 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_OR
,
855 result_type
, a
, b
, loc
);
858 context::new_logical_and (type result_type
,
862 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_AND
,
863 result_type
, a
, b
, loc
);
866 context::new_logical_or (type result_type
,
870 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_OR
,
871 result_type
, a
, b
, loc
);
875 context::new_comparison (enum gcc_jit_comparison op
,
879 return rvalue (gcc_jit_context_new_comparison (m_inner_ctxt
,
880 loc
.get_inner_location (),
882 a
.get_inner_rvalue (),
883 b
.get_inner_rvalue ()));
886 context::new_eq (rvalue a
, rvalue b
,
889 return new_comparison (GCC_JIT_COMPARISON_EQ
,
893 context::new_ne (rvalue a
, rvalue b
,
896 return new_comparison (GCC_JIT_COMPARISON_NE
,
900 context::new_lt (rvalue a
, rvalue b
,
903 return new_comparison (GCC_JIT_COMPARISON_LT
,
907 context::new_le (rvalue a
, rvalue b
,
910 return new_comparison (GCC_JIT_COMPARISON_LE
,
914 context::new_gt (rvalue a
, rvalue b
,
917 return new_comparison (GCC_JIT_COMPARISON_GT
,
921 context::new_ge (rvalue a
, rvalue b
,
924 return new_comparison (GCC_JIT_COMPARISON_GE
,
929 context::new_call (function func
,
930 std::vector
<rvalue
> &args
,
933 /* Treat std::vector as an array, relying on it not being resized: */
934 rvalue
*as_array_of_wrappers
= &args
[0];
936 /* Treat the array as being of the underlying pointers, relying on
937 the wrapper type being such a pointer internally. */
938 gcc_jit_rvalue
**as_array_of_ptrs
=
939 reinterpret_cast<gcc_jit_rvalue
**> (as_array_of_wrappers
);
940 return gcc_jit_context_new_call (m_inner_ctxt
,
941 loc
.get_inner_location (),
942 func
.get_inner_function (),
947 context::new_call (function func
,
950 std::vector
<rvalue
> args
;
951 return new_call (func
, args
, loc
);
955 context::new_call (function func
,
959 std::vector
<rvalue
> args(1);
961 return new_call (func
, args
, loc
);
964 context::new_call (function func
,
965 rvalue arg0
, rvalue arg1
,
968 std::vector
<rvalue
> args(2);
971 return new_call (func
, args
, loc
);
974 context::new_call (function func
,
975 rvalue arg0
, rvalue arg1
, rvalue arg2
,
978 std::vector
<rvalue
> args(3);
982 return new_call (func
, args
, loc
);
985 context::new_call (function func
,
986 rvalue arg0
, rvalue arg1
, rvalue arg2
,
990 std::vector
<rvalue
> args(4);
995 return new_call (func
, args
, loc
);
998 context::new_call (function func
,
999 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1000 rvalue arg3
, rvalue arg4
,
1003 std::vector
<rvalue
> args(5);
1009 return new_call (func
, args
, loc
);
1012 context::new_call (function func
,
1013 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1014 rvalue arg3
, rvalue arg4
, rvalue arg5
,
1017 std::vector
<rvalue
> args(6);
1024 return new_call (func
, args
, loc
);
1028 context::new_cast (rvalue expr
,
1032 return rvalue (gcc_jit_context_new_cast (m_inner_ctxt
,
1033 loc
.get_inner_location (),
1034 expr
.get_inner_rvalue (),
1035 type_
.get_inner_type ()));
1039 context::new_array_access (rvalue ptr
,
1043 return lvalue (gcc_jit_context_new_array_access (m_inner_ctxt
,
1044 loc
.get_inner_location (),
1045 ptr
.get_inner_rvalue (),
1046 index
.get_inner_rvalue ()));
1051 object::get_context () const
1053 return context (gcc_jit_object_get_context (m_inner_obj
));
1057 object::get_debug_string () const
1059 return gcc_jit_object_get_debug_string (m_inner_obj
);
1062 inline object::object () : m_inner_obj (NULL
) {}
1063 inline object::object (gcc_jit_object
*obj
) : m_inner_obj (obj
)
1069 inline gcc_jit_object
*
1070 object::get_inner_object () const
1075 inline std::ostream
&
1076 operator << (std::ostream
& stream
, const object
&obj
)
1078 return stream
<< obj
.get_debug_string ();
1082 inline location::location () : object () {}
1083 inline location::location (gcc_jit_location
*loc
)
1084 : object (gcc_jit_location_as_object (loc
))
1087 inline gcc_jit_location
*
1088 location::get_inner_location () const
1090 /* Manual downcast: */
1091 return reinterpret_cast<gcc_jit_location
*> (get_inner_object ());
1095 inline field::field () : object () {}
1096 inline field::field (gcc_jit_field
*inner
)
1097 : object (gcc_jit_field_as_object (inner
))
1100 inline gcc_jit_field
*
1101 field::get_inner_field () const
1103 /* Manual downcast: */
1104 return reinterpret_cast<gcc_jit_field
*> (get_inner_object ());
1108 inline type::type () : object () {}
1109 inline type::type (gcc_jit_type
*inner
)
1110 : object (gcc_jit_type_as_object (inner
))
1113 inline gcc_jit_type
*
1114 type::get_inner_type () const
1116 /* Manual downcast: */
1117 return reinterpret_cast<gcc_jit_type
*> (get_inner_object ());
1121 type::get_pointer ()
1123 return type (gcc_jit_type_get_pointer (get_inner_type ()));
1127 type::get_volatile ()
1129 return type (gcc_jit_type_get_volatile (get_inner_type ()));
1135 return get_context ().new_rvalue (*this, 0);
1141 return get_context ().new_rvalue (*this, 1);
1145 inline struct_::struct_ () : type (NULL
) {}
1146 inline struct_::struct_ (gcc_jit_struct
*inner
) :
1147 type (gcc_jit_struct_as_type (inner
))
1151 inline gcc_jit_struct
*
1152 struct_::get_inner_struct () const
1154 /* Manual downcast: */
1155 return reinterpret_cast<gcc_jit_struct
*> (get_inner_object ());
1159 inline function::function () : object () {}
1160 inline function::function (gcc_jit_function
*inner
)
1161 : object (gcc_jit_function_as_object (inner
))
1164 inline gcc_jit_function
*
1165 function::get_inner_function () const
1167 /* Manual downcast: */
1168 return reinterpret_cast<gcc_jit_function
*> (get_inner_object ());
1172 function::dump_to_dot (const std::string
&path
)
1174 gcc_jit_function_dump_to_dot (get_inner_function (),
1179 function::get_param (int index
) const
1181 return param (gcc_jit_function_get_param (get_inner_function (),
1186 function::new_block ()
1188 return block (gcc_jit_function_new_block (get_inner_function (),
1193 function::new_block (const std::string
&name
)
1195 return block (gcc_jit_function_new_block (get_inner_function (),
1200 function::new_local (type type_
,
1201 const std::string
&name
,
1204 return lvalue (gcc_jit_function_new_local (get_inner_function (),
1205 loc
.get_inner_location (),
1206 type_
.get_inner_type (),
1211 block::get_function () const
1213 return function (gcc_jit_block_get_function ( get_inner_block ()));
1217 block::add_eval (rvalue rvalue
,
1220 gcc_jit_block_add_eval (get_inner_block (),
1221 loc
.get_inner_location (),
1222 rvalue
.get_inner_rvalue ());
1226 block::add_assignment (lvalue lvalue
,
1230 gcc_jit_block_add_assignment (get_inner_block (),
1231 loc
.get_inner_location (),
1232 lvalue
.get_inner_lvalue (),
1233 rvalue
.get_inner_rvalue ());
1237 block::add_assignment_op (lvalue lvalue
,
1238 enum gcc_jit_binary_op op
,
1242 gcc_jit_block_add_assignment_op (get_inner_block (),
1243 loc
.get_inner_location (),
1244 lvalue
.get_inner_lvalue (),
1246 rvalue
.get_inner_rvalue ());
1250 block::add_comment (const std::string
&text
,
1253 gcc_jit_block_add_comment (get_inner_block (),
1254 loc
.get_inner_location (),
1259 block::end_with_conditional (rvalue boolval
,
1264 gcc_jit_block_end_with_conditional (get_inner_block (),
1265 loc
.get_inner_location (),
1266 boolval
.get_inner_rvalue (),
1267 on_true
.get_inner_block (),
1268 on_false
.get_inner_block ());
1272 block::end_with_jump (block target
,
1275 gcc_jit_block_end_with_jump (get_inner_block (),
1276 loc
.get_inner_location (),
1277 target
.get_inner_block ());
1281 block::end_with_return (rvalue rvalue
,
1284 gcc_jit_block_end_with_return (get_inner_block (),
1285 loc
.get_inner_location (),
1286 rvalue
.get_inner_rvalue ());
1290 block::end_with_return (location loc
)
1292 gcc_jit_block_end_with_void_return (get_inner_block (),
1293 loc
.get_inner_location ());
1297 block::add_call (function other
,
1300 rvalue c
= get_context ().new_call (other
, loc
);
1305 block::add_call (function other
,
1309 rvalue c
= get_context ().new_call (other
, arg0
, loc
);
1314 block::add_call (function other
,
1315 rvalue arg0
, rvalue arg1
,
1318 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, loc
);
1323 block::add_call (function other
,
1324 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1327 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, loc
);
1333 block::add_call (function other
,
1334 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
1337 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, arg3
, loc
);
1343 function::operator() (location loc
)
1345 return get_context ().new_call (*this, loc
);
1348 function::operator() (rvalue arg0
,
1351 return get_context ().new_call (*this,
1356 function::operator() (rvalue arg0
, rvalue arg1
,
1359 return get_context ().new_call (*this,
1364 function::operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
1367 return get_context ().new_call (*this,
1373 inline block::block () : object () {}
1374 inline block::block (gcc_jit_block
*inner
)
1375 : object (gcc_jit_block_as_object (inner
))
1378 inline gcc_jit_block
*
1379 block::get_inner_block () const
1381 /* Manual downcast: */
1382 return reinterpret_cast<gcc_jit_block
*> (get_inner_object ());
1386 inline rvalue::rvalue () : object () {}
1387 inline rvalue::rvalue (gcc_jit_rvalue
*inner
)
1388 : object (gcc_jit_rvalue_as_object (inner
))
1391 inline gcc_jit_rvalue
*
1392 rvalue::get_inner_rvalue () const
1394 /* Manual downcast: */
1395 return reinterpret_cast<gcc_jit_rvalue
*> (get_inner_object ());
1401 return type (gcc_jit_rvalue_get_type (get_inner_rvalue ()));
1405 rvalue::access_field (field field
,
1408 return rvalue (gcc_jit_rvalue_access_field (get_inner_rvalue (),
1409 loc
.get_inner_location (),
1410 field
.get_inner_field ()));
1414 rvalue::dereference_field (field field
,
1417 return lvalue (gcc_jit_rvalue_dereference_field (get_inner_rvalue (),
1418 loc
.get_inner_location (),
1419 field
.get_inner_field ()));
1423 rvalue::dereference (location loc
)
1425 return lvalue (gcc_jit_rvalue_dereference (get_inner_rvalue (),
1426 loc
.get_inner_location ()));
1430 rvalue::cast_to (type type_
,
1433 return get_context ().new_cast (*this, type_
, loc
);
1437 rvalue::operator[] (rvalue index
)
1439 return get_context ().new_array_access (*this, index
);
1443 rvalue::operator[] (int index
)
1445 context ctxt
= get_context ();
1446 type int_t
= ctxt
.get_int_type
<int> ();
1447 return ctxt
.new_array_access (*this,
1448 ctxt
.new_rvalue (int_t
,
1452 // class lvalue : public rvalue
1453 inline lvalue::lvalue () : rvalue () {}
1454 inline lvalue::lvalue (gcc_jit_lvalue
*inner
)
1455 : rvalue (gcc_jit_lvalue_as_rvalue (inner
))
1458 inline gcc_jit_lvalue
*
1459 lvalue::get_inner_lvalue () const
1461 /* Manual downcast: */
1462 return reinterpret_cast<gcc_jit_lvalue
*> (get_inner_object ());
1466 lvalue::access_field (field field
, location loc
)
1468 return lvalue (gcc_jit_lvalue_access_field (get_inner_lvalue (),
1469 loc
.get_inner_location (),
1470 field
.get_inner_field ()));
1474 lvalue::get_address (location loc
)
1476 return rvalue (gcc_jit_lvalue_get_address (get_inner_lvalue (),
1477 loc
.get_inner_location ()));
1480 // class param : public lvalue
1481 inline param::param () : lvalue () {}
1482 inline param::param (gcc_jit_param
*inner
)
1483 : lvalue (gcc_jit_param_as_lvalue (inner
))
1486 /* Overloaded operators. */
1488 inline rvalue
operator- (rvalue a
)
1490 return a
.get_context ().new_minus (a
.get_type (), a
);
1492 inline rvalue
operator~ (rvalue a
)
1494 return a
.get_context ().new_bitwise_negate (a
.get_type (), a
);
1496 inline rvalue
operator! (rvalue a
)
1498 return a
.get_context ().new_logical_negate (a
.get_type (), a
);
1502 inline rvalue
operator+ (rvalue a
, rvalue b
)
1504 return a
.get_context ().new_plus (a
.get_type (), a
, b
);
1506 inline rvalue
operator- (rvalue a
, rvalue b
)
1508 return a
.get_context ().new_minus (a
.get_type (), a
, b
);
1510 inline rvalue
operator* (rvalue a
, rvalue b
)
1512 return a
.get_context ().new_mult (a
.get_type (), a
, b
);
1514 inline rvalue
operator/ (rvalue a
, rvalue b
)
1516 return a
.get_context ().new_divide (a
.get_type (), a
, b
);
1518 inline rvalue
operator% (rvalue a
, rvalue b
)
1520 return a
.get_context ().new_modulo (a
.get_type (), a
, b
);
1522 inline rvalue
operator& (rvalue a
, rvalue b
)
1524 return a
.get_context ().new_bitwise_and (a
.get_type (), a
, b
);
1526 inline rvalue
operator^ (rvalue a
, rvalue b
)
1528 return a
.get_context ().new_bitwise_xor (a
.get_type (), a
, b
);
1530 inline rvalue
operator| (rvalue a
, rvalue b
)
1532 return a
.get_context ().new_bitwise_or (a
.get_type (), a
, b
);
1534 inline rvalue
operator&& (rvalue a
, rvalue b
)
1536 return a
.get_context ().new_logical_and (a
.get_type (), a
, b
);
1538 inline rvalue
operator|| (rvalue a
, rvalue b
)
1540 return a
.get_context ().new_logical_or (a
.get_type (), a
, b
);
1544 inline rvalue
operator== (rvalue a
, rvalue b
)
1546 return a
.get_context ().new_eq (a
, b
);
1548 inline rvalue
operator!= (rvalue a
, rvalue b
)
1550 return a
.get_context ().new_ne (a
, b
);
1552 inline rvalue
operator< (rvalue a
, rvalue b
)
1554 return a
.get_context ().new_lt (a
, b
);
1556 inline rvalue
operator<= (rvalue a
, rvalue b
)
1558 return a
.get_context ().new_le (a
, b
);
1560 inline rvalue
operator> (rvalue a
, rvalue b
)
1562 return a
.get_context ().new_gt (a
, b
);
1564 inline rvalue
operator>= (rvalue a
, rvalue b
)
1566 return a
.get_context ().new_ge (a
, b
);
1569 /* Dereferencing. */
1570 inline lvalue
operator* (rvalue ptr
)
1572 return ptr
.dereference ();
1575 } // namespace gccjit
1577 #endif /* #ifndef LIBGCCJIT_PLUS_PLUS_H */