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 ****************************************************************************/
46 /* Errors within the API become C++ exceptions of this class. */
54 context
get_context () const;
56 std::string
get_debug_string () const;
60 object (gcc_jit_object
*obj
);
62 gcc_jit_object
*get_inner_object () const;
65 gcc_jit_object
*m_inner_obj
;
68 inline std::ostream
& operator << (std::ostream
& stream
, const object
&obj
);
70 /* Some client code will want to supply source code locations, others
71 won't. To avoid doubling the number of entrypoints, everything
72 accepting a location also has a default argument. To do this, the
73 other classes need to see that "location" has a default constructor,
74 hence we need to declare it first. */
75 class location
: public object
79 location (gcc_jit_location
*loc
);
81 gcc_jit_location
*get_inner_location () const;
87 static context
acquire ();
89 context (gcc_jit_context
*ctxt
);
91 gccjit::context
new_child_context ();
93 gcc_jit_context
*get_inner_context () { return m_inner_ctxt
; }
97 gcc_jit_result
*compile ();
99 void dump_to_file (const std::string
&path
,
100 bool update_locations
);
102 void set_int_option (enum gcc_jit_int_option opt
,
105 void set_bool_option (enum gcc_jit_bool_option opt
,
109 new_location (const std::string
&filename
,
113 type
get_type (enum gcc_jit_types kind
);
114 type
get_int_type (size_t num_bytes
, int is_signed
);
116 /* A way to map a specific int type, using the compiler to
117 get the details automatically e.g.:
118 gccjit::type type = get_int_type <my_int_type_t> (); */
119 template <typename T
>
120 type
get_int_type ();
122 type
new_array_type (type element_type
, int num_elements
,
123 location loc
= location ());
125 field
new_field (type type_
, const std::string
&name
,
126 location loc
= location ());
128 struct_
new_struct_type (const std::string
&name
,
129 std::vector
<field
> &fields
,
130 location loc
= location ());
132 struct_
new_opaque_struct_type (const std::string
&name
,
133 location loc
= location ());
135 param
new_param (type type_
,
136 const std::string
&name
,
137 location loc
= location ());
139 function
new_function (enum gcc_jit_function_kind kind
,
141 const std::string
&name
,
142 std::vector
<param
> ¶ms
,
144 location loc
= location ());
146 function
get_builtin_function (const std::string
&name
);
148 lvalue
new_global (type type_
,
149 const std::string
&name
,
150 location loc
= location ());
152 rvalue
new_rvalue (type numeric_type
,
154 rvalue
zero (type numeric_type
) const;
155 rvalue
one (type numeric_type
) const;
156 rvalue
new_rvalue (type numeric_type
,
158 rvalue
new_rvalue (type pointer_type
,
160 rvalue
new_rvalue (const std::string
&value
) const;
162 /* Generic unary operations... */
163 rvalue
new_unary_op (enum gcc_jit_unary_op op
,
166 location loc
= location ());
168 /* ...and shorter ways to spell the various specific kinds of
170 rvalue
new_minus (type result_type
,
172 location loc
= location ());
173 rvalue
new_bitwise_negate (type result_type
,
175 location loc
= location ());
176 rvalue
new_logical_negate (type result_type
,
178 location loc
= location ());
180 /* Generic binary operations... */
181 rvalue
new_binary_op (enum gcc_jit_binary_op op
,
184 location loc
= location ());
186 /* ...and shorter ways to spell the various specific kinds of
188 rvalue
new_plus (type result_type
,
190 location loc
= location ());
191 rvalue
new_minus (type result_type
,
193 location loc
= location ());
194 rvalue
new_mult (type result_type
,
196 location loc
= location ());
197 rvalue
new_divide (type result_type
,
199 location loc
= location ());
200 rvalue
new_modulo (type result_type
,
202 location loc
= location ());
203 rvalue
new_bitwise_and (type result_type
,
205 location loc
= location ());
206 rvalue
new_bitwise_xor (type result_type
,
208 location loc
= location ());
209 rvalue
new_bitwise_or (type result_type
,
211 location loc
= location ());
212 rvalue
new_logical_and (type result_type
,
214 location loc
= location ());
215 rvalue
new_logical_or (type result_type
,
217 location loc
= location ());
219 /* Generic comparisons... */
220 rvalue
new_comparison (enum gcc_jit_comparison op
,
222 location loc
= location ());
223 /* ...and shorter ways to spell the various specific kinds of
225 rvalue
new_eq (rvalue a
, rvalue b
,
226 location loc
= location ());
227 rvalue
new_ne (rvalue a
, rvalue b
,
228 location loc
= location ());
229 rvalue
new_lt (rvalue a
, rvalue b
,
230 location loc
= location ());
231 rvalue
new_le (rvalue a
, rvalue b
,
232 location loc
= location ());
233 rvalue
new_gt (rvalue a
, rvalue b
,
234 location loc
= location ());
235 rvalue
new_ge (rvalue a
, rvalue b
,
236 location loc
= location ());
238 /* The most general way of creating a function call. */
239 rvalue
new_call (function func
,
240 std::vector
<rvalue
> &args
,
241 location loc
= location ());
243 /* In addition, we provide a series of overloaded "new_call" methods
244 for specific numbers of args (from 0 - 6), to avoid the need for
245 client code to manually build a vector. */
246 rvalue
new_call (function func
,
247 location loc
= location ());
248 rvalue
new_call (function func
,
250 location loc
= location ());
251 rvalue
new_call (function func
,
252 rvalue arg0
, rvalue arg1
,
253 location loc
= location ());
254 rvalue
new_call (function func
,
255 rvalue arg0
, rvalue arg1
, rvalue arg2
,
256 location loc
= location ());
257 rvalue
new_call (function func
,
258 rvalue arg0
, rvalue arg1
, rvalue arg2
,
260 location loc
= location ());
261 rvalue
new_call (function func
,
262 rvalue arg0
, rvalue arg1
, rvalue arg2
,
263 rvalue arg3
, rvalue arg4
,
264 location loc
= location ());
265 rvalue
new_call (function func
,
266 rvalue arg0
, rvalue arg1
, rvalue arg2
,
267 rvalue arg3
, rvalue arg4
, rvalue arg5
,
268 location loc
= location ());
270 rvalue
new_cast (rvalue expr
,
272 location loc
= location ());
274 lvalue
new_array_access (rvalue ptr
,
276 location loc
= location ());
279 gcc_jit_context
*m_inner_ctxt
;
282 class field
: public object
286 field (gcc_jit_field
*inner
);
288 gcc_jit_field
*get_inner_field () const;
291 class type
: public object
295 type (gcc_jit_type
*inner
);
297 gcc_jit_type
*get_inner_type () const;
300 type
get_volatile ();
302 // Shortcuts for getting values of numeric types:
307 class struct_
: public type
311 struct_ (gcc_jit_struct
*inner
);
313 gcc_jit_struct
*get_inner_struct () const;
316 class function
: public object
320 function (gcc_jit_function
*func
);
322 gcc_jit_function
*get_inner_function () const;
324 void dump_to_dot (const std::string
&path
);
326 param
get_param (int index
) const;
329 block
new_block (const std::string
&name
);
331 lvalue
new_local (type type_
,
332 const std::string
&name
,
333 location loc
= location ());
335 /* A series of overloaded operator () with various numbers of arguments
336 for a very terse way of creating a call to this function. The call
337 is created within the same context as the function itself, which may
338 not be what you want. */
339 rvalue
operator() (location loc
= location ());
340 rvalue
operator() (rvalue arg0
,
341 location loc
= location ());
342 rvalue
operator() (rvalue arg0
, rvalue arg1
,
343 location loc
= location ());
344 rvalue
operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
345 location loc
= location ());
348 class block
: public object
352 block (gcc_jit_block
*inner
);
354 gcc_jit_block
*get_inner_block () const;
356 function
get_function () const;
358 void add_eval (rvalue rvalue
,
359 location loc
= location ());
361 void add_assignment (lvalue lvalue
,
363 location loc
= location ());
365 void add_assignment_op (lvalue lvalue
,
366 enum gcc_jit_binary_op op
,
368 location loc
= location ());
370 /* A way to add a function call to the body of a function being
371 defined, with various numbers of args. */
372 rvalue
add_call (function other
,
373 location loc
= location ());
374 rvalue
add_call (function other
,
376 location loc
= location ());
377 rvalue
add_call (function other
,
378 rvalue arg0
, rvalue arg1
,
379 location loc
= location ());
380 rvalue
add_call (function other
,
381 rvalue arg0
, rvalue arg1
, rvalue arg2
,
382 location loc
= location ());
383 rvalue
add_call (function other
,
384 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
385 location loc
= location ());
387 void add_comment (const std::string
&text
,
388 location loc
= location ());
390 void end_with_conditional (rvalue boolval
,
393 location loc
= location ());
395 void end_with_jump (block target
,
396 location loc
= location ());
398 void end_with_return (rvalue rvalue
,
399 location loc
= location ());
400 void end_with_return (location loc
= location ());
404 class rvalue
: public object
408 rvalue (gcc_jit_rvalue
*inner
);
409 gcc_jit_rvalue
*get_inner_rvalue () const;
413 rvalue
access_field (field field
,
414 location loc
= location ());
416 lvalue
dereference_field (field field
,
417 location loc
= location ());
419 lvalue
dereference (location loc
= location ());
421 rvalue
cast_to (type type_
,
422 location loc
= location ());
425 lvalue
operator[] (rvalue index
);
426 lvalue
operator[] (int index
);
429 class lvalue
: public rvalue
433 lvalue (gcc_jit_lvalue
*inner
);
435 gcc_jit_lvalue
*get_inner_lvalue () const;
437 lvalue
access_field (field field
,
438 location loc
= location ());
440 rvalue
get_address (location loc
= location ());
443 class param
: public lvalue
447 param (gcc_jit_param
*inner
);
449 gcc_jit_param
*get_inner_param () const;
453 /* Overloaded operators, for those who want the most terse API
454 (at the possible risk of being a little too magical).
456 In each case, the first parameter is used to determine which context
457 owns the resulting expression, and, where appropriate, what the
460 /* Unary operators. */
461 rvalue
operator- (rvalue a
); // unary minus
462 rvalue
operator~ (rvalue a
); // unary bitwise negate
463 rvalue
operator! (rvalue a
); // unary logical negate
465 /* Binary operators. */
466 rvalue
operator+ (rvalue a
, rvalue b
);
467 rvalue
operator- (rvalue a
, rvalue b
);
468 rvalue
operator* (rvalue a
, rvalue b
);
469 rvalue
operator/ (rvalue a
, rvalue b
);
470 rvalue
operator% (rvalue a
, rvalue b
);
471 rvalue
operator& (rvalue a
, rvalue b
); // bitwise and
472 rvalue
operator^ (rvalue a
, rvalue b
); // bitwise_xor
473 rvalue
operator| (rvalue a
, rvalue b
); // bitwise_or
474 rvalue
operator&& (rvalue a
, rvalue b
); // logical_and
475 rvalue
operator|| (rvalue a
, rvalue b
); // logical_or
478 rvalue
operator== (rvalue a
, rvalue b
);
479 rvalue
operator!= (rvalue a
, rvalue b
);
480 rvalue
operator< (rvalue a
, rvalue b
);
481 rvalue
operator<= (rvalue a
, rvalue b
);
482 rvalue
operator> (rvalue a
, rvalue b
);
483 rvalue
operator>= (rvalue a
, rvalue b
);
486 lvalue
operator* (rvalue ptr
);
489 /****************************************************************************
490 Implementation of the API
491 ****************************************************************************/
495 inline context
context::acquire ()
497 return context (gcc_jit_context_acquire ());
499 inline context::context () : m_inner_ctxt (NULL
) {}
500 inline context::context (gcc_jit_context
*inner
) : m_inner_ctxt (inner
)
506 inline gccjit::context
507 context::new_child_context ()
509 return context (gcc_jit_context_new_child_context (m_inner_ctxt
));
515 gcc_jit_context_release (m_inner_ctxt
);
519 inline gcc_jit_result
*
522 gcc_jit_result
*result
= gcc_jit_context_compile (m_inner_ctxt
);
529 context::dump_to_file (const std::string
&path
,
530 bool update_locations
)
532 gcc_jit_context_dump_to_file (m_inner_ctxt
,
538 context::set_int_option (enum gcc_jit_int_option opt
,
541 gcc_jit_context_set_int_option (m_inner_ctxt
, opt
, value
);
546 context::set_bool_option (enum gcc_jit_bool_option opt
,
549 gcc_jit_context_set_bool_option (m_inner_ctxt
, opt
, value
);
554 context::new_location (const std::string
&filename
,
558 return location (gcc_jit_context_new_location (m_inner_ctxt
,
565 context::get_type (enum gcc_jit_types kind
)
567 return type (gcc_jit_context_get_type (m_inner_ctxt
, kind
));
571 context::get_int_type (size_t num_bytes
, int is_signed
)
573 return type (gcc_jit_context_get_int_type (m_inner_ctxt
,
578 template <typename T
>
580 context::get_int_type ()
582 return get_int_type (sizeof (T
), std::numeric_limits
<T
>::is_signed
);
586 context::new_array_type (type element_type
, int num_elements
, location loc
)
588 return type (gcc_jit_context_new_array_type (
590 loc
.get_inner_location (),
591 element_type
.get_inner_type (),
596 context::new_field (type type_
, const std::string
&name
, location loc
)
598 return field (gcc_jit_context_new_field (m_inner_ctxt
,
599 loc
.get_inner_location (),
600 type_
.get_inner_type (),
605 context::new_struct_type (const std::string
&name
,
606 std::vector
<field
> &fields
,
609 /* Treat std::vector as an array, relying on it not being resized: */
610 field
*as_array_of_wrappers
= &fields
[0];
612 /* Treat the array as being of the underlying pointers, relying on
613 the wrapper type being such a pointer internally. */
614 gcc_jit_field
**as_array_of_ptrs
=
615 reinterpret_cast<gcc_jit_field
**> (as_array_of_wrappers
);
617 return struct_ (gcc_jit_context_new_struct_type (m_inner_ctxt
,
618 loc
.get_inner_location (),
625 context::new_opaque_struct_type (const std::string
&name
,
628 return struct_ (gcc_jit_context_new_opaque_struct (
630 loc
.get_inner_location (),
635 context::new_param (type type_
,
636 const std::string
&name
,
639 return param (gcc_jit_context_new_param (m_inner_ctxt
,
640 loc
.get_inner_location (),
641 type_
.get_inner_type (),
646 context::new_function (enum gcc_jit_function_kind kind
,
648 const std::string
&name
,
649 std::vector
<param
> ¶ms
,
653 /* Treat std::vector as an array, relying on it not being resized: */
654 param
*as_array_of_wrappers
= ¶ms
[0];
656 /* Treat the array as being of the underlying pointers, relying on
657 the wrapper type being such a pointer internally. */
658 gcc_jit_param
**as_array_of_ptrs
=
659 reinterpret_cast<gcc_jit_param
**> (as_array_of_wrappers
);
661 return function (gcc_jit_context_new_function (m_inner_ctxt
,
662 loc
.get_inner_location (),
664 return_type
.get_inner_type (),
672 context::get_builtin_function (const std::string
&name
)
674 return function (gcc_jit_context_get_builtin_function (m_inner_ctxt
,
679 context::new_global (type type_
,
680 const std::string
&name
,
683 return lvalue (gcc_jit_context_new_global (m_inner_ctxt
,
684 loc
.get_inner_location (),
685 type_
.get_inner_type (),
690 context::new_rvalue (type numeric_type
,
694 gcc_jit_context_new_rvalue_from_int (m_inner_ctxt
,
695 numeric_type
.get_inner_type (),
700 context::zero (type numeric_type
) const
702 return rvalue (gcc_jit_context_zero (m_inner_ctxt
,
703 numeric_type
.get_inner_type ()));
707 context::one (type numeric_type
) const
709 return rvalue (gcc_jit_context_one (m_inner_ctxt
,
710 numeric_type
.get_inner_type ()));
714 context::new_rvalue (type numeric_type
,
718 gcc_jit_context_new_rvalue_from_double (m_inner_ctxt
,
719 numeric_type
.get_inner_type (),
724 context::new_rvalue (type pointer_type
,
728 gcc_jit_context_new_rvalue_from_ptr (m_inner_ctxt
,
729 pointer_type
.get_inner_type (),
734 context::new_rvalue (const std::string
&value
) const
737 gcc_jit_context_new_string_literal (m_inner_ctxt
, value
.c_str ()));
741 context::new_unary_op (enum gcc_jit_unary_op op
,
746 return rvalue (gcc_jit_context_new_unary_op (m_inner_ctxt
,
747 loc
.get_inner_location (),
749 result_type
.get_inner_type (),
750 a
.get_inner_rvalue ()));
753 context::new_minus (type result_type
,
757 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_MINUS
,
758 result_type
, a
, loc
));
761 context::new_bitwise_negate (type result_type
,
765 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_BITWISE_NEGATE
,
766 result_type
, a
, loc
));
769 context::new_logical_negate (type result_type
,
773 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_LOGICAL_NEGATE
,
774 result_type
, a
, loc
));
778 context::new_binary_op (enum gcc_jit_binary_op op
,
783 return rvalue (gcc_jit_context_new_binary_op (m_inner_ctxt
,
784 loc
.get_inner_location (),
786 result_type
.get_inner_type (),
787 a
.get_inner_rvalue (),
788 b
.get_inner_rvalue ()));
791 context::new_plus (type result_type
,
795 return new_binary_op (GCC_JIT_BINARY_OP_PLUS
,
796 result_type
, a
, b
, loc
);
799 context::new_minus (type result_type
,
803 return new_binary_op (GCC_JIT_BINARY_OP_MINUS
,
804 result_type
, a
, b
, loc
);
807 context::new_mult (type result_type
,
811 return new_binary_op (GCC_JIT_BINARY_OP_MULT
,
812 result_type
, a
, b
, loc
);
815 context::new_divide (type result_type
,
819 return new_binary_op (GCC_JIT_BINARY_OP_DIVIDE
,
820 result_type
, a
, b
, loc
);
823 context::new_modulo (type result_type
,
827 return new_binary_op (GCC_JIT_BINARY_OP_MODULO
,
828 result_type
, a
, b
, loc
);
831 context::new_bitwise_and (type result_type
,
835 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_AND
,
836 result_type
, a
, b
, loc
);
839 context::new_bitwise_xor (type result_type
,
843 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_XOR
,
844 result_type
, a
, b
, loc
);
847 context::new_bitwise_or (type result_type
,
851 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_OR
,
852 result_type
, a
, b
, loc
);
855 context::new_logical_and (type result_type
,
859 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_AND
,
860 result_type
, a
, b
, loc
);
863 context::new_logical_or (type result_type
,
867 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_OR
,
868 result_type
, a
, b
, loc
);
872 context::new_comparison (enum gcc_jit_comparison op
,
876 return rvalue (gcc_jit_context_new_comparison (m_inner_ctxt
,
877 loc
.get_inner_location (),
879 a
.get_inner_rvalue (),
880 b
.get_inner_rvalue ()));
883 context::new_eq (rvalue a
, rvalue b
,
886 return new_comparison (GCC_JIT_COMPARISON_EQ
,
890 context::new_ne (rvalue a
, rvalue b
,
893 return new_comparison (GCC_JIT_COMPARISON_NE
,
897 context::new_lt (rvalue a
, rvalue b
,
900 return new_comparison (GCC_JIT_COMPARISON_LT
,
904 context::new_le (rvalue a
, rvalue b
,
907 return new_comparison (GCC_JIT_COMPARISON_LE
,
911 context::new_gt (rvalue a
, rvalue b
,
914 return new_comparison (GCC_JIT_COMPARISON_GT
,
918 context::new_ge (rvalue a
, rvalue b
,
921 return new_comparison (GCC_JIT_COMPARISON_GE
,
926 context::new_call (function func
,
927 std::vector
<rvalue
> &args
,
930 /* Treat std::vector as an array, relying on it not being resized: */
931 rvalue
*as_array_of_wrappers
= &args
[0];
933 /* Treat the array as being of the underlying pointers, relying on
934 the wrapper type being such a pointer internally. */
935 gcc_jit_rvalue
**as_array_of_ptrs
=
936 reinterpret_cast<gcc_jit_rvalue
**> (as_array_of_wrappers
);
937 return gcc_jit_context_new_call (m_inner_ctxt
,
938 loc
.get_inner_location (),
939 func
.get_inner_function (),
944 context::new_call (function func
,
947 std::vector
<rvalue
> args
;
948 return new_call (func
, args
, loc
);
952 context::new_call (function func
,
956 std::vector
<rvalue
> args(1);
958 return new_call (func
, args
, loc
);
961 context::new_call (function func
,
962 rvalue arg0
, rvalue arg1
,
965 std::vector
<rvalue
> args(2);
968 return new_call (func
, args
, loc
);
971 context::new_call (function func
,
972 rvalue arg0
, rvalue arg1
, rvalue arg2
,
975 std::vector
<rvalue
> args(3);
979 return new_call (func
, args
, loc
);
982 context::new_call (function func
,
983 rvalue arg0
, rvalue arg1
, rvalue arg2
,
987 std::vector
<rvalue
> args(4);
992 return new_call (func
, args
, loc
);
995 context::new_call (function func
,
996 rvalue arg0
, rvalue arg1
, rvalue arg2
,
997 rvalue arg3
, rvalue arg4
,
1000 std::vector
<rvalue
> args(5);
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
, rvalue arg5
,
1014 std::vector
<rvalue
> args(6);
1021 return new_call (func
, args
, loc
);
1025 context::new_cast (rvalue expr
,
1029 return rvalue (gcc_jit_context_new_cast (m_inner_ctxt
,
1030 loc
.get_inner_location (),
1031 expr
.get_inner_rvalue (),
1032 type_
.get_inner_type ()));
1036 context::new_array_access (rvalue ptr
,
1040 return lvalue (gcc_jit_context_new_array_access (m_inner_ctxt
,
1041 loc
.get_inner_location (),
1042 ptr
.get_inner_rvalue (),
1043 index
.get_inner_rvalue ()));
1048 object::get_context () const
1050 return context (gcc_jit_object_get_context (m_inner_obj
));
1054 object::get_debug_string () const
1056 return gcc_jit_object_get_debug_string (m_inner_obj
);
1059 inline object::object () : m_inner_obj (NULL
) {}
1060 inline object::object (gcc_jit_object
*obj
) : m_inner_obj (obj
)
1066 inline gcc_jit_object
*
1067 object::get_inner_object () const
1072 inline std::ostream
&
1073 operator << (std::ostream
& stream
, const object
&obj
)
1075 return stream
<< obj
.get_debug_string ();
1079 inline location::location () : object () {}
1080 inline location::location (gcc_jit_location
*loc
)
1081 : object (gcc_jit_location_as_object (loc
))
1084 inline gcc_jit_location
*
1085 location::get_inner_location () const
1087 /* Manual downcast: */
1088 return reinterpret_cast<gcc_jit_location
*> (get_inner_object ());
1092 inline field::field () : object () {}
1093 inline field::field (gcc_jit_field
*inner
)
1094 : object (gcc_jit_field_as_object (inner
))
1097 inline gcc_jit_field
*
1098 field::get_inner_field () const
1100 /* Manual downcast: */
1101 return reinterpret_cast<gcc_jit_field
*> (get_inner_object ());
1105 inline type::type () : object () {}
1106 inline type::type (gcc_jit_type
*inner
)
1107 : object (gcc_jit_type_as_object (inner
))
1110 inline gcc_jit_type
*
1111 type::get_inner_type () const
1113 /* Manual downcast: */
1114 return reinterpret_cast<gcc_jit_type
*> (get_inner_object ());
1118 type::get_pointer ()
1120 return type (gcc_jit_type_get_pointer (get_inner_type ()));
1124 type::get_volatile ()
1126 return type (gcc_jit_type_get_volatile (get_inner_type ()));
1132 return get_context ().new_rvalue (*this, 0);
1138 return get_context ().new_rvalue (*this, 1);
1142 inline struct_::struct_ () : type (NULL
) {}
1143 inline struct_::struct_ (gcc_jit_struct
*inner
) :
1144 type (gcc_jit_struct_as_type (inner
))
1148 inline gcc_jit_struct
*
1149 struct_::get_inner_struct () const
1151 /* Manual downcast: */
1152 return reinterpret_cast<gcc_jit_struct
*> (get_inner_object ());
1156 inline function::function () : object () {}
1157 inline function::function (gcc_jit_function
*inner
)
1158 : object (gcc_jit_function_as_object (inner
))
1161 inline gcc_jit_function
*
1162 function::get_inner_function () const
1164 /* Manual downcast: */
1165 return reinterpret_cast<gcc_jit_function
*> (get_inner_object ());
1169 function::dump_to_dot (const std::string
&path
)
1171 gcc_jit_function_dump_to_dot (get_inner_function (),
1176 function::get_param (int index
) const
1178 return param (gcc_jit_function_get_param (get_inner_function (),
1183 function::new_block ()
1185 return block (gcc_jit_function_new_block (get_inner_function (),
1190 function::new_block (const std::string
&name
)
1192 return block (gcc_jit_function_new_block (get_inner_function (),
1197 function::new_local (type type_
,
1198 const std::string
&name
,
1201 return lvalue (gcc_jit_function_new_local (get_inner_function (),
1202 loc
.get_inner_location (),
1203 type_
.get_inner_type (),
1208 block::get_function () const
1210 return function (gcc_jit_block_get_function ( get_inner_block ()));
1214 block::add_eval (rvalue rvalue
,
1217 gcc_jit_block_add_eval (get_inner_block (),
1218 loc
.get_inner_location (),
1219 rvalue
.get_inner_rvalue ());
1223 block::add_assignment (lvalue lvalue
,
1227 gcc_jit_block_add_assignment (get_inner_block (),
1228 loc
.get_inner_location (),
1229 lvalue
.get_inner_lvalue (),
1230 rvalue
.get_inner_rvalue ());
1234 block::add_assignment_op (lvalue lvalue
,
1235 enum gcc_jit_binary_op op
,
1239 gcc_jit_block_add_assignment_op (get_inner_block (),
1240 loc
.get_inner_location (),
1241 lvalue
.get_inner_lvalue (),
1243 rvalue
.get_inner_rvalue ());
1247 block::add_comment (const std::string
&text
,
1250 gcc_jit_block_add_comment (get_inner_block (),
1251 loc
.get_inner_location (),
1256 block::end_with_conditional (rvalue boolval
,
1261 gcc_jit_block_end_with_conditional (get_inner_block (),
1262 loc
.get_inner_location (),
1263 boolval
.get_inner_rvalue (),
1264 on_true
.get_inner_block (),
1265 on_false
.get_inner_block ());
1269 block::end_with_jump (block target
,
1272 gcc_jit_block_end_with_jump (get_inner_block (),
1273 loc
.get_inner_location (),
1274 target
.get_inner_block ());
1278 block::end_with_return (rvalue rvalue
,
1281 gcc_jit_block_end_with_return (get_inner_block (),
1282 loc
.get_inner_location (),
1283 rvalue
.get_inner_rvalue ());
1287 block::end_with_return (location loc
)
1289 gcc_jit_block_end_with_void_return (get_inner_block (),
1290 loc
.get_inner_location ());
1294 block::add_call (function other
,
1297 rvalue c
= get_context ().new_call (other
, loc
);
1302 block::add_call (function other
,
1306 rvalue c
= get_context ().new_call (other
, arg0
, loc
);
1311 block::add_call (function other
,
1312 rvalue arg0
, rvalue arg1
,
1315 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, loc
);
1320 block::add_call (function other
,
1321 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1324 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, loc
);
1330 block::add_call (function other
,
1331 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
1334 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, arg3
, loc
);
1340 function::operator() (location loc
)
1342 return get_context ().new_call (*this, loc
);
1345 function::operator() (rvalue arg0
,
1348 return get_context ().new_call (*this,
1353 function::operator() (rvalue arg0
, rvalue arg1
,
1356 return get_context ().new_call (*this,
1361 function::operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
1364 return get_context ().new_call (*this,
1370 inline block::block () : object () {}
1371 inline block::block (gcc_jit_block
*inner
)
1372 : object (gcc_jit_block_as_object (inner
))
1375 inline gcc_jit_block
*
1376 block::get_inner_block () const
1378 /* Manual downcast: */
1379 return reinterpret_cast<gcc_jit_block
*> (get_inner_object ());
1383 inline rvalue::rvalue () : object () {}
1384 inline rvalue::rvalue (gcc_jit_rvalue
*inner
)
1385 : object (gcc_jit_rvalue_as_object (inner
))
1388 inline gcc_jit_rvalue
*
1389 rvalue::get_inner_rvalue () const
1391 /* Manual downcast: */
1392 return reinterpret_cast<gcc_jit_rvalue
*> (get_inner_object ());
1398 return type (gcc_jit_rvalue_get_type (get_inner_rvalue ()));
1402 rvalue::access_field (field field
,
1405 return rvalue (gcc_jit_rvalue_access_field (get_inner_rvalue (),
1406 loc
.get_inner_location (),
1407 field
.get_inner_field ()));
1411 rvalue::dereference_field (field field
,
1414 return lvalue (gcc_jit_rvalue_dereference_field (get_inner_rvalue (),
1415 loc
.get_inner_location (),
1416 field
.get_inner_field ()));
1420 rvalue::dereference (location loc
)
1422 return lvalue (gcc_jit_rvalue_dereference (get_inner_rvalue (),
1423 loc
.get_inner_location ()));
1427 rvalue::cast_to (type type_
,
1430 return get_context ().new_cast (*this, type_
, loc
);
1434 rvalue::operator[] (rvalue index
)
1436 return get_context ().new_array_access (*this, index
);
1440 rvalue::operator[] (int index
)
1442 context ctxt
= get_context ();
1443 type int_t
= ctxt
.get_int_type
<int> ();
1444 return ctxt
.new_array_access (*this,
1445 ctxt
.new_rvalue (int_t
,
1449 // class lvalue : public rvalue
1450 inline lvalue::lvalue () : rvalue () {}
1451 inline lvalue::lvalue (gcc_jit_lvalue
*inner
)
1452 : rvalue (gcc_jit_lvalue_as_rvalue (inner
))
1455 inline gcc_jit_lvalue
*
1456 lvalue::get_inner_lvalue () const
1458 /* Manual downcast: */
1459 return reinterpret_cast<gcc_jit_lvalue
*> (get_inner_object ());
1463 lvalue::access_field (field field
, location loc
)
1465 return lvalue (gcc_jit_lvalue_access_field (get_inner_lvalue (),
1466 loc
.get_inner_location (),
1467 field
.get_inner_field ()));
1471 lvalue::get_address (location loc
)
1473 return rvalue (gcc_jit_lvalue_get_address (get_inner_lvalue (),
1474 loc
.get_inner_location ()));
1477 // class param : public lvalue
1478 inline param::param () : lvalue () {}
1479 inline param::param (gcc_jit_param
*inner
)
1480 : lvalue (gcc_jit_param_as_lvalue (inner
))
1483 /* Overloaded operators. */
1485 inline rvalue
operator- (rvalue a
)
1487 return a
.get_context ().new_minus (a
.get_type (), a
);
1489 inline rvalue
operator~ (rvalue a
)
1491 return a
.get_context ().new_bitwise_negate (a
.get_type (), a
);
1493 inline rvalue
operator! (rvalue a
)
1495 return a
.get_context ().new_logical_negate (a
.get_type (), a
);
1499 inline rvalue
operator+ (rvalue a
, rvalue b
)
1501 return a
.get_context ().new_plus (a
.get_type (), a
, b
);
1503 inline rvalue
operator- (rvalue a
, rvalue b
)
1505 return a
.get_context ().new_minus (a
.get_type (), a
, b
);
1507 inline rvalue
operator* (rvalue a
, rvalue b
)
1509 return a
.get_context ().new_mult (a
.get_type (), a
, b
);
1511 inline rvalue
operator/ (rvalue a
, rvalue b
)
1513 return a
.get_context ().new_divide (a
.get_type (), a
, b
);
1515 inline rvalue
operator% (rvalue a
, rvalue b
)
1517 return a
.get_context ().new_modulo (a
.get_type (), a
, b
);
1519 inline rvalue
operator& (rvalue a
, rvalue b
)
1521 return a
.get_context ().new_bitwise_and (a
.get_type (), a
, b
);
1523 inline rvalue
operator^ (rvalue a
, rvalue b
)
1525 return a
.get_context ().new_bitwise_xor (a
.get_type (), a
, b
);
1527 inline rvalue
operator| (rvalue a
, rvalue b
)
1529 return a
.get_context ().new_bitwise_or (a
.get_type (), a
, b
);
1531 inline rvalue
operator&& (rvalue a
, rvalue b
)
1533 return a
.get_context ().new_logical_and (a
.get_type (), a
, b
);
1535 inline rvalue
operator|| (rvalue a
, rvalue b
)
1537 return a
.get_context ().new_logical_or (a
.get_type (), a
, b
);
1541 inline rvalue
operator== (rvalue a
, rvalue b
)
1543 return a
.get_context ().new_eq (a
, b
);
1545 inline rvalue
operator!= (rvalue a
, rvalue b
)
1547 return a
.get_context ().new_ne (a
, b
);
1549 inline rvalue
operator< (rvalue a
, rvalue b
)
1551 return a
.get_context ().new_lt (a
, b
);
1553 inline rvalue
operator<= (rvalue a
, rvalue b
)
1555 return a
.get_context ().new_le (a
, b
);
1557 inline rvalue
operator> (rvalue a
, rvalue b
)
1559 return a
.get_context ().new_gt (a
, b
);
1561 inline rvalue
operator>= (rvalue a
, rvalue b
)
1563 return a
.get_context ().new_ge (a
, b
);
1566 /* Dereferencing. */
1567 inline lvalue
operator* (rvalue ptr
)
1569 return ptr
.dereference ();
1572 } // namespace gccjit
1574 #endif /* #ifndef LIBGCCJIT_PLUS_PLUS_H */