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_str_option (enum gcc_jit_str_option opt
,
108 void set_int_option (enum gcc_jit_int_option opt
,
111 void set_bool_option (enum gcc_jit_bool_option opt
,
115 new_location (const std::string
&filename
,
119 type
get_type (enum gcc_jit_types kind
);
120 type
get_int_type (size_t num_bytes
, int is_signed
);
122 /* A way to map a specific int type, using the compiler to
123 get the details automatically e.g.:
124 gccjit::type type = get_int_type <my_int_type_t> (); */
125 template <typename T
>
126 type
get_int_type ();
128 type
new_array_type (type element_type
, int num_elements
,
129 location loc
= location ());
131 field
new_field (type type_
, const std::string
&name
,
132 location loc
= location ());
134 struct_
new_struct_type (const std::string
&name
,
135 std::vector
<field
> &fields
,
136 location loc
= location ());
138 struct_
new_opaque_struct_type (const std::string
&name
,
139 location loc
= location ());
141 param
new_param (type type_
,
142 const std::string
&name
,
143 location loc
= location ());
145 function
new_function (enum gcc_jit_function_kind kind
,
147 const std::string
&name
,
148 std::vector
<param
> ¶ms
,
150 location loc
= location ());
152 function
get_builtin_function (const std::string
&name
);
154 lvalue
new_global (type type_
,
155 const std::string
&name
,
156 location loc
= location ());
158 rvalue
new_rvalue (type numeric_type
,
160 rvalue
zero (type numeric_type
) const;
161 rvalue
one (type numeric_type
) const;
162 rvalue
new_rvalue (type numeric_type
,
164 rvalue
new_rvalue (type pointer_type
,
166 rvalue
new_rvalue (const std::string
&value
) const;
168 /* Generic unary operations... */
169 rvalue
new_unary_op (enum gcc_jit_unary_op op
,
172 location loc
= location ());
174 /* ...and shorter ways to spell the various specific kinds of
176 rvalue
new_minus (type result_type
,
178 location loc
= location ());
179 rvalue
new_bitwise_negate (type result_type
,
181 location loc
= location ());
182 rvalue
new_logical_negate (type result_type
,
184 location loc
= location ());
186 /* Generic binary operations... */
187 rvalue
new_binary_op (enum gcc_jit_binary_op op
,
190 location loc
= location ());
192 /* ...and shorter ways to spell the various specific kinds of
194 rvalue
new_plus (type result_type
,
196 location loc
= location ());
197 rvalue
new_minus (type result_type
,
199 location loc
= location ());
200 rvalue
new_mult (type result_type
,
202 location loc
= location ());
203 rvalue
new_divide (type result_type
,
205 location loc
= location ());
206 rvalue
new_modulo (type result_type
,
208 location loc
= location ());
209 rvalue
new_bitwise_and (type result_type
,
211 location loc
= location ());
212 rvalue
new_bitwise_xor (type result_type
,
214 location loc
= location ());
215 rvalue
new_bitwise_or (type result_type
,
217 location loc
= location ());
218 rvalue
new_logical_and (type result_type
,
220 location loc
= location ());
221 rvalue
new_logical_or (type result_type
,
223 location loc
= location ());
225 /* Generic comparisons... */
226 rvalue
new_comparison (enum gcc_jit_comparison op
,
228 location loc
= location ());
229 /* ...and shorter ways to spell the various specific kinds of
231 rvalue
new_eq (rvalue a
, rvalue b
,
232 location loc
= location ());
233 rvalue
new_ne (rvalue a
, rvalue b
,
234 location loc
= location ());
235 rvalue
new_lt (rvalue a
, rvalue b
,
236 location loc
= location ());
237 rvalue
new_le (rvalue a
, rvalue b
,
238 location loc
= location ());
239 rvalue
new_gt (rvalue a
, rvalue b
,
240 location loc
= location ());
241 rvalue
new_ge (rvalue a
, rvalue b
,
242 location loc
= location ());
244 /* The most general way of creating a function call. */
245 rvalue
new_call (function func
,
246 std::vector
<rvalue
> &args
,
247 location loc
= location ());
249 /* In addition, we provide a series of overloaded "new_call" methods
250 for specific numbers of args (from 0 - 6), to avoid the need for
251 client code to manually build a vector. */
252 rvalue
new_call (function func
,
253 location loc
= location ());
254 rvalue
new_call (function func
,
256 location loc
= location ());
257 rvalue
new_call (function func
,
258 rvalue arg0
, rvalue arg1
,
259 location loc
= location ());
260 rvalue
new_call (function func
,
261 rvalue arg0
, rvalue arg1
, rvalue arg2
,
262 location loc
= location ());
263 rvalue
new_call (function func
,
264 rvalue arg0
, rvalue arg1
, rvalue arg2
,
266 location loc
= location ());
267 rvalue
new_call (function func
,
268 rvalue arg0
, rvalue arg1
, rvalue arg2
,
269 rvalue arg3
, rvalue arg4
,
270 location loc
= location ());
271 rvalue
new_call (function func
,
272 rvalue arg0
, rvalue arg1
, rvalue arg2
,
273 rvalue arg3
, rvalue arg4
, rvalue arg5
,
274 location loc
= location ());
276 rvalue
new_cast (rvalue expr
,
278 location loc
= location ());
280 lvalue
new_array_access (rvalue ptr
,
282 location loc
= location ());
285 gcc_jit_context
*m_inner_ctxt
;
288 class field
: public object
292 field (gcc_jit_field
*inner
);
294 gcc_jit_field
*get_inner_field () const;
297 class type
: public object
301 type (gcc_jit_type
*inner
);
303 gcc_jit_type
*get_inner_type () const;
306 type
get_volatile ();
308 // Shortcuts for getting values of numeric types:
313 class struct_
: public type
317 struct_ (gcc_jit_struct
*inner
);
319 gcc_jit_struct
*get_inner_struct () const;
322 class function
: public object
326 function (gcc_jit_function
*func
);
328 gcc_jit_function
*get_inner_function () const;
330 void dump_to_dot (const std::string
&path
);
332 param
get_param (int index
) const;
335 block
new_block (const std::string
&name
);
337 lvalue
new_local (type type_
,
338 const std::string
&name
,
339 location loc
= location ());
341 /* A series of overloaded operator () with various numbers of arguments
342 for a very terse way of creating a call to this function. The call
343 is created within the same context as the function itself, which may
344 not be what you want. */
345 rvalue
operator() (location loc
= location ());
346 rvalue
operator() (rvalue arg0
,
347 location loc
= location ());
348 rvalue
operator() (rvalue arg0
, rvalue arg1
,
349 location loc
= location ());
350 rvalue
operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
351 location loc
= location ());
354 class block
: public object
358 block (gcc_jit_block
*inner
);
360 gcc_jit_block
*get_inner_block () const;
362 function
get_function () const;
364 void add_eval (rvalue rvalue
,
365 location loc
= location ());
367 void add_assignment (lvalue lvalue
,
369 location loc
= location ());
371 void add_assignment_op (lvalue lvalue
,
372 enum gcc_jit_binary_op op
,
374 location loc
= location ());
376 /* A way to add a function call to the body of a function being
377 defined, with various numbers of args. */
378 rvalue
add_call (function other
,
379 location loc
= location ());
380 rvalue
add_call (function other
,
382 location loc
= location ());
383 rvalue
add_call (function other
,
384 rvalue arg0
, rvalue arg1
,
385 location loc
= location ());
386 rvalue
add_call (function other
,
387 rvalue arg0
, rvalue arg1
, rvalue arg2
,
388 location loc
= location ());
389 rvalue
add_call (function other
,
390 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
391 location loc
= location ());
393 void add_comment (const std::string
&text
,
394 location loc
= location ());
396 void end_with_conditional (rvalue boolval
,
399 location loc
= location ());
401 void end_with_jump (block target
,
402 location loc
= location ());
404 void end_with_return (rvalue rvalue
,
405 location loc
= location ());
406 void end_with_return (location loc
= location ());
410 class rvalue
: public object
414 rvalue (gcc_jit_rvalue
*inner
);
415 gcc_jit_rvalue
*get_inner_rvalue () const;
419 rvalue
access_field (field field
,
420 location loc
= location ());
422 lvalue
dereference_field (field field
,
423 location loc
= location ());
425 lvalue
dereference (location loc
= location ());
427 rvalue
cast_to (type type_
,
428 location loc
= location ());
431 lvalue
operator[] (rvalue index
);
432 lvalue
operator[] (int index
);
435 class lvalue
: public rvalue
439 lvalue (gcc_jit_lvalue
*inner
);
441 gcc_jit_lvalue
*get_inner_lvalue () const;
443 lvalue
access_field (field field
,
444 location loc
= location ());
446 rvalue
get_address (location loc
= location ());
449 class param
: public lvalue
453 param (gcc_jit_param
*inner
);
455 gcc_jit_param
*get_inner_param () const;
459 /* Overloaded operators, for those who want the most terse API
460 (at the possible risk of being a little too magical).
462 In each case, the first parameter is used to determine which context
463 owns the resulting expression, and, where appropriate, what the
466 /* Unary operators. */
467 rvalue
operator- (rvalue a
); // unary minus
468 rvalue
operator~ (rvalue a
); // unary bitwise negate
469 rvalue
operator! (rvalue a
); // unary logical negate
471 /* Binary operators. */
472 rvalue
operator+ (rvalue a
, rvalue b
);
473 rvalue
operator- (rvalue a
, rvalue b
);
474 rvalue
operator* (rvalue a
, rvalue b
);
475 rvalue
operator/ (rvalue a
, rvalue b
);
476 rvalue
operator% (rvalue a
, rvalue b
);
477 rvalue
operator& (rvalue a
, rvalue b
); // bitwise and
478 rvalue
operator^ (rvalue a
, rvalue b
); // bitwise_xor
479 rvalue
operator| (rvalue a
, rvalue b
); // bitwise_or
480 rvalue
operator&& (rvalue a
, rvalue b
); // logical_and
481 rvalue
operator|| (rvalue a
, rvalue b
); // logical_or
484 rvalue
operator== (rvalue a
, rvalue b
);
485 rvalue
operator!= (rvalue a
, rvalue b
);
486 rvalue
operator< (rvalue a
, rvalue b
);
487 rvalue
operator<= (rvalue a
, rvalue b
);
488 rvalue
operator> (rvalue a
, rvalue b
);
489 rvalue
operator>= (rvalue a
, rvalue b
);
492 lvalue
operator* (rvalue ptr
);
495 /****************************************************************************
496 Implementation of the API
497 ****************************************************************************/
501 inline context
context::acquire ()
503 return context (gcc_jit_context_acquire ());
505 inline context::context () : m_inner_ctxt (NULL
) {}
506 inline context::context (gcc_jit_context
*inner
) : m_inner_ctxt (inner
)
512 inline gccjit::context
513 context::new_child_context ()
515 return context (gcc_jit_context_new_child_context (m_inner_ctxt
));
521 gcc_jit_context_release (m_inner_ctxt
);
525 inline gcc_jit_result
*
528 gcc_jit_result
*result
= gcc_jit_context_compile (m_inner_ctxt
);
535 context::dump_to_file (const std::string
&path
,
536 bool update_locations
)
538 gcc_jit_context_dump_to_file (m_inner_ctxt
,
544 context::set_str_option (enum gcc_jit_str_option opt
,
547 gcc_jit_context_set_str_option (m_inner_ctxt
, opt
, value
);
552 context::set_int_option (enum gcc_jit_int_option opt
,
555 gcc_jit_context_set_int_option (m_inner_ctxt
, opt
, value
);
560 context::set_bool_option (enum gcc_jit_bool_option opt
,
563 gcc_jit_context_set_bool_option (m_inner_ctxt
, opt
, value
);
568 context::new_location (const std::string
&filename
,
572 return location (gcc_jit_context_new_location (m_inner_ctxt
,
579 context::get_type (enum gcc_jit_types kind
)
581 return type (gcc_jit_context_get_type (m_inner_ctxt
, kind
));
585 context::get_int_type (size_t num_bytes
, int is_signed
)
587 return type (gcc_jit_context_get_int_type (m_inner_ctxt
,
592 template <typename T
>
594 context::get_int_type ()
596 return get_int_type (sizeof (T
), std::numeric_limits
<T
>::is_signed
);
600 context::new_array_type (type element_type
, int num_elements
, location loc
)
602 return type (gcc_jit_context_new_array_type (
604 loc
.get_inner_location (),
605 element_type
.get_inner_type (),
610 context::new_field (type type_
, const std::string
&name
, location loc
)
612 return field (gcc_jit_context_new_field (m_inner_ctxt
,
613 loc
.get_inner_location (),
614 type_
.get_inner_type (),
619 context::new_struct_type (const std::string
&name
,
620 std::vector
<field
> &fields
,
623 /* Treat std::vector as an array, relying on it not being resized: */
624 field
*as_array_of_wrappers
= &fields
[0];
626 /* Treat the array as being of the underlying pointers, relying on
627 the wrapper type being such a pointer internally. */
628 gcc_jit_field
**as_array_of_ptrs
=
629 reinterpret_cast<gcc_jit_field
**> (as_array_of_wrappers
);
631 return struct_ (gcc_jit_context_new_struct_type (m_inner_ctxt
,
632 loc
.get_inner_location (),
639 context::new_opaque_struct_type (const std::string
&name
,
642 return struct_ (gcc_jit_context_new_opaque_struct (
644 loc
.get_inner_location (),
649 context::new_param (type type_
,
650 const std::string
&name
,
653 return param (gcc_jit_context_new_param (m_inner_ctxt
,
654 loc
.get_inner_location (),
655 type_
.get_inner_type (),
660 context::new_function (enum gcc_jit_function_kind kind
,
662 const std::string
&name
,
663 std::vector
<param
> ¶ms
,
667 /* Treat std::vector as an array, relying on it not being resized: */
668 param
*as_array_of_wrappers
= ¶ms
[0];
670 /* Treat the array as being of the underlying pointers, relying on
671 the wrapper type being such a pointer internally. */
672 gcc_jit_param
**as_array_of_ptrs
=
673 reinterpret_cast<gcc_jit_param
**> (as_array_of_wrappers
);
675 return function (gcc_jit_context_new_function (m_inner_ctxt
,
676 loc
.get_inner_location (),
678 return_type
.get_inner_type (),
686 context::get_builtin_function (const std::string
&name
)
688 return function (gcc_jit_context_get_builtin_function (m_inner_ctxt
,
693 context::new_global (type type_
,
694 const std::string
&name
,
697 return lvalue (gcc_jit_context_new_global (m_inner_ctxt
,
698 loc
.get_inner_location (),
699 type_
.get_inner_type (),
704 context::new_rvalue (type numeric_type
,
708 gcc_jit_context_new_rvalue_from_int (m_inner_ctxt
,
709 numeric_type
.get_inner_type (),
714 context::zero (type numeric_type
) const
716 return rvalue (gcc_jit_context_zero (m_inner_ctxt
,
717 numeric_type
.get_inner_type ()));
721 context::one (type numeric_type
) const
723 return rvalue (gcc_jit_context_one (m_inner_ctxt
,
724 numeric_type
.get_inner_type ()));
728 context::new_rvalue (type numeric_type
,
732 gcc_jit_context_new_rvalue_from_double (m_inner_ctxt
,
733 numeric_type
.get_inner_type (),
738 context::new_rvalue (type pointer_type
,
742 gcc_jit_context_new_rvalue_from_ptr (m_inner_ctxt
,
743 pointer_type
.get_inner_type (),
748 context::new_rvalue (const std::string
&value
) const
751 gcc_jit_context_new_string_literal (m_inner_ctxt
, value
.c_str ()));
755 context::new_unary_op (enum gcc_jit_unary_op op
,
760 return rvalue (gcc_jit_context_new_unary_op (m_inner_ctxt
,
761 loc
.get_inner_location (),
763 result_type
.get_inner_type (),
764 a
.get_inner_rvalue ()));
767 context::new_minus (type result_type
,
771 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_MINUS
,
772 result_type
, a
, loc
));
775 context::new_bitwise_negate (type result_type
,
779 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_BITWISE_NEGATE
,
780 result_type
, a
, loc
));
783 context::new_logical_negate (type result_type
,
787 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_LOGICAL_NEGATE
,
788 result_type
, a
, loc
));
792 context::new_binary_op (enum gcc_jit_binary_op op
,
797 return rvalue (gcc_jit_context_new_binary_op (m_inner_ctxt
,
798 loc
.get_inner_location (),
800 result_type
.get_inner_type (),
801 a
.get_inner_rvalue (),
802 b
.get_inner_rvalue ()));
805 context::new_plus (type result_type
,
809 return new_binary_op (GCC_JIT_BINARY_OP_PLUS
,
810 result_type
, a
, b
, loc
);
813 context::new_minus (type result_type
,
817 return new_binary_op (GCC_JIT_BINARY_OP_MINUS
,
818 result_type
, a
, b
, loc
);
821 context::new_mult (type result_type
,
825 return new_binary_op (GCC_JIT_BINARY_OP_MULT
,
826 result_type
, a
, b
, loc
);
829 context::new_divide (type result_type
,
833 return new_binary_op (GCC_JIT_BINARY_OP_DIVIDE
,
834 result_type
, a
, b
, loc
);
837 context::new_modulo (type result_type
,
841 return new_binary_op (GCC_JIT_BINARY_OP_MODULO
,
842 result_type
, a
, b
, loc
);
845 context::new_bitwise_and (type result_type
,
849 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_AND
,
850 result_type
, a
, b
, loc
);
853 context::new_bitwise_xor (type result_type
,
857 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_XOR
,
858 result_type
, a
, b
, loc
);
861 context::new_bitwise_or (type result_type
,
865 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_OR
,
866 result_type
, a
, b
, loc
);
869 context::new_logical_and (type result_type
,
873 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_AND
,
874 result_type
, a
, b
, loc
);
877 context::new_logical_or (type result_type
,
881 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_OR
,
882 result_type
, a
, b
, loc
);
886 context::new_comparison (enum gcc_jit_comparison op
,
890 return rvalue (gcc_jit_context_new_comparison (m_inner_ctxt
,
891 loc
.get_inner_location (),
893 a
.get_inner_rvalue (),
894 b
.get_inner_rvalue ()));
897 context::new_eq (rvalue a
, rvalue b
,
900 return new_comparison (GCC_JIT_COMPARISON_EQ
,
904 context::new_ne (rvalue a
, rvalue b
,
907 return new_comparison (GCC_JIT_COMPARISON_NE
,
911 context::new_lt (rvalue a
, rvalue b
,
914 return new_comparison (GCC_JIT_COMPARISON_LT
,
918 context::new_le (rvalue a
, rvalue b
,
921 return new_comparison (GCC_JIT_COMPARISON_LE
,
925 context::new_gt (rvalue a
, rvalue b
,
928 return new_comparison (GCC_JIT_COMPARISON_GT
,
932 context::new_ge (rvalue a
, rvalue b
,
935 return new_comparison (GCC_JIT_COMPARISON_GE
,
940 context::new_call (function func
,
941 std::vector
<rvalue
> &args
,
944 /* Treat std::vector as an array, relying on it not being resized: */
945 rvalue
*as_array_of_wrappers
= &args
[0];
947 /* Treat the array as being of the underlying pointers, relying on
948 the wrapper type being such a pointer internally. */
949 gcc_jit_rvalue
**as_array_of_ptrs
=
950 reinterpret_cast<gcc_jit_rvalue
**> (as_array_of_wrappers
);
951 return gcc_jit_context_new_call (m_inner_ctxt
,
952 loc
.get_inner_location (),
953 func
.get_inner_function (),
958 context::new_call (function func
,
961 std::vector
<rvalue
> args
;
962 return new_call (func
, args
, loc
);
966 context::new_call (function func
,
970 std::vector
<rvalue
> args(1);
972 return new_call (func
, args
, loc
);
975 context::new_call (function func
,
976 rvalue arg0
, rvalue arg1
,
979 std::vector
<rvalue
> args(2);
982 return new_call (func
, args
, loc
);
985 context::new_call (function func
,
986 rvalue arg0
, rvalue arg1
, rvalue arg2
,
989 std::vector
<rvalue
> args(3);
993 return new_call (func
, args
, loc
);
996 context::new_call (function func
,
997 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1001 std::vector
<rvalue
> args(4);
1006 return new_call (func
, args
, loc
);
1009 context::new_call (function func
,
1010 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1011 rvalue arg3
, rvalue arg4
,
1014 std::vector
<rvalue
> args(5);
1020 return new_call (func
, args
, loc
);
1023 context::new_call (function func
,
1024 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1025 rvalue arg3
, rvalue arg4
, rvalue arg5
,
1028 std::vector
<rvalue
> args(6);
1035 return new_call (func
, args
, loc
);
1039 context::new_cast (rvalue expr
,
1043 return rvalue (gcc_jit_context_new_cast (m_inner_ctxt
,
1044 loc
.get_inner_location (),
1045 expr
.get_inner_rvalue (),
1046 type_
.get_inner_type ()));
1050 context::new_array_access (rvalue ptr
,
1054 return lvalue (gcc_jit_context_new_array_access (m_inner_ctxt
,
1055 loc
.get_inner_location (),
1056 ptr
.get_inner_rvalue (),
1057 index
.get_inner_rvalue ()));
1062 object::get_context () const
1064 return context (gcc_jit_object_get_context (m_inner_obj
));
1068 object::get_debug_string () const
1070 return gcc_jit_object_get_debug_string (m_inner_obj
);
1073 inline object::object () : m_inner_obj (NULL
) {}
1074 inline object::object (gcc_jit_object
*obj
) : m_inner_obj (obj
)
1080 inline gcc_jit_object
*
1081 object::get_inner_object () const
1086 inline std::ostream
&
1087 operator << (std::ostream
& stream
, const object
&obj
)
1089 return stream
<< obj
.get_debug_string ();
1093 inline location::location () : object () {}
1094 inline location::location (gcc_jit_location
*loc
)
1095 : object (gcc_jit_location_as_object (loc
))
1098 inline gcc_jit_location
*
1099 location::get_inner_location () const
1101 /* Manual downcast: */
1102 return reinterpret_cast<gcc_jit_location
*> (get_inner_object ());
1106 inline field::field () : object () {}
1107 inline field::field (gcc_jit_field
*inner
)
1108 : object (gcc_jit_field_as_object (inner
))
1111 inline gcc_jit_field
*
1112 field::get_inner_field () const
1114 /* Manual downcast: */
1115 return reinterpret_cast<gcc_jit_field
*> (get_inner_object ());
1119 inline type::type () : object () {}
1120 inline type::type (gcc_jit_type
*inner
)
1121 : object (gcc_jit_type_as_object (inner
))
1124 inline gcc_jit_type
*
1125 type::get_inner_type () const
1127 /* Manual downcast: */
1128 return reinterpret_cast<gcc_jit_type
*> (get_inner_object ());
1132 type::get_pointer ()
1134 return type (gcc_jit_type_get_pointer (get_inner_type ()));
1138 type::get_volatile ()
1140 return type (gcc_jit_type_get_volatile (get_inner_type ()));
1146 return get_context ().new_rvalue (*this, 0);
1152 return get_context ().new_rvalue (*this, 1);
1156 inline struct_::struct_ () : type (NULL
) {}
1157 inline struct_::struct_ (gcc_jit_struct
*inner
) :
1158 type (gcc_jit_struct_as_type (inner
))
1162 inline gcc_jit_struct
*
1163 struct_::get_inner_struct () const
1165 /* Manual downcast: */
1166 return reinterpret_cast<gcc_jit_struct
*> (get_inner_object ());
1170 inline function::function () : object () {}
1171 inline function::function (gcc_jit_function
*inner
)
1172 : object (gcc_jit_function_as_object (inner
))
1175 inline gcc_jit_function
*
1176 function::get_inner_function () const
1178 /* Manual downcast: */
1179 return reinterpret_cast<gcc_jit_function
*> (get_inner_object ());
1183 function::dump_to_dot (const std::string
&path
)
1185 gcc_jit_function_dump_to_dot (get_inner_function (),
1190 function::get_param (int index
) const
1192 return param (gcc_jit_function_get_param (get_inner_function (),
1197 function::new_block ()
1199 return block (gcc_jit_function_new_block (get_inner_function (),
1204 function::new_block (const std::string
&name
)
1206 return block (gcc_jit_function_new_block (get_inner_function (),
1211 function::new_local (type type_
,
1212 const std::string
&name
,
1215 return lvalue (gcc_jit_function_new_local (get_inner_function (),
1216 loc
.get_inner_location (),
1217 type_
.get_inner_type (),
1222 block::get_function () const
1224 return function (gcc_jit_block_get_function ( get_inner_block ()));
1228 block::add_eval (rvalue rvalue
,
1231 gcc_jit_block_add_eval (get_inner_block (),
1232 loc
.get_inner_location (),
1233 rvalue
.get_inner_rvalue ());
1237 block::add_assignment (lvalue lvalue
,
1241 gcc_jit_block_add_assignment (get_inner_block (),
1242 loc
.get_inner_location (),
1243 lvalue
.get_inner_lvalue (),
1244 rvalue
.get_inner_rvalue ());
1248 block::add_assignment_op (lvalue lvalue
,
1249 enum gcc_jit_binary_op op
,
1253 gcc_jit_block_add_assignment_op (get_inner_block (),
1254 loc
.get_inner_location (),
1255 lvalue
.get_inner_lvalue (),
1257 rvalue
.get_inner_rvalue ());
1261 block::add_comment (const std::string
&text
,
1264 gcc_jit_block_add_comment (get_inner_block (),
1265 loc
.get_inner_location (),
1270 block::end_with_conditional (rvalue boolval
,
1275 gcc_jit_block_end_with_conditional (get_inner_block (),
1276 loc
.get_inner_location (),
1277 boolval
.get_inner_rvalue (),
1278 on_true
.get_inner_block (),
1279 on_false
.get_inner_block ());
1283 block::end_with_jump (block target
,
1286 gcc_jit_block_end_with_jump (get_inner_block (),
1287 loc
.get_inner_location (),
1288 target
.get_inner_block ());
1292 block::end_with_return (rvalue rvalue
,
1295 gcc_jit_block_end_with_return (get_inner_block (),
1296 loc
.get_inner_location (),
1297 rvalue
.get_inner_rvalue ());
1301 block::end_with_return (location loc
)
1303 gcc_jit_block_end_with_void_return (get_inner_block (),
1304 loc
.get_inner_location ());
1308 block::add_call (function other
,
1311 rvalue c
= get_context ().new_call (other
, loc
);
1316 block::add_call (function other
,
1320 rvalue c
= get_context ().new_call (other
, arg0
, loc
);
1325 block::add_call (function other
,
1326 rvalue arg0
, rvalue arg1
,
1329 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, loc
);
1334 block::add_call (function other
,
1335 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1338 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, loc
);
1344 block::add_call (function other
,
1345 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
1348 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, arg3
, loc
);
1354 function::operator() (location loc
)
1356 return get_context ().new_call (*this, loc
);
1359 function::operator() (rvalue arg0
,
1362 return get_context ().new_call (*this,
1367 function::operator() (rvalue arg0
, rvalue arg1
,
1370 return get_context ().new_call (*this,
1375 function::operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
1378 return get_context ().new_call (*this,
1384 inline block::block () : object () {}
1385 inline block::block (gcc_jit_block
*inner
)
1386 : object (gcc_jit_block_as_object (inner
))
1389 inline gcc_jit_block
*
1390 block::get_inner_block () const
1392 /* Manual downcast: */
1393 return reinterpret_cast<gcc_jit_block
*> (get_inner_object ());
1397 inline rvalue::rvalue () : object () {}
1398 inline rvalue::rvalue (gcc_jit_rvalue
*inner
)
1399 : object (gcc_jit_rvalue_as_object (inner
))
1402 inline gcc_jit_rvalue
*
1403 rvalue::get_inner_rvalue () const
1405 /* Manual downcast: */
1406 return reinterpret_cast<gcc_jit_rvalue
*> (get_inner_object ());
1412 return type (gcc_jit_rvalue_get_type (get_inner_rvalue ()));
1416 rvalue::access_field (field field
,
1419 return rvalue (gcc_jit_rvalue_access_field (get_inner_rvalue (),
1420 loc
.get_inner_location (),
1421 field
.get_inner_field ()));
1425 rvalue::dereference_field (field field
,
1428 return lvalue (gcc_jit_rvalue_dereference_field (get_inner_rvalue (),
1429 loc
.get_inner_location (),
1430 field
.get_inner_field ()));
1434 rvalue::dereference (location loc
)
1436 return lvalue (gcc_jit_rvalue_dereference (get_inner_rvalue (),
1437 loc
.get_inner_location ()));
1441 rvalue::cast_to (type type_
,
1444 return get_context ().new_cast (*this, type_
, loc
);
1448 rvalue::operator[] (rvalue index
)
1450 return get_context ().new_array_access (*this, index
);
1454 rvalue::operator[] (int index
)
1456 context ctxt
= get_context ();
1457 type int_t
= ctxt
.get_int_type
<int> ();
1458 return ctxt
.new_array_access (*this,
1459 ctxt
.new_rvalue (int_t
,
1463 // class lvalue : public rvalue
1464 inline lvalue::lvalue () : rvalue () {}
1465 inline lvalue::lvalue (gcc_jit_lvalue
*inner
)
1466 : rvalue (gcc_jit_lvalue_as_rvalue (inner
))
1469 inline gcc_jit_lvalue
*
1470 lvalue::get_inner_lvalue () const
1472 /* Manual downcast: */
1473 return reinterpret_cast<gcc_jit_lvalue
*> (get_inner_object ());
1477 lvalue::access_field (field field
, location loc
)
1479 return lvalue (gcc_jit_lvalue_access_field (get_inner_lvalue (),
1480 loc
.get_inner_location (),
1481 field
.get_inner_field ()));
1485 lvalue::get_address (location loc
)
1487 return rvalue (gcc_jit_lvalue_get_address (get_inner_lvalue (),
1488 loc
.get_inner_location ()));
1491 // class param : public lvalue
1492 inline param::param () : lvalue () {}
1493 inline param::param (gcc_jit_param
*inner
)
1494 : lvalue (gcc_jit_param_as_lvalue (inner
))
1497 /* Overloaded operators. */
1499 inline rvalue
operator- (rvalue a
)
1501 return a
.get_context ().new_minus (a
.get_type (), a
);
1503 inline rvalue
operator~ (rvalue a
)
1505 return a
.get_context ().new_bitwise_negate (a
.get_type (), a
);
1507 inline rvalue
operator! (rvalue a
)
1509 return a
.get_context ().new_logical_negate (a
.get_type (), a
);
1513 inline rvalue
operator+ (rvalue a
, rvalue b
)
1515 return a
.get_context ().new_plus (a
.get_type (), a
, b
);
1517 inline rvalue
operator- (rvalue a
, rvalue b
)
1519 return a
.get_context ().new_minus (a
.get_type (), a
, b
);
1521 inline rvalue
operator* (rvalue a
, rvalue b
)
1523 return a
.get_context ().new_mult (a
.get_type (), a
, b
);
1525 inline rvalue
operator/ (rvalue a
, rvalue b
)
1527 return a
.get_context ().new_divide (a
.get_type (), a
, b
);
1529 inline rvalue
operator% (rvalue a
, rvalue b
)
1531 return a
.get_context ().new_modulo (a
.get_type (), a
, b
);
1533 inline rvalue
operator& (rvalue a
, rvalue b
)
1535 return a
.get_context ().new_bitwise_and (a
.get_type (), a
, b
);
1537 inline rvalue
operator^ (rvalue a
, rvalue b
)
1539 return a
.get_context ().new_bitwise_xor (a
.get_type (), a
, b
);
1541 inline rvalue
operator| (rvalue a
, rvalue b
)
1543 return a
.get_context ().new_bitwise_or (a
.get_type (), a
, b
);
1545 inline rvalue
operator&& (rvalue a
, rvalue b
)
1547 return a
.get_context ().new_logical_and (a
.get_type (), a
, b
);
1549 inline rvalue
operator|| (rvalue a
, rvalue b
)
1551 return a
.get_context ().new_logical_or (a
.get_type (), a
, b
);
1555 inline rvalue
operator== (rvalue a
, rvalue b
)
1557 return a
.get_context ().new_eq (a
, b
);
1559 inline rvalue
operator!= (rvalue a
, rvalue b
)
1561 return a
.get_context ().new_ne (a
, b
);
1563 inline rvalue
operator< (rvalue a
, rvalue b
)
1565 return a
.get_context ().new_lt (a
, b
);
1567 inline rvalue
operator<= (rvalue a
, rvalue b
)
1569 return a
.get_context ().new_le (a
, b
);
1571 inline rvalue
operator> (rvalue a
, rvalue b
)
1573 return a
.get_context ().new_gt (a
, b
);
1575 inline rvalue
operator>= (rvalue a
, rvalue b
)
1577 return a
.get_context ().new_ge (a
, b
);
1580 /* Dereferencing. */
1581 inline lvalue
operator* (rvalue ptr
)
1583 return ptr
.dereference ();
1586 } // namespace gccjit
1588 #endif /* #ifndef LIBGCCJIT_PLUS_PLUS_H */