1 /* A C++ API for libgccjit, purely as inline wrapper functions.
2 Copyright (C) 2014-2015 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 compile_to_file (enum gcc_jit_output_kind output_kind
,
103 const char *output_path
);
105 void dump_to_file (const std::string
&path
,
106 bool update_locations
);
108 void set_logfile (FILE *logfile
,
112 void dump_reproducer_to_file (const char *path
);
114 void set_str_option (enum gcc_jit_str_option opt
,
117 void set_int_option (enum gcc_jit_int_option opt
,
120 void set_bool_option (enum gcc_jit_bool_option opt
,
124 new_location (const std::string
&filename
,
128 type
get_type (enum gcc_jit_types kind
);
129 type
get_int_type (size_t num_bytes
, int is_signed
);
131 /* A way to map a specific int type, using the compiler to
132 get the details automatically e.g.:
133 gccjit::type type = get_int_type <my_int_type_t> (); */
134 template <typename T
>
135 type
get_int_type ();
137 type
new_array_type (type element_type
, int num_elements
,
138 location loc
= location ());
140 field
new_field (type type_
, const std::string
&name
,
141 location loc
= location ());
143 struct_
new_struct_type (const std::string
&name
,
144 std::vector
<field
> &fields
,
145 location loc
= location ());
147 struct_
new_opaque_struct_type (const std::string
&name
,
148 location loc
= location ());
150 param
new_param (type type_
,
151 const std::string
&name
,
152 location loc
= location ());
154 function
new_function (enum gcc_jit_function_kind kind
,
156 const std::string
&name
,
157 std::vector
<param
> ¶ms
,
159 location loc
= location ());
161 function
get_builtin_function (const std::string
&name
);
163 lvalue
new_global (enum gcc_jit_global_kind kind
,
165 const std::string
&name
,
166 location loc
= location ());
168 rvalue
new_rvalue (type numeric_type
,
170 rvalue
new_rvalue (type numeric_type
,
172 rvalue
zero (type numeric_type
) const;
173 rvalue
one (type numeric_type
) const;
174 rvalue
new_rvalue (type numeric_type
,
176 rvalue
new_rvalue (type pointer_type
,
178 rvalue
new_rvalue (const std::string
&value
) const;
180 /* Generic unary operations... */
181 rvalue
new_unary_op (enum gcc_jit_unary_op op
,
184 location loc
= location ());
186 /* ...and shorter ways to spell the various specific kinds of
188 rvalue
new_minus (type result_type
,
190 location loc
= location ());
191 rvalue
new_bitwise_negate (type result_type
,
193 location loc
= location ());
194 rvalue
new_logical_negate (type result_type
,
196 location loc
= location ());
198 /* Generic binary operations... */
199 rvalue
new_binary_op (enum gcc_jit_binary_op op
,
202 location loc
= location ());
204 /* ...and shorter ways to spell the various specific kinds of
206 rvalue
new_plus (type result_type
,
208 location loc
= location ());
209 rvalue
new_minus (type result_type
,
211 location loc
= location ());
212 rvalue
new_mult (type result_type
,
214 location loc
= location ());
215 rvalue
new_divide (type result_type
,
217 location loc
= location ());
218 rvalue
new_modulo (type result_type
,
220 location loc
= location ());
221 rvalue
new_bitwise_and (type result_type
,
223 location loc
= location ());
224 rvalue
new_bitwise_xor (type result_type
,
226 location loc
= location ());
227 rvalue
new_bitwise_or (type result_type
,
229 location loc
= location ());
230 rvalue
new_logical_and (type result_type
,
232 location loc
= location ());
233 rvalue
new_logical_or (type result_type
,
235 location loc
= location ());
237 /* Generic comparisons... */
238 rvalue
new_comparison (enum gcc_jit_comparison op
,
240 location loc
= location ());
241 /* ...and shorter ways to spell the various specific kinds of
243 rvalue
new_eq (rvalue a
, rvalue b
,
244 location loc
= location ());
245 rvalue
new_ne (rvalue a
, rvalue b
,
246 location loc
= location ());
247 rvalue
new_lt (rvalue a
, rvalue b
,
248 location loc
= location ());
249 rvalue
new_le (rvalue a
, rvalue b
,
250 location loc
= location ());
251 rvalue
new_gt (rvalue a
, rvalue b
,
252 location loc
= location ());
253 rvalue
new_ge (rvalue a
, rvalue b
,
254 location loc
= location ());
256 /* The most general way of creating a function call. */
257 rvalue
new_call (function func
,
258 std::vector
<rvalue
> &args
,
259 location loc
= location ());
261 /* In addition, we provide a series of overloaded "new_call" methods
262 for specific numbers of args (from 0 - 6), to avoid the need for
263 client code to manually build a vector. */
264 rvalue
new_call (function func
,
265 location loc
= location ());
266 rvalue
new_call (function func
,
268 location loc
= location ());
269 rvalue
new_call (function func
,
270 rvalue arg0
, rvalue arg1
,
271 location loc
= location ());
272 rvalue
new_call (function func
,
273 rvalue arg0
, rvalue arg1
, rvalue arg2
,
274 location loc
= location ());
275 rvalue
new_call (function func
,
276 rvalue arg0
, rvalue arg1
, rvalue arg2
,
278 location loc
= location ());
279 rvalue
new_call (function func
,
280 rvalue arg0
, rvalue arg1
, rvalue arg2
,
281 rvalue arg3
, rvalue arg4
,
282 location loc
= location ());
283 rvalue
new_call (function func
,
284 rvalue arg0
, rvalue arg1
, rvalue arg2
,
285 rvalue arg3
, rvalue arg4
, rvalue arg5
,
286 location loc
= location ());
288 rvalue
new_cast (rvalue expr
,
290 location loc
= location ());
292 lvalue
new_array_access (rvalue ptr
,
294 location loc
= location ());
297 gcc_jit_context
*m_inner_ctxt
;
300 class field
: public object
304 field (gcc_jit_field
*inner
);
306 gcc_jit_field
*get_inner_field () const;
309 class type
: public object
313 type (gcc_jit_type
*inner
);
315 gcc_jit_type
*get_inner_type () const;
318 type
get_volatile ();
320 // Shortcuts for getting values of numeric types:
325 class struct_
: public type
329 struct_ (gcc_jit_struct
*inner
);
331 gcc_jit_struct
*get_inner_struct () const;
334 class function
: public object
338 function (gcc_jit_function
*func
);
340 gcc_jit_function
*get_inner_function () const;
342 void dump_to_dot (const std::string
&path
);
344 param
get_param (int index
) const;
347 block
new_block (const std::string
&name
);
349 lvalue
new_local (type type_
,
350 const std::string
&name
,
351 location loc
= location ());
353 /* A series of overloaded operator () with various numbers of arguments
354 for a very terse way of creating a call to this function. The call
355 is created within the same context as the function itself, which may
356 not be what you want. */
357 rvalue
operator() (location loc
= location ());
358 rvalue
operator() (rvalue arg0
,
359 location loc
= location ());
360 rvalue
operator() (rvalue arg0
, rvalue arg1
,
361 location loc
= location ());
362 rvalue
operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
363 location loc
= location ());
366 class block
: public object
370 block (gcc_jit_block
*inner
);
372 gcc_jit_block
*get_inner_block () const;
374 function
get_function () const;
376 void add_eval (rvalue rvalue
,
377 location loc
= location ());
379 void add_assignment (lvalue lvalue
,
381 location loc
= location ());
383 void add_assignment_op (lvalue lvalue
,
384 enum gcc_jit_binary_op op
,
386 location loc
= location ());
388 /* A way to add a function call to the body of a function being
389 defined, with various numbers of args. */
390 rvalue
add_call (function other
,
391 location loc
= location ());
392 rvalue
add_call (function other
,
394 location loc
= location ());
395 rvalue
add_call (function other
,
396 rvalue arg0
, rvalue arg1
,
397 location loc
= location ());
398 rvalue
add_call (function other
,
399 rvalue arg0
, rvalue arg1
, rvalue arg2
,
400 location loc
= location ());
401 rvalue
add_call (function other
,
402 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
403 location loc
= location ());
405 void add_comment (const std::string
&text
,
406 location loc
= location ());
408 void end_with_conditional (rvalue boolval
,
411 location loc
= location ());
413 void end_with_jump (block target
,
414 location loc
= location ());
416 void end_with_return (rvalue rvalue
,
417 location loc
= location ());
418 void end_with_return (location loc
= location ());
422 class rvalue
: public object
426 rvalue (gcc_jit_rvalue
*inner
);
427 gcc_jit_rvalue
*get_inner_rvalue () const;
431 rvalue
access_field (field field
,
432 location loc
= location ());
434 lvalue
dereference_field (field field
,
435 location loc
= location ());
437 lvalue
dereference (location loc
= location ());
439 rvalue
cast_to (type type_
,
440 location loc
= location ());
443 lvalue
operator[] (rvalue index
);
444 lvalue
operator[] (int index
);
447 class lvalue
: public rvalue
451 lvalue (gcc_jit_lvalue
*inner
);
453 gcc_jit_lvalue
*get_inner_lvalue () const;
455 lvalue
access_field (field field
,
456 location loc
= location ());
458 rvalue
get_address (location loc
= location ());
461 class param
: public lvalue
465 param (gcc_jit_param
*inner
);
467 gcc_jit_param
*get_inner_param () const;
471 /* Overloaded operators, for those who want the most terse API
472 (at the possible risk of being a little too magical).
474 In each case, the first parameter is used to determine which context
475 owns the resulting expression, and, where appropriate, what the
478 /* Unary operators. */
479 rvalue
operator- (rvalue a
); // unary minus
480 rvalue
operator~ (rvalue a
); // unary bitwise negate
481 rvalue
operator! (rvalue a
); // unary logical negate
483 /* Binary operators. */
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
); // bitwise and
490 rvalue
operator^ (rvalue a
, rvalue b
); // bitwise_xor
491 rvalue
operator| (rvalue a
, rvalue b
); // bitwise_or
492 rvalue
operator&& (rvalue a
, rvalue b
); // logical_and
493 rvalue
operator|| (rvalue a
, rvalue b
); // logical_or
496 rvalue
operator== (rvalue a
, rvalue b
);
497 rvalue
operator!= (rvalue a
, rvalue b
);
498 rvalue
operator< (rvalue a
, rvalue b
);
499 rvalue
operator<= (rvalue a
, rvalue b
);
500 rvalue
operator> (rvalue a
, rvalue b
);
501 rvalue
operator>= (rvalue a
, rvalue b
);
504 lvalue
operator* (rvalue ptr
);
507 /****************************************************************************
508 Implementation of the API
509 ****************************************************************************/
513 inline context
context::acquire ()
515 return context (gcc_jit_context_acquire ());
517 inline context::context () : m_inner_ctxt (NULL
) {}
518 inline context::context (gcc_jit_context
*inner
) : m_inner_ctxt (inner
)
524 inline gccjit::context
525 context::new_child_context ()
527 return context (gcc_jit_context_new_child_context (m_inner_ctxt
));
533 gcc_jit_context_release (m_inner_ctxt
);
537 inline gcc_jit_result
*
540 gcc_jit_result
*result
= gcc_jit_context_compile (m_inner_ctxt
);
547 context::compile_to_file (enum gcc_jit_output_kind output_kind
,
548 const char *output_path
)
550 gcc_jit_context_compile_to_file (m_inner_ctxt
,
556 context::dump_to_file (const std::string
&path
,
557 bool update_locations
)
559 gcc_jit_context_dump_to_file (m_inner_ctxt
,
565 context::set_logfile (FILE *logfile
,
569 gcc_jit_context_set_logfile (m_inner_ctxt
,
576 context::dump_reproducer_to_file (const char *path
)
578 gcc_jit_context_dump_reproducer_to_file (m_inner_ctxt
,
583 context::set_str_option (enum gcc_jit_str_option opt
,
586 gcc_jit_context_set_str_option (m_inner_ctxt
, opt
, value
);
591 context::set_int_option (enum gcc_jit_int_option opt
,
594 gcc_jit_context_set_int_option (m_inner_ctxt
, opt
, value
);
599 context::set_bool_option (enum gcc_jit_bool_option opt
,
602 gcc_jit_context_set_bool_option (m_inner_ctxt
, opt
, value
);
607 context::new_location (const std::string
&filename
,
611 return location (gcc_jit_context_new_location (m_inner_ctxt
,
618 context::get_type (enum gcc_jit_types kind
)
620 return type (gcc_jit_context_get_type (m_inner_ctxt
, kind
));
624 context::get_int_type (size_t num_bytes
, int is_signed
)
626 return type (gcc_jit_context_get_int_type (m_inner_ctxt
,
631 template <typename T
>
633 context::get_int_type ()
635 return get_int_type (sizeof (T
), std::numeric_limits
<T
>::is_signed
);
639 context::new_array_type (type element_type
, int num_elements
, location loc
)
641 return type (gcc_jit_context_new_array_type (
643 loc
.get_inner_location (),
644 element_type
.get_inner_type (),
649 context::new_field (type type_
, const std::string
&name
, location loc
)
651 return field (gcc_jit_context_new_field (m_inner_ctxt
,
652 loc
.get_inner_location (),
653 type_
.get_inner_type (),
658 context::new_struct_type (const std::string
&name
,
659 std::vector
<field
> &fields
,
662 /* Treat std::vector as an array, relying on it not being resized: */
663 field
*as_array_of_wrappers
= &fields
[0];
665 /* Treat the array as being of the underlying pointers, relying on
666 the wrapper type being such a pointer internally. */
667 gcc_jit_field
**as_array_of_ptrs
=
668 reinterpret_cast<gcc_jit_field
**> (as_array_of_wrappers
);
670 return struct_ (gcc_jit_context_new_struct_type (m_inner_ctxt
,
671 loc
.get_inner_location (),
678 context::new_opaque_struct_type (const std::string
&name
,
681 return struct_ (gcc_jit_context_new_opaque_struct (
683 loc
.get_inner_location (),
688 context::new_param (type type_
,
689 const std::string
&name
,
692 return param (gcc_jit_context_new_param (m_inner_ctxt
,
693 loc
.get_inner_location (),
694 type_
.get_inner_type (),
699 context::new_function (enum gcc_jit_function_kind kind
,
701 const std::string
&name
,
702 std::vector
<param
> ¶ms
,
706 /* Treat std::vector as an array, relying on it not being resized: */
707 param
*as_array_of_wrappers
= ¶ms
[0];
709 /* Treat the array as being of the underlying pointers, relying on
710 the wrapper type being such a pointer internally. */
711 gcc_jit_param
**as_array_of_ptrs
=
712 reinterpret_cast<gcc_jit_param
**> (as_array_of_wrappers
);
714 return function (gcc_jit_context_new_function (m_inner_ctxt
,
715 loc
.get_inner_location (),
717 return_type
.get_inner_type (),
725 context::get_builtin_function (const std::string
&name
)
727 return function (gcc_jit_context_get_builtin_function (m_inner_ctxt
,
732 context::new_global (enum gcc_jit_global_kind kind
,
734 const std::string
&name
,
737 return lvalue (gcc_jit_context_new_global (m_inner_ctxt
,
738 loc
.get_inner_location (),
740 type_
.get_inner_type (),
745 context::new_rvalue (type numeric_type
,
749 gcc_jit_context_new_rvalue_from_int (m_inner_ctxt
,
750 numeric_type
.get_inner_type (),
755 context::new_rvalue (type numeric_type
,
759 gcc_jit_context_new_rvalue_from_long (m_inner_ctxt
,
760 numeric_type
.get_inner_type (),
765 context::zero (type numeric_type
) const
767 return rvalue (gcc_jit_context_zero (m_inner_ctxt
,
768 numeric_type
.get_inner_type ()));
772 context::one (type numeric_type
) const
774 return rvalue (gcc_jit_context_one (m_inner_ctxt
,
775 numeric_type
.get_inner_type ()));
779 context::new_rvalue (type numeric_type
,
783 gcc_jit_context_new_rvalue_from_double (m_inner_ctxt
,
784 numeric_type
.get_inner_type (),
789 context::new_rvalue (type pointer_type
,
793 gcc_jit_context_new_rvalue_from_ptr (m_inner_ctxt
,
794 pointer_type
.get_inner_type (),
799 context::new_rvalue (const std::string
&value
) const
802 gcc_jit_context_new_string_literal (m_inner_ctxt
, value
.c_str ()));
806 context::new_unary_op (enum gcc_jit_unary_op op
,
811 return rvalue (gcc_jit_context_new_unary_op (m_inner_ctxt
,
812 loc
.get_inner_location (),
814 result_type
.get_inner_type (),
815 a
.get_inner_rvalue ()));
818 context::new_minus (type result_type
,
822 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_MINUS
,
823 result_type
, a
, loc
));
826 context::new_bitwise_negate (type result_type
,
830 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_BITWISE_NEGATE
,
831 result_type
, a
, loc
));
834 context::new_logical_negate (type result_type
,
838 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_LOGICAL_NEGATE
,
839 result_type
, a
, loc
));
843 context::new_binary_op (enum gcc_jit_binary_op op
,
848 return rvalue (gcc_jit_context_new_binary_op (m_inner_ctxt
,
849 loc
.get_inner_location (),
851 result_type
.get_inner_type (),
852 a
.get_inner_rvalue (),
853 b
.get_inner_rvalue ()));
856 context::new_plus (type result_type
,
860 return new_binary_op (GCC_JIT_BINARY_OP_PLUS
,
861 result_type
, a
, b
, loc
);
864 context::new_minus (type result_type
,
868 return new_binary_op (GCC_JIT_BINARY_OP_MINUS
,
869 result_type
, a
, b
, loc
);
872 context::new_mult (type result_type
,
876 return new_binary_op (GCC_JIT_BINARY_OP_MULT
,
877 result_type
, a
, b
, loc
);
880 context::new_divide (type result_type
,
884 return new_binary_op (GCC_JIT_BINARY_OP_DIVIDE
,
885 result_type
, a
, b
, loc
);
888 context::new_modulo (type result_type
,
892 return new_binary_op (GCC_JIT_BINARY_OP_MODULO
,
893 result_type
, a
, b
, loc
);
896 context::new_bitwise_and (type result_type
,
900 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_AND
,
901 result_type
, a
, b
, loc
);
904 context::new_bitwise_xor (type result_type
,
908 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_XOR
,
909 result_type
, a
, b
, loc
);
912 context::new_bitwise_or (type result_type
,
916 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_OR
,
917 result_type
, a
, b
, loc
);
920 context::new_logical_and (type result_type
,
924 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_AND
,
925 result_type
, a
, b
, loc
);
928 context::new_logical_or (type result_type
,
932 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_OR
,
933 result_type
, a
, b
, loc
);
937 context::new_comparison (enum gcc_jit_comparison op
,
941 return rvalue (gcc_jit_context_new_comparison (m_inner_ctxt
,
942 loc
.get_inner_location (),
944 a
.get_inner_rvalue (),
945 b
.get_inner_rvalue ()));
948 context::new_eq (rvalue a
, rvalue b
,
951 return new_comparison (GCC_JIT_COMPARISON_EQ
,
955 context::new_ne (rvalue a
, rvalue b
,
958 return new_comparison (GCC_JIT_COMPARISON_NE
,
962 context::new_lt (rvalue a
, rvalue b
,
965 return new_comparison (GCC_JIT_COMPARISON_LT
,
969 context::new_le (rvalue a
, rvalue b
,
972 return new_comparison (GCC_JIT_COMPARISON_LE
,
976 context::new_gt (rvalue a
, rvalue b
,
979 return new_comparison (GCC_JIT_COMPARISON_GT
,
983 context::new_ge (rvalue a
, rvalue b
,
986 return new_comparison (GCC_JIT_COMPARISON_GE
,
991 context::new_call (function func
,
992 std::vector
<rvalue
> &args
,
995 /* Treat std::vector as an array, relying on it not being resized: */
996 rvalue
*as_array_of_wrappers
= &args
[0];
998 /* Treat the array as being of the underlying pointers, relying on
999 the wrapper type being such a pointer internally. */
1000 gcc_jit_rvalue
**as_array_of_ptrs
=
1001 reinterpret_cast<gcc_jit_rvalue
**> (as_array_of_wrappers
);
1002 return gcc_jit_context_new_call (m_inner_ctxt
,
1003 loc
.get_inner_location (),
1004 func
.get_inner_function (),
1009 context::new_call (function func
,
1012 std::vector
<rvalue
> args
;
1013 return new_call (func
, args
, loc
);
1017 context::new_call (function func
,
1021 std::vector
<rvalue
> args(1);
1023 return new_call (func
, args
, loc
);
1026 context::new_call (function func
,
1027 rvalue arg0
, rvalue arg1
,
1030 std::vector
<rvalue
> args(2);
1033 return new_call (func
, args
, loc
);
1036 context::new_call (function func
,
1037 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1040 std::vector
<rvalue
> args(3);
1044 return new_call (func
, args
, loc
);
1047 context::new_call (function func
,
1048 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1052 std::vector
<rvalue
> args(4);
1057 return new_call (func
, args
, loc
);
1060 context::new_call (function func
,
1061 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1062 rvalue arg3
, rvalue arg4
,
1065 std::vector
<rvalue
> args(5);
1071 return new_call (func
, args
, loc
);
1074 context::new_call (function func
,
1075 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1076 rvalue arg3
, rvalue arg4
, rvalue arg5
,
1079 std::vector
<rvalue
> args(6);
1086 return new_call (func
, args
, loc
);
1090 context::new_cast (rvalue expr
,
1094 return rvalue (gcc_jit_context_new_cast (m_inner_ctxt
,
1095 loc
.get_inner_location (),
1096 expr
.get_inner_rvalue (),
1097 type_
.get_inner_type ()));
1101 context::new_array_access (rvalue ptr
,
1105 return lvalue (gcc_jit_context_new_array_access (m_inner_ctxt
,
1106 loc
.get_inner_location (),
1107 ptr
.get_inner_rvalue (),
1108 index
.get_inner_rvalue ()));
1113 object::get_context () const
1115 return context (gcc_jit_object_get_context (m_inner_obj
));
1119 object::get_debug_string () const
1121 return gcc_jit_object_get_debug_string (m_inner_obj
);
1124 inline object::object () : m_inner_obj (NULL
) {}
1125 inline object::object (gcc_jit_object
*obj
) : m_inner_obj (obj
)
1131 inline gcc_jit_object
*
1132 object::get_inner_object () const
1137 inline std::ostream
&
1138 operator << (std::ostream
& stream
, const object
&obj
)
1140 return stream
<< obj
.get_debug_string ();
1144 inline location::location () : object () {}
1145 inline location::location (gcc_jit_location
*loc
)
1146 : object (gcc_jit_location_as_object (loc
))
1149 inline gcc_jit_location
*
1150 location::get_inner_location () const
1152 /* Manual downcast: */
1153 return reinterpret_cast<gcc_jit_location
*> (get_inner_object ());
1157 inline field::field () : object () {}
1158 inline field::field (gcc_jit_field
*inner
)
1159 : object (gcc_jit_field_as_object (inner
))
1162 inline gcc_jit_field
*
1163 field::get_inner_field () const
1165 /* Manual downcast: */
1166 return reinterpret_cast<gcc_jit_field
*> (get_inner_object ());
1170 inline type::type () : object () {}
1171 inline type::type (gcc_jit_type
*inner
)
1172 : object (gcc_jit_type_as_object (inner
))
1175 inline gcc_jit_type
*
1176 type::get_inner_type () const
1178 /* Manual downcast: */
1179 return reinterpret_cast<gcc_jit_type
*> (get_inner_object ());
1183 type::get_pointer ()
1185 return type (gcc_jit_type_get_pointer (get_inner_type ()));
1189 type::get_volatile ()
1191 return type (gcc_jit_type_get_volatile (get_inner_type ()));
1197 return get_context ().new_rvalue (*this, 0);
1203 return get_context ().new_rvalue (*this, 1);
1207 inline struct_::struct_ () : type (NULL
) {}
1208 inline struct_::struct_ (gcc_jit_struct
*inner
) :
1209 type (gcc_jit_struct_as_type (inner
))
1213 inline gcc_jit_struct
*
1214 struct_::get_inner_struct () const
1216 /* Manual downcast: */
1217 return reinterpret_cast<gcc_jit_struct
*> (get_inner_object ());
1221 inline function::function () : object () {}
1222 inline function::function (gcc_jit_function
*inner
)
1223 : object (gcc_jit_function_as_object (inner
))
1226 inline gcc_jit_function
*
1227 function::get_inner_function () const
1229 /* Manual downcast: */
1230 return reinterpret_cast<gcc_jit_function
*> (get_inner_object ());
1234 function::dump_to_dot (const std::string
&path
)
1236 gcc_jit_function_dump_to_dot (get_inner_function (),
1241 function::get_param (int index
) const
1243 return param (gcc_jit_function_get_param (get_inner_function (),
1248 function::new_block ()
1250 return block (gcc_jit_function_new_block (get_inner_function (),
1255 function::new_block (const std::string
&name
)
1257 return block (gcc_jit_function_new_block (get_inner_function (),
1262 function::new_local (type type_
,
1263 const std::string
&name
,
1266 return lvalue (gcc_jit_function_new_local (get_inner_function (),
1267 loc
.get_inner_location (),
1268 type_
.get_inner_type (),
1273 block::get_function () const
1275 return function (gcc_jit_block_get_function ( get_inner_block ()));
1279 block::add_eval (rvalue rvalue
,
1282 gcc_jit_block_add_eval (get_inner_block (),
1283 loc
.get_inner_location (),
1284 rvalue
.get_inner_rvalue ());
1288 block::add_assignment (lvalue lvalue
,
1292 gcc_jit_block_add_assignment (get_inner_block (),
1293 loc
.get_inner_location (),
1294 lvalue
.get_inner_lvalue (),
1295 rvalue
.get_inner_rvalue ());
1299 block::add_assignment_op (lvalue lvalue
,
1300 enum gcc_jit_binary_op op
,
1304 gcc_jit_block_add_assignment_op (get_inner_block (),
1305 loc
.get_inner_location (),
1306 lvalue
.get_inner_lvalue (),
1308 rvalue
.get_inner_rvalue ());
1312 block::add_comment (const std::string
&text
,
1315 gcc_jit_block_add_comment (get_inner_block (),
1316 loc
.get_inner_location (),
1321 block::end_with_conditional (rvalue boolval
,
1326 gcc_jit_block_end_with_conditional (get_inner_block (),
1327 loc
.get_inner_location (),
1328 boolval
.get_inner_rvalue (),
1329 on_true
.get_inner_block (),
1330 on_false
.get_inner_block ());
1334 block::end_with_jump (block target
,
1337 gcc_jit_block_end_with_jump (get_inner_block (),
1338 loc
.get_inner_location (),
1339 target
.get_inner_block ());
1343 block::end_with_return (rvalue rvalue
,
1346 gcc_jit_block_end_with_return (get_inner_block (),
1347 loc
.get_inner_location (),
1348 rvalue
.get_inner_rvalue ());
1352 block::end_with_return (location loc
)
1354 gcc_jit_block_end_with_void_return (get_inner_block (),
1355 loc
.get_inner_location ());
1359 block::add_call (function other
,
1362 rvalue c
= get_context ().new_call (other
, loc
);
1367 block::add_call (function other
,
1371 rvalue c
= get_context ().new_call (other
, arg0
, loc
);
1376 block::add_call (function other
,
1377 rvalue arg0
, rvalue arg1
,
1380 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, loc
);
1385 block::add_call (function other
,
1386 rvalue arg0
, rvalue arg1
, rvalue arg2
,
1389 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, loc
);
1395 block::add_call (function other
,
1396 rvalue arg0
, rvalue arg1
, rvalue arg2
, rvalue arg3
,
1399 rvalue c
= get_context ().new_call (other
, arg0
, arg1
, arg2
, arg3
, loc
);
1405 function::operator() (location loc
)
1407 return get_context ().new_call (*this, loc
);
1410 function::operator() (rvalue arg0
,
1413 return get_context ().new_call (*this,
1418 function::operator() (rvalue arg0
, rvalue arg1
,
1421 return get_context ().new_call (*this,
1426 function::operator() (rvalue arg0
, rvalue arg1
, rvalue arg2
,
1429 return get_context ().new_call (*this,
1435 inline block::block () : object () {}
1436 inline block::block (gcc_jit_block
*inner
)
1437 : object (gcc_jit_block_as_object (inner
))
1440 inline gcc_jit_block
*
1441 block::get_inner_block () const
1443 /* Manual downcast: */
1444 return reinterpret_cast<gcc_jit_block
*> (get_inner_object ());
1448 inline rvalue::rvalue () : object () {}
1449 inline rvalue::rvalue (gcc_jit_rvalue
*inner
)
1450 : object (gcc_jit_rvalue_as_object (inner
))
1453 inline gcc_jit_rvalue
*
1454 rvalue::get_inner_rvalue () const
1456 /* Manual downcast: */
1457 return reinterpret_cast<gcc_jit_rvalue
*> (get_inner_object ());
1463 return type (gcc_jit_rvalue_get_type (get_inner_rvalue ()));
1467 rvalue::access_field (field field
,
1470 return rvalue (gcc_jit_rvalue_access_field (get_inner_rvalue (),
1471 loc
.get_inner_location (),
1472 field
.get_inner_field ()));
1476 rvalue::dereference_field (field field
,
1479 return lvalue (gcc_jit_rvalue_dereference_field (get_inner_rvalue (),
1480 loc
.get_inner_location (),
1481 field
.get_inner_field ()));
1485 rvalue::dereference (location loc
)
1487 return lvalue (gcc_jit_rvalue_dereference (get_inner_rvalue (),
1488 loc
.get_inner_location ()));
1492 rvalue::cast_to (type type_
,
1495 return get_context ().new_cast (*this, type_
, loc
);
1499 rvalue::operator[] (rvalue index
)
1501 return get_context ().new_array_access (*this, index
);
1505 rvalue::operator[] (int index
)
1507 context ctxt
= get_context ();
1508 type int_t
= ctxt
.get_int_type
<int> ();
1509 return ctxt
.new_array_access (*this,
1510 ctxt
.new_rvalue (int_t
,
1514 // class lvalue : public rvalue
1515 inline lvalue::lvalue () : rvalue () {}
1516 inline lvalue::lvalue (gcc_jit_lvalue
*inner
)
1517 : rvalue (gcc_jit_lvalue_as_rvalue (inner
))
1520 inline gcc_jit_lvalue
*
1521 lvalue::get_inner_lvalue () const
1523 /* Manual downcast: */
1524 return reinterpret_cast<gcc_jit_lvalue
*> (get_inner_object ());
1528 lvalue::access_field (field field
, location loc
)
1530 return lvalue (gcc_jit_lvalue_access_field (get_inner_lvalue (),
1531 loc
.get_inner_location (),
1532 field
.get_inner_field ()));
1536 lvalue::get_address (location loc
)
1538 return rvalue (gcc_jit_lvalue_get_address (get_inner_lvalue (),
1539 loc
.get_inner_location ()));
1542 // class param : public lvalue
1543 inline param::param () : lvalue () {}
1544 inline param::param (gcc_jit_param
*inner
)
1545 : lvalue (gcc_jit_param_as_lvalue (inner
))
1548 /* Overloaded operators. */
1550 inline rvalue
operator- (rvalue a
)
1552 return a
.get_context ().new_minus (a
.get_type (), a
);
1554 inline rvalue
operator~ (rvalue a
)
1556 return a
.get_context ().new_bitwise_negate (a
.get_type (), a
);
1558 inline rvalue
operator! (rvalue a
)
1560 return a
.get_context ().new_logical_negate (a
.get_type (), a
);
1564 inline rvalue
operator+ (rvalue a
, rvalue b
)
1566 return a
.get_context ().new_plus (a
.get_type (), a
, b
);
1568 inline rvalue
operator- (rvalue a
, rvalue b
)
1570 return a
.get_context ().new_minus (a
.get_type (), a
, b
);
1572 inline rvalue
operator* (rvalue a
, rvalue b
)
1574 return a
.get_context ().new_mult (a
.get_type (), a
, b
);
1576 inline rvalue
operator/ (rvalue a
, rvalue b
)
1578 return a
.get_context ().new_divide (a
.get_type (), a
, b
);
1580 inline rvalue
operator% (rvalue a
, rvalue b
)
1582 return a
.get_context ().new_modulo (a
.get_type (), a
, b
);
1584 inline rvalue
operator& (rvalue a
, rvalue b
)
1586 return a
.get_context ().new_bitwise_and (a
.get_type (), a
, b
);
1588 inline rvalue
operator^ (rvalue a
, rvalue b
)
1590 return a
.get_context ().new_bitwise_xor (a
.get_type (), a
, b
);
1592 inline rvalue
operator| (rvalue a
, rvalue b
)
1594 return a
.get_context ().new_bitwise_or (a
.get_type (), a
, b
);
1596 inline rvalue
operator&& (rvalue a
, rvalue b
)
1598 return a
.get_context ().new_logical_and (a
.get_type (), a
, b
);
1600 inline rvalue
operator|| (rvalue a
, rvalue b
)
1602 return a
.get_context ().new_logical_or (a
.get_type (), a
, b
);
1606 inline rvalue
operator== (rvalue a
, rvalue b
)
1608 return a
.get_context ().new_eq (a
, b
);
1610 inline rvalue
operator!= (rvalue a
, rvalue b
)
1612 return a
.get_context ().new_ne (a
, b
);
1614 inline rvalue
operator< (rvalue a
, rvalue b
)
1616 return a
.get_context ().new_lt (a
, b
);
1618 inline rvalue
operator<= (rvalue a
, rvalue b
)
1620 return a
.get_context ().new_le (a
, b
);
1622 inline rvalue
operator> (rvalue a
, rvalue b
)
1624 return a
.get_context ().new_gt (a
, b
);
1626 inline rvalue
operator>= (rvalue a
, rvalue b
)
1628 return a
.get_context ().new_ge (a
, b
);
1631 /* Dereferencing. */
1632 inline lvalue
operator* (rvalue ptr
)
1634 return ptr
.dereference ();
1637 } // namespace gccjit
1639 #endif /* #ifndef LIBGCCJIT_PLUS_PLUS_H */