PR target/81369
[official-gcc.git] / gcc / jit / jit-recording.h
blob5faf35e0b17428b55263df9eae8b1b9a1ef15e60
1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2017 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef JIT_RECORDING_H
22 #define JIT_RECORDING_H
24 #include "jit-common.h"
25 #include "jit-logging.h"
27 class timer;
29 namespace gcc {
31 namespace jit {
33 class result;
34 class dump;
35 class reproducer;
37 /**********************************************************************
38 Recording.
39 **********************************************************************/
41 namespace recording {
43 playback::location *
44 playback_location (replayer *r, location *loc);
46 const char *
47 playback_string (string *str);
49 playback::block *
50 playback_block (block *b);
52 /* A recording of a call to gcc_jit_context_enable_dump. */
53 struct requested_dump
55 const char *m_dumpname;
56 char **m_out_ptr;
59 /* A JIT-compilation context. */
60 class context : public log_user
62 public:
63 context (context *parent_ctxt);
64 ~context ();
66 builtins_manager *
67 get_builtins_manager ();
69 void record (memento *m);
70 void replay_into (replayer *r);
71 void disassociate_from_playback ();
73 string *
74 new_string (const char *text);
76 location *
77 new_location (const char *filename,
78 int line,
79 int column,
80 bool created_by_user);
82 type *
83 get_type (enum gcc_jit_types type);
85 type *
86 get_int_type (int num_bytes, int is_signed);
88 type *
89 new_array_type (location *loc,
90 type *element_type,
91 int num_elements);
93 field *
94 new_field (location *loc,
95 type *type,
96 const char *name);
98 struct_ *
99 new_struct_type (location *loc,
100 const char *name);
102 union_ *
103 new_union_type (location *loc,
104 const char *name);
106 function_type *
107 new_function_type (type *return_type,
108 int num_params,
109 type **param_types,
110 int is_variadic);
112 type *
113 new_function_ptr_type (location *loc,
114 type *return_type,
115 int num_params,
116 type **param_types,
117 int is_variadic);
119 param *
120 new_param (location *loc,
121 type *type,
122 const char *name);
124 function *
125 new_function (location *loc,
126 enum gcc_jit_function_kind kind,
127 type *return_type,
128 const char *name,
129 int num_params,
130 param **params,
131 int is_variadic,
132 enum built_in_function builtin_id);
134 function *
135 get_builtin_function (const char *name);
137 lvalue *
138 new_global (location *loc,
139 enum gcc_jit_global_kind kind,
140 type *type,
141 const char *name);
143 template <typename HOST_TYPE>
144 rvalue *
145 new_rvalue_from_const (type *type,
146 HOST_TYPE value);
148 rvalue *
149 new_string_literal (const char *value);
151 rvalue *
152 new_unary_op (location *loc,
153 enum gcc_jit_unary_op op,
154 type *result_type,
155 rvalue *a);
157 rvalue *
158 new_binary_op (location *loc,
159 enum gcc_jit_binary_op op,
160 type *result_type,
161 rvalue *a, rvalue *b);
163 rvalue *
164 new_comparison (location *loc,
165 enum gcc_jit_comparison op,
166 rvalue *a, rvalue *b);
168 rvalue *
169 new_call (location *loc,
170 function *func,
171 int numargs, rvalue **args);
173 rvalue *
174 new_call_through_ptr (location *loc,
175 rvalue *fn_ptr,
176 int numargs, rvalue **args);
178 rvalue *
179 new_cast (location *loc,
180 rvalue *expr,
181 type *type_);
183 lvalue *
184 new_array_access (location *loc,
185 rvalue *ptr,
186 rvalue *index);
188 case_ *
189 new_case (rvalue *min_value,
190 rvalue *max_value,
191 block *block);
193 void
194 set_str_option (enum gcc_jit_str_option opt,
195 const char *value);
197 void
198 set_int_option (enum gcc_jit_int_option opt,
199 int value);
201 void
202 set_bool_option (enum gcc_jit_bool_option opt,
203 int value);
205 void
206 set_inner_bool_option (enum inner_bool_option inner_opt,
207 int value);
209 void
210 add_command_line_option (const char *optname);
212 void
213 append_command_line_options (vec <char *> *argvec);
215 void
216 enable_dump (const char *dumpname,
217 char **out_ptr);
219 const char *
220 get_str_option (enum gcc_jit_str_option opt) const
222 return m_str_options[opt];
226 get_int_option (enum gcc_jit_int_option opt) const
228 return m_int_options[opt];
232 get_bool_option (enum gcc_jit_bool_option opt) const
234 return m_bool_options[opt];
238 get_inner_bool_option (enum inner_bool_option opt) const
240 return m_inner_bool_options[opt];
243 result *
244 compile ();
246 void
247 compile_to_file (enum gcc_jit_output_kind output_kind,
248 const char *output_path);
250 void
251 add_error (location *loc, const char *fmt, ...)
252 GNU_PRINTF(3, 4);
254 void
255 add_error_va (location *loc, const char *fmt, va_list ap)
256 GNU_PRINTF(3, 0);
258 const char *
259 get_first_error () const;
261 const char *
262 get_last_error () const;
264 bool errors_occurred () const
266 if (m_parent_ctxt)
267 if (m_parent_ctxt->errors_occurred ())
268 return true;
269 return m_error_count;
272 type *get_opaque_FILE_type ();
274 void dump_to_file (const char *path, bool update_locations);
276 void dump_reproducer_to_file (const char *path);
278 void
279 get_all_requested_dumps (vec <recording::requested_dump> *out);
281 void set_timer (timer *t) { m_timer = t; }
282 timer *get_timer () const { return m_timer; }
284 private:
285 void log_all_options () const;
286 void log_str_option (enum gcc_jit_str_option opt) const;
287 void log_int_option (enum gcc_jit_int_option opt) const;
288 void log_bool_option (enum gcc_jit_bool_option opt) const;
289 void log_inner_bool_option (enum inner_bool_option opt) const;
291 void validate ();
293 private:
294 context *m_parent_ctxt;
296 /* The ultimate ancestor of the contexts within a family tree of
297 contexts. This has itself as its own m_toplevel_ctxt. */
298 context *m_toplevel_ctxt;
300 timer *m_timer;
302 int m_error_count;
304 char *m_first_error_str;
305 bool m_owns_first_error_str;
307 char *m_last_error_str;
308 bool m_owns_last_error_str;
310 char *m_str_options[GCC_JIT_NUM_STR_OPTIONS];
311 int m_int_options[GCC_JIT_NUM_INT_OPTIONS];
312 bool m_bool_options[GCC_JIT_NUM_BOOL_OPTIONS];
313 bool m_inner_bool_options[NUM_INNER_BOOL_OPTIONS];
314 auto_vec <char *> m_command_line_options;
316 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
317 auto_vec<requested_dump> m_requested_dumps;
319 /* Recorded API usage. */
320 auto_vec<memento *> m_mementos;
322 /* Specific recordings, for use by dump_to_file. */
323 auto_vec<compound_type *> m_compound_types;
324 auto_vec<global *> m_globals;
325 auto_vec<function *> m_functions;
327 type *m_basic_types[NUM_GCC_JIT_TYPES];
328 type *m_FILE_type;
330 builtins_manager *m_builtins_manager; // lazily created
334 /* An object with lifetime managed by the context i.e.
335 it lives until the context is released, at which
336 point it itself is cleaned up. */
338 class memento
340 public:
341 virtual ~memento () {}
343 /* Hook for replaying this. */
344 virtual void replay_into (replayer *r) = 0;
346 void set_playback_obj (void *obj) { m_playback_obj = obj; }
349 /* Get the context that owns this object.
351 Implements the post-error-checking part of
352 gcc_jit_object_get_context. */
353 context *get_context () { return m_ctxt; }
355 memento *
356 as_object () { return this; }
358 /* Debugging hook, for use in generating error messages etc.
359 Implements the post-error-checking part of
360 gcc_jit_object_get_debug_string. */
361 const char *
362 get_debug_string ();
364 virtual void write_to_dump (dump &d);
365 virtual void write_reproducer (reproducer &r) = 0;
366 virtual location *dyn_cast_location () { return NULL; }
368 protected:
369 memento (context *ctxt)
370 : m_ctxt (ctxt),
371 m_playback_obj (NULL),
372 m_debug_string (NULL)
374 gcc_assert (ctxt);
377 string *new_string (const char *text) { return m_ctxt->new_string (text); }
379 private:
380 virtual string * make_debug_string () = 0;
382 public:
383 context *m_ctxt;
385 protected:
386 void *m_playback_obj;
388 private:
389 string *m_debug_string;
392 /* or just use std::string? */
393 class string : public memento
395 public:
396 string (context *ctxt, const char *text);
397 ~string ();
399 const char *c_str () { return m_buffer; }
401 static string * from_printf (context *ctxt, const char *fmt, ...)
402 GNU_PRINTF(2, 3);
404 void replay_into (replayer *) FINAL OVERRIDE {}
406 private:
407 string * make_debug_string () FINAL OVERRIDE;
408 void write_reproducer (reproducer &r) FINAL OVERRIDE;
410 private:
411 size_t m_len;
412 char *m_buffer;
415 class location : public memento
417 public:
418 location (context *ctxt, string *filename, int line, int column,
419 bool created_by_user)
420 : memento (ctxt),
421 m_filename (filename),
422 m_line (line),
423 m_column (column),
424 m_created_by_user (created_by_user)
427 void replay_into (replayer *r) FINAL OVERRIDE;
429 playback::location *
430 playback_location (replayer *r)
432 /* Normally during playback, we can walk forwards through the list of
433 recording objects, playing them back. The ordering of recording
434 ensures that everything that a recording object refers to has
435 already been played back, so we can simply look up the relevant
436 m_playback_obj.
438 Locations are an exception, due to the "write_to_dump" method of
439 recording::statement. This method can set a new location on a
440 statement after the statement is created, and thus the location
441 appears in the context's memento list *after* the statement that
442 refers to it.
444 In such circumstances, the statement is replayed *before* the location,
445 when the latter doesn't yet have a playback object.
447 Hence we need to ensure that locations have playback objects. */
448 if (!m_playback_obj)
450 replay_into (r);
452 gcc_assert (m_playback_obj);
453 return static_cast <playback::location *> (m_playback_obj);
456 location *dyn_cast_location () FINAL OVERRIDE { return this; }
457 bool created_by_user () const { return m_created_by_user; }
459 private:
460 string * make_debug_string () FINAL OVERRIDE;
461 void write_reproducer (reproducer &r) FINAL OVERRIDE;
463 private:
464 string *m_filename;
465 int m_line;
466 int m_column;
467 bool m_created_by_user;
470 class type : public memento
472 public:
473 type *get_pointer ();
474 type *get_const ();
475 type *get_volatile ();
476 type *get_aligned (size_t alignment_in_bytes);
478 /* Get the type obtained when dereferencing this type.
480 This will return NULL if it's not valid to dereference this type.
481 The caller is responsible for setting an error. */
482 virtual type *dereference () = 0;
484 /* Dynamic casts. */
485 virtual function_type *dyn_cast_function_type () { return NULL; }
486 virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
487 virtual struct_ *dyn_cast_struct () { return NULL; }
489 /* Is it typesafe to copy to this type from rtype? */
490 virtual bool accepts_writes_from (type *rtype)
492 gcc_assert (rtype);
493 return this->unqualified () == rtype->unqualified ();
496 /* Strip off "const" etc */
497 virtual type *unqualified ()
499 return this;
502 virtual bool is_int () const = 0;
503 virtual bool is_float () const = 0;
504 virtual bool is_bool () const = 0;
505 virtual type *is_pointer () = 0;
506 virtual type *is_array () = 0;
507 virtual bool is_void () const { return false; }
508 virtual bool has_known_size () const { return true; }
510 bool is_numeric () const
512 return is_int () || is_float () || is_bool ();
515 playback::type *
516 playback_type ()
518 return static_cast <playback::type *> (m_playback_obj);
521 virtual const char *access_as_type (reproducer &r);
523 protected:
524 type (context *ctxt)
525 : memento (ctxt),
526 m_pointer_to_this_type (NULL)
529 private:
530 type *m_pointer_to_this_type;
533 /* Result of "gcc_jit_context_get_type". */
534 class memento_of_get_type : public type
536 public:
537 memento_of_get_type (context *ctxt,
538 enum gcc_jit_types kind)
539 : type (ctxt),
540 m_kind (kind) {}
542 type *dereference () FINAL OVERRIDE;
544 bool accepts_writes_from (type *rtype) FINAL OVERRIDE
546 if (m_kind == GCC_JIT_TYPE_VOID_PTR)
547 if (rtype->is_pointer ())
549 /* LHS (this) is type (void *), and the RHS is a pointer:
550 accept it: */
551 return true;
554 return type::accepts_writes_from (rtype);
557 bool is_int () const FINAL OVERRIDE;
558 bool is_float () const FINAL OVERRIDE;
559 bool is_bool () const FINAL OVERRIDE;
560 type *is_pointer () FINAL OVERRIDE { return dereference (); }
561 type *is_array () FINAL OVERRIDE { return NULL; }
562 bool is_void () const FINAL OVERRIDE { return m_kind == GCC_JIT_TYPE_VOID; }
564 public:
565 void replay_into (replayer *r) FINAL OVERRIDE;
567 private:
568 string * make_debug_string () FINAL OVERRIDE;
569 void write_reproducer (reproducer &r) FINAL OVERRIDE;
571 private:
572 enum gcc_jit_types m_kind;
575 /* Result of "gcc_jit_type_get_pointer". */
576 class memento_of_get_pointer : public type
578 public:
579 memento_of_get_pointer (type *other_type)
580 : type (other_type->m_ctxt),
581 m_other_type (other_type) {}
583 type *dereference () FINAL OVERRIDE { return m_other_type; }
585 bool accepts_writes_from (type *rtype) FINAL OVERRIDE;
587 void replay_into (replayer *r) FINAL OVERRIDE;
589 bool is_int () const FINAL OVERRIDE { return false; }
590 bool is_float () const FINAL OVERRIDE { return false; }
591 bool is_bool () const FINAL OVERRIDE { return false; }
592 type *is_pointer () FINAL OVERRIDE { return m_other_type; }
593 type *is_array () FINAL OVERRIDE { return NULL; }
595 private:
596 string * make_debug_string () FINAL OVERRIDE;
597 void write_reproducer (reproducer &r) FINAL OVERRIDE;
599 private:
600 type *m_other_type;
603 /* A decorated version of a type, for get_const, get_volatile and
604 get_aligned. */
606 class decorated_type : public type
608 public:
609 decorated_type (type *other_type)
610 : type (other_type->m_ctxt),
611 m_other_type (other_type) {}
613 type *dereference () FINAL OVERRIDE { return m_other_type->dereference (); }
615 bool is_int () const FINAL OVERRIDE { return m_other_type->is_int (); }
616 bool is_float () const FINAL OVERRIDE { return m_other_type->is_float (); }
617 bool is_bool () const FINAL OVERRIDE { return m_other_type->is_bool (); }
618 type *is_pointer () FINAL OVERRIDE { return m_other_type->is_pointer (); }
619 type *is_array () FINAL OVERRIDE { return m_other_type->is_array (); }
621 protected:
622 type *m_other_type;
625 /* Result of "gcc_jit_type_get_const". */
626 class memento_of_get_const : public decorated_type
628 public:
629 memento_of_get_const (type *other_type)
630 : decorated_type (other_type) {}
632 bool accepts_writes_from (type */*rtype*/) FINAL OVERRIDE
634 /* Can't write to a "const". */
635 return false;
638 /* Strip off the "const", giving the underlying type. */
639 type *unqualified () FINAL OVERRIDE { return m_other_type; }
641 void replay_into (replayer *) FINAL OVERRIDE;
643 private:
644 string * make_debug_string () FINAL OVERRIDE;
645 void write_reproducer (reproducer &r) FINAL OVERRIDE;
648 /* Result of "gcc_jit_type_get_volatile". */
649 class memento_of_get_volatile : public decorated_type
651 public:
652 memento_of_get_volatile (type *other_type)
653 : decorated_type (other_type) {}
655 /* Strip off the "volatile", giving the underlying type. */
656 type *unqualified () FINAL OVERRIDE { return m_other_type; }
658 void replay_into (replayer *) FINAL OVERRIDE;
660 private:
661 string * make_debug_string () FINAL OVERRIDE;
662 void write_reproducer (reproducer &r) FINAL OVERRIDE;
665 /* Result of "gcc_jit_type_get_aligned". */
666 class memento_of_get_aligned : public decorated_type
668 public:
669 memento_of_get_aligned (type *other_type, size_t alignment_in_bytes)
670 : decorated_type (other_type),
671 m_alignment_in_bytes (alignment_in_bytes) {}
673 /* Strip off the alignment, giving the underlying type. */
674 type *unqualified () FINAL OVERRIDE { return m_other_type; }
676 void replay_into (replayer *) FINAL OVERRIDE;
678 private:
679 string * make_debug_string () FINAL OVERRIDE;
680 void write_reproducer (reproducer &r) FINAL OVERRIDE;
682 private:
683 size_t m_alignment_in_bytes;
686 class array_type : public type
688 public:
689 array_type (context *ctxt,
690 location *loc,
691 type *element_type,
692 int num_elements)
693 : type (ctxt),
694 m_loc (loc),
695 m_element_type (element_type),
696 m_num_elements (num_elements)
699 type *dereference () FINAL OVERRIDE;
701 bool is_int () const FINAL OVERRIDE { return false; }
702 bool is_float () const FINAL OVERRIDE { return false; }
703 bool is_bool () const FINAL OVERRIDE { return false; }
704 type *is_pointer () FINAL OVERRIDE { return NULL; }
705 type *is_array () FINAL OVERRIDE { return m_element_type; }
707 void replay_into (replayer *) FINAL OVERRIDE;
709 private:
710 string * make_debug_string () FINAL OVERRIDE;
711 void write_reproducer (reproducer &r) FINAL OVERRIDE;
713 private:
714 location *m_loc;
715 type *m_element_type;
716 int m_num_elements;
719 class function_type : public type
721 public:
722 function_type (context *ctxt,
723 type *return_type,
724 int num_params,
725 type **param_types,
726 int is_variadic);
728 type *dereference () FINAL OVERRIDE;
729 function_type *dyn_cast_function_type () FINAL OVERRIDE { return this; }
730 function_type *as_a_function_type () FINAL OVERRIDE { return this; }
732 bool is_int () const FINAL OVERRIDE { return false; }
733 bool is_float () const FINAL OVERRIDE { return false; }
734 bool is_bool () const FINAL OVERRIDE { return false; }
735 type *is_pointer () FINAL OVERRIDE { return NULL; }
736 type *is_array () FINAL OVERRIDE { return NULL; }
738 void replay_into (replayer *) FINAL OVERRIDE;
740 type * get_return_type () const { return m_return_type; }
741 const vec<type *> &get_param_types () const { return m_param_types; }
742 int is_variadic () const { return m_is_variadic; }
744 string * make_debug_string_with_ptr ();
746 void
747 write_deferred_reproducer (reproducer &r,
748 memento *ptr_type);
750 private:
751 string * make_debug_string () FINAL OVERRIDE;
752 string * make_debug_string_with (const char *);
753 void write_reproducer (reproducer &r) FINAL OVERRIDE;
755 private:
756 type *m_return_type;
757 auto_vec<type *> m_param_types;
758 int m_is_variadic;
761 class field : public memento
763 public:
764 field (context *ctxt,
765 location *loc,
766 type *type,
767 string *name)
768 : memento (ctxt),
769 m_loc (loc),
770 m_type (type),
771 m_name (name),
772 m_container (NULL)
775 type * get_type () const { return m_type; }
777 compound_type * get_container () const { return m_container; }
778 void set_container (compound_type *c) { m_container = c; }
780 void replay_into (replayer *) FINAL OVERRIDE;
782 void write_to_dump (dump &d) FINAL OVERRIDE;
784 playback::field *
785 playback_field () const
787 return static_cast <playback::field *> (m_playback_obj);
790 private:
791 string * make_debug_string () FINAL OVERRIDE;
792 void write_reproducer (reproducer &r) FINAL OVERRIDE;
794 private:
795 location *m_loc;
796 type *m_type;
797 string *m_name;
798 compound_type *m_container;
801 /* Base class for struct_ and union_ */
802 class compound_type : public type
804 public:
805 compound_type (context *ctxt,
806 location *loc,
807 string *name);
809 string *get_name () const { return m_name; }
810 location *get_loc () const { return m_loc; }
811 fields * get_fields () { return m_fields; }
813 void
814 set_fields (location *loc,
815 int num_fields,
816 field **fields);
818 type *dereference () FINAL OVERRIDE;
820 bool is_int () const FINAL OVERRIDE { return false; }
821 bool is_float () const FINAL OVERRIDE { return false; }
822 bool is_bool () const FINAL OVERRIDE { return false; }
823 type *is_pointer () FINAL OVERRIDE { return NULL; }
824 type *is_array () FINAL OVERRIDE { return NULL; }
826 bool has_known_size () const FINAL OVERRIDE { return m_fields != NULL; }
828 playback::compound_type *
829 playback_compound_type ()
831 return static_cast <playback::compound_type *> (m_playback_obj);
834 private:
835 location *m_loc;
836 string *m_name;
837 fields *m_fields;
840 class struct_ : public compound_type
842 public:
843 struct_ (context *ctxt,
844 location *loc,
845 string *name);
847 struct_ *dyn_cast_struct () FINAL OVERRIDE { return this; }
849 type *
850 as_type () { return this; }
852 void replay_into (replayer *r) FINAL OVERRIDE;
854 const char *access_as_type (reproducer &r) FINAL OVERRIDE;
856 private:
857 string * make_debug_string () FINAL OVERRIDE;
858 void write_reproducer (reproducer &r) FINAL OVERRIDE;
861 // memento of struct_::set_fields
862 class fields : public memento
864 public:
865 fields (compound_type *struct_or_union,
866 int num_fields,
867 field **fields);
869 void replay_into (replayer *r) FINAL OVERRIDE;
871 void write_to_dump (dump &d) FINAL OVERRIDE;
873 int length () const { return m_fields.length (); }
874 field *get_field (int i) const { return m_fields[i]; }
876 private:
877 string * make_debug_string () FINAL OVERRIDE;
878 void write_reproducer (reproducer &r) FINAL OVERRIDE;
880 private:
881 compound_type *m_struct_or_union;
882 auto_vec<field *> m_fields;
885 class union_ : public compound_type
887 public:
888 union_ (context *ctxt,
889 location *loc,
890 string *name);
892 void replay_into (replayer *r) FINAL OVERRIDE;
894 private:
895 string * make_debug_string () FINAL OVERRIDE;
896 void write_reproducer (reproducer &r) FINAL OVERRIDE;
898 private:
899 location *m_loc;
900 string *m_name;
903 /* An abstract base class for operations that visit all rvalues within an
904 expression tree.
905 Currently the only implementation is class rvalue_usage_validator within
906 jit-recording.c. */
908 class rvalue_visitor
910 public:
911 virtual ~rvalue_visitor () {}
912 virtual void visit (rvalue *rvalue) = 0;
915 /* When generating debug strings for rvalues we mimic C, so we need to
916 mimic C's precedence levels when handling compound expressions.
917 These are in order from strongest precedence to weakest. */
918 enum precedence
920 PRECEDENCE_PRIMARY,
921 PRECEDENCE_POSTFIX,
922 PRECEDENCE_UNARY,
923 PRECEDENCE_CAST,
924 PRECEDENCE_MULTIPLICATIVE,
925 PRECEDENCE_ADDITIVE,
926 PRECEDENCE_SHIFT,
927 PRECEDENCE_RELATIONAL,
928 PRECEDENCE_EQUALITY,
929 PRECEDENCE_BITWISE_AND,
930 PRECEDENCE_BITWISE_XOR,
931 PRECEDENCE_BITWISE_IOR,
932 PRECEDENCE_LOGICAL_AND,
933 PRECEDENCE_LOGICAL_OR
936 class rvalue : public memento
938 public:
939 rvalue (context *ctxt,
940 location *loc,
941 type *type_)
942 : memento (ctxt),
943 m_loc (loc),
944 m_type (type_),
945 m_scope (NULL),
946 m_parenthesized_string (NULL)
948 gcc_assert (type_);
951 location * get_loc () const { return m_loc; }
953 /* Get the recording::type of this rvalue.
955 Implements the post-error-checking part of
956 gcc_jit_rvalue_get_type. */
957 type * get_type () const { return m_type; }
959 playback::rvalue *
960 playback_rvalue () const
962 return static_cast <playback::rvalue *> (m_playback_obj);
964 rvalue *
965 access_field (location *loc,
966 field *field);
968 lvalue *
969 dereference_field (location *loc,
970 field *field);
972 lvalue *
973 dereference (location *loc);
975 void
976 verify_valid_within_stmt (const char *api_funcname, statement *s);
978 virtual void visit_children (rvalue_visitor *v) = 0;
980 void set_scope (function *scope);
981 function *get_scope () const { return m_scope; }
983 /* Dynamic casts. */
984 virtual param *dyn_cast_param () { return NULL; }
985 virtual base_call *dyn_cast_base_call () { return NULL; }
987 virtual const char *access_as_rvalue (reproducer &r);
989 /* Get the debug string, wrapped in parentheses. */
990 const char *
991 get_debug_string_parens (enum precedence outer_prec);
993 virtual bool is_constant () const { return false; }
994 virtual bool get_wide_int (wide_int *) const { return false; }
996 private:
997 virtual enum precedence get_precedence () const = 0;
999 protected:
1000 location *m_loc;
1001 type *m_type;
1003 private:
1004 function *m_scope; /* NULL for globals, non-NULL for locals/params */
1005 string *m_parenthesized_string;
1008 class lvalue : public rvalue
1010 public:
1011 lvalue (context *ctxt,
1012 location *loc,
1013 type *type_)
1014 : rvalue (ctxt, loc, type_)
1017 playback::lvalue *
1018 playback_lvalue () const
1020 return static_cast <playback::lvalue *> (m_playback_obj);
1023 lvalue *
1024 access_field (location *loc,
1025 field *field);
1027 rvalue *
1028 get_address (location *loc);
1030 rvalue *
1031 as_rvalue () { return this; }
1033 const char *access_as_rvalue (reproducer &r) OVERRIDE;
1034 virtual const char *access_as_lvalue (reproducer &r);
1037 class param : public lvalue
1039 public:
1040 param (context *ctxt,
1041 location *loc,
1042 type *type,
1043 string *name)
1044 : lvalue (ctxt, loc, type),
1045 m_name (name) {}
1047 lvalue *
1048 as_lvalue () { return this; }
1050 void replay_into (replayer *r) FINAL OVERRIDE;
1052 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1054 playback::param *
1055 playback_param () const
1057 return static_cast <playback::param *> (m_playback_obj);
1060 param *dyn_cast_param () FINAL OVERRIDE { return this; }
1062 const char *access_as_rvalue (reproducer &r) FINAL OVERRIDE;
1063 const char *access_as_lvalue (reproducer &r) FINAL OVERRIDE;
1065 private:
1066 string * make_debug_string () FINAL OVERRIDE { return m_name; }
1067 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1068 enum precedence get_precedence () const FINAL OVERRIDE
1070 return PRECEDENCE_PRIMARY;
1073 private:
1074 string *m_name;
1077 class function : public memento
1079 public:
1080 function (context *ctxt,
1081 location *loc,
1082 enum gcc_jit_function_kind kind,
1083 type *return_type,
1084 string *name,
1085 int num_params,
1086 param **params,
1087 int is_variadic,
1088 enum built_in_function builtin_id);
1090 void replay_into (replayer *r) FINAL OVERRIDE;
1092 playback::function *
1093 playback_function () const
1095 return static_cast <playback::function *> (m_playback_obj);
1098 enum gcc_jit_function_kind get_kind () const { return m_kind; }
1100 lvalue *
1101 new_local (location *loc,
1102 type *type,
1103 const char *name);
1105 block*
1106 new_block (const char *name);
1108 location *get_loc () const { return m_loc; }
1109 type *get_return_type () const { return m_return_type; }
1110 string * get_name () const { return m_name; }
1111 const vec<param *> &get_params () const { return m_params; }
1113 /* Get the given param by index.
1114 Implements the post-error-checking part of
1115 gcc_jit_function_get_param. */
1116 param *get_param (int i) const { return m_params[i]; }
1118 bool is_variadic () const { return m_is_variadic; }
1120 void write_to_dump (dump &d) FINAL OVERRIDE;
1122 void validate ();
1124 void dump_to_dot (const char *path);
1126 private:
1127 string * make_debug_string () FINAL OVERRIDE;
1128 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1130 private:
1131 location *m_loc;
1132 enum gcc_jit_function_kind m_kind;
1133 type *m_return_type;
1134 string *m_name;
1135 auto_vec<param *> m_params;
1136 int m_is_variadic;
1137 enum built_in_function m_builtin_id;
1138 auto_vec<local *> m_locals;
1139 auto_vec<block *> m_blocks;
1142 class block : public memento
1144 public:
1145 block (function *func, int index, string *name)
1146 : memento (func->m_ctxt),
1147 m_func (func),
1148 m_index (index),
1149 m_name (name),
1150 m_statements (),
1151 m_has_been_terminated (false),
1152 m_is_reachable (false)
1156 /* Get the recording::function containing this block.
1157 Implements the post-error-checking part of
1158 gcc_jit_block_get_function. */
1159 function *get_function () { return m_func; }
1161 bool has_been_terminated () { return m_has_been_terminated; }
1162 bool is_reachable () { return m_is_reachable; }
1164 statement *
1165 add_eval (location *loc,
1166 rvalue *rvalue);
1168 statement *
1169 add_assignment (location *loc,
1170 lvalue *lvalue,
1171 rvalue *rvalue);
1173 statement *
1174 add_assignment_op (location *loc,
1175 lvalue *lvalue,
1176 enum gcc_jit_binary_op op,
1177 rvalue *rvalue);
1179 statement *
1180 add_comment (location *loc,
1181 const char *text);
1183 statement *
1184 end_with_conditional (location *loc,
1185 rvalue *boolval,
1186 block *on_true,
1187 block *on_false);
1189 statement *
1190 end_with_jump (location *loc,
1191 block *target);
1193 statement *
1194 end_with_return (location *loc,
1195 rvalue *rvalue);
1197 statement *
1198 end_with_switch (location *loc,
1199 rvalue *expr,
1200 block *default_block,
1201 int num_cases,
1202 case_ **cases);
1204 playback::block *
1205 playback_block () const
1207 return static_cast <playback::block *> (m_playback_obj);
1210 void write_to_dump (dump &d) FINAL OVERRIDE;
1212 bool validate ();
1214 location *get_loc () const;
1216 statement *get_first_statement () const;
1217 statement *get_last_statement () const;
1219 vec <block *> get_successor_blocks () const;
1221 private:
1222 string * make_debug_string () FINAL OVERRIDE;
1223 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1225 void replay_into (replayer *r) FINAL OVERRIDE;
1227 void dump_to_dot (pretty_printer *pp);
1228 void dump_edges_to_dot (pretty_printer *pp);
1230 private:
1231 function *m_func;
1232 int m_index;
1233 string *m_name;
1234 auto_vec<statement *> m_statements;
1235 bool m_has_been_terminated;
1236 bool m_is_reachable;
1238 friend class function;
1241 class global : public lvalue
1243 public:
1244 global (context *ctxt,
1245 location *loc,
1246 enum gcc_jit_global_kind kind,
1247 type *type,
1248 string *name)
1249 : lvalue (ctxt, loc, type),
1250 m_kind (kind),
1251 m_name (name)
1254 void replay_into (replayer *) FINAL OVERRIDE;
1256 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1258 void write_to_dump (dump &d) FINAL OVERRIDE;
1260 private:
1261 string * make_debug_string () FINAL OVERRIDE { return m_name; }
1262 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1263 enum precedence get_precedence () const FINAL OVERRIDE
1265 return PRECEDENCE_PRIMARY;
1268 private:
1269 enum gcc_jit_global_kind m_kind;
1270 string *m_name;
1273 template <typename HOST_TYPE>
1274 class memento_of_new_rvalue_from_const : public rvalue
1276 public:
1277 memento_of_new_rvalue_from_const (context *ctxt,
1278 location *loc,
1279 type *type,
1280 HOST_TYPE value)
1281 : rvalue (ctxt, loc, type),
1282 m_value (value) {}
1284 void replay_into (replayer *r) FINAL OVERRIDE;
1286 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1288 bool is_constant () const FINAL OVERRIDE { return true; }
1290 bool get_wide_int (wide_int *out) const FINAL OVERRIDE;
1292 private:
1293 string * make_debug_string () FINAL OVERRIDE;
1294 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1295 enum precedence get_precedence () const FINAL OVERRIDE
1297 return PRECEDENCE_PRIMARY;
1300 private:
1301 HOST_TYPE m_value;
1304 class memento_of_new_string_literal : public rvalue
1306 public:
1307 memento_of_new_string_literal (context *ctxt,
1308 location *loc,
1309 string *value)
1310 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR)),
1311 m_value (value) {}
1313 void replay_into (replayer *r) FINAL OVERRIDE;
1315 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1317 private:
1318 string * make_debug_string () FINAL OVERRIDE;
1319 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1320 enum precedence get_precedence () const FINAL OVERRIDE
1322 return PRECEDENCE_PRIMARY;
1325 private:
1326 string *m_value;
1329 class unary_op : public rvalue
1331 public:
1332 unary_op (context *ctxt,
1333 location *loc,
1334 enum gcc_jit_unary_op op,
1335 type *result_type,
1336 rvalue *a)
1337 : rvalue (ctxt, loc, result_type),
1338 m_op (op),
1339 m_a (a)
1342 void replay_into (replayer *r) FINAL OVERRIDE;
1344 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1346 private:
1347 string * make_debug_string () FINAL OVERRIDE;
1348 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1349 enum precedence get_precedence () const FINAL OVERRIDE
1351 return PRECEDENCE_UNARY;
1354 private:
1355 enum gcc_jit_unary_op m_op;
1356 rvalue *m_a;
1359 class binary_op : public rvalue
1361 public:
1362 binary_op (context *ctxt,
1363 location *loc,
1364 enum gcc_jit_binary_op op,
1365 type *result_type,
1366 rvalue *a, rvalue *b)
1367 : rvalue (ctxt, loc, result_type),
1368 m_op (op),
1369 m_a (a),
1370 m_b (b) {}
1372 void replay_into (replayer *r) FINAL OVERRIDE;
1374 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1376 private:
1377 string * make_debug_string () FINAL OVERRIDE;
1378 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1379 enum precedence get_precedence () const FINAL OVERRIDE;
1381 private:
1382 enum gcc_jit_binary_op m_op;
1383 rvalue *m_a;
1384 rvalue *m_b;
1387 class comparison : public rvalue
1389 public:
1390 comparison (context *ctxt,
1391 location *loc,
1392 enum gcc_jit_comparison op,
1393 rvalue *a, rvalue *b)
1394 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_BOOL)),
1395 m_op (op),
1396 m_a (a),
1397 m_b (b)
1400 void replay_into (replayer *r) FINAL OVERRIDE;
1402 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1404 private:
1405 string * make_debug_string () FINAL OVERRIDE;
1406 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1407 enum precedence get_precedence () const FINAL OVERRIDE;
1409 private:
1410 enum gcc_jit_comparison m_op;
1411 rvalue *m_a;
1412 rvalue *m_b;
1415 class cast : public rvalue
1417 public:
1418 cast (context *ctxt,
1419 location *loc,
1420 rvalue *a,
1421 type *type_)
1422 : rvalue (ctxt, loc, type_),
1423 m_rvalue (a)
1426 void replay_into (replayer *r) FINAL OVERRIDE;
1428 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1430 private:
1431 string * make_debug_string () FINAL OVERRIDE;
1432 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1433 enum precedence get_precedence () const FINAL OVERRIDE
1435 return PRECEDENCE_CAST;
1438 private:
1439 rvalue *m_rvalue;
1442 class base_call : public rvalue
1444 public:
1445 base_call (context *ctxt,
1446 location *loc,
1447 type *type_,
1448 int numargs,
1449 rvalue **args);
1451 enum precedence get_precedence () const FINAL OVERRIDE
1453 return PRECEDENCE_POSTFIX;
1456 base_call *dyn_cast_base_call () FINAL OVERRIDE { return this; }
1458 void set_require_tail_call (bool require_tail_call)
1460 m_require_tail_call = require_tail_call;
1463 protected:
1464 void write_reproducer_tail_call (reproducer &r, const char *id);
1466 protected:
1467 auto_vec<rvalue *> m_args;
1468 bool m_require_tail_call;
1471 class call : public base_call
1473 public:
1474 call (context *ctxt,
1475 location *loc,
1476 function *func,
1477 int numargs,
1478 rvalue **args);
1480 void replay_into (replayer *r) FINAL OVERRIDE;
1482 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1484 private:
1485 string * make_debug_string () FINAL OVERRIDE;
1486 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1488 private:
1489 function *m_func;
1492 class call_through_ptr : public base_call
1494 public:
1495 call_through_ptr (context *ctxt,
1496 location *loc,
1497 rvalue *fn_ptr,
1498 int numargs,
1499 rvalue **args);
1501 void replay_into (replayer *r) FINAL OVERRIDE;
1503 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1505 private:
1506 string * make_debug_string () FINAL OVERRIDE;
1507 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1509 private:
1510 rvalue *m_fn_ptr;
1513 class array_access : public lvalue
1515 public:
1516 array_access (context *ctxt,
1517 location *loc,
1518 rvalue *ptr,
1519 rvalue *index)
1520 : lvalue (ctxt, loc, ptr->get_type ()->dereference ()),
1521 m_ptr (ptr),
1522 m_index (index)
1525 void replay_into (replayer *r) FINAL OVERRIDE;
1527 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1529 private:
1530 string * make_debug_string () FINAL OVERRIDE;
1531 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1532 enum precedence get_precedence () const FINAL OVERRIDE
1534 return PRECEDENCE_POSTFIX;
1537 private:
1538 rvalue *m_ptr;
1539 rvalue *m_index;
1542 class access_field_of_lvalue : public lvalue
1544 public:
1545 access_field_of_lvalue (context *ctxt,
1546 location *loc,
1547 lvalue *val,
1548 field *field)
1549 : lvalue (ctxt, loc, field->get_type ()),
1550 m_lvalue (val),
1551 m_field (field)
1554 void replay_into (replayer *r) FINAL OVERRIDE;
1556 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1558 private:
1559 string * make_debug_string () FINAL OVERRIDE;
1560 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1561 enum precedence get_precedence () const FINAL OVERRIDE
1563 return PRECEDENCE_POSTFIX;
1566 private:
1567 lvalue *m_lvalue;
1568 field *m_field;
1571 class access_field_rvalue : public rvalue
1573 public:
1574 access_field_rvalue (context *ctxt,
1575 location *loc,
1576 rvalue *val,
1577 field *field)
1578 : rvalue (ctxt, loc, field->get_type ()),
1579 m_rvalue (val),
1580 m_field (field)
1583 void replay_into (replayer *r) FINAL OVERRIDE;
1585 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1587 private:
1588 string * make_debug_string () FINAL OVERRIDE;
1589 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1590 enum precedence get_precedence () const FINAL OVERRIDE
1592 return PRECEDENCE_POSTFIX;
1595 private:
1596 rvalue *m_rvalue;
1597 field *m_field;
1600 class dereference_field_rvalue : public lvalue
1602 public:
1603 dereference_field_rvalue (context *ctxt,
1604 location *loc,
1605 rvalue *val,
1606 field *field)
1607 : lvalue (ctxt, loc, field->get_type ()),
1608 m_rvalue (val),
1609 m_field (field)
1612 void replay_into (replayer *r) FINAL OVERRIDE;
1614 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1616 private:
1617 string * make_debug_string () FINAL OVERRIDE;
1618 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1619 enum precedence get_precedence () const FINAL OVERRIDE
1621 return PRECEDENCE_POSTFIX;
1624 private:
1625 rvalue *m_rvalue;
1626 field *m_field;
1629 class dereference_rvalue : public lvalue
1631 public:
1632 dereference_rvalue (context *ctxt,
1633 location *loc,
1634 rvalue *val)
1635 : lvalue (ctxt, loc, val->get_type ()->dereference ()),
1636 m_rvalue (val) {}
1638 void replay_into (replayer *r) FINAL OVERRIDE;
1640 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1642 private:
1643 string * make_debug_string () FINAL OVERRIDE;
1644 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1645 enum precedence get_precedence () const FINAL OVERRIDE
1647 return PRECEDENCE_UNARY;
1650 private:
1651 rvalue *m_rvalue;
1654 class get_address_of_lvalue : public rvalue
1656 public:
1657 get_address_of_lvalue (context *ctxt,
1658 location *loc,
1659 lvalue *val)
1660 : rvalue (ctxt, loc, val->get_type ()->get_pointer ()),
1661 m_lvalue (val)
1664 void replay_into (replayer *r) FINAL OVERRIDE;
1666 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1668 private:
1669 string * make_debug_string () FINAL OVERRIDE;
1670 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1671 enum precedence get_precedence () const FINAL OVERRIDE
1673 return PRECEDENCE_UNARY;
1676 private:
1677 lvalue *m_lvalue;
1680 class local : public lvalue
1682 public:
1683 local (function *func, location *loc, type *type_, string *name)
1684 : lvalue (func->m_ctxt, loc, type_),
1685 m_func (func),
1686 m_name (name)
1688 set_scope (func);
1691 void replay_into (replayer *r) FINAL OVERRIDE;
1693 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1695 void write_to_dump (dump &d) FINAL OVERRIDE;
1697 private:
1698 string * make_debug_string () FINAL OVERRIDE { return m_name; }
1699 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1700 enum precedence get_precedence () const FINAL OVERRIDE
1702 return PRECEDENCE_PRIMARY;
1705 private:
1706 function *m_func;
1707 string *m_name;
1710 class statement : public memento
1712 public:
1713 virtual vec <block *> get_successor_blocks () const;
1715 void write_to_dump (dump &d) FINAL OVERRIDE;
1717 block *get_block () const { return m_block; }
1718 location *get_loc () const { return m_loc; }
1720 protected:
1721 statement (block *b, location *loc)
1722 : memento (b->m_ctxt),
1723 m_block (b),
1724 m_loc (loc) {}
1726 playback::location *
1727 playback_location (replayer *r) const
1729 return ::gcc::jit::recording::playback_location (r, m_loc);
1732 private:
1733 block *m_block;
1734 location *m_loc;
1737 class eval : public statement
1739 public:
1740 eval (block *b,
1741 location *loc,
1742 rvalue *rvalue)
1743 : statement (b, loc),
1744 m_rvalue (rvalue) {}
1746 void replay_into (replayer *r) FINAL OVERRIDE;
1748 private:
1749 string * make_debug_string () FINAL OVERRIDE;
1750 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1752 private:
1753 rvalue *m_rvalue;
1756 class assignment : public statement
1758 public:
1759 assignment (block *b,
1760 location *loc,
1761 lvalue *lvalue,
1762 rvalue *rvalue)
1763 : statement (b, loc),
1764 m_lvalue (lvalue),
1765 m_rvalue (rvalue) {}
1767 void replay_into (replayer *r) FINAL OVERRIDE;
1769 private:
1770 string * make_debug_string () FINAL OVERRIDE;
1771 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1773 private:
1774 lvalue *m_lvalue;
1775 rvalue *m_rvalue;
1778 class assignment_op : public statement
1780 public:
1781 assignment_op (block *b,
1782 location *loc,
1783 lvalue *lvalue,
1784 enum gcc_jit_binary_op op,
1785 rvalue *rvalue)
1786 : statement (b, loc),
1787 m_lvalue (lvalue),
1788 m_op (op),
1789 m_rvalue (rvalue) {}
1791 void replay_into (replayer *r) FINAL OVERRIDE;
1793 private:
1794 string * make_debug_string () FINAL OVERRIDE;
1795 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1797 private:
1798 lvalue *m_lvalue;
1799 enum gcc_jit_binary_op m_op;
1800 rvalue *m_rvalue;
1803 class comment : public statement
1805 public:
1806 comment (block *b,
1807 location *loc,
1808 string *text)
1809 : statement (b, loc),
1810 m_text (text) {}
1812 void replay_into (replayer *r) FINAL OVERRIDE;
1814 private:
1815 string * make_debug_string () FINAL OVERRIDE;
1816 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1818 private:
1819 string *m_text;
1822 class conditional : public statement
1824 public:
1825 conditional (block *b,
1826 location *loc,
1827 rvalue *boolval,
1828 block *on_true,
1829 block *on_false)
1830 : statement (b, loc),
1831 m_boolval (boolval),
1832 m_on_true (on_true),
1833 m_on_false (on_false) {}
1835 void replay_into (replayer *r) FINAL OVERRIDE;
1837 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
1839 private:
1840 string * make_debug_string () FINAL OVERRIDE;
1841 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1843 private:
1844 rvalue *m_boolval;
1845 block *m_on_true;
1846 block *m_on_false;
1849 class jump : public statement
1851 public:
1852 jump (block *b,
1853 location *loc,
1854 block *target)
1855 : statement (b, loc),
1856 m_target (target) {}
1858 void replay_into (replayer *r) FINAL OVERRIDE;
1860 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
1862 private:
1863 string * make_debug_string () FINAL OVERRIDE;
1864 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1866 private:
1867 block *m_target;
1870 class return_ : public statement
1872 public:
1873 return_ (block *b,
1874 location *loc,
1875 rvalue *rvalue)
1876 : statement (b, loc),
1877 m_rvalue (rvalue) {}
1879 void replay_into (replayer *r) FINAL OVERRIDE;
1881 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
1883 private:
1884 string * make_debug_string () FINAL OVERRIDE;
1885 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1887 private:
1888 rvalue *m_rvalue;
1891 class case_ : public memento
1893 public:
1894 case_ (context *ctxt,
1895 rvalue *min_value,
1896 rvalue *max_value,
1897 block *dest_block)
1898 : memento (ctxt),
1899 m_min_value (min_value),
1900 m_max_value (max_value),
1901 m_dest_block (dest_block)
1904 rvalue *get_min_value () const { return m_min_value; }
1905 rvalue *get_max_value () const { return m_max_value; }
1906 block *get_dest_block () const { return m_dest_block; }
1908 void replay_into (replayer *) FINAL OVERRIDE { /* empty */ }
1910 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1912 private:
1913 string * make_debug_string () FINAL OVERRIDE;
1915 private:
1916 rvalue *m_min_value;
1917 rvalue *m_max_value;
1918 block *m_dest_block;
1921 class switch_ : public statement
1923 public:
1924 switch_ (block *b,
1925 location *loc,
1926 rvalue *expr,
1927 block *default_block,
1928 int num_cases,
1929 case_ **cases);
1931 void replay_into (replayer *r) FINAL OVERRIDE;
1933 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
1935 private:
1936 string * make_debug_string () FINAL OVERRIDE;
1937 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1939 private:
1940 rvalue *m_expr;
1941 block *m_default_block;
1942 auto_vec <case_ *> m_cases;
1945 } // namespace gcc::jit::recording
1947 /* Create a recording::memento_of_new_rvalue_from_const instance and add
1948 it to this context's list of mementos.
1950 Implements the post-error-checking part of
1951 gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
1953 template <typename HOST_TYPE>
1954 recording::rvalue *
1955 recording::context::new_rvalue_from_const (recording::type *type,
1956 HOST_TYPE value)
1958 recording::rvalue *result =
1959 new memento_of_new_rvalue_from_const <HOST_TYPE> (this, NULL, type, value);
1960 record (result);
1961 return result;
1964 } // namespace gcc::jit
1966 } // namespace gcc
1968 #endif /* JIT_RECORDING_H */