libgo: update to Go 1.15.4 release
[official-gcc.git] / gcc / jit / libgccjit++.h
blob1b9ef1a5db98becf4a079a5422fec2cb11d4c2ff
1 /* A C++ API for libgccjit, purely as inline wrapper functions.
2 Copyright (C) 2014-2020 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)
9 any later version.
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"
25 #include <limits>
26 #include <ostream>
27 #include <vector>
29 /****************************************************************************
30 C++ API
31 ****************************************************************************/
33 namespace gccjit
35 /* Indentation indicates inheritance. */
36 class context;
37 class error;
38 class object;
39 class location;
40 class field;
41 class type;
42 class struct_;
43 class function;
44 class block;
45 class rvalue;
46 class lvalue;
47 class param;
48 class case_;
49 class timer;
50 class auto_time;
52 namespace version {};
54 /* Errors within the API become C++ exceptions of this class. */
55 class error
59 class object
61 public:
62 context get_context () const;
64 std::string get_debug_string () const;
66 protected:
67 object ();
68 object (gcc_jit_object *obj);
70 gcc_jit_object *get_inner_object () const;
72 private:
73 gcc_jit_object *m_inner_obj;
76 inline std::ostream& operator << (std::ostream& stream, const object &obj);
78 /* Some client code will want to supply source code locations, others
79 won't. To avoid doubling the number of entrypoints, everything
80 accepting a location also has a default argument. To do this, the
81 other classes need to see that "location" has a default constructor,
82 hence we need to declare it first. */
83 class location : public object
85 public:
86 location ();
87 location (gcc_jit_location *loc);
89 gcc_jit_location *get_inner_location () const;
92 class context
94 public:
95 static context acquire ();
96 context ();
97 context (gcc_jit_context *ctxt);
99 gccjit::context new_child_context ();
101 gcc_jit_context *get_inner_context () { return m_inner_ctxt; }
103 void release ();
105 gcc_jit_result *compile ();
107 void compile_to_file (enum gcc_jit_output_kind output_kind,
108 const char *output_path);
110 void dump_to_file (const std::string &path,
111 bool update_locations);
113 void set_logfile (FILE *logfile,
114 int flags,
115 int verbosity);
117 void dump_reproducer_to_file (const char *path);
119 void set_str_option (enum gcc_jit_str_option opt,
120 const char *value);
122 void set_int_option (enum gcc_jit_int_option opt,
123 int value);
125 void set_bool_option (enum gcc_jit_bool_option opt,
126 int value);
128 void set_bool_allow_unreachable_blocks (int bool_value);
129 void set_bool_use_external_driver (int bool_value);
131 void add_command_line_option (const char *optname);
132 void add_driver_option (const char *optname);
134 void set_timer (gccjit::timer t);
135 gccjit::timer get_timer () const;
137 location
138 new_location (const std::string &filename,
139 int line,
140 int column);
142 type get_type (enum gcc_jit_types kind);
143 type get_int_type (size_t num_bytes, int is_signed);
145 /* A way to map a specific int type, using the compiler to
146 get the details automatically e.g.:
147 gccjit::type type = get_int_type <my_int_type_t> (); */
148 template <typename T>
149 type get_int_type ();
151 type new_array_type (type element_type, int num_elements,
152 location loc = location ());
154 field new_field (type type_, const std::string &name,
155 location loc = location ());
157 field new_bitfield (type type_, int width, const std::string &name,
158 location loc = location ());
160 struct_ new_struct_type (const std::string &name,
161 std::vector<field> &fields,
162 location loc = location ());
164 struct_ new_opaque_struct_type (const std::string &name,
165 location loc = location ());
167 param new_param (type type_,
168 const std::string &name,
169 location loc = location ());
171 function new_function (enum gcc_jit_function_kind kind,
172 type return_type,
173 const std::string &name,
174 std::vector<param> &params,
175 int is_variadic,
176 location loc = location ());
178 function get_builtin_function (const std::string &name);
180 lvalue new_global (enum gcc_jit_global_kind kind,
181 type type_,
182 const std::string &name,
183 location loc = location ());
185 rvalue new_rvalue (type numeric_type,
186 int value) const;
187 rvalue new_rvalue (type numeric_type,
188 long value) const;
189 rvalue zero (type numeric_type) const;
190 rvalue one (type numeric_type) const;
191 rvalue new_rvalue (type numeric_type,
192 double value) const;
193 rvalue new_rvalue (type pointer_type,
194 void *value) const;
195 rvalue new_rvalue (const std::string &value) const;
196 rvalue new_rvalue (type vector_type,
197 std::vector<rvalue> elements) const;
199 /* Generic unary operations... */
200 rvalue new_unary_op (enum gcc_jit_unary_op op,
201 type result_type,
202 rvalue a,
203 location loc = location ());
205 /* ...and shorter ways to spell the various specific kinds of
206 unary op. */
207 rvalue new_minus (type result_type,
208 rvalue a,
209 location loc = location ());
210 rvalue new_bitwise_negate (type result_type,
211 rvalue a,
212 location loc = location ());
213 rvalue new_logical_negate (type result_type,
214 rvalue a,
215 location loc = location ());
217 /* Generic binary operations... */
218 rvalue new_binary_op (enum gcc_jit_binary_op op,
219 type result_type,
220 rvalue a, rvalue b,
221 location loc = location ());
223 /* ...and shorter ways to spell the various specific kinds of
224 binary op. */
225 rvalue new_plus (type result_type,
226 rvalue a, rvalue b,
227 location loc = location ());
228 rvalue new_minus (type result_type,
229 rvalue a, rvalue b,
230 location loc = location ());
231 rvalue new_mult (type result_type,
232 rvalue a, rvalue b,
233 location loc = location ());
234 rvalue new_divide (type result_type,
235 rvalue a, rvalue b,
236 location loc = location ());
237 rvalue new_modulo (type result_type,
238 rvalue a, rvalue b,
239 location loc = location ());
240 rvalue new_bitwise_and (type result_type,
241 rvalue a, rvalue b,
242 location loc = location ());
243 rvalue new_bitwise_xor (type result_type,
244 rvalue a, rvalue b,
245 location loc = location ());
246 rvalue new_bitwise_or (type result_type,
247 rvalue a, rvalue b,
248 location loc = location ());
249 rvalue new_logical_and (type result_type,
250 rvalue a, rvalue b,
251 location loc = location ());
252 rvalue new_logical_or (type result_type,
253 rvalue a, rvalue b,
254 location loc = location ());
256 /* Generic comparisons... */
257 rvalue new_comparison (enum gcc_jit_comparison op,
258 rvalue a, rvalue b,
259 location loc = location ());
260 /* ...and shorter ways to spell the various specific kinds of
261 comparison. */
262 rvalue new_eq (rvalue a, rvalue b,
263 location loc = location ());
264 rvalue new_ne (rvalue a, rvalue b,
265 location loc = location ());
266 rvalue new_lt (rvalue a, rvalue b,
267 location loc = location ());
268 rvalue new_le (rvalue a, rvalue b,
269 location loc = location ());
270 rvalue new_gt (rvalue a, rvalue b,
271 location loc = location ());
272 rvalue new_ge (rvalue a, rvalue b,
273 location loc = location ());
275 /* The most general way of creating a function call. */
276 rvalue new_call (function func,
277 std::vector<rvalue> &args,
278 location loc = location ());
280 /* In addition, we provide a series of overloaded "new_call" methods
281 for specific numbers of args (from 0 - 6), to avoid the need for
282 client code to manually build a vector. */
283 rvalue new_call (function func,
284 location loc = location ());
285 rvalue new_call (function func,
286 rvalue arg0,
287 location loc = location ());
288 rvalue new_call (function func,
289 rvalue arg0, rvalue arg1,
290 location loc = location ());
291 rvalue new_call (function func,
292 rvalue arg0, rvalue arg1, rvalue arg2,
293 location loc = location ());
294 rvalue new_call (function func,
295 rvalue arg0, rvalue arg1, rvalue arg2,
296 rvalue arg3,
297 location loc = location ());
298 rvalue new_call (function func,
299 rvalue arg0, rvalue arg1, rvalue arg2,
300 rvalue arg3, rvalue arg4,
301 location loc = location ());
302 rvalue new_call (function func,
303 rvalue arg0, rvalue arg1, rvalue arg2,
304 rvalue arg3, rvalue arg4, rvalue arg5,
305 location loc = location ());
307 rvalue new_cast (rvalue expr,
308 type type_,
309 location loc = location ());
311 lvalue new_array_access (rvalue ptr,
312 rvalue index,
313 location loc = location ());
315 case_ new_case (rvalue min_value,
316 rvalue max_value,
317 block dest_block);
319 private:
320 gcc_jit_context *m_inner_ctxt;
323 class field : public object
325 public:
326 field ();
327 field (gcc_jit_field *inner);
329 gcc_jit_field *get_inner_field () const;
332 class type : public object
334 public:
335 type ();
336 type (gcc_jit_type *inner);
338 gcc_jit_type *get_inner_type () const;
340 type get_pointer ();
341 type get_const ();
342 type get_volatile ();
343 type get_aligned (size_t alignment_in_bytes);
344 type get_vector (size_t num_units);
346 // Shortcuts for getting values of numeric types:
347 rvalue zero ();
348 rvalue one ();
351 class struct_ : public type
353 public:
354 struct_ ();
355 struct_ (gcc_jit_struct *inner);
357 gcc_jit_struct *get_inner_struct () const;
360 class function : public object
362 public:
363 function ();
364 function (gcc_jit_function *func);
366 gcc_jit_function *get_inner_function () const;
368 void dump_to_dot (const std::string &path);
370 param get_param (int index) const;
372 block new_block ();
373 block new_block (const std::string &name);
375 lvalue new_local (type type_,
376 const std::string &name,
377 location loc = location ());
379 rvalue get_address (location loc = location ());
381 /* A series of overloaded operator () with various numbers of arguments
382 for a very terse way of creating a call to this function. The call
383 is created within the same context as the function itself, which may
384 not be what you want. */
385 rvalue operator() (location loc = location ());
386 rvalue operator() (rvalue arg0,
387 location loc = location ());
388 rvalue operator() (rvalue arg0, rvalue arg1,
389 location loc = location ());
390 rvalue operator() (rvalue arg0, rvalue arg1, rvalue arg2,
391 location loc = location ());
394 class block : public object
396 public:
397 block ();
398 block (gcc_jit_block *inner);
400 gcc_jit_block *get_inner_block () const;
402 function get_function () const;
404 void add_eval (rvalue rvalue,
405 location loc = location ());
407 void add_assignment (lvalue lvalue,
408 rvalue rvalue,
409 location loc = location ());
411 void add_assignment_op (lvalue lvalue,
412 enum gcc_jit_binary_op op,
413 rvalue rvalue,
414 location loc = location ());
416 /* A way to add a function call to the body of a function being
417 defined, with various numbers of args. */
418 rvalue add_call (function other,
419 location loc = location ());
420 rvalue add_call (function other,
421 rvalue arg0,
422 location loc = location ());
423 rvalue add_call (function other,
424 rvalue arg0, rvalue arg1,
425 location loc = location ());
426 rvalue add_call (function other,
427 rvalue arg0, rvalue arg1, rvalue arg2,
428 location loc = location ());
429 rvalue add_call (function other,
430 rvalue arg0, rvalue arg1, rvalue arg2, rvalue arg3,
431 location loc = location ());
433 void add_comment (const std::string &text,
434 location loc = location ());
436 void end_with_conditional (rvalue boolval,
437 block on_true,
438 block on_false,
439 location loc = location ());
441 void end_with_jump (block target,
442 location loc = location ());
444 void end_with_return (rvalue rvalue,
445 location loc = location ());
446 void end_with_return (location loc = location ());
448 void end_with_switch (rvalue expr,
449 block default_block,
450 std::vector <case_> cases,
451 location loc = location ());
454 class rvalue : public object
456 public:
457 rvalue ();
458 rvalue (gcc_jit_rvalue *inner);
459 gcc_jit_rvalue *get_inner_rvalue () const;
461 type get_type ();
463 rvalue access_field (field field,
464 location loc = location ());
466 lvalue dereference_field (field field,
467 location loc = location ());
469 lvalue dereference (location loc = location ());
471 rvalue cast_to (type type_,
472 location loc = location ());
474 /* Array access. */
475 lvalue operator[] (rvalue index);
476 lvalue operator[] (int index);
479 class lvalue : public rvalue
481 public:
482 lvalue ();
483 lvalue (gcc_jit_lvalue *inner);
485 gcc_jit_lvalue *get_inner_lvalue () const;
487 lvalue access_field (field field,
488 location loc = location ());
490 rvalue get_address (location loc = location ());
491 lvalue set_initializer (const void *blob, size_t num_bytes);
494 class param : public lvalue
496 public:
497 param ();
498 param (gcc_jit_param *inner);
500 gcc_jit_param *get_inner_param () const;
503 class case_ : public object
505 public:
506 case_ ();
507 case_ (gcc_jit_case *inner);
509 gcc_jit_case *get_inner_case () const;
512 /* Overloaded operators, for those who want the most terse API
513 (at the possible risk of being a little too magical).
515 In each case, the first parameter is used to determine which context
516 owns the resulting expression, and, where appropriate, what the
517 latter's type is. */
519 /* Unary operators. */
520 rvalue operator- (rvalue a); // unary minus
521 rvalue operator~ (rvalue a); // unary bitwise negate
522 rvalue operator! (rvalue a); // unary logical negate
524 /* Binary operators. */
525 rvalue operator+ (rvalue a, rvalue b);
526 rvalue operator- (rvalue a, rvalue b);
527 rvalue operator* (rvalue a, rvalue b);
528 rvalue operator/ (rvalue a, rvalue b);
529 rvalue operator% (rvalue a, rvalue b);
530 rvalue operator& (rvalue a, rvalue b); // bitwise and
531 rvalue operator^ (rvalue a, rvalue b); // bitwise_xor
532 rvalue operator| (rvalue a, rvalue b); // bitwise_or
533 rvalue operator&& (rvalue a, rvalue b); // logical_and
534 rvalue operator|| (rvalue a, rvalue b); // logical_or
536 /* Comparisons. */
537 rvalue operator== (rvalue a, rvalue b);
538 rvalue operator!= (rvalue a, rvalue b);
539 rvalue operator< (rvalue a, rvalue b);
540 rvalue operator<= (rvalue a, rvalue b);
541 rvalue operator> (rvalue a, rvalue b);
542 rvalue operator>= (rvalue a, rvalue b);
544 /* Dereferencing. */
545 lvalue operator* (rvalue ptr);
547 class timer
549 public:
550 timer ();
551 timer (gcc_jit_timer *inner_timer);
553 void push (const char *item_name);
554 void pop (const char *item_name);
555 void print (FILE *f_out) const;
557 void release ();
559 gcc_jit_timer *get_inner_timer () const;
561 private:
562 gcc_jit_timer *m_inner_timer;
565 class auto_time
567 public:
568 auto_time (timer t, const char *item_name);
569 auto_time (context ctxt, const char *item_name);
570 ~auto_time ();
572 private:
573 timer m_timer;
574 const char *m_item_name;
578 /****************************************************************************
579 Implementation of the API
580 ****************************************************************************/
581 namespace gccjit {
583 // class context
584 inline context context::acquire ()
586 return context (gcc_jit_context_acquire ());
588 inline context::context () : m_inner_ctxt (NULL) {}
589 inline context::context (gcc_jit_context *inner) : m_inner_ctxt (inner)
591 if (!inner)
592 throw error ();
595 inline gccjit::context
596 context::new_child_context ()
598 return context (gcc_jit_context_new_child_context (m_inner_ctxt));
601 inline void
602 context::release ()
604 gcc_jit_context_release (m_inner_ctxt);
605 m_inner_ctxt = NULL;
608 inline gcc_jit_result *
609 context::compile ()
611 gcc_jit_result *result = gcc_jit_context_compile (m_inner_ctxt);
612 if (!result)
613 throw error ();
614 return result;
617 inline void
618 context::compile_to_file (enum gcc_jit_output_kind output_kind,
619 const char *output_path)
621 gcc_jit_context_compile_to_file (m_inner_ctxt,
622 output_kind,
623 output_path);
626 inline void
627 context::dump_to_file (const std::string &path,
628 bool update_locations)
630 gcc_jit_context_dump_to_file (m_inner_ctxt,
631 path.c_str (),
632 update_locations);
635 inline void
636 context::set_logfile (FILE *logfile,
637 int flags,
638 int verbosity)
640 gcc_jit_context_set_logfile (m_inner_ctxt,
641 logfile,
642 flags,
643 verbosity);
646 inline void
647 context::dump_reproducer_to_file (const char *path)
649 gcc_jit_context_dump_reproducer_to_file (m_inner_ctxt,
650 path);
653 inline void
654 context::set_str_option (enum gcc_jit_str_option opt,
655 const char *value)
657 gcc_jit_context_set_str_option (m_inner_ctxt, opt, value);
661 inline void
662 context::set_int_option (enum gcc_jit_int_option opt,
663 int value)
665 gcc_jit_context_set_int_option (m_inner_ctxt, opt, value);
669 inline void
670 context::set_bool_option (enum gcc_jit_bool_option opt,
671 int value)
673 gcc_jit_context_set_bool_option (m_inner_ctxt, opt, value);
676 inline void
677 context::set_bool_allow_unreachable_blocks (int bool_value)
679 gcc_jit_context_set_bool_allow_unreachable_blocks (m_inner_ctxt,
680 bool_value);
683 inline void
684 context::set_bool_use_external_driver (int bool_value)
686 gcc_jit_context_set_bool_use_external_driver (m_inner_ctxt,
687 bool_value);
690 inline void
691 context::add_command_line_option (const char *optname)
693 gcc_jit_context_add_command_line_option (m_inner_ctxt, optname);
696 inline void
697 context::add_driver_option (const char *optname)
699 gcc_jit_context_add_driver_option (m_inner_ctxt, optname);
702 inline void
703 context::set_timer (gccjit::timer t)
705 gcc_jit_context_set_timer (m_inner_ctxt, t.get_inner_timer ());
708 inline gccjit::timer
709 context::get_timer () const
711 return gccjit::timer (gcc_jit_context_get_timer (m_inner_ctxt));
715 inline location
716 context::new_location (const std::string &filename,
717 int line,
718 int column)
720 return location (gcc_jit_context_new_location (m_inner_ctxt,
721 filename.c_str (),
722 line,
723 column));
726 inline type
727 context::get_type (enum gcc_jit_types kind)
729 return type (gcc_jit_context_get_type (m_inner_ctxt, kind));
732 inline type
733 context::get_int_type (size_t num_bytes, int is_signed)
735 return type (gcc_jit_context_get_int_type (m_inner_ctxt,
736 num_bytes,
737 is_signed));
740 template <typename T>
741 inline type
742 context::get_int_type ()
744 return get_int_type (sizeof (T), std::numeric_limits<T>::is_signed);
747 inline type
748 context::new_array_type (type element_type, int num_elements, location loc)
750 return type (gcc_jit_context_new_array_type (
751 m_inner_ctxt,
752 loc.get_inner_location (),
753 element_type.get_inner_type (),
754 num_elements));
757 inline field
758 context::new_field (type type_, const std::string &name, location loc)
760 return field (gcc_jit_context_new_field (m_inner_ctxt,
761 loc.get_inner_location (),
762 type_.get_inner_type (),
763 name.c_str ()));
766 inline field
767 context::new_bitfield (type type_, int width, const std::string &name,
768 location loc)
770 return field (gcc_jit_context_new_bitfield (m_inner_ctxt,
771 loc.get_inner_location (),
772 type_.get_inner_type (),
773 width,
774 name.c_str ()));
777 inline struct_
778 context::new_struct_type (const std::string &name,
779 std::vector<field> &fields,
780 location loc)
782 /* Treat std::vector as an array, relying on it not being resized: */
783 field *as_array_of_wrappers = &fields[0];
785 /* Treat the array as being of the underlying pointers, relying on
786 the wrapper type being such a pointer internally. */
787 gcc_jit_field **as_array_of_ptrs =
788 reinterpret_cast<gcc_jit_field **> (as_array_of_wrappers);
790 return struct_ (gcc_jit_context_new_struct_type (m_inner_ctxt,
791 loc.get_inner_location (),
792 name.c_str (),
793 fields.size (),
794 as_array_of_ptrs));
797 inline struct_
798 context::new_opaque_struct_type (const std::string &name,
799 location loc)
801 return struct_ (gcc_jit_context_new_opaque_struct (
802 m_inner_ctxt,
803 loc.get_inner_location (),
804 name.c_str ()));
807 inline param
808 context::new_param (type type_,
809 const std::string &name,
810 location loc)
812 return param (gcc_jit_context_new_param (m_inner_ctxt,
813 loc.get_inner_location (),
814 type_.get_inner_type (),
815 name.c_str ()));
818 inline function
819 context::new_function (enum gcc_jit_function_kind kind,
820 type return_type,
821 const std::string &name,
822 std::vector<param> &params,
823 int is_variadic,
824 location loc)
826 /* Treat std::vector as an array, relying on it not being resized: */
827 param *as_array_of_wrappers = &params[0];
829 /* Treat the array as being of the underlying pointers, relying on
830 the wrapper type being such a pointer internally. */
831 gcc_jit_param **as_array_of_ptrs =
832 reinterpret_cast<gcc_jit_param **> (as_array_of_wrappers);
834 return function (gcc_jit_context_new_function (m_inner_ctxt,
835 loc.get_inner_location (),
836 kind,
837 return_type.get_inner_type (),
838 name.c_str (),
839 params.size (),
840 as_array_of_ptrs,
841 is_variadic));
844 inline function
845 context::get_builtin_function (const std::string &name)
847 return function (gcc_jit_context_get_builtin_function (m_inner_ctxt,
848 name.c_str ()));
851 inline lvalue
852 context::new_global (enum gcc_jit_global_kind kind,
853 type type_,
854 const std::string &name,
855 location loc)
857 return lvalue (gcc_jit_context_new_global (m_inner_ctxt,
858 loc.get_inner_location (),
859 kind,
860 type_.get_inner_type (),
861 name.c_str ()));
864 inline rvalue
865 context::new_rvalue (type numeric_type,
866 int value) const
868 return rvalue (
869 gcc_jit_context_new_rvalue_from_int (m_inner_ctxt,
870 numeric_type.get_inner_type (),
871 value));
874 inline rvalue
875 context::new_rvalue (type numeric_type,
876 long value) const
878 return rvalue (
879 gcc_jit_context_new_rvalue_from_long (m_inner_ctxt,
880 numeric_type.get_inner_type (),
881 value));
884 inline rvalue
885 context::zero (type numeric_type) const
887 return rvalue (gcc_jit_context_zero (m_inner_ctxt,
888 numeric_type.get_inner_type ()));
891 inline rvalue
892 context::one (type numeric_type) const
894 return rvalue (gcc_jit_context_one (m_inner_ctxt,
895 numeric_type.get_inner_type ()));
898 inline rvalue
899 context::new_rvalue (type numeric_type,
900 double value) const
902 return rvalue (
903 gcc_jit_context_new_rvalue_from_double (m_inner_ctxt,
904 numeric_type.get_inner_type (),
905 value));
908 inline rvalue
909 context::new_rvalue (type pointer_type,
910 void *value) const
912 return rvalue (
913 gcc_jit_context_new_rvalue_from_ptr (m_inner_ctxt,
914 pointer_type.get_inner_type (),
915 value));
918 inline rvalue
919 context::new_rvalue (const std::string &value) const
921 return rvalue (
922 gcc_jit_context_new_string_literal (m_inner_ctxt, value.c_str ()));
925 inline rvalue
926 context::new_rvalue (type vector_type,
927 std::vector<rvalue> elements) const
929 /* Treat std::vector as an array, relying on it not being resized: */
930 rvalue *as_array_of_wrappers = &elements[0];
932 /* Treat the array as being of the underlying pointers, relying on
933 the wrapper type being such a pointer internally. */
934 gcc_jit_rvalue **as_array_of_ptrs =
935 reinterpret_cast<gcc_jit_rvalue **> (as_array_of_wrappers);
937 return rvalue (
938 gcc_jit_context_new_rvalue_from_vector (m_inner_ctxt,
939 NULL,
940 vector_type.get_inner_type (),
941 elements.size (),
942 as_array_of_ptrs));
945 inline rvalue
946 context::new_unary_op (enum gcc_jit_unary_op op,
947 type result_type,
948 rvalue a,
949 location loc)
951 return rvalue (gcc_jit_context_new_unary_op (m_inner_ctxt,
952 loc.get_inner_location (),
954 result_type.get_inner_type (),
955 a.get_inner_rvalue ()));
957 inline rvalue
958 context::new_minus (type result_type,
959 rvalue a,
960 location loc)
962 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_MINUS,
963 result_type, a, loc));
965 inline rvalue
966 context::new_bitwise_negate (type result_type,
967 rvalue a,
968 location loc)
970 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_BITWISE_NEGATE,
971 result_type, a, loc));
973 inline rvalue
974 context::new_logical_negate (type result_type,
975 rvalue a,
976 location loc)
978 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_LOGICAL_NEGATE,
979 result_type, a, loc));
982 inline rvalue
983 context::new_binary_op (enum gcc_jit_binary_op op,
984 type result_type,
985 rvalue a, rvalue b,
986 location loc)
988 return rvalue (gcc_jit_context_new_binary_op (m_inner_ctxt,
989 loc.get_inner_location (),
991 result_type.get_inner_type (),
992 a.get_inner_rvalue (),
993 b.get_inner_rvalue ()));
995 inline rvalue
996 context::new_plus (type result_type,
997 rvalue a, rvalue b,
998 location loc)
1000 return new_binary_op (GCC_JIT_BINARY_OP_PLUS,
1001 result_type, a, b, loc);
1003 inline rvalue
1004 context::new_minus (type result_type,
1005 rvalue a, rvalue b,
1006 location loc)
1008 return new_binary_op (GCC_JIT_BINARY_OP_MINUS,
1009 result_type, a, b, loc);
1011 inline rvalue
1012 context::new_mult (type result_type,
1013 rvalue a, rvalue b,
1014 location loc)
1016 return new_binary_op (GCC_JIT_BINARY_OP_MULT,
1017 result_type, a, b, loc);
1019 inline rvalue
1020 context::new_divide (type result_type,
1021 rvalue a, rvalue b,
1022 location loc)
1024 return new_binary_op (GCC_JIT_BINARY_OP_DIVIDE,
1025 result_type, a, b, loc);
1027 inline rvalue
1028 context::new_modulo (type result_type,
1029 rvalue a, rvalue b,
1030 location loc)
1032 return new_binary_op (GCC_JIT_BINARY_OP_MODULO,
1033 result_type, a, b, loc);
1035 inline rvalue
1036 context::new_bitwise_and (type result_type,
1037 rvalue a, rvalue b,
1038 location loc)
1040 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_AND,
1041 result_type, a, b, loc);
1043 inline rvalue
1044 context::new_bitwise_xor (type result_type,
1045 rvalue a, rvalue b,
1046 location loc)
1048 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_XOR,
1049 result_type, a, b, loc);
1051 inline rvalue
1052 context::new_bitwise_or (type result_type,
1053 rvalue a, rvalue b,
1054 location loc)
1056 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_OR,
1057 result_type, a, b, loc);
1059 inline rvalue
1060 context::new_logical_and (type result_type,
1061 rvalue a, rvalue b,
1062 location loc)
1064 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_AND,
1065 result_type, a, b, loc);
1067 inline rvalue
1068 context::new_logical_or (type result_type,
1069 rvalue a, rvalue b,
1070 location loc)
1072 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_OR,
1073 result_type, a, b, loc);
1076 inline rvalue
1077 context::new_comparison (enum gcc_jit_comparison op,
1078 rvalue a, rvalue b,
1079 location loc)
1081 return rvalue (gcc_jit_context_new_comparison (m_inner_ctxt,
1082 loc.get_inner_location (),
1084 a.get_inner_rvalue (),
1085 b.get_inner_rvalue ()));
1087 inline rvalue
1088 context::new_eq (rvalue a, rvalue b,
1089 location loc)
1091 return new_comparison (GCC_JIT_COMPARISON_EQ,
1092 a, b, loc);
1094 inline rvalue
1095 context::new_ne (rvalue a, rvalue b,
1096 location loc)
1098 return new_comparison (GCC_JIT_COMPARISON_NE,
1099 a, b, loc);
1101 inline rvalue
1102 context::new_lt (rvalue a, rvalue b,
1103 location loc)
1105 return new_comparison (GCC_JIT_COMPARISON_LT,
1106 a, b, loc);
1108 inline rvalue
1109 context::new_le (rvalue a, rvalue b,
1110 location loc)
1112 return new_comparison (GCC_JIT_COMPARISON_LE,
1113 a, b, loc);
1115 inline rvalue
1116 context::new_gt (rvalue a, rvalue b,
1117 location loc)
1119 return new_comparison (GCC_JIT_COMPARISON_GT,
1120 a, b, loc);
1122 inline rvalue
1123 context::new_ge (rvalue a, rvalue b,
1124 location loc)
1126 return new_comparison (GCC_JIT_COMPARISON_GE,
1127 a, b, loc);
1130 inline rvalue
1131 context::new_call (function func,
1132 std::vector<rvalue> &args,
1133 location loc)
1135 /* Treat std::vector as an array, relying on it not being resized: */
1136 rvalue *as_array_of_wrappers = &args[0];
1138 /* Treat the array as being of the underlying pointers, relying on
1139 the wrapper type being such a pointer internally. */
1140 gcc_jit_rvalue **as_array_of_ptrs =
1141 reinterpret_cast<gcc_jit_rvalue **> (as_array_of_wrappers);
1142 return gcc_jit_context_new_call (m_inner_ctxt,
1143 loc.get_inner_location (),
1144 func.get_inner_function (),
1145 args.size (),
1146 as_array_of_ptrs);
1148 inline rvalue
1149 context::new_call (function func,
1150 location loc)
1152 std::vector<rvalue> args;
1153 return new_call (func, args, loc);
1156 inline rvalue
1157 context::new_call (function func,
1158 rvalue arg0,
1159 location loc)
1161 std::vector<rvalue> args(1);
1162 args[0] = arg0;
1163 return new_call (func, args, loc);
1165 inline rvalue
1166 context::new_call (function func,
1167 rvalue arg0, rvalue arg1,
1168 location loc)
1170 std::vector<rvalue> args(2);
1171 args[0] = arg0;
1172 args[1] = arg1;
1173 return new_call (func, args, loc);
1175 inline rvalue
1176 context::new_call (function func,
1177 rvalue arg0, rvalue arg1, rvalue arg2,
1178 location loc)
1180 std::vector<rvalue> args(3);
1181 args[0] = arg0;
1182 args[1] = arg1;
1183 args[2] = arg2;
1184 return new_call (func, args, loc);
1186 inline rvalue
1187 context::new_call (function func,
1188 rvalue arg0, rvalue arg1, rvalue arg2,
1189 rvalue arg3,
1190 location loc)
1192 std::vector<rvalue> args(4);
1193 args[0] = arg0;
1194 args[1] = arg1;
1195 args[2] = arg2;
1196 args[3] = arg3;
1197 return new_call (func, args, loc);
1199 inline rvalue
1200 context::new_call (function func,
1201 rvalue arg0, rvalue arg1, rvalue arg2,
1202 rvalue arg3, rvalue arg4,
1203 location loc)
1205 std::vector<rvalue> args(5);
1206 args[0] = arg0;
1207 args[1] = arg1;
1208 args[2] = arg2;
1209 args[3] = arg3;
1210 args[4] = arg4;
1211 return new_call (func, args, loc);
1213 inline rvalue
1214 context::new_call (function func,
1215 rvalue arg0, rvalue arg1, rvalue arg2,
1216 rvalue arg3, rvalue arg4, rvalue arg5,
1217 location loc)
1219 std::vector<rvalue> args(6);
1220 args[0] = arg0;
1221 args[1] = arg1;
1222 args[2] = arg2;
1223 args[3] = arg3;
1224 args[4] = arg4;
1225 args[5] = arg5;
1226 return new_call (func, args, loc);
1229 inline rvalue
1230 context::new_cast (rvalue expr,
1231 type type_,
1232 location loc)
1234 return rvalue (gcc_jit_context_new_cast (m_inner_ctxt,
1235 loc.get_inner_location (),
1236 expr.get_inner_rvalue (),
1237 type_.get_inner_type ()));
1240 inline lvalue
1241 context::new_array_access (rvalue ptr,
1242 rvalue index,
1243 location loc)
1245 return lvalue (gcc_jit_context_new_array_access (m_inner_ctxt,
1246 loc.get_inner_location (),
1247 ptr.get_inner_rvalue (),
1248 index.get_inner_rvalue ()));
1251 inline case_
1252 context::new_case (rvalue min_value,
1253 rvalue max_value,
1254 block dest_block)
1256 return case_ (gcc_jit_context_new_case (m_inner_ctxt,
1257 min_value.get_inner_rvalue (),
1258 max_value.get_inner_rvalue (),
1259 dest_block.get_inner_block ()));
1262 // class object
1263 inline context
1264 object::get_context () const
1266 return context (gcc_jit_object_get_context (m_inner_obj));
1269 inline std::string
1270 object::get_debug_string () const
1272 return gcc_jit_object_get_debug_string (m_inner_obj);
1275 inline object::object () : m_inner_obj (NULL) {}
1276 inline object::object (gcc_jit_object *obj) : m_inner_obj (obj)
1278 if (!obj)
1279 throw error ();
1282 inline gcc_jit_object *
1283 object::get_inner_object () const
1285 return m_inner_obj;
1288 inline std::ostream&
1289 operator << (std::ostream& stream, const object &obj)
1291 return stream << obj.get_debug_string ();
1294 // class location
1295 inline location::location () : object () {}
1296 inline location::location (gcc_jit_location *loc)
1297 : object (gcc_jit_location_as_object (loc))
1300 inline gcc_jit_location *
1301 location::get_inner_location () const
1303 /* Manual downcast: */
1304 return reinterpret_cast<gcc_jit_location *> (get_inner_object ());
1307 // class field
1308 inline field::field () : object () {}
1309 inline field::field (gcc_jit_field *inner)
1310 : object (gcc_jit_field_as_object (inner))
1313 inline gcc_jit_field *
1314 field::get_inner_field () const
1316 /* Manual downcast: */
1317 return reinterpret_cast<gcc_jit_field *> (get_inner_object ());
1320 // class type
1321 inline type::type () : object () {}
1322 inline type::type (gcc_jit_type *inner)
1323 : object (gcc_jit_type_as_object (inner))
1326 inline gcc_jit_type *
1327 type::get_inner_type () const
1329 /* Manual downcast: */
1330 return reinterpret_cast<gcc_jit_type *> (get_inner_object ());
1333 inline type
1334 type::get_pointer ()
1336 return type (gcc_jit_type_get_pointer (get_inner_type ()));
1339 inline type
1340 type::get_const ()
1342 return type (gcc_jit_type_get_const (get_inner_type ()));
1345 inline type
1346 type::get_volatile ()
1348 return type (gcc_jit_type_get_volatile (get_inner_type ()));
1351 inline type
1352 type::get_aligned (size_t alignment_in_bytes)
1354 return type (gcc_jit_type_get_aligned (get_inner_type (),
1355 alignment_in_bytes));
1358 inline type
1359 type::get_vector (size_t num_units)
1361 return type (gcc_jit_type_get_vector (get_inner_type (),
1362 num_units));
1365 inline rvalue
1366 type::zero ()
1368 return get_context ().new_rvalue (*this, 0);
1371 inline rvalue
1372 type::one ()
1374 return get_context ().new_rvalue (*this, 1);
1377 // class struct_
1378 inline struct_::struct_ () : type (NULL) {}
1379 inline struct_::struct_ (gcc_jit_struct *inner) :
1380 type (gcc_jit_struct_as_type (inner))
1384 inline gcc_jit_struct *
1385 struct_::get_inner_struct () const
1387 /* Manual downcast: */
1388 return reinterpret_cast<gcc_jit_struct *> (get_inner_object ());
1391 // class function
1392 inline function::function () : object () {}
1393 inline function::function (gcc_jit_function *inner)
1394 : object (gcc_jit_function_as_object (inner))
1397 inline gcc_jit_function *
1398 function::get_inner_function () const
1400 /* Manual downcast: */
1401 return reinterpret_cast<gcc_jit_function *> (get_inner_object ());
1404 inline void
1405 function::dump_to_dot (const std::string &path)
1407 gcc_jit_function_dump_to_dot (get_inner_function (),
1408 path.c_str ());
1411 inline param
1412 function::get_param (int index) const
1414 return param (gcc_jit_function_get_param (get_inner_function (),
1415 index));
1418 inline block
1419 function::new_block ()
1421 return block (gcc_jit_function_new_block (get_inner_function (),
1422 NULL));
1425 inline block
1426 function::new_block (const std::string &name)
1428 return block (gcc_jit_function_new_block (get_inner_function (),
1429 name.c_str ()));
1432 inline lvalue
1433 function::new_local (type type_,
1434 const std::string &name,
1435 location loc)
1437 return lvalue (gcc_jit_function_new_local (get_inner_function (),
1438 loc.get_inner_location (),
1439 type_.get_inner_type (),
1440 name.c_str ()));
1443 inline rvalue
1444 function::get_address (location loc)
1446 return rvalue (gcc_jit_function_get_address (get_inner_function (),
1447 loc.get_inner_location ()));
1450 inline function
1451 block::get_function () const
1453 return function (gcc_jit_block_get_function ( get_inner_block ()));
1456 inline void
1457 block::add_eval (rvalue rvalue,
1458 location loc)
1460 gcc_jit_block_add_eval (get_inner_block (),
1461 loc.get_inner_location (),
1462 rvalue.get_inner_rvalue ());
1465 inline void
1466 block::add_assignment (lvalue lvalue,
1467 rvalue rvalue,
1468 location loc)
1470 gcc_jit_block_add_assignment (get_inner_block (),
1471 loc.get_inner_location (),
1472 lvalue.get_inner_lvalue (),
1473 rvalue.get_inner_rvalue ());
1476 inline void
1477 block::add_assignment_op (lvalue lvalue,
1478 enum gcc_jit_binary_op op,
1479 rvalue rvalue,
1480 location loc)
1482 gcc_jit_block_add_assignment_op (get_inner_block (),
1483 loc.get_inner_location (),
1484 lvalue.get_inner_lvalue (),
1486 rvalue.get_inner_rvalue ());
1489 inline void
1490 block::add_comment (const std::string &text,
1491 location loc)
1493 gcc_jit_block_add_comment (get_inner_block (),
1494 loc.get_inner_location (),
1495 text.c_str ());
1498 inline void
1499 block::end_with_conditional (rvalue boolval,
1500 block on_true,
1501 block on_false,
1502 location loc)
1504 gcc_jit_block_end_with_conditional (get_inner_block (),
1505 loc.get_inner_location (),
1506 boolval.get_inner_rvalue (),
1507 on_true.get_inner_block (),
1508 on_false.get_inner_block ());
1511 inline void
1512 block::end_with_jump (block target,
1513 location loc)
1515 gcc_jit_block_end_with_jump (get_inner_block (),
1516 loc.get_inner_location (),
1517 target.get_inner_block ());
1520 inline void
1521 block::end_with_return (rvalue rvalue,
1522 location loc)
1524 gcc_jit_block_end_with_return (get_inner_block (),
1525 loc.get_inner_location (),
1526 rvalue.get_inner_rvalue ());
1529 inline void
1530 block::end_with_return (location loc)
1532 gcc_jit_block_end_with_void_return (get_inner_block (),
1533 loc.get_inner_location ());
1536 inline void
1537 block::end_with_switch (rvalue expr,
1538 block default_block,
1539 std::vector <case_> cases,
1540 location loc)
1542 /* Treat std::vector as an array, relying on it not being resized: */
1543 case_ *as_array_of_wrappers = &cases[0];
1545 /* Treat the array as being of the underlying pointers, relying on
1546 the wrapper type being such a pointer internally. */
1547 gcc_jit_case **as_array_of_ptrs =
1548 reinterpret_cast<gcc_jit_case **> (as_array_of_wrappers);
1549 gcc_jit_block_end_with_switch (get_inner_block (),
1550 loc.get_inner_location (),
1551 expr.get_inner_rvalue (),
1552 default_block.get_inner_block (),
1553 cases.size (),
1554 as_array_of_ptrs);
1557 inline rvalue
1558 block::add_call (function other,
1559 location loc)
1561 rvalue c = get_context ().new_call (other, loc);
1562 add_eval (c);
1563 return c;
1565 inline rvalue
1566 block::add_call (function other,
1567 rvalue arg0,
1568 location loc)
1570 rvalue c = get_context ().new_call (other, arg0, loc);
1571 add_eval (c);
1572 return c;
1574 inline rvalue
1575 block::add_call (function other,
1576 rvalue arg0, rvalue arg1,
1577 location loc)
1579 rvalue c = get_context ().new_call (other, arg0, arg1, loc);
1580 add_eval (c);
1581 return c;
1583 inline rvalue
1584 block::add_call (function other,
1585 rvalue arg0, rvalue arg1, rvalue arg2,
1586 location loc)
1588 rvalue c = get_context ().new_call (other, arg0, arg1, arg2, loc);
1589 add_eval (c);
1590 return c;
1593 inline rvalue
1594 block::add_call (function other,
1595 rvalue arg0, rvalue arg1, rvalue arg2, rvalue arg3,
1596 location loc)
1598 rvalue c = get_context ().new_call (other, arg0, arg1, arg2, arg3, loc);
1599 add_eval (c);
1600 return c;
1603 inline rvalue
1604 function::operator() (location loc)
1606 return get_context ().new_call (*this, loc);
1608 inline rvalue
1609 function::operator() (rvalue arg0,
1610 location loc)
1612 return get_context ().new_call (*this,
1613 arg0,
1614 loc);
1616 inline rvalue
1617 function::operator() (rvalue arg0, rvalue arg1,
1618 location loc)
1620 return get_context ().new_call (*this,
1621 arg0, arg1,
1622 loc);
1624 inline rvalue
1625 function::operator() (rvalue arg0, rvalue arg1, rvalue arg2,
1626 location loc)
1628 return get_context ().new_call (*this,
1629 arg0, arg1, arg2,
1630 loc);
1633 // class block
1634 inline block::block () : object () {}
1635 inline block::block (gcc_jit_block *inner)
1636 : object (gcc_jit_block_as_object (inner))
1639 inline gcc_jit_block *
1640 block::get_inner_block () const
1642 /* Manual downcast: */
1643 return reinterpret_cast<gcc_jit_block *> (get_inner_object ());
1646 // class rvalue
1647 inline rvalue::rvalue () : object () {}
1648 inline rvalue::rvalue (gcc_jit_rvalue *inner)
1649 : object (gcc_jit_rvalue_as_object (inner))
1652 inline gcc_jit_rvalue *
1653 rvalue::get_inner_rvalue () const
1655 /* Manual downcast: */
1656 return reinterpret_cast<gcc_jit_rvalue *> (get_inner_object ());
1659 inline type
1660 rvalue::get_type ()
1662 return type (gcc_jit_rvalue_get_type (get_inner_rvalue ()));
1665 inline rvalue
1666 rvalue::access_field (field field,
1667 location loc)
1669 return rvalue (gcc_jit_rvalue_access_field (get_inner_rvalue (),
1670 loc.get_inner_location (),
1671 field.get_inner_field ()));
1674 inline lvalue
1675 rvalue::dereference_field (field field,
1676 location loc)
1678 return lvalue (gcc_jit_rvalue_dereference_field (get_inner_rvalue (),
1679 loc.get_inner_location (),
1680 field.get_inner_field ()));
1683 inline lvalue
1684 rvalue::dereference (location loc)
1686 return lvalue (gcc_jit_rvalue_dereference (get_inner_rvalue (),
1687 loc.get_inner_location ()));
1690 inline rvalue
1691 rvalue::cast_to (type type_,
1692 location loc)
1694 return get_context ().new_cast (*this, type_, loc);
1697 inline lvalue
1698 rvalue::operator[] (rvalue index)
1700 return get_context ().new_array_access (*this, index);
1703 inline lvalue
1704 rvalue::operator[] (int index)
1706 context ctxt = get_context ();
1707 type int_t = ctxt.get_int_type <int> ();
1708 return ctxt.new_array_access (*this,
1709 ctxt.new_rvalue (int_t,
1710 index));
1713 // class lvalue : public rvalue
1714 inline lvalue::lvalue () : rvalue () {}
1715 inline lvalue::lvalue (gcc_jit_lvalue *inner)
1716 : rvalue (gcc_jit_lvalue_as_rvalue (inner))
1719 inline gcc_jit_lvalue *
1720 lvalue::get_inner_lvalue () const
1722 /* Manual downcast: */
1723 return reinterpret_cast<gcc_jit_lvalue *> (get_inner_object ());
1726 inline lvalue
1727 lvalue::access_field (field field, location loc)
1729 return lvalue (gcc_jit_lvalue_access_field (get_inner_lvalue (),
1730 loc.get_inner_location (),
1731 field.get_inner_field ()));
1734 inline rvalue
1735 lvalue::get_address (location loc)
1737 return rvalue (gcc_jit_lvalue_get_address (get_inner_lvalue (),
1738 loc.get_inner_location ()));
1741 inline lvalue
1742 lvalue::set_initializer (const void *blob, size_t num_bytes)
1744 gcc_jit_global_set_initializer (get_inner_lvalue (),
1745 blob,
1746 num_bytes);
1747 return *this;
1750 // class param : public lvalue
1751 inline param::param () : lvalue () {}
1752 inline param::param (gcc_jit_param *inner)
1753 : lvalue (gcc_jit_param_as_lvalue (inner))
1756 // class case_ : public object
1757 inline case_::case_ () : object () {}
1758 inline case_::case_ (gcc_jit_case *inner)
1759 : object (gcc_jit_case_as_object (inner))
1763 inline gcc_jit_case *
1764 case_::get_inner_case () const
1766 /* Manual downcast: */
1767 return reinterpret_cast<gcc_jit_case *> (get_inner_object ());
1770 /* Overloaded operators. */
1771 // Unary operators
1772 inline rvalue operator- (rvalue a)
1774 return a.get_context ().new_minus (a.get_type (), a);
1776 inline rvalue operator~ (rvalue a)
1778 return a.get_context ().new_bitwise_negate (a.get_type (), a);
1780 inline rvalue operator! (rvalue a)
1782 return a.get_context ().new_logical_negate (a.get_type (), a);
1785 // Binary operators
1786 inline rvalue operator+ (rvalue a, rvalue b)
1788 return a.get_context ().new_plus (a.get_type (), a, b);
1790 inline rvalue operator- (rvalue a, rvalue b)
1792 return a.get_context ().new_minus (a.get_type (), a, b);
1794 inline rvalue operator* (rvalue a, rvalue b)
1796 return a.get_context ().new_mult (a.get_type (), a, b);
1798 inline rvalue operator/ (rvalue a, rvalue b)
1800 return a.get_context ().new_divide (a.get_type (), a, b);
1802 inline rvalue operator% (rvalue a, rvalue b)
1804 return a.get_context ().new_modulo (a.get_type (), a, b);
1806 inline rvalue operator& (rvalue a, rvalue b)
1808 return a.get_context ().new_bitwise_and (a.get_type (), a, b);
1810 inline rvalue operator^ (rvalue a, rvalue b)
1812 return a.get_context ().new_bitwise_xor (a.get_type (), a, b);
1814 inline rvalue operator| (rvalue a, rvalue b)
1816 return a.get_context ().new_bitwise_or (a.get_type (), a, b);
1818 inline rvalue operator&& (rvalue a, rvalue b)
1820 return a.get_context ().new_logical_and (a.get_type (), a, b);
1822 inline rvalue operator|| (rvalue a, rvalue b)
1824 return a.get_context ().new_logical_or (a.get_type (), a, b);
1827 /* Comparisons. */
1828 inline rvalue operator== (rvalue a, rvalue b)
1830 return a.get_context ().new_eq (a, b);
1832 inline rvalue operator!= (rvalue a, rvalue b)
1834 return a.get_context ().new_ne (a, b);
1836 inline rvalue operator< (rvalue a, rvalue b)
1838 return a.get_context ().new_lt (a, b);
1840 inline rvalue operator<= (rvalue a, rvalue b)
1842 return a.get_context ().new_le (a, b);
1844 inline rvalue operator> (rvalue a, rvalue b)
1846 return a.get_context ().new_gt (a, b);
1848 inline rvalue operator>= (rvalue a, rvalue b)
1850 return a.get_context ().new_ge (a, b);
1853 /* Dereferencing. */
1854 inline lvalue operator* (rvalue ptr)
1856 return ptr.dereference ();
1859 // class timer
1860 inline
1861 timer::timer ()
1863 m_inner_timer = gcc_jit_timer_new ();
1866 inline
1867 timer::timer (gcc_jit_timer *inner_timer)
1869 m_inner_timer = inner_timer;
1872 inline void
1873 timer::push (const char *item_name)
1875 gcc_jit_timer_push (m_inner_timer, item_name);
1879 inline void
1880 timer::pop (const char *item_name)
1882 gcc_jit_timer_pop (m_inner_timer, item_name);
1885 inline void
1886 timer::print (FILE *f_out) const
1888 gcc_jit_timer_print (m_inner_timer, f_out);
1891 inline gcc_jit_timer *
1892 timer::get_inner_timer () const
1894 return m_inner_timer;
1897 inline void
1898 timer::release ()
1900 gcc_jit_timer_release (m_inner_timer);
1901 m_inner_timer = NULL;
1904 // class auto_time
1906 inline
1907 auto_time::auto_time (timer t, const char *item_name)
1908 : m_timer (t),
1909 m_item_name (item_name)
1911 t.push (item_name);
1914 inline
1915 auto_time::auto_time (context ctxt, const char *item_name)
1916 : m_timer (ctxt.get_timer ()),
1917 m_item_name (item_name)
1919 m_timer.push (item_name);
1922 inline
1923 auto_time::~auto_time ()
1925 m_timer.pop (m_item_name);
1928 namespace version
1930 inline int
1931 major_v ()
1933 return gcc_jit_version_major ();
1936 inline int
1937 minor_v ()
1939 return gcc_jit_version_minor ();
1942 inline int
1943 patchlevel_v ()
1945 return gcc_jit_version_patchlevel ();
1947 } // namespace version
1948 } // namespace gccjit
1950 #endif /* #ifndef LIBGCCJIT_PLUS_PLUS_H */