Daily bump.
[official-gcc.git] / gcc / jit / libgccjit++.h
blob82831ff5da0488c84a565d33da6aec7343149055
1 /* A C++ API for libgccjit, purely as inline wrapper functions.
2 Copyright (C) 2014-2021 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 extended_asm;
50 class timer;
51 class auto_time;
53 namespace version {};
55 /* Errors within the API become C++ exceptions of this class. */
56 class error
60 class object
62 public:
63 context get_context () const;
65 std::string get_debug_string () const;
67 protected:
68 object ();
69 object (gcc_jit_object *obj);
71 gcc_jit_object *get_inner_object () const;
73 private:
74 gcc_jit_object *m_inner_obj;
77 inline std::ostream& operator << (std::ostream& stream, const object &obj);
79 /* Some client code will want to supply source code locations, others
80 won't. To avoid doubling the number of entrypoints, everything
81 accepting a location also has a default argument. To do this, the
82 other classes need to see that "location" has a default constructor,
83 hence we need to declare it first. */
84 class location : public object
86 public:
87 location ();
88 location (gcc_jit_location *loc);
90 gcc_jit_location *get_inner_location () const;
93 class context
95 public:
96 static context acquire ();
97 context ();
98 context (gcc_jit_context *ctxt);
100 gccjit::context new_child_context ();
102 gcc_jit_context *get_inner_context () { return m_inner_ctxt; }
104 void release ();
106 gcc_jit_result *compile ();
108 void compile_to_file (enum gcc_jit_output_kind output_kind,
109 const char *output_path);
111 void dump_to_file (const std::string &path,
112 bool update_locations);
114 void set_logfile (FILE *logfile,
115 int flags,
116 int verbosity);
118 void dump_reproducer_to_file (const char *path);
120 void set_str_option (enum gcc_jit_str_option opt,
121 const char *value);
123 void set_int_option (enum gcc_jit_int_option opt,
124 int value);
126 void set_bool_option (enum gcc_jit_bool_option opt,
127 int value);
129 void set_bool_allow_unreachable_blocks (int bool_value);
130 void set_bool_use_external_driver (int bool_value);
132 void add_command_line_option (const char *optname);
133 void add_driver_option (const char *optname);
135 void set_timer (gccjit::timer t);
136 gccjit::timer get_timer () const;
138 location
139 new_location (const std::string &filename,
140 int line,
141 int column);
143 type get_type (enum gcc_jit_types kind);
144 type get_int_type (size_t num_bytes, int is_signed);
146 /* A way to map a specific int type, using the compiler to
147 get the details automatically e.g.:
148 gccjit::type type = get_int_type <my_int_type_t> (); */
149 template <typename T>
150 type get_int_type ();
152 type new_array_type (type element_type, int num_elements,
153 location loc = location ());
155 field new_field (type type_, const std::string &name,
156 location loc = location ());
158 field new_bitfield (type type_, int width, const std::string &name,
159 location loc = location ());
161 struct_ new_struct_type (const std::string &name,
162 std::vector<field> &fields,
163 location loc = location ());
165 struct_ new_opaque_struct_type (const std::string &name,
166 location loc = location ());
168 param new_param (type type_,
169 const std::string &name,
170 location loc = location ());
172 function new_function (enum gcc_jit_function_kind kind,
173 type return_type,
174 const std::string &name,
175 std::vector<param> &params,
176 int is_variadic,
177 location loc = location ());
179 function get_builtin_function (const std::string &name);
181 lvalue new_global (enum gcc_jit_global_kind kind,
182 type type_,
183 const std::string &name,
184 location loc = location ());
186 rvalue new_rvalue (type numeric_type,
187 int value) const;
188 rvalue new_rvalue (type numeric_type,
189 long value) const;
190 rvalue zero (type numeric_type) const;
191 rvalue one (type numeric_type) const;
192 rvalue new_rvalue (type numeric_type,
193 double value) const;
194 rvalue new_rvalue (type pointer_type,
195 void *value) const;
196 rvalue new_rvalue (const std::string &value) const;
197 rvalue new_rvalue (type vector_type,
198 std::vector<rvalue> elements) const;
200 /* Generic unary operations... */
201 rvalue new_unary_op (enum gcc_jit_unary_op op,
202 type result_type,
203 rvalue a,
204 location loc = location ());
206 /* ...and shorter ways to spell the various specific kinds of
207 unary op. */
208 rvalue new_minus (type result_type,
209 rvalue a,
210 location loc = location ());
211 rvalue new_bitwise_negate (type result_type,
212 rvalue a,
213 location loc = location ());
214 rvalue new_logical_negate (type result_type,
215 rvalue a,
216 location loc = location ());
218 /* Generic binary operations... */
219 rvalue new_binary_op (enum gcc_jit_binary_op op,
220 type result_type,
221 rvalue a, rvalue b,
222 location loc = location ());
224 /* ...and shorter ways to spell the various specific kinds of
225 binary op. */
226 rvalue new_plus (type result_type,
227 rvalue a, rvalue b,
228 location loc = location ());
229 rvalue new_minus (type result_type,
230 rvalue a, rvalue b,
231 location loc = location ());
232 rvalue new_mult (type result_type,
233 rvalue a, rvalue b,
234 location loc = location ());
235 rvalue new_divide (type result_type,
236 rvalue a, rvalue b,
237 location loc = location ());
238 rvalue new_modulo (type result_type,
239 rvalue a, rvalue b,
240 location loc = location ());
241 rvalue new_bitwise_and (type result_type,
242 rvalue a, rvalue b,
243 location loc = location ());
244 rvalue new_bitwise_xor (type result_type,
245 rvalue a, rvalue b,
246 location loc = location ());
247 rvalue new_bitwise_or (type result_type,
248 rvalue a, rvalue b,
249 location loc = location ());
250 rvalue new_logical_and (type result_type,
251 rvalue a, rvalue b,
252 location loc = location ());
253 rvalue new_logical_or (type result_type,
254 rvalue a, rvalue b,
255 location loc = location ());
257 /* Generic comparisons... */
258 rvalue new_comparison (enum gcc_jit_comparison op,
259 rvalue a, rvalue b,
260 location loc = location ());
261 /* ...and shorter ways to spell the various specific kinds of
262 comparison. */
263 rvalue new_eq (rvalue a, rvalue b,
264 location loc = location ());
265 rvalue new_ne (rvalue a, rvalue b,
266 location loc = location ());
267 rvalue new_lt (rvalue a, rvalue b,
268 location loc = location ());
269 rvalue new_le (rvalue a, rvalue b,
270 location loc = location ());
271 rvalue new_gt (rvalue a, rvalue b,
272 location loc = location ());
273 rvalue new_ge (rvalue a, rvalue b,
274 location loc = location ());
276 /* The most general way of creating a function call. */
277 rvalue new_call (function func,
278 std::vector<rvalue> &args,
279 location loc = location ());
281 /* In addition, we provide a series of overloaded "new_call" methods
282 for specific numbers of args (from 0 - 6), to avoid the need for
283 client code to manually build a vector. */
284 rvalue new_call (function func,
285 location loc = location ());
286 rvalue new_call (function func,
287 rvalue arg0,
288 location loc = location ());
289 rvalue new_call (function func,
290 rvalue arg0, rvalue arg1,
291 location loc = location ());
292 rvalue new_call (function func,
293 rvalue arg0, rvalue arg1, rvalue arg2,
294 location loc = location ());
295 rvalue new_call (function func,
296 rvalue arg0, rvalue arg1, rvalue arg2,
297 rvalue arg3,
298 location loc = location ());
299 rvalue new_call (function func,
300 rvalue arg0, rvalue arg1, rvalue arg2,
301 rvalue arg3, rvalue arg4,
302 location loc = location ());
303 rvalue new_call (function func,
304 rvalue arg0, rvalue arg1, rvalue arg2,
305 rvalue arg3, rvalue arg4, rvalue arg5,
306 location loc = location ());
308 rvalue new_cast (rvalue expr,
309 type type_,
310 location loc = location ());
312 lvalue new_array_access (rvalue ptr,
313 rvalue index,
314 location loc = location ());
316 case_ new_case (rvalue min_value,
317 rvalue max_value,
318 block dest_block);
320 void add_top_level_asm (const char *asm_stmts,
321 location loc = location ());
323 private:
324 gcc_jit_context *m_inner_ctxt;
327 class field : public object
329 public:
330 field ();
331 field (gcc_jit_field *inner);
333 gcc_jit_field *get_inner_field () const;
336 class type : public object
338 public:
339 type ();
340 type (gcc_jit_type *inner);
342 gcc_jit_type *get_inner_type () const;
344 type get_pointer ();
345 type get_const ();
346 type get_volatile ();
347 type get_aligned (size_t alignment_in_bytes);
348 type get_vector (size_t num_units);
350 // Shortcuts for getting values of numeric types:
351 rvalue zero ();
352 rvalue one ();
355 class struct_ : public type
357 public:
358 struct_ ();
359 struct_ (gcc_jit_struct *inner);
361 gcc_jit_struct *get_inner_struct () const;
364 class function : public object
366 public:
367 function ();
368 function (gcc_jit_function *func);
370 gcc_jit_function *get_inner_function () const;
372 void dump_to_dot (const std::string &path);
374 param get_param (int index) const;
376 block new_block ();
377 block new_block (const std::string &name);
379 lvalue new_local (type type_,
380 const std::string &name,
381 location loc = location ());
383 rvalue get_address (location loc = location ());
385 /* A series of overloaded operator () with various numbers of arguments
386 for a very terse way of creating a call to this function. The call
387 is created within the same context as the function itself, which may
388 not be what you want. */
389 rvalue operator() (location loc = location ());
390 rvalue operator() (rvalue arg0,
391 location loc = location ());
392 rvalue operator() (rvalue arg0, rvalue arg1,
393 location loc = location ());
394 rvalue operator() (rvalue arg0, rvalue arg1, rvalue arg2,
395 location loc = location ());
398 class block : public object
400 public:
401 block ();
402 block (gcc_jit_block *inner);
404 gcc_jit_block *get_inner_block () const;
406 function get_function () const;
408 void add_eval (rvalue rvalue,
409 location loc = location ());
411 void add_assignment (lvalue lvalue,
412 rvalue rvalue,
413 location loc = location ());
415 void add_assignment_op (lvalue lvalue,
416 enum gcc_jit_binary_op op,
417 rvalue rvalue,
418 location loc = location ());
420 /* A way to add a function call to the body of a function being
421 defined, with various numbers of args. */
422 rvalue add_call (function other,
423 location loc = location ());
424 rvalue add_call (function other,
425 rvalue arg0,
426 location loc = location ());
427 rvalue add_call (function other,
428 rvalue arg0, rvalue arg1,
429 location loc = location ());
430 rvalue add_call (function other,
431 rvalue arg0, rvalue arg1, rvalue arg2,
432 location loc = location ());
433 rvalue add_call (function other,
434 rvalue arg0, rvalue arg1, rvalue arg2, rvalue arg3,
435 location loc = location ());
437 void add_comment (const std::string &text,
438 location loc = location ());
440 void end_with_conditional (rvalue boolval,
441 block on_true,
442 block on_false,
443 location loc = location ());
445 void end_with_jump (block target,
446 location loc = location ());
448 void end_with_return (rvalue rvalue,
449 location loc = location ());
450 void end_with_return (location loc = location ());
452 void end_with_switch (rvalue expr,
453 block default_block,
454 std::vector <case_> cases,
455 location loc = location ());
457 extended_asm add_extended_asm (const std::string &asm_template,
458 location loc = location ());
459 extended_asm end_with_extended_asm_goto (const std::string &asm_template,
460 std::vector<block> goto_blocks,
461 block *fallthrough_block,
462 location loc = location ());
465 class rvalue : public object
467 public:
468 rvalue ();
469 rvalue (gcc_jit_rvalue *inner);
470 gcc_jit_rvalue *get_inner_rvalue () const;
472 type get_type ();
474 rvalue access_field (field field,
475 location loc = location ());
477 lvalue dereference_field (field field,
478 location loc = location ());
480 lvalue dereference (location loc = location ());
482 rvalue cast_to (type type_,
483 location loc = location ());
485 /* Array access. */
486 lvalue operator[] (rvalue index);
487 lvalue operator[] (int index);
490 class lvalue : public rvalue
492 public:
493 lvalue ();
494 lvalue (gcc_jit_lvalue *inner);
496 gcc_jit_lvalue *get_inner_lvalue () const;
498 lvalue access_field (field field,
499 location loc = location ());
501 rvalue get_address (location loc = location ());
502 lvalue set_initializer (const void *blob, size_t num_bytes);
505 class param : public lvalue
507 public:
508 param ();
509 param (gcc_jit_param *inner);
511 gcc_jit_param *get_inner_param () const;
514 class case_ : public object
516 public:
517 case_ ();
518 case_ (gcc_jit_case *inner);
520 gcc_jit_case *get_inner_case () const;
523 class extended_asm : public object
525 public:
526 extended_asm ();
527 extended_asm (gcc_jit_extended_asm *inner);
529 extended_asm &
530 set_volatile_flag (bool flag);
532 extended_asm &
533 set_inline_flag (bool flag);
535 extended_asm&
536 add_output_operand (const std::string &asm_symbolic_name,
537 const std::string &constraint,
538 gccjit::lvalue dest);
539 extended_asm&
540 add_output_operand (const std::string &constraint,
541 gccjit::lvalue dest);
543 extended_asm&
544 add_input_operand (const std::string &asm_symbolic_name,
545 const std::string &constraint,
546 gccjit::rvalue src);
547 extended_asm&
548 add_input_operand (const std::string &constraint,
549 gccjit::rvalue src);
551 extended_asm&
552 add_clobber (const std::string &victim);
554 gcc_jit_extended_asm *get_inner_extended_asm () const;
557 /* Overloaded operators, for those who want the most terse API
558 (at the possible risk of being a little too magical).
560 In each case, the first parameter is used to determine which context
561 owns the resulting expression, and, where appropriate, what the
562 latter's type is. */
564 /* Unary operators. */
565 rvalue operator- (rvalue a); // unary minus
566 rvalue operator~ (rvalue a); // unary bitwise negate
567 rvalue operator! (rvalue a); // unary logical negate
569 /* Binary operators. */
570 rvalue operator+ (rvalue a, rvalue b);
571 rvalue operator- (rvalue a, rvalue b);
572 rvalue operator* (rvalue a, rvalue b);
573 rvalue operator/ (rvalue a, rvalue b);
574 rvalue operator% (rvalue a, rvalue b);
575 rvalue operator& (rvalue a, rvalue b); // bitwise and
576 rvalue operator^ (rvalue a, rvalue b); // bitwise_xor
577 rvalue operator| (rvalue a, rvalue b); // bitwise_or
578 rvalue operator&& (rvalue a, rvalue b); // logical_and
579 rvalue operator|| (rvalue a, rvalue b); // logical_or
581 /* Comparisons. */
582 rvalue operator== (rvalue a, rvalue b);
583 rvalue operator!= (rvalue a, rvalue b);
584 rvalue operator< (rvalue a, rvalue b);
585 rvalue operator<= (rvalue a, rvalue b);
586 rvalue operator> (rvalue a, rvalue b);
587 rvalue operator>= (rvalue a, rvalue b);
589 /* Dereferencing. */
590 lvalue operator* (rvalue ptr);
592 class timer
594 public:
595 timer ();
596 timer (gcc_jit_timer *inner_timer);
598 void push (const char *item_name);
599 void pop (const char *item_name);
600 void print (FILE *f_out) const;
602 void release ();
604 gcc_jit_timer *get_inner_timer () const;
606 private:
607 gcc_jit_timer *m_inner_timer;
610 class auto_time
612 public:
613 auto_time (timer t, const char *item_name);
614 auto_time (context ctxt, const char *item_name);
615 ~auto_time ();
617 private:
618 timer m_timer;
619 const char *m_item_name;
623 /****************************************************************************
624 Implementation of the API
625 ****************************************************************************/
626 namespace gccjit {
628 // class context
629 inline context context::acquire ()
631 return context (gcc_jit_context_acquire ());
633 inline context::context () : m_inner_ctxt (NULL) {}
634 inline context::context (gcc_jit_context *inner) : m_inner_ctxt (inner)
636 if (!inner)
637 throw error ();
640 inline gccjit::context
641 context::new_child_context ()
643 return context (gcc_jit_context_new_child_context (m_inner_ctxt));
646 inline void
647 context::release ()
649 gcc_jit_context_release (m_inner_ctxt);
650 m_inner_ctxt = NULL;
653 inline gcc_jit_result *
654 context::compile ()
656 gcc_jit_result *result = gcc_jit_context_compile (m_inner_ctxt);
657 if (!result)
658 throw error ();
659 return result;
662 inline void
663 context::compile_to_file (enum gcc_jit_output_kind output_kind,
664 const char *output_path)
666 gcc_jit_context_compile_to_file (m_inner_ctxt,
667 output_kind,
668 output_path);
671 inline void
672 context::dump_to_file (const std::string &path,
673 bool update_locations)
675 gcc_jit_context_dump_to_file (m_inner_ctxt,
676 path.c_str (),
677 update_locations);
680 inline void
681 context::set_logfile (FILE *logfile,
682 int flags,
683 int verbosity)
685 gcc_jit_context_set_logfile (m_inner_ctxt,
686 logfile,
687 flags,
688 verbosity);
691 inline void
692 context::dump_reproducer_to_file (const char *path)
694 gcc_jit_context_dump_reproducer_to_file (m_inner_ctxt,
695 path);
698 inline void
699 context::set_str_option (enum gcc_jit_str_option opt,
700 const char *value)
702 gcc_jit_context_set_str_option (m_inner_ctxt, opt, value);
706 inline void
707 context::set_int_option (enum gcc_jit_int_option opt,
708 int value)
710 gcc_jit_context_set_int_option (m_inner_ctxt, opt, value);
714 inline void
715 context::set_bool_option (enum gcc_jit_bool_option opt,
716 int value)
718 gcc_jit_context_set_bool_option (m_inner_ctxt, opt, value);
721 inline void
722 context::set_bool_allow_unreachable_blocks (int bool_value)
724 gcc_jit_context_set_bool_allow_unreachable_blocks (m_inner_ctxt,
725 bool_value);
728 inline void
729 context::set_bool_use_external_driver (int bool_value)
731 gcc_jit_context_set_bool_use_external_driver (m_inner_ctxt,
732 bool_value);
735 inline void
736 context::add_command_line_option (const char *optname)
738 gcc_jit_context_add_command_line_option (m_inner_ctxt, optname);
741 inline void
742 context::add_driver_option (const char *optname)
744 gcc_jit_context_add_driver_option (m_inner_ctxt, optname);
747 inline void
748 context::set_timer (gccjit::timer t)
750 gcc_jit_context_set_timer (m_inner_ctxt, t.get_inner_timer ());
753 inline gccjit::timer
754 context::get_timer () const
756 return gccjit::timer (gcc_jit_context_get_timer (m_inner_ctxt));
760 inline location
761 context::new_location (const std::string &filename,
762 int line,
763 int column)
765 return location (gcc_jit_context_new_location (m_inner_ctxt,
766 filename.c_str (),
767 line,
768 column));
771 inline type
772 context::get_type (enum gcc_jit_types kind)
774 return type (gcc_jit_context_get_type (m_inner_ctxt, kind));
777 inline type
778 context::get_int_type (size_t num_bytes, int is_signed)
780 return type (gcc_jit_context_get_int_type (m_inner_ctxt,
781 num_bytes,
782 is_signed));
785 template <typename T>
786 inline type
787 context::get_int_type ()
789 return get_int_type (sizeof (T), std::numeric_limits<T>::is_signed);
792 inline type
793 context::new_array_type (type element_type, int num_elements, location loc)
795 return type (gcc_jit_context_new_array_type (
796 m_inner_ctxt,
797 loc.get_inner_location (),
798 element_type.get_inner_type (),
799 num_elements));
802 inline field
803 context::new_field (type type_, const std::string &name, location loc)
805 return field (gcc_jit_context_new_field (m_inner_ctxt,
806 loc.get_inner_location (),
807 type_.get_inner_type (),
808 name.c_str ()));
811 inline field
812 context::new_bitfield (type type_, int width, const std::string &name,
813 location loc)
815 return field (gcc_jit_context_new_bitfield (m_inner_ctxt,
816 loc.get_inner_location (),
817 type_.get_inner_type (),
818 width,
819 name.c_str ()));
822 inline struct_
823 context::new_struct_type (const std::string &name,
824 std::vector<field> &fields,
825 location loc)
827 /* Treat std::vector as an array, relying on it not being resized: */
828 field *as_array_of_wrappers = &fields[0];
830 /* Treat the array as being of the underlying pointers, relying on
831 the wrapper type being such a pointer internally. */
832 gcc_jit_field **as_array_of_ptrs =
833 reinterpret_cast<gcc_jit_field **> (as_array_of_wrappers);
835 return struct_ (gcc_jit_context_new_struct_type (m_inner_ctxt,
836 loc.get_inner_location (),
837 name.c_str (),
838 fields.size (),
839 as_array_of_ptrs));
842 inline struct_
843 context::new_opaque_struct_type (const std::string &name,
844 location loc)
846 return struct_ (gcc_jit_context_new_opaque_struct (
847 m_inner_ctxt,
848 loc.get_inner_location (),
849 name.c_str ()));
852 inline param
853 context::new_param (type type_,
854 const std::string &name,
855 location loc)
857 return param (gcc_jit_context_new_param (m_inner_ctxt,
858 loc.get_inner_location (),
859 type_.get_inner_type (),
860 name.c_str ()));
863 inline function
864 context::new_function (enum gcc_jit_function_kind kind,
865 type return_type,
866 const std::string &name,
867 std::vector<param> &params,
868 int is_variadic,
869 location loc)
871 /* Treat std::vector as an array, relying on it not being resized: */
872 param *as_array_of_wrappers = &params[0];
874 /* Treat the array as being of the underlying pointers, relying on
875 the wrapper type being such a pointer internally. */
876 gcc_jit_param **as_array_of_ptrs =
877 reinterpret_cast<gcc_jit_param **> (as_array_of_wrappers);
879 return function (gcc_jit_context_new_function (m_inner_ctxt,
880 loc.get_inner_location (),
881 kind,
882 return_type.get_inner_type (),
883 name.c_str (),
884 params.size (),
885 as_array_of_ptrs,
886 is_variadic));
889 inline function
890 context::get_builtin_function (const std::string &name)
892 return function (gcc_jit_context_get_builtin_function (m_inner_ctxt,
893 name.c_str ()));
896 inline lvalue
897 context::new_global (enum gcc_jit_global_kind kind,
898 type type_,
899 const std::string &name,
900 location loc)
902 return lvalue (gcc_jit_context_new_global (m_inner_ctxt,
903 loc.get_inner_location (),
904 kind,
905 type_.get_inner_type (),
906 name.c_str ()));
909 inline rvalue
910 context::new_rvalue (type numeric_type,
911 int value) const
913 return rvalue (
914 gcc_jit_context_new_rvalue_from_int (m_inner_ctxt,
915 numeric_type.get_inner_type (),
916 value));
919 inline rvalue
920 context::new_rvalue (type numeric_type,
921 long value) const
923 return rvalue (
924 gcc_jit_context_new_rvalue_from_long (m_inner_ctxt,
925 numeric_type.get_inner_type (),
926 value));
929 inline rvalue
930 context::zero (type numeric_type) const
932 return rvalue (gcc_jit_context_zero (m_inner_ctxt,
933 numeric_type.get_inner_type ()));
936 inline rvalue
937 context::one (type numeric_type) const
939 return rvalue (gcc_jit_context_one (m_inner_ctxt,
940 numeric_type.get_inner_type ()));
943 inline rvalue
944 context::new_rvalue (type numeric_type,
945 double value) const
947 return rvalue (
948 gcc_jit_context_new_rvalue_from_double (m_inner_ctxt,
949 numeric_type.get_inner_type (),
950 value));
953 inline rvalue
954 context::new_rvalue (type pointer_type,
955 void *value) const
957 return rvalue (
958 gcc_jit_context_new_rvalue_from_ptr (m_inner_ctxt,
959 pointer_type.get_inner_type (),
960 value));
963 inline rvalue
964 context::new_rvalue (const std::string &value) const
966 return rvalue (
967 gcc_jit_context_new_string_literal (m_inner_ctxt, value.c_str ()));
970 inline rvalue
971 context::new_rvalue (type vector_type,
972 std::vector<rvalue> elements) const
974 /* Treat std::vector as an array, relying on it not being resized: */
975 rvalue *as_array_of_wrappers = &elements[0];
977 /* Treat the array as being of the underlying pointers, relying on
978 the wrapper type being such a pointer internally. */
979 gcc_jit_rvalue **as_array_of_ptrs =
980 reinterpret_cast<gcc_jit_rvalue **> (as_array_of_wrappers);
982 return rvalue (
983 gcc_jit_context_new_rvalue_from_vector (m_inner_ctxt,
984 NULL,
985 vector_type.get_inner_type (),
986 elements.size (),
987 as_array_of_ptrs));
990 inline rvalue
991 context::new_unary_op (enum gcc_jit_unary_op op,
992 type result_type,
993 rvalue a,
994 location loc)
996 return rvalue (gcc_jit_context_new_unary_op (m_inner_ctxt,
997 loc.get_inner_location (),
999 result_type.get_inner_type (),
1000 a.get_inner_rvalue ()));
1002 inline rvalue
1003 context::new_minus (type result_type,
1004 rvalue a,
1005 location loc)
1007 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_MINUS,
1008 result_type, a, loc));
1010 inline rvalue
1011 context::new_bitwise_negate (type result_type,
1012 rvalue a,
1013 location loc)
1015 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_BITWISE_NEGATE,
1016 result_type, a, loc));
1018 inline rvalue
1019 context::new_logical_negate (type result_type,
1020 rvalue a,
1021 location loc)
1023 return rvalue (new_unary_op (GCC_JIT_UNARY_OP_LOGICAL_NEGATE,
1024 result_type, a, loc));
1027 inline rvalue
1028 context::new_binary_op (enum gcc_jit_binary_op op,
1029 type result_type,
1030 rvalue a, rvalue b,
1031 location loc)
1033 return rvalue (gcc_jit_context_new_binary_op (m_inner_ctxt,
1034 loc.get_inner_location (),
1036 result_type.get_inner_type (),
1037 a.get_inner_rvalue (),
1038 b.get_inner_rvalue ()));
1040 inline rvalue
1041 context::new_plus (type result_type,
1042 rvalue a, rvalue b,
1043 location loc)
1045 return new_binary_op (GCC_JIT_BINARY_OP_PLUS,
1046 result_type, a, b, loc);
1048 inline rvalue
1049 context::new_minus (type result_type,
1050 rvalue a, rvalue b,
1051 location loc)
1053 return new_binary_op (GCC_JIT_BINARY_OP_MINUS,
1054 result_type, a, b, loc);
1056 inline rvalue
1057 context::new_mult (type result_type,
1058 rvalue a, rvalue b,
1059 location loc)
1061 return new_binary_op (GCC_JIT_BINARY_OP_MULT,
1062 result_type, a, b, loc);
1064 inline rvalue
1065 context::new_divide (type result_type,
1066 rvalue a, rvalue b,
1067 location loc)
1069 return new_binary_op (GCC_JIT_BINARY_OP_DIVIDE,
1070 result_type, a, b, loc);
1072 inline rvalue
1073 context::new_modulo (type result_type,
1074 rvalue a, rvalue b,
1075 location loc)
1077 return new_binary_op (GCC_JIT_BINARY_OP_MODULO,
1078 result_type, a, b, loc);
1080 inline rvalue
1081 context::new_bitwise_and (type result_type,
1082 rvalue a, rvalue b,
1083 location loc)
1085 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_AND,
1086 result_type, a, b, loc);
1088 inline rvalue
1089 context::new_bitwise_xor (type result_type,
1090 rvalue a, rvalue b,
1091 location loc)
1093 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_XOR,
1094 result_type, a, b, loc);
1096 inline rvalue
1097 context::new_bitwise_or (type result_type,
1098 rvalue a, rvalue b,
1099 location loc)
1101 return new_binary_op (GCC_JIT_BINARY_OP_BITWISE_OR,
1102 result_type, a, b, loc);
1104 inline rvalue
1105 context::new_logical_and (type result_type,
1106 rvalue a, rvalue b,
1107 location loc)
1109 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_AND,
1110 result_type, a, b, loc);
1112 inline rvalue
1113 context::new_logical_or (type result_type,
1114 rvalue a, rvalue b,
1115 location loc)
1117 return new_binary_op (GCC_JIT_BINARY_OP_LOGICAL_OR,
1118 result_type, a, b, loc);
1121 inline rvalue
1122 context::new_comparison (enum gcc_jit_comparison op,
1123 rvalue a, rvalue b,
1124 location loc)
1126 return rvalue (gcc_jit_context_new_comparison (m_inner_ctxt,
1127 loc.get_inner_location (),
1129 a.get_inner_rvalue (),
1130 b.get_inner_rvalue ()));
1132 inline rvalue
1133 context::new_eq (rvalue a, rvalue b,
1134 location loc)
1136 return new_comparison (GCC_JIT_COMPARISON_EQ,
1137 a, b, loc);
1139 inline rvalue
1140 context::new_ne (rvalue a, rvalue b,
1141 location loc)
1143 return new_comparison (GCC_JIT_COMPARISON_NE,
1144 a, b, loc);
1146 inline rvalue
1147 context::new_lt (rvalue a, rvalue b,
1148 location loc)
1150 return new_comparison (GCC_JIT_COMPARISON_LT,
1151 a, b, loc);
1153 inline rvalue
1154 context::new_le (rvalue a, rvalue b,
1155 location loc)
1157 return new_comparison (GCC_JIT_COMPARISON_LE,
1158 a, b, loc);
1160 inline rvalue
1161 context::new_gt (rvalue a, rvalue b,
1162 location loc)
1164 return new_comparison (GCC_JIT_COMPARISON_GT,
1165 a, b, loc);
1167 inline rvalue
1168 context::new_ge (rvalue a, rvalue b,
1169 location loc)
1171 return new_comparison (GCC_JIT_COMPARISON_GE,
1172 a, b, loc);
1175 inline rvalue
1176 context::new_call (function func,
1177 std::vector<rvalue> &args,
1178 location loc)
1180 /* Treat std::vector as an array, relying on it not being resized: */
1181 rvalue *as_array_of_wrappers = &args[0];
1183 /* Treat the array as being of the underlying pointers, relying on
1184 the wrapper type being such a pointer internally. */
1185 gcc_jit_rvalue **as_array_of_ptrs =
1186 reinterpret_cast<gcc_jit_rvalue **> (as_array_of_wrappers);
1187 return gcc_jit_context_new_call (m_inner_ctxt,
1188 loc.get_inner_location (),
1189 func.get_inner_function (),
1190 args.size (),
1191 as_array_of_ptrs);
1193 inline rvalue
1194 context::new_call (function func,
1195 location loc)
1197 std::vector<rvalue> args;
1198 return new_call (func, args, loc);
1201 inline rvalue
1202 context::new_call (function func,
1203 rvalue arg0,
1204 location loc)
1206 std::vector<rvalue> args(1);
1207 args[0] = arg0;
1208 return new_call (func, args, loc);
1210 inline rvalue
1211 context::new_call (function func,
1212 rvalue arg0, rvalue arg1,
1213 location loc)
1215 std::vector<rvalue> args(2);
1216 args[0] = arg0;
1217 args[1] = arg1;
1218 return new_call (func, args, loc);
1220 inline rvalue
1221 context::new_call (function func,
1222 rvalue arg0, rvalue arg1, rvalue arg2,
1223 location loc)
1225 std::vector<rvalue> args(3);
1226 args[0] = arg0;
1227 args[1] = arg1;
1228 args[2] = arg2;
1229 return new_call (func, args, loc);
1231 inline rvalue
1232 context::new_call (function func,
1233 rvalue arg0, rvalue arg1, rvalue arg2,
1234 rvalue arg3,
1235 location loc)
1237 std::vector<rvalue> args(4);
1238 args[0] = arg0;
1239 args[1] = arg1;
1240 args[2] = arg2;
1241 args[3] = arg3;
1242 return new_call (func, args, loc);
1244 inline rvalue
1245 context::new_call (function func,
1246 rvalue arg0, rvalue arg1, rvalue arg2,
1247 rvalue arg3, rvalue arg4,
1248 location loc)
1250 std::vector<rvalue> args(5);
1251 args[0] = arg0;
1252 args[1] = arg1;
1253 args[2] = arg2;
1254 args[3] = arg3;
1255 args[4] = arg4;
1256 return new_call (func, args, loc);
1258 inline rvalue
1259 context::new_call (function func,
1260 rvalue arg0, rvalue arg1, rvalue arg2,
1261 rvalue arg3, rvalue arg4, rvalue arg5,
1262 location loc)
1264 std::vector<rvalue> args(6);
1265 args[0] = arg0;
1266 args[1] = arg1;
1267 args[2] = arg2;
1268 args[3] = arg3;
1269 args[4] = arg4;
1270 args[5] = arg5;
1271 return new_call (func, args, loc);
1274 inline rvalue
1275 context::new_cast (rvalue expr,
1276 type type_,
1277 location loc)
1279 return rvalue (gcc_jit_context_new_cast (m_inner_ctxt,
1280 loc.get_inner_location (),
1281 expr.get_inner_rvalue (),
1282 type_.get_inner_type ()));
1285 inline lvalue
1286 context::new_array_access (rvalue ptr,
1287 rvalue index,
1288 location loc)
1290 return lvalue (gcc_jit_context_new_array_access (m_inner_ctxt,
1291 loc.get_inner_location (),
1292 ptr.get_inner_rvalue (),
1293 index.get_inner_rvalue ()));
1296 inline case_
1297 context::new_case (rvalue min_value,
1298 rvalue max_value,
1299 block dest_block)
1301 return case_ (gcc_jit_context_new_case (m_inner_ctxt,
1302 min_value.get_inner_rvalue (),
1303 max_value.get_inner_rvalue (),
1304 dest_block.get_inner_block ()));
1307 inline void
1308 context::add_top_level_asm (const char *asm_stmts, location loc)
1310 gcc_jit_context_add_top_level_asm (m_inner_ctxt,
1311 loc.get_inner_location (),
1312 asm_stmts);
1315 // class object
1316 inline context
1317 object::get_context () const
1319 return context (gcc_jit_object_get_context (m_inner_obj));
1322 inline std::string
1323 object::get_debug_string () const
1325 return gcc_jit_object_get_debug_string (m_inner_obj);
1328 inline object::object () : m_inner_obj (NULL) {}
1329 inline object::object (gcc_jit_object *obj) : m_inner_obj (obj)
1331 if (!obj)
1332 throw error ();
1335 inline gcc_jit_object *
1336 object::get_inner_object () const
1338 return m_inner_obj;
1341 inline std::ostream&
1342 operator << (std::ostream& stream, const object &obj)
1344 return stream << obj.get_debug_string ();
1347 // class location
1348 inline location::location () : object () {}
1349 inline location::location (gcc_jit_location *loc)
1350 : object (gcc_jit_location_as_object (loc))
1353 inline gcc_jit_location *
1354 location::get_inner_location () const
1356 /* Manual downcast: */
1357 return reinterpret_cast<gcc_jit_location *> (get_inner_object ());
1360 // class field
1361 inline field::field () : object () {}
1362 inline field::field (gcc_jit_field *inner)
1363 : object (gcc_jit_field_as_object (inner))
1366 inline gcc_jit_field *
1367 field::get_inner_field () const
1369 /* Manual downcast: */
1370 return reinterpret_cast<gcc_jit_field *> (get_inner_object ());
1373 // class type
1374 inline type::type () : object () {}
1375 inline type::type (gcc_jit_type *inner)
1376 : object (gcc_jit_type_as_object (inner))
1379 inline gcc_jit_type *
1380 type::get_inner_type () const
1382 /* Manual downcast: */
1383 return reinterpret_cast<gcc_jit_type *> (get_inner_object ());
1386 inline type
1387 type::get_pointer ()
1389 return type (gcc_jit_type_get_pointer (get_inner_type ()));
1392 inline type
1393 type::get_const ()
1395 return type (gcc_jit_type_get_const (get_inner_type ()));
1398 inline type
1399 type::get_volatile ()
1401 return type (gcc_jit_type_get_volatile (get_inner_type ()));
1404 inline type
1405 type::get_aligned (size_t alignment_in_bytes)
1407 return type (gcc_jit_type_get_aligned (get_inner_type (),
1408 alignment_in_bytes));
1411 inline type
1412 type::get_vector (size_t num_units)
1414 return type (gcc_jit_type_get_vector (get_inner_type (),
1415 num_units));
1418 inline rvalue
1419 type::zero ()
1421 return get_context ().new_rvalue (*this, 0);
1424 inline rvalue
1425 type::one ()
1427 return get_context ().new_rvalue (*this, 1);
1430 // class struct_
1431 inline struct_::struct_ () : type (NULL) {}
1432 inline struct_::struct_ (gcc_jit_struct *inner) :
1433 type (gcc_jit_struct_as_type (inner))
1437 inline gcc_jit_struct *
1438 struct_::get_inner_struct () const
1440 /* Manual downcast: */
1441 return reinterpret_cast<gcc_jit_struct *> (get_inner_object ());
1444 // class function
1445 inline function::function () : object () {}
1446 inline function::function (gcc_jit_function *inner)
1447 : object (gcc_jit_function_as_object (inner))
1450 inline gcc_jit_function *
1451 function::get_inner_function () const
1453 /* Manual downcast: */
1454 return reinterpret_cast<gcc_jit_function *> (get_inner_object ());
1457 inline void
1458 function::dump_to_dot (const std::string &path)
1460 gcc_jit_function_dump_to_dot (get_inner_function (),
1461 path.c_str ());
1464 inline param
1465 function::get_param (int index) const
1467 return param (gcc_jit_function_get_param (get_inner_function (),
1468 index));
1471 inline block
1472 function::new_block ()
1474 return block (gcc_jit_function_new_block (get_inner_function (),
1475 NULL));
1478 inline block
1479 function::new_block (const std::string &name)
1481 return block (gcc_jit_function_new_block (get_inner_function (),
1482 name.c_str ()));
1485 inline lvalue
1486 function::new_local (type type_,
1487 const std::string &name,
1488 location loc)
1490 return lvalue (gcc_jit_function_new_local (get_inner_function (),
1491 loc.get_inner_location (),
1492 type_.get_inner_type (),
1493 name.c_str ()));
1496 inline rvalue
1497 function::get_address (location loc)
1499 return rvalue (gcc_jit_function_get_address (get_inner_function (),
1500 loc.get_inner_location ()));
1503 inline function
1504 block::get_function () const
1506 return function (gcc_jit_block_get_function ( get_inner_block ()));
1509 inline void
1510 block::add_eval (rvalue rvalue,
1511 location loc)
1513 gcc_jit_block_add_eval (get_inner_block (),
1514 loc.get_inner_location (),
1515 rvalue.get_inner_rvalue ());
1518 inline void
1519 block::add_assignment (lvalue lvalue,
1520 rvalue rvalue,
1521 location loc)
1523 gcc_jit_block_add_assignment (get_inner_block (),
1524 loc.get_inner_location (),
1525 lvalue.get_inner_lvalue (),
1526 rvalue.get_inner_rvalue ());
1529 inline void
1530 block::add_assignment_op (lvalue lvalue,
1531 enum gcc_jit_binary_op op,
1532 rvalue rvalue,
1533 location loc)
1535 gcc_jit_block_add_assignment_op (get_inner_block (),
1536 loc.get_inner_location (),
1537 lvalue.get_inner_lvalue (),
1539 rvalue.get_inner_rvalue ());
1542 inline void
1543 block::add_comment (const std::string &text,
1544 location loc)
1546 gcc_jit_block_add_comment (get_inner_block (),
1547 loc.get_inner_location (),
1548 text.c_str ());
1551 inline void
1552 block::end_with_conditional (rvalue boolval,
1553 block on_true,
1554 block on_false,
1555 location loc)
1557 gcc_jit_block_end_with_conditional (get_inner_block (),
1558 loc.get_inner_location (),
1559 boolval.get_inner_rvalue (),
1560 on_true.get_inner_block (),
1561 on_false.get_inner_block ());
1564 inline void
1565 block::end_with_jump (block target,
1566 location loc)
1568 gcc_jit_block_end_with_jump (get_inner_block (),
1569 loc.get_inner_location (),
1570 target.get_inner_block ());
1573 inline void
1574 block::end_with_return (rvalue rvalue,
1575 location loc)
1577 gcc_jit_block_end_with_return (get_inner_block (),
1578 loc.get_inner_location (),
1579 rvalue.get_inner_rvalue ());
1582 inline void
1583 block::end_with_return (location loc)
1585 gcc_jit_block_end_with_void_return (get_inner_block (),
1586 loc.get_inner_location ());
1589 inline void
1590 block::end_with_switch (rvalue expr,
1591 block default_block,
1592 std::vector <case_> cases,
1593 location loc)
1595 /* Treat std::vector as an array, relying on it not being resized: */
1596 case_ *as_array_of_wrappers = &cases[0];
1598 /* Treat the array as being of the underlying pointers, relying on
1599 the wrapper type being such a pointer internally. */
1600 gcc_jit_case **as_array_of_ptrs =
1601 reinterpret_cast<gcc_jit_case **> (as_array_of_wrappers);
1602 gcc_jit_block_end_with_switch (get_inner_block (),
1603 loc.get_inner_location (),
1604 expr.get_inner_rvalue (),
1605 default_block.get_inner_block (),
1606 cases.size (),
1607 as_array_of_ptrs);
1610 inline extended_asm
1611 block::add_extended_asm (const std::string &asm_template,
1612 location loc)
1614 return gcc_jit_block_add_extended_asm (get_inner_block (),
1615 loc.get_inner_location (),
1616 asm_template.c_str ());
1619 inline extended_asm
1620 block::end_with_extended_asm_goto (const std::string &asm_template,
1621 std::vector<block> goto_blocks,
1622 block *fallthrough_block,
1623 location loc)
1625 /* Treat std::vector as an array, relying on it not being resized: */
1626 block *as_array_of_wrappers = &goto_blocks[0];
1628 /* Treat the array as being of the underlying pointers, relying on
1629 the wrapper type being such a pointer internally. */
1630 gcc_jit_block **as_array_of_ptrs =
1631 reinterpret_cast<gcc_jit_block **> (as_array_of_wrappers);
1632 return gcc_jit_block_end_with_extended_asm_goto
1633 (get_inner_block (),
1634 loc.get_inner_location (),
1635 asm_template.c_str (),
1636 goto_blocks.size (),
1637 as_array_of_ptrs,
1638 fallthrough_block ? fallthrough_block->get_inner_block () : NULL);
1641 inline rvalue
1642 block::add_call (function other,
1643 location loc)
1645 rvalue c = get_context ().new_call (other, loc);
1646 add_eval (c);
1647 return c;
1649 inline rvalue
1650 block::add_call (function other,
1651 rvalue arg0,
1652 location loc)
1654 rvalue c = get_context ().new_call (other, arg0, loc);
1655 add_eval (c);
1656 return c;
1658 inline rvalue
1659 block::add_call (function other,
1660 rvalue arg0, rvalue arg1,
1661 location loc)
1663 rvalue c = get_context ().new_call (other, arg0, arg1, loc);
1664 add_eval (c);
1665 return c;
1667 inline rvalue
1668 block::add_call (function other,
1669 rvalue arg0, rvalue arg1, rvalue arg2,
1670 location loc)
1672 rvalue c = get_context ().new_call (other, arg0, arg1, arg2, loc);
1673 add_eval (c);
1674 return c;
1677 inline rvalue
1678 block::add_call (function other,
1679 rvalue arg0, rvalue arg1, rvalue arg2, rvalue arg3,
1680 location loc)
1682 rvalue c = get_context ().new_call (other, arg0, arg1, arg2, arg3, loc);
1683 add_eval (c);
1684 return c;
1687 inline rvalue
1688 function::operator() (location loc)
1690 return get_context ().new_call (*this, loc);
1692 inline rvalue
1693 function::operator() (rvalue arg0,
1694 location loc)
1696 return get_context ().new_call (*this,
1697 arg0,
1698 loc);
1700 inline rvalue
1701 function::operator() (rvalue arg0, rvalue arg1,
1702 location loc)
1704 return get_context ().new_call (*this,
1705 arg0, arg1,
1706 loc);
1708 inline rvalue
1709 function::operator() (rvalue arg0, rvalue arg1, rvalue arg2,
1710 location loc)
1712 return get_context ().new_call (*this,
1713 arg0, arg1, arg2,
1714 loc);
1717 // class block
1718 inline block::block () : object () {}
1719 inline block::block (gcc_jit_block *inner)
1720 : object (gcc_jit_block_as_object (inner))
1723 inline gcc_jit_block *
1724 block::get_inner_block () const
1726 /* Manual downcast: */
1727 return reinterpret_cast<gcc_jit_block *> (get_inner_object ());
1730 // class rvalue
1731 inline rvalue::rvalue () : object () {}
1732 inline rvalue::rvalue (gcc_jit_rvalue *inner)
1733 : object (gcc_jit_rvalue_as_object (inner))
1736 inline gcc_jit_rvalue *
1737 rvalue::get_inner_rvalue () const
1739 /* Manual downcast: */
1740 return reinterpret_cast<gcc_jit_rvalue *> (get_inner_object ());
1743 inline type
1744 rvalue::get_type ()
1746 return type (gcc_jit_rvalue_get_type (get_inner_rvalue ()));
1749 inline rvalue
1750 rvalue::access_field (field field,
1751 location loc)
1753 return rvalue (gcc_jit_rvalue_access_field (get_inner_rvalue (),
1754 loc.get_inner_location (),
1755 field.get_inner_field ()));
1758 inline lvalue
1759 rvalue::dereference_field (field field,
1760 location loc)
1762 return lvalue (gcc_jit_rvalue_dereference_field (get_inner_rvalue (),
1763 loc.get_inner_location (),
1764 field.get_inner_field ()));
1767 inline lvalue
1768 rvalue::dereference (location loc)
1770 return lvalue (gcc_jit_rvalue_dereference (get_inner_rvalue (),
1771 loc.get_inner_location ()));
1774 inline rvalue
1775 rvalue::cast_to (type type_,
1776 location loc)
1778 return get_context ().new_cast (*this, type_, loc);
1781 inline lvalue
1782 rvalue::operator[] (rvalue index)
1784 return get_context ().new_array_access (*this, index);
1787 inline lvalue
1788 rvalue::operator[] (int index)
1790 context ctxt = get_context ();
1791 type int_t = ctxt.get_int_type <int> ();
1792 return ctxt.new_array_access (*this,
1793 ctxt.new_rvalue (int_t,
1794 index));
1797 // class lvalue : public rvalue
1798 inline lvalue::lvalue () : rvalue () {}
1799 inline lvalue::lvalue (gcc_jit_lvalue *inner)
1800 : rvalue (gcc_jit_lvalue_as_rvalue (inner))
1803 inline gcc_jit_lvalue *
1804 lvalue::get_inner_lvalue () const
1806 /* Manual downcast: */
1807 return reinterpret_cast<gcc_jit_lvalue *> (get_inner_object ());
1810 inline lvalue
1811 lvalue::access_field (field field, location loc)
1813 return lvalue (gcc_jit_lvalue_access_field (get_inner_lvalue (),
1814 loc.get_inner_location (),
1815 field.get_inner_field ()));
1818 inline rvalue
1819 lvalue::get_address (location loc)
1821 return rvalue (gcc_jit_lvalue_get_address (get_inner_lvalue (),
1822 loc.get_inner_location ()));
1825 inline lvalue
1826 lvalue::set_initializer (const void *blob, size_t num_bytes)
1828 gcc_jit_global_set_initializer (get_inner_lvalue (),
1829 blob,
1830 num_bytes);
1831 return *this;
1834 // class param : public lvalue
1835 inline param::param () : lvalue () {}
1836 inline param::param (gcc_jit_param *inner)
1837 : lvalue (gcc_jit_param_as_lvalue (inner))
1840 // class case_ : public object
1841 inline case_::case_ () : object () {}
1842 inline case_::case_ (gcc_jit_case *inner)
1843 : object (gcc_jit_case_as_object (inner))
1847 inline gcc_jit_case *
1848 case_::get_inner_case () const
1850 /* Manual downcast: */
1851 return reinterpret_cast<gcc_jit_case *> (get_inner_object ());
1854 // class extended_asm : public object
1855 inline extended_asm::extended_asm () : object () {}
1856 inline extended_asm::extended_asm (gcc_jit_extended_asm *inner)
1857 : object (gcc_jit_extended_asm_as_object (inner))
1861 inline extended_asm&
1862 extended_asm::set_volatile_flag (bool flag)
1864 gcc_jit_extended_asm_set_volatile_flag (get_inner_extended_asm (), flag);
1865 return *this;
1868 inline extended_asm&
1869 extended_asm::set_inline_flag (bool flag)
1871 gcc_jit_extended_asm_set_inline_flag (get_inner_extended_asm (), flag);
1872 return *this;
1875 inline extended_asm&
1876 extended_asm::add_output_operand (const std::string &asm_symbolic_name,
1877 const std::string &constraint,
1878 gccjit::lvalue dest)
1880 gcc_jit_extended_asm_add_output_operand
1881 (get_inner_extended_asm (),
1882 asm_symbolic_name.c_str (),
1883 constraint.c_str (),
1884 dest.get_inner_lvalue ());
1885 return *this;
1888 inline extended_asm&
1889 extended_asm::add_output_operand (const std::string &constraint,
1890 gccjit::lvalue dest)
1892 gcc_jit_extended_asm_add_output_operand
1893 (get_inner_extended_asm (),
1894 NULL, /* asm_symbolic_name */
1895 constraint.c_str (),
1896 dest.get_inner_lvalue ());
1897 return *this;
1900 inline extended_asm&
1901 extended_asm::add_input_operand (const std::string &asm_symbolic_name,
1902 const std::string &constraint,
1903 gccjit::rvalue src)
1905 gcc_jit_extended_asm_add_input_operand
1906 (get_inner_extended_asm (),
1907 asm_symbolic_name.c_str (),
1908 constraint.c_str (),
1909 src.get_inner_rvalue ());
1910 return *this;
1913 inline extended_asm&
1914 extended_asm::add_input_operand (const std::string &constraint,
1915 gccjit::rvalue src)
1917 gcc_jit_extended_asm_add_input_operand
1918 (get_inner_extended_asm (),
1919 NULL, /* asm_symbolic_name */
1920 constraint.c_str (),
1921 src.get_inner_rvalue ());
1922 return *this;
1925 inline extended_asm&
1926 extended_asm::add_clobber (const std::string &victim)
1928 gcc_jit_extended_asm_add_clobber (get_inner_extended_asm (),
1929 victim.c_str ());
1930 return *this;
1933 inline gcc_jit_extended_asm *
1934 extended_asm::get_inner_extended_asm () const
1936 /* Manual downcast: */
1937 return reinterpret_cast<gcc_jit_extended_asm *> (get_inner_object ());
1940 /* Overloaded operators. */
1941 // Unary operators
1942 inline rvalue operator- (rvalue a)
1944 return a.get_context ().new_minus (a.get_type (), a);
1946 inline rvalue operator~ (rvalue a)
1948 return a.get_context ().new_bitwise_negate (a.get_type (), a);
1950 inline rvalue operator! (rvalue a)
1952 return a.get_context ().new_logical_negate (a.get_type (), a);
1955 // Binary operators
1956 inline rvalue operator+ (rvalue a, rvalue b)
1958 return a.get_context ().new_plus (a.get_type (), a, b);
1960 inline rvalue operator- (rvalue a, rvalue b)
1962 return a.get_context ().new_minus (a.get_type (), a, b);
1964 inline rvalue operator* (rvalue a, rvalue b)
1966 return a.get_context ().new_mult (a.get_type (), a, b);
1968 inline rvalue operator/ (rvalue a, rvalue b)
1970 return a.get_context ().new_divide (a.get_type (), a, b);
1972 inline rvalue operator% (rvalue a, rvalue b)
1974 return a.get_context ().new_modulo (a.get_type (), a, b);
1976 inline rvalue operator& (rvalue a, rvalue b)
1978 return a.get_context ().new_bitwise_and (a.get_type (), a, b);
1980 inline rvalue operator^ (rvalue a, rvalue b)
1982 return a.get_context ().new_bitwise_xor (a.get_type (), a, b);
1984 inline rvalue operator| (rvalue a, rvalue b)
1986 return a.get_context ().new_bitwise_or (a.get_type (), a, b);
1988 inline rvalue operator&& (rvalue a, rvalue b)
1990 return a.get_context ().new_logical_and (a.get_type (), a, b);
1992 inline rvalue operator|| (rvalue a, rvalue b)
1994 return a.get_context ().new_logical_or (a.get_type (), a, b);
1997 /* Comparisons. */
1998 inline rvalue operator== (rvalue a, rvalue b)
2000 return a.get_context ().new_eq (a, b);
2002 inline rvalue operator!= (rvalue a, rvalue b)
2004 return a.get_context ().new_ne (a, b);
2006 inline rvalue operator< (rvalue a, rvalue b)
2008 return a.get_context ().new_lt (a, b);
2010 inline rvalue operator<= (rvalue a, rvalue b)
2012 return a.get_context ().new_le (a, b);
2014 inline rvalue operator> (rvalue a, rvalue b)
2016 return a.get_context ().new_gt (a, b);
2018 inline rvalue operator>= (rvalue a, rvalue b)
2020 return a.get_context ().new_ge (a, b);
2023 /* Dereferencing. */
2024 inline lvalue operator* (rvalue ptr)
2026 return ptr.dereference ();
2029 // class timer
2030 inline
2031 timer::timer ()
2033 m_inner_timer = gcc_jit_timer_new ();
2036 inline
2037 timer::timer (gcc_jit_timer *inner_timer)
2039 m_inner_timer = inner_timer;
2042 inline void
2043 timer::push (const char *item_name)
2045 gcc_jit_timer_push (m_inner_timer, item_name);
2049 inline void
2050 timer::pop (const char *item_name)
2052 gcc_jit_timer_pop (m_inner_timer, item_name);
2055 inline void
2056 timer::print (FILE *f_out) const
2058 gcc_jit_timer_print (m_inner_timer, f_out);
2061 inline gcc_jit_timer *
2062 timer::get_inner_timer () const
2064 return m_inner_timer;
2067 inline void
2068 timer::release ()
2070 gcc_jit_timer_release (m_inner_timer);
2071 m_inner_timer = NULL;
2074 // class auto_time
2076 inline
2077 auto_time::auto_time (timer t, const char *item_name)
2078 : m_timer (t),
2079 m_item_name (item_name)
2081 t.push (item_name);
2084 inline
2085 auto_time::auto_time (context ctxt, const char *item_name)
2086 : m_timer (ctxt.get_timer ()),
2087 m_item_name (item_name)
2089 m_timer.push (item_name);
2092 inline
2093 auto_time::~auto_time ()
2095 m_timer.pop (m_item_name);
2098 namespace version
2100 inline int
2101 major_v ()
2103 return gcc_jit_version_major ();
2106 inline int
2107 minor_v ()
2109 return gcc_jit_version_minor ();
2112 inline int
2113 patchlevel_v ()
2115 return gcc_jit_version_patchlevel ();
2117 } // namespace version
2118 } // namespace gccjit
2120 #endif /* #ifndef LIBGCCJIT_PLUS_PLUS_H */