Simplify X * C1 == C2 with undefined overflow
[official-gcc.git] / gcc / jit / jit-recording.h
blob726b9c4b83719bed718e45c6d308028793b1a7ac
1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2020 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 extern const char * const unary_op_reproducer_strings[];
34 extern const char * const binary_op_reproducer_strings[];
36 class result;
37 class dump;
38 class reproducer;
40 /**********************************************************************
41 Recording.
42 **********************************************************************/
44 namespace recording {
46 playback::location *
47 playback_location (replayer *r, location *loc);
49 const char *
50 playback_string (string *str);
52 playback::block *
53 playback_block (block *b);
55 /* A recording of a call to gcc_jit_context_enable_dump. */
56 struct requested_dump
58 const char *m_dumpname;
59 char **m_out_ptr;
62 /* A JIT-compilation context. */
63 class context : public log_user
65 public:
66 context (context *parent_ctxt);
67 ~context ();
69 builtins_manager *
70 get_builtins_manager ();
72 void record (memento *m);
73 void replay_into (replayer *r);
74 void disassociate_from_playback ();
76 string *
77 new_string (const char *text);
79 location *
80 new_location (const char *filename,
81 int line,
82 int column,
83 bool created_by_user);
85 type *
86 get_type (enum gcc_jit_types type);
88 type *
89 get_int_type (int num_bytes, int is_signed);
91 type *
92 new_array_type (location *loc,
93 type *element_type,
94 int num_elements);
96 field *
97 new_field (location *loc,
98 type *type,
99 const char *name);
101 field *
102 new_bitfield (location *loc,
103 type *type,
104 int width,
105 const char *name);
107 struct_ *
108 new_struct_type (location *loc,
109 const char *name);
111 union_ *
112 new_union_type (location *loc,
113 const char *name);
115 function_type *
116 new_function_type (type *return_type,
117 int num_params,
118 type **param_types,
119 int is_variadic);
121 type *
122 new_function_ptr_type (location *loc,
123 type *return_type,
124 int num_params,
125 type **param_types,
126 int is_variadic);
128 param *
129 new_param (location *loc,
130 type *type,
131 const char *name);
133 function *
134 new_function (location *loc,
135 enum gcc_jit_function_kind kind,
136 type *return_type,
137 const char *name,
138 int num_params,
139 param **params,
140 int is_variadic,
141 enum built_in_function builtin_id);
143 function *
144 get_builtin_function (const char *name);
146 lvalue *
147 new_global (location *loc,
148 enum gcc_jit_global_kind kind,
149 type *type,
150 const char *name);
152 template <typename HOST_TYPE>
153 rvalue *
154 new_rvalue_from_const (type *type,
155 HOST_TYPE value);
157 rvalue *
158 new_string_literal (const char *value);
160 rvalue *
161 new_rvalue_from_vector (location *loc,
162 vector_type *type,
163 rvalue **elements);
165 rvalue *
166 new_unary_op (location *loc,
167 enum gcc_jit_unary_op op,
168 type *result_type,
169 rvalue *a);
171 rvalue *
172 new_binary_op (location *loc,
173 enum gcc_jit_binary_op op,
174 type *result_type,
175 rvalue *a, rvalue *b);
177 rvalue *
178 new_comparison (location *loc,
179 enum gcc_jit_comparison op,
180 rvalue *a, rvalue *b);
182 rvalue *
183 new_call (location *loc,
184 function *func,
185 int numargs, rvalue **args);
187 rvalue *
188 new_call_through_ptr (location *loc,
189 rvalue *fn_ptr,
190 int numargs, rvalue **args);
192 rvalue *
193 new_cast (location *loc,
194 rvalue *expr,
195 type *type_);
197 lvalue *
198 new_array_access (location *loc,
199 rvalue *ptr,
200 rvalue *index);
202 case_ *
203 new_case (rvalue *min_value,
204 rvalue *max_value,
205 block *block);
207 void
208 set_str_option (enum gcc_jit_str_option opt,
209 const char *value);
211 void
212 set_int_option (enum gcc_jit_int_option opt,
213 int value);
215 void
216 set_bool_option (enum gcc_jit_bool_option opt,
217 int value);
219 void
220 set_inner_bool_option (enum inner_bool_option inner_opt,
221 int value);
223 void
224 add_command_line_option (const char *optname);
226 void
227 append_command_line_options (vec <char *> *argvec);
229 void
230 add_driver_option (const char *optname);
232 void
233 append_driver_options (auto_string_vec *argvec);
235 void
236 enable_dump (const char *dumpname,
237 char **out_ptr);
239 const char *
240 get_str_option (enum gcc_jit_str_option opt) const
242 return m_str_options[opt];
246 get_int_option (enum gcc_jit_int_option opt) const
248 return m_int_options[opt];
252 get_bool_option (enum gcc_jit_bool_option opt) const
254 return m_bool_options[opt];
258 get_inner_bool_option (enum inner_bool_option opt) const
260 return m_inner_bool_options[opt];
263 result *
264 compile ();
266 void
267 compile_to_file (enum gcc_jit_output_kind output_kind,
268 const char *output_path);
270 void
271 add_error (location *loc, const char *fmt, ...)
272 GNU_PRINTF(3, 4);
274 void
275 add_error_va (location *loc, const char *fmt, va_list ap)
276 GNU_PRINTF(3, 0);
278 const char *
279 get_first_error () const;
281 const char *
282 get_last_error () const;
284 bool errors_occurred () const
286 if (m_parent_ctxt)
287 if (m_parent_ctxt->errors_occurred ())
288 return true;
289 return m_error_count;
292 type *get_opaque_FILE_type ();
294 void dump_to_file (const char *path, bool update_locations);
296 void dump_reproducer_to_file (const char *path);
298 void
299 get_all_requested_dumps (vec <recording::requested_dump> *out);
301 void set_timer (timer *t) { m_timer = t; }
302 timer *get_timer () const { return m_timer; }
304 private:
305 void log_all_options () const;
306 void log_str_option (enum gcc_jit_str_option opt) const;
307 void log_int_option (enum gcc_jit_int_option opt) const;
308 void log_bool_option (enum gcc_jit_bool_option opt) const;
309 void log_inner_bool_option (enum inner_bool_option opt) const;
311 void validate ();
313 private:
314 context *m_parent_ctxt;
316 /* The ultimate ancestor of the contexts within a family tree of
317 contexts. This has itself as its own m_toplevel_ctxt. */
318 context *m_toplevel_ctxt;
320 timer *m_timer;
322 int m_error_count;
324 char *m_first_error_str;
325 bool m_owns_first_error_str;
327 char *m_last_error_str;
328 bool m_owns_last_error_str;
330 char *m_str_options[GCC_JIT_NUM_STR_OPTIONS];
331 int m_int_options[GCC_JIT_NUM_INT_OPTIONS];
332 bool m_bool_options[GCC_JIT_NUM_BOOL_OPTIONS];
333 bool m_inner_bool_options[NUM_INNER_BOOL_OPTIONS];
334 auto_vec <char *> m_command_line_options;
335 auto_vec <char *> m_driver_options;
337 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
338 auto_vec<requested_dump> m_requested_dumps;
340 /* Recorded API usage. */
341 auto_vec<memento *> m_mementos;
343 /* Specific recordings, for use by dump_to_file. */
344 auto_vec<compound_type *> m_compound_types;
345 auto_vec<global *> m_globals;
346 auto_vec<function *> m_functions;
348 type *m_basic_types[NUM_GCC_JIT_TYPES];
349 type *m_FILE_type;
351 builtins_manager *m_builtins_manager; // lazily created
355 /* An object with lifetime managed by the context i.e.
356 it lives until the context is released, at which
357 point it itself is cleaned up. */
359 class memento
361 public:
362 virtual ~memento () {}
364 /* Hook for replaying this. */
365 virtual void replay_into (replayer *r) = 0;
367 void set_playback_obj (void *obj) { m_playback_obj = obj; }
370 /* Get the context that owns this object.
372 Implements the post-error-checking part of
373 gcc_jit_object_get_context. */
374 context *get_context () { return m_ctxt; }
376 memento *
377 as_object () { return this; }
379 /* Debugging hook, for use in generating error messages etc.
380 Implements the post-error-checking part of
381 gcc_jit_object_get_debug_string. */
382 const char *
383 get_debug_string ();
385 virtual void write_to_dump (dump &d);
386 virtual void write_reproducer (reproducer &r) = 0;
387 virtual location *dyn_cast_location () { return NULL; }
389 protected:
390 memento (context *ctxt)
391 : m_ctxt (ctxt),
392 m_playback_obj (NULL),
393 m_debug_string (NULL)
395 gcc_assert (ctxt);
398 string *new_string (const char *text) { return m_ctxt->new_string (text); }
400 private:
401 virtual string * make_debug_string () = 0;
403 public:
404 context *m_ctxt;
406 protected:
407 void *m_playback_obj;
409 private:
410 string *m_debug_string;
413 /* or just use std::string? */
414 class string : public memento
416 public:
417 string (context *ctxt, const char *text);
418 ~string ();
420 const char *c_str () { return m_buffer; }
422 static string * from_printf (context *ctxt, const char *fmt, ...)
423 GNU_PRINTF(2, 3);
425 void replay_into (replayer *) FINAL OVERRIDE {}
427 private:
428 string * make_debug_string () FINAL OVERRIDE;
429 void write_reproducer (reproducer &r) FINAL OVERRIDE;
431 private:
432 size_t m_len;
433 char *m_buffer;
436 class location : public memento
438 public:
439 location (context *ctxt, string *filename, int line, int column,
440 bool created_by_user)
441 : memento (ctxt),
442 m_filename (filename),
443 m_line (line),
444 m_column (column),
445 m_created_by_user (created_by_user)
448 void replay_into (replayer *r) FINAL OVERRIDE;
450 playback::location *
451 playback_location (replayer *r)
453 /* Normally during playback, we can walk forwards through the list of
454 recording objects, playing them back. The ordering of recording
455 ensures that everything that a recording object refers to has
456 already been played back, so we can simply look up the relevant
457 m_playback_obj.
459 Locations are an exception, due to the "write_to_dump" method of
460 recording::statement. This method can set a new location on a
461 statement after the statement is created, and thus the location
462 appears in the context's memento list *after* the statement that
463 refers to it.
465 In such circumstances, the statement is replayed *before* the location,
466 when the latter doesn't yet have a playback object.
468 Hence we need to ensure that locations have playback objects. */
469 if (!m_playback_obj)
471 replay_into (r);
473 gcc_assert (m_playback_obj);
474 return static_cast <playback::location *> (m_playback_obj);
477 location *dyn_cast_location () FINAL OVERRIDE { return this; }
478 bool created_by_user () const { return m_created_by_user; }
480 private:
481 string * make_debug_string () FINAL OVERRIDE;
482 void write_reproducer (reproducer &r) FINAL OVERRIDE;
484 private:
485 string *m_filename;
486 int m_line;
487 int m_column;
488 bool m_created_by_user;
491 class type : public memento
493 public:
494 type *get_pointer ();
495 type *get_const ();
496 type *get_volatile ();
497 type *get_aligned (size_t alignment_in_bytes);
498 type *get_vector (size_t num_units);
500 /* Get the type obtained when dereferencing this type.
502 This will return NULL if it's not valid to dereference this type.
503 The caller is responsible for setting an error. */
504 virtual type *dereference () = 0;
506 /* Dynamic casts. */
507 virtual function_type *dyn_cast_function_type () { return NULL; }
508 virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
509 virtual struct_ *dyn_cast_struct () { return NULL; }
510 virtual vector_type *dyn_cast_vector_type () { return NULL; }
512 /* Is it typesafe to copy to this type from rtype? */
513 virtual bool accepts_writes_from (type *rtype)
515 gcc_assert (rtype);
516 return this->unqualified ()->is_same_type_as (rtype->unqualified ());
519 virtual bool is_same_type_as (type *other)
521 return this == other;
524 /* Strip off "const" etc */
525 virtual type *unqualified ()
527 return this;
530 virtual bool is_int () const = 0;
531 virtual bool is_float () const = 0;
532 virtual bool is_bool () const = 0;
533 virtual type *is_pointer () = 0;
534 virtual type *is_array () = 0;
535 virtual bool is_void () const { return false; }
536 virtual bool has_known_size () const { return true; }
538 bool is_numeric () const
540 return is_int () || is_float () || is_bool ();
543 playback::type *
544 playback_type ()
546 return static_cast <playback::type *> (m_playback_obj);
549 virtual const char *access_as_type (reproducer &r);
551 protected:
552 type (context *ctxt)
553 : memento (ctxt),
554 m_pointer_to_this_type (NULL)
557 private:
558 type *m_pointer_to_this_type;
561 /* Result of "gcc_jit_context_get_type". */
562 class memento_of_get_type : public type
564 public:
565 memento_of_get_type (context *ctxt,
566 enum gcc_jit_types kind)
567 : type (ctxt),
568 m_kind (kind) {}
570 type *dereference () FINAL OVERRIDE;
572 bool accepts_writes_from (type *rtype) FINAL OVERRIDE
574 if (m_kind == GCC_JIT_TYPE_VOID_PTR)
575 if (rtype->is_pointer ())
577 /* LHS (this) is type (void *), and the RHS is a pointer:
578 accept it: */
579 return true;
582 return type::accepts_writes_from (rtype);
585 bool is_int () const FINAL OVERRIDE;
586 bool is_float () const FINAL OVERRIDE;
587 bool is_bool () const FINAL OVERRIDE;
588 type *is_pointer () FINAL OVERRIDE { return dereference (); }
589 type *is_array () FINAL OVERRIDE { return NULL; }
590 bool is_void () const FINAL OVERRIDE { return m_kind == GCC_JIT_TYPE_VOID; }
592 public:
593 void replay_into (replayer *r) FINAL OVERRIDE;
595 private:
596 string * make_debug_string () FINAL OVERRIDE;
597 void write_reproducer (reproducer &r) FINAL OVERRIDE;
599 private:
600 enum gcc_jit_types m_kind;
603 /* Result of "gcc_jit_type_get_pointer". */
604 class memento_of_get_pointer : public type
606 public:
607 memento_of_get_pointer (type *other_type)
608 : type (other_type->m_ctxt),
609 m_other_type (other_type) {}
611 type *dereference () FINAL OVERRIDE { return m_other_type; }
613 bool accepts_writes_from (type *rtype) FINAL OVERRIDE;
615 void replay_into (replayer *r) FINAL OVERRIDE;
617 bool is_int () const FINAL OVERRIDE { return false; }
618 bool is_float () const FINAL OVERRIDE { return false; }
619 bool is_bool () const FINAL OVERRIDE { return false; }
620 type *is_pointer () FINAL OVERRIDE { return m_other_type; }
621 type *is_array () FINAL OVERRIDE { return NULL; }
623 private:
624 string * make_debug_string () FINAL OVERRIDE;
625 void write_reproducer (reproducer &r) FINAL OVERRIDE;
627 private:
628 type *m_other_type;
631 /* A decorated version of a type, for get_const, get_volatile,
632 get_aligned, and get_vector. */
634 class decorated_type : public type
636 public:
637 decorated_type (type *other_type)
638 : type (other_type->m_ctxt),
639 m_other_type (other_type) {}
641 type *dereference () FINAL OVERRIDE { return m_other_type->dereference (); }
643 bool is_int () const FINAL OVERRIDE { return m_other_type->is_int (); }
644 bool is_float () const FINAL OVERRIDE { return m_other_type->is_float (); }
645 bool is_bool () const FINAL OVERRIDE { return m_other_type->is_bool (); }
646 type *is_pointer () FINAL OVERRIDE { return m_other_type->is_pointer (); }
647 type *is_array () FINAL OVERRIDE { return m_other_type->is_array (); }
649 protected:
650 type *m_other_type;
653 /* Result of "gcc_jit_type_get_const". */
654 class memento_of_get_const : public decorated_type
656 public:
657 memento_of_get_const (type *other_type)
658 : decorated_type (other_type) {}
660 bool accepts_writes_from (type */*rtype*/) FINAL OVERRIDE
662 /* Can't write to a "const". */
663 return false;
666 /* Strip off the "const", giving the underlying type. */
667 type *unqualified () FINAL OVERRIDE { return m_other_type; }
669 void replay_into (replayer *) FINAL OVERRIDE;
671 private:
672 string * make_debug_string () FINAL OVERRIDE;
673 void write_reproducer (reproducer &r) FINAL OVERRIDE;
676 /* Result of "gcc_jit_type_get_volatile". */
677 class memento_of_get_volatile : public decorated_type
679 public:
680 memento_of_get_volatile (type *other_type)
681 : decorated_type (other_type) {}
683 /* Strip off the "volatile", giving the underlying type. */
684 type *unqualified () FINAL OVERRIDE { return m_other_type; }
686 void replay_into (replayer *) FINAL OVERRIDE;
688 private:
689 string * make_debug_string () FINAL OVERRIDE;
690 void write_reproducer (reproducer &r) FINAL OVERRIDE;
693 /* Result of "gcc_jit_type_get_aligned". */
694 class memento_of_get_aligned : public decorated_type
696 public:
697 memento_of_get_aligned (type *other_type, size_t alignment_in_bytes)
698 : decorated_type (other_type),
699 m_alignment_in_bytes (alignment_in_bytes) {}
701 /* Strip off the alignment, giving the underlying type. */
702 type *unqualified () FINAL OVERRIDE { return m_other_type; }
704 void replay_into (replayer *) FINAL OVERRIDE;
706 private:
707 string * make_debug_string () FINAL OVERRIDE;
708 void write_reproducer (reproducer &r) FINAL OVERRIDE;
710 private:
711 size_t m_alignment_in_bytes;
714 /* Result of "gcc_jit_type_get_vector". */
715 class vector_type : public decorated_type
717 public:
718 vector_type (type *other_type, size_t num_units)
719 : decorated_type (other_type),
720 m_num_units (num_units) {}
722 size_t get_num_units () const { return m_num_units; }
724 vector_type *dyn_cast_vector_type () FINAL OVERRIDE { return this; }
726 type *get_element_type () { return m_other_type; }
728 void replay_into (replayer *) FINAL OVERRIDE;
730 private:
731 string * make_debug_string () FINAL OVERRIDE;
732 void write_reproducer (reproducer &r) FINAL OVERRIDE;
734 private:
735 size_t m_num_units;
738 class array_type : public type
740 public:
741 array_type (context *ctxt,
742 location *loc,
743 type *element_type,
744 int num_elements)
745 : type (ctxt),
746 m_loc (loc),
747 m_element_type (element_type),
748 m_num_elements (num_elements)
751 type *dereference () FINAL OVERRIDE;
753 bool is_int () const FINAL OVERRIDE { return false; }
754 bool is_float () const FINAL OVERRIDE { return false; }
755 bool is_bool () const FINAL OVERRIDE { return false; }
756 type *is_pointer () FINAL OVERRIDE { return NULL; }
757 type *is_array () FINAL OVERRIDE { return m_element_type; }
759 void replay_into (replayer *) FINAL OVERRIDE;
761 private:
762 string * make_debug_string () FINAL OVERRIDE;
763 void write_reproducer (reproducer &r) FINAL OVERRIDE;
765 private:
766 location *m_loc;
767 type *m_element_type;
768 int m_num_elements;
771 class function_type : public type
773 public:
774 function_type (context *ctxt,
775 type *return_type,
776 int num_params,
777 type **param_types,
778 int is_variadic);
780 type *dereference () FINAL OVERRIDE;
781 function_type *dyn_cast_function_type () FINAL OVERRIDE { return this; }
782 function_type *as_a_function_type () FINAL OVERRIDE { return this; }
784 bool is_same_type_as (type *other) FINAL OVERRIDE;
786 bool is_int () const FINAL OVERRIDE { return false; }
787 bool is_float () const FINAL OVERRIDE { return false; }
788 bool is_bool () const FINAL OVERRIDE { return false; }
789 type *is_pointer () FINAL OVERRIDE { return NULL; }
790 type *is_array () FINAL OVERRIDE { return NULL; }
792 void replay_into (replayer *) FINAL OVERRIDE;
794 type * get_return_type () const { return m_return_type; }
795 const vec<type *> &get_param_types () const { return m_param_types; }
796 int is_variadic () const { return m_is_variadic; }
798 string * make_debug_string_with_ptr ();
800 void
801 write_deferred_reproducer (reproducer &r,
802 memento *ptr_type);
804 private:
805 string * make_debug_string () FINAL OVERRIDE;
806 string * make_debug_string_with (const char *);
807 void write_reproducer (reproducer &r) FINAL OVERRIDE;
809 private:
810 type *m_return_type;
811 auto_vec<type *> m_param_types;
812 int m_is_variadic;
815 class field : public memento
817 public:
818 field (context *ctxt,
819 location *loc,
820 type *type,
821 string *name)
822 : memento (ctxt),
823 m_loc (loc),
824 m_type (type),
825 m_name (name),
826 m_container (NULL)
829 type * get_type () const { return m_type; }
831 compound_type * get_container () const { return m_container; }
832 void set_container (compound_type *c) { m_container = c; }
834 void replay_into (replayer *) OVERRIDE;
836 void write_to_dump (dump &d) OVERRIDE;
838 playback::field *
839 playback_field () const
841 return static_cast <playback::field *> (m_playback_obj);
844 private:
845 string * make_debug_string () OVERRIDE;
846 void write_reproducer (reproducer &r) OVERRIDE;
848 protected:
849 location *m_loc;
850 type *m_type;
851 string *m_name;
852 compound_type *m_container;
856 class bitfield : public field
858 public:
859 bitfield (context *ctxt,
860 location *loc,
861 type *type,
862 int width,
863 string *name)
864 : field (ctxt, loc, type, name),
865 m_width (width)
868 void replay_into (replayer *) FINAL OVERRIDE;
870 void write_to_dump (dump &d) FINAL OVERRIDE;
872 private:
873 string * make_debug_string () FINAL OVERRIDE;
874 void write_reproducer (reproducer &r) FINAL OVERRIDE;
876 private:
877 int m_width;
880 /* Base class for struct_ and union_ */
881 class compound_type : public type
883 public:
884 compound_type (context *ctxt,
885 location *loc,
886 string *name);
888 string *get_name () const { return m_name; }
889 location *get_loc () const { return m_loc; }
890 fields * get_fields () { return m_fields; }
892 void
893 set_fields (location *loc,
894 int num_fields,
895 field **fields);
897 type *dereference () FINAL OVERRIDE;
899 bool is_int () const FINAL OVERRIDE { return false; }
900 bool is_float () const FINAL OVERRIDE { return false; }
901 bool is_bool () const FINAL OVERRIDE { return false; }
902 type *is_pointer () FINAL OVERRIDE { return NULL; }
903 type *is_array () FINAL OVERRIDE { return NULL; }
905 bool has_known_size () const FINAL OVERRIDE { return m_fields != NULL; }
907 playback::compound_type *
908 playback_compound_type ()
910 return static_cast <playback::compound_type *> (m_playback_obj);
913 private:
914 location *m_loc;
915 string *m_name;
916 fields *m_fields;
919 class struct_ : public compound_type
921 public:
922 struct_ (context *ctxt,
923 location *loc,
924 string *name);
926 struct_ *dyn_cast_struct () FINAL OVERRIDE { return this; }
928 type *
929 as_type () { return this; }
931 void replay_into (replayer *r) FINAL OVERRIDE;
933 const char *access_as_type (reproducer &r) FINAL OVERRIDE;
935 private:
936 string * make_debug_string () FINAL OVERRIDE;
937 void write_reproducer (reproducer &r) FINAL OVERRIDE;
940 // memento of struct_::set_fields
941 class fields : public memento
943 public:
944 fields (compound_type *struct_or_union,
945 int num_fields,
946 field **fields);
948 void replay_into (replayer *r) FINAL OVERRIDE;
950 void write_to_dump (dump &d) FINAL OVERRIDE;
952 int length () const { return m_fields.length (); }
953 field *get_field (int i) const { return m_fields[i]; }
955 private:
956 string * make_debug_string () FINAL OVERRIDE;
957 void write_reproducer (reproducer &r) FINAL OVERRIDE;
959 private:
960 compound_type *m_struct_or_union;
961 auto_vec<field *> m_fields;
964 class union_ : public compound_type
966 public:
967 union_ (context *ctxt,
968 location *loc,
969 string *name);
971 void replay_into (replayer *r) FINAL OVERRIDE;
973 private:
974 string * make_debug_string () FINAL OVERRIDE;
975 void write_reproducer (reproducer &r) FINAL OVERRIDE;
978 /* An abstract base class for operations that visit all rvalues within an
979 expression tree.
980 Currently the only implementation is class rvalue_usage_validator within
981 jit-recording.c. */
983 class rvalue_visitor
985 public:
986 virtual ~rvalue_visitor () {}
987 virtual void visit (rvalue *rvalue) = 0;
990 /* When generating debug strings for rvalues we mimic C, so we need to
991 mimic C's precedence levels when handling compound expressions.
992 These are in order from strongest precedence to weakest. */
993 enum precedence
995 PRECEDENCE_PRIMARY,
996 PRECEDENCE_POSTFIX,
997 PRECEDENCE_UNARY,
998 PRECEDENCE_CAST,
999 PRECEDENCE_MULTIPLICATIVE,
1000 PRECEDENCE_ADDITIVE,
1001 PRECEDENCE_SHIFT,
1002 PRECEDENCE_RELATIONAL,
1003 PRECEDENCE_EQUALITY,
1004 PRECEDENCE_BITWISE_AND,
1005 PRECEDENCE_BITWISE_XOR,
1006 PRECEDENCE_BITWISE_IOR,
1007 PRECEDENCE_LOGICAL_AND,
1008 PRECEDENCE_LOGICAL_OR
1011 class rvalue : public memento
1013 public:
1014 rvalue (context *ctxt,
1015 location *loc,
1016 type *type_)
1017 : memento (ctxt),
1018 m_loc (loc),
1019 m_type (type_),
1020 m_scope (NULL),
1021 m_parenthesized_string (NULL)
1023 gcc_assert (type_);
1026 location * get_loc () const { return m_loc; }
1028 /* Get the recording::type of this rvalue.
1030 Implements the post-error-checking part of
1031 gcc_jit_rvalue_get_type. */
1032 type * get_type () const { return m_type; }
1034 playback::rvalue *
1035 playback_rvalue () const
1037 return static_cast <playback::rvalue *> (m_playback_obj);
1039 rvalue *
1040 access_field (location *loc,
1041 field *field);
1043 lvalue *
1044 dereference_field (location *loc,
1045 field *field);
1047 lvalue *
1048 dereference (location *loc);
1050 void
1051 verify_valid_within_stmt (const char *api_funcname, statement *s);
1053 virtual void visit_children (rvalue_visitor *v) = 0;
1055 void set_scope (function *scope);
1056 function *get_scope () const { return m_scope; }
1058 /* Dynamic casts. */
1059 virtual param *dyn_cast_param () { return NULL; }
1060 virtual base_call *dyn_cast_base_call () { return NULL; }
1062 virtual const char *access_as_rvalue (reproducer &r);
1064 /* Get the debug string, wrapped in parentheses. */
1065 const char *
1066 get_debug_string_parens (enum precedence outer_prec);
1068 virtual bool is_constant () const { return false; }
1069 virtual bool get_wide_int (wide_int *) const { return false; }
1071 private:
1072 virtual enum precedence get_precedence () const = 0;
1074 protected:
1075 location *m_loc;
1076 type *m_type;
1078 private:
1079 function *m_scope; /* NULL for globals, non-NULL for locals/params */
1080 string *m_parenthesized_string;
1083 class lvalue : public rvalue
1085 public:
1086 lvalue (context *ctxt,
1087 location *loc,
1088 type *type_)
1089 : rvalue (ctxt, loc, type_)
1092 playback::lvalue *
1093 playback_lvalue () const
1095 return static_cast <playback::lvalue *> (m_playback_obj);
1098 lvalue *
1099 access_field (location *loc,
1100 field *field);
1102 rvalue *
1103 get_address (location *loc);
1105 rvalue *
1106 as_rvalue () { return this; }
1108 const char *access_as_rvalue (reproducer &r) OVERRIDE;
1109 virtual const char *access_as_lvalue (reproducer &r);
1112 class param : public lvalue
1114 public:
1115 param (context *ctxt,
1116 location *loc,
1117 type *type,
1118 string *name)
1119 : lvalue (ctxt, loc, type),
1120 m_name (name) {}
1122 lvalue *
1123 as_lvalue () { return this; }
1125 void replay_into (replayer *r) FINAL OVERRIDE;
1127 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1129 playback::param *
1130 playback_param () const
1132 return static_cast <playback::param *> (m_playback_obj);
1135 param *dyn_cast_param () FINAL OVERRIDE { return this; }
1137 const char *access_as_rvalue (reproducer &r) FINAL OVERRIDE;
1138 const char *access_as_lvalue (reproducer &r) FINAL OVERRIDE;
1140 private:
1141 string * make_debug_string () FINAL OVERRIDE { return m_name; }
1142 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1143 enum precedence get_precedence () const FINAL OVERRIDE
1145 return PRECEDENCE_PRIMARY;
1148 private:
1149 string *m_name;
1152 class function : public memento
1154 public:
1155 function (context *ctxt,
1156 location *loc,
1157 enum gcc_jit_function_kind kind,
1158 type *return_type,
1159 string *name,
1160 int num_params,
1161 param **params,
1162 int is_variadic,
1163 enum built_in_function builtin_id);
1165 void replay_into (replayer *r) FINAL OVERRIDE;
1167 playback::function *
1168 playback_function () const
1170 return static_cast <playback::function *> (m_playback_obj);
1173 enum gcc_jit_function_kind get_kind () const { return m_kind; }
1175 lvalue *
1176 new_local (location *loc,
1177 type *type,
1178 const char *name);
1180 block*
1181 new_block (const char *name);
1183 location *get_loc () const { return m_loc; }
1184 type *get_return_type () const { return m_return_type; }
1185 string * get_name () const { return m_name; }
1186 const vec<param *> &get_params () const { return m_params; }
1188 /* Get the given param by index.
1189 Implements the post-error-checking part of
1190 gcc_jit_function_get_param. */
1191 param *get_param (int i) const { return m_params[i]; }
1193 bool is_variadic () const { return m_is_variadic; }
1195 void write_to_dump (dump &d) FINAL OVERRIDE;
1197 void validate ();
1199 void dump_to_dot (const char *path);
1201 rvalue *get_address (location *loc);
1203 private:
1204 string * make_debug_string () FINAL OVERRIDE;
1205 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1207 private:
1208 location *m_loc;
1209 enum gcc_jit_function_kind m_kind;
1210 type *m_return_type;
1211 string *m_name;
1212 auto_vec<param *> m_params;
1213 int m_is_variadic;
1214 enum built_in_function m_builtin_id;
1215 auto_vec<local *> m_locals;
1216 auto_vec<block *> m_blocks;
1217 type *m_fn_ptr_type;
1220 class block : public memento
1222 public:
1223 block (function *func, int index, string *name)
1224 : memento (func->m_ctxt),
1225 m_func (func),
1226 m_index (index),
1227 m_name (name),
1228 m_statements (),
1229 m_has_been_terminated (false),
1230 m_is_reachable (false)
1234 /* Get the recording::function containing this block.
1235 Implements the post-error-checking part of
1236 gcc_jit_block_get_function. */
1237 function *get_function () { return m_func; }
1239 bool has_been_terminated () { return m_has_been_terminated; }
1240 bool is_reachable () { return m_is_reachable; }
1242 statement *
1243 add_eval (location *loc,
1244 rvalue *rvalue);
1246 statement *
1247 add_assignment (location *loc,
1248 lvalue *lvalue,
1249 rvalue *rvalue);
1251 statement *
1252 add_assignment_op (location *loc,
1253 lvalue *lvalue,
1254 enum gcc_jit_binary_op op,
1255 rvalue *rvalue);
1257 statement *
1258 add_comment (location *loc,
1259 const char *text);
1261 statement *
1262 end_with_conditional (location *loc,
1263 rvalue *boolval,
1264 block *on_true,
1265 block *on_false);
1267 statement *
1268 end_with_jump (location *loc,
1269 block *target);
1271 statement *
1272 end_with_return (location *loc,
1273 rvalue *rvalue);
1275 statement *
1276 end_with_switch (location *loc,
1277 rvalue *expr,
1278 block *default_block,
1279 int num_cases,
1280 case_ **cases);
1282 playback::block *
1283 playback_block () const
1285 return static_cast <playback::block *> (m_playback_obj);
1288 void write_to_dump (dump &d) FINAL OVERRIDE;
1290 bool validate ();
1292 location *get_loc () const;
1294 statement *get_first_statement () const;
1295 statement *get_last_statement () const;
1297 vec <block *> get_successor_blocks () const;
1299 private:
1300 string * make_debug_string () FINAL OVERRIDE;
1301 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1303 void replay_into (replayer *r) FINAL OVERRIDE;
1305 void dump_to_dot (pretty_printer *pp);
1306 void dump_edges_to_dot (pretty_printer *pp);
1308 private:
1309 function *m_func;
1310 int m_index;
1311 string *m_name;
1312 auto_vec<statement *> m_statements;
1313 bool m_has_been_terminated;
1314 bool m_is_reachable;
1316 friend class function;
1319 class global : public lvalue
1321 public:
1322 global (context *ctxt,
1323 location *loc,
1324 enum gcc_jit_global_kind kind,
1325 type *type,
1326 string *name)
1327 : lvalue (ctxt, loc, type),
1328 m_kind (kind),
1329 m_name (name)
1332 void replay_into (replayer *) FINAL OVERRIDE;
1334 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1336 void write_to_dump (dump &d) FINAL OVERRIDE;
1338 private:
1339 string * make_debug_string () FINAL OVERRIDE { return m_name; }
1340 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1341 enum precedence get_precedence () const FINAL OVERRIDE
1343 return PRECEDENCE_PRIMARY;
1346 private:
1347 enum gcc_jit_global_kind m_kind;
1348 string *m_name;
1351 template <typename HOST_TYPE>
1352 class memento_of_new_rvalue_from_const : public rvalue
1354 public:
1355 memento_of_new_rvalue_from_const (context *ctxt,
1356 location *loc,
1357 type *type,
1358 HOST_TYPE value)
1359 : rvalue (ctxt, loc, type),
1360 m_value (value) {}
1362 void replay_into (replayer *r) FINAL OVERRIDE;
1364 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1366 bool is_constant () const FINAL OVERRIDE { return true; }
1368 bool get_wide_int (wide_int *out) const FINAL OVERRIDE;
1370 private:
1371 string * make_debug_string () FINAL OVERRIDE;
1372 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1373 enum precedence get_precedence () const FINAL OVERRIDE
1375 return PRECEDENCE_PRIMARY;
1378 private:
1379 HOST_TYPE m_value;
1382 class memento_of_new_string_literal : public rvalue
1384 public:
1385 memento_of_new_string_literal (context *ctxt,
1386 location *loc,
1387 string *value)
1388 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR)),
1389 m_value (value) {}
1391 void replay_into (replayer *r) FINAL OVERRIDE;
1393 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1395 private:
1396 string * make_debug_string () FINAL OVERRIDE;
1397 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1398 enum precedence get_precedence () const FINAL OVERRIDE
1400 return PRECEDENCE_PRIMARY;
1403 private:
1404 string *m_value;
1407 class memento_of_new_rvalue_from_vector : public rvalue
1409 public:
1410 memento_of_new_rvalue_from_vector (context *ctxt,
1411 location *loc,
1412 vector_type *type,
1413 rvalue **elements);
1415 void replay_into (replayer *r) FINAL OVERRIDE;
1417 void visit_children (rvalue_visitor *) FINAL OVERRIDE;
1419 private:
1420 string * make_debug_string () FINAL OVERRIDE;
1421 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1422 enum precedence get_precedence () const FINAL OVERRIDE
1424 return PRECEDENCE_PRIMARY;
1427 private:
1428 vector_type *m_vector_type;
1429 auto_vec<rvalue *> m_elements;
1432 class unary_op : public rvalue
1434 public:
1435 unary_op (context *ctxt,
1436 location *loc,
1437 enum gcc_jit_unary_op op,
1438 type *result_type,
1439 rvalue *a)
1440 : rvalue (ctxt, loc, result_type),
1441 m_op (op),
1442 m_a (a)
1445 void replay_into (replayer *r) FINAL OVERRIDE;
1447 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1449 private:
1450 string * make_debug_string () FINAL OVERRIDE;
1451 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1452 enum precedence get_precedence () const FINAL OVERRIDE
1454 return PRECEDENCE_UNARY;
1457 private:
1458 enum gcc_jit_unary_op m_op;
1459 rvalue *m_a;
1462 class binary_op : public rvalue
1464 public:
1465 binary_op (context *ctxt,
1466 location *loc,
1467 enum gcc_jit_binary_op op,
1468 type *result_type,
1469 rvalue *a, rvalue *b)
1470 : rvalue (ctxt, loc, result_type),
1471 m_op (op),
1472 m_a (a),
1473 m_b (b) {}
1475 void replay_into (replayer *r) FINAL OVERRIDE;
1477 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1479 private:
1480 string * make_debug_string () FINAL OVERRIDE;
1481 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1482 enum precedence get_precedence () const FINAL OVERRIDE;
1484 private:
1485 enum gcc_jit_binary_op m_op;
1486 rvalue *m_a;
1487 rvalue *m_b;
1490 class comparison : public rvalue
1492 public:
1493 comparison (context *ctxt,
1494 location *loc,
1495 enum gcc_jit_comparison op,
1496 rvalue *a, rvalue *b)
1497 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_BOOL)),
1498 m_op (op),
1499 m_a (a),
1500 m_b (b)
1503 void replay_into (replayer *r) FINAL OVERRIDE;
1505 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1507 private:
1508 string * make_debug_string () FINAL OVERRIDE;
1509 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1510 enum precedence get_precedence () const FINAL OVERRIDE;
1512 private:
1513 enum gcc_jit_comparison m_op;
1514 rvalue *m_a;
1515 rvalue *m_b;
1518 class cast : public rvalue
1520 public:
1521 cast (context *ctxt,
1522 location *loc,
1523 rvalue *a,
1524 type *type_)
1525 : rvalue (ctxt, loc, type_),
1526 m_rvalue (a)
1529 void replay_into (replayer *r) FINAL OVERRIDE;
1531 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1533 private:
1534 string * make_debug_string () FINAL OVERRIDE;
1535 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1536 enum precedence get_precedence () const FINAL OVERRIDE
1538 return PRECEDENCE_CAST;
1541 private:
1542 rvalue *m_rvalue;
1545 class base_call : public rvalue
1547 public:
1548 base_call (context *ctxt,
1549 location *loc,
1550 type *type_,
1551 int numargs,
1552 rvalue **args);
1554 enum precedence get_precedence () const FINAL OVERRIDE
1556 return PRECEDENCE_POSTFIX;
1559 base_call *dyn_cast_base_call () FINAL OVERRIDE { return this; }
1561 void set_require_tail_call (bool require_tail_call)
1563 m_require_tail_call = require_tail_call;
1566 protected:
1567 void write_reproducer_tail_call (reproducer &r, const char *id);
1569 protected:
1570 auto_vec<rvalue *> m_args;
1571 bool m_require_tail_call;
1574 class call : public base_call
1576 public:
1577 call (context *ctxt,
1578 location *loc,
1579 function *func,
1580 int numargs,
1581 rvalue **args);
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;
1591 private:
1592 function *m_func;
1595 class call_through_ptr : public base_call
1597 public:
1598 call_through_ptr (context *ctxt,
1599 location *loc,
1600 rvalue *fn_ptr,
1601 int numargs,
1602 rvalue **args);
1604 void replay_into (replayer *r) FINAL OVERRIDE;
1606 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1608 private:
1609 string * make_debug_string () FINAL OVERRIDE;
1610 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1612 private:
1613 rvalue *m_fn_ptr;
1616 class array_access : public lvalue
1618 public:
1619 array_access (context *ctxt,
1620 location *loc,
1621 rvalue *ptr,
1622 rvalue *index)
1623 : lvalue (ctxt, loc, ptr->get_type ()->dereference ()),
1624 m_ptr (ptr),
1625 m_index (index)
1628 void replay_into (replayer *r) FINAL OVERRIDE;
1630 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1632 private:
1633 string * make_debug_string () FINAL OVERRIDE;
1634 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1635 enum precedence get_precedence () const FINAL OVERRIDE
1637 return PRECEDENCE_POSTFIX;
1640 private:
1641 rvalue *m_ptr;
1642 rvalue *m_index;
1645 class access_field_of_lvalue : public lvalue
1647 public:
1648 access_field_of_lvalue (context *ctxt,
1649 location *loc,
1650 lvalue *val,
1651 field *field)
1652 : lvalue (ctxt, loc, field->get_type ()),
1653 m_lvalue (val),
1654 m_field (field)
1657 void replay_into (replayer *r) FINAL OVERRIDE;
1659 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1661 private:
1662 string * make_debug_string () FINAL OVERRIDE;
1663 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1664 enum precedence get_precedence () const FINAL OVERRIDE
1666 return PRECEDENCE_POSTFIX;
1669 private:
1670 lvalue *m_lvalue;
1671 field *m_field;
1674 class access_field_rvalue : public rvalue
1676 public:
1677 access_field_rvalue (context *ctxt,
1678 location *loc,
1679 rvalue *val,
1680 field *field)
1681 : rvalue (ctxt, loc, field->get_type ()),
1682 m_rvalue (val),
1683 m_field (field)
1686 void replay_into (replayer *r) FINAL OVERRIDE;
1688 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1690 private:
1691 string * make_debug_string () FINAL OVERRIDE;
1692 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1693 enum precedence get_precedence () const FINAL OVERRIDE
1695 return PRECEDENCE_POSTFIX;
1698 private:
1699 rvalue *m_rvalue;
1700 field *m_field;
1703 class dereference_field_rvalue : public lvalue
1705 public:
1706 dereference_field_rvalue (context *ctxt,
1707 location *loc,
1708 rvalue *val,
1709 field *field)
1710 : lvalue (ctxt, loc, field->get_type ()),
1711 m_rvalue (val),
1712 m_field (field)
1715 void replay_into (replayer *r) FINAL OVERRIDE;
1717 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1719 private:
1720 string * make_debug_string () FINAL OVERRIDE;
1721 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1722 enum precedence get_precedence () const FINAL OVERRIDE
1724 return PRECEDENCE_POSTFIX;
1727 private:
1728 rvalue *m_rvalue;
1729 field *m_field;
1732 class dereference_rvalue : public lvalue
1734 public:
1735 dereference_rvalue (context *ctxt,
1736 location *loc,
1737 rvalue *val)
1738 : lvalue (ctxt, loc, val->get_type ()->dereference ()),
1739 m_rvalue (val) {}
1741 void replay_into (replayer *r) FINAL OVERRIDE;
1743 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1745 private:
1746 string * make_debug_string () FINAL OVERRIDE;
1747 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1748 enum precedence get_precedence () const FINAL OVERRIDE
1750 return PRECEDENCE_UNARY;
1753 private:
1754 rvalue *m_rvalue;
1757 class get_address_of_lvalue : public rvalue
1759 public:
1760 get_address_of_lvalue (context *ctxt,
1761 location *loc,
1762 lvalue *val)
1763 : rvalue (ctxt, loc, val->get_type ()->get_pointer ()),
1764 m_lvalue (val)
1767 void replay_into (replayer *r) FINAL OVERRIDE;
1769 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1771 private:
1772 string * make_debug_string () FINAL OVERRIDE;
1773 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1774 enum precedence get_precedence () const FINAL OVERRIDE
1776 return PRECEDENCE_UNARY;
1779 private:
1780 lvalue *m_lvalue;
1783 class function_pointer : public rvalue
1785 public:
1786 function_pointer (context *ctxt,
1787 location *loc,
1788 function *fn,
1789 type *type)
1790 : rvalue (ctxt, loc, type),
1791 m_fn (fn) {}
1793 void replay_into (replayer *r) FINAL OVERRIDE;
1795 void visit_children (rvalue_visitor *v) FINAL OVERRIDE;
1797 private:
1798 string * make_debug_string () FINAL OVERRIDE;
1799 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1800 enum precedence get_precedence () const FINAL OVERRIDE
1802 return PRECEDENCE_UNARY;
1805 private:
1806 function *m_fn;
1809 class local : public lvalue
1811 public:
1812 local (function *func, location *loc, type *type_, string *name)
1813 : lvalue (func->m_ctxt, loc, type_),
1814 m_func (func),
1815 m_name (name)
1817 set_scope (func);
1820 void replay_into (replayer *r) FINAL OVERRIDE;
1822 void visit_children (rvalue_visitor *) FINAL OVERRIDE {}
1824 void write_to_dump (dump &d) FINAL OVERRIDE;
1826 private:
1827 string * make_debug_string () FINAL OVERRIDE { return m_name; }
1828 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1829 enum precedence get_precedence () const FINAL OVERRIDE
1831 return PRECEDENCE_PRIMARY;
1834 private:
1835 function *m_func;
1836 string *m_name;
1839 class statement : public memento
1841 public:
1842 virtual vec <block *> get_successor_blocks () const;
1844 void write_to_dump (dump &d) FINAL OVERRIDE;
1846 block *get_block () const { return m_block; }
1847 location *get_loc () const { return m_loc; }
1849 protected:
1850 statement (block *b, location *loc)
1851 : memento (b->m_ctxt),
1852 m_block (b),
1853 m_loc (loc) {}
1855 playback::location *
1856 playback_location (replayer *r) const
1858 return ::gcc::jit::recording::playback_location (r, m_loc);
1861 private:
1862 block *m_block;
1863 location *m_loc;
1866 class eval : public statement
1868 public:
1869 eval (block *b,
1870 location *loc,
1871 rvalue *rvalue)
1872 : statement (b, loc),
1873 m_rvalue (rvalue) {}
1875 void replay_into (replayer *r) FINAL OVERRIDE;
1877 private:
1878 string * make_debug_string () FINAL OVERRIDE;
1879 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1881 private:
1882 rvalue *m_rvalue;
1885 class assignment : public statement
1887 public:
1888 assignment (block *b,
1889 location *loc,
1890 lvalue *lvalue,
1891 rvalue *rvalue)
1892 : statement (b, loc),
1893 m_lvalue (lvalue),
1894 m_rvalue (rvalue) {}
1896 void replay_into (replayer *r) FINAL OVERRIDE;
1898 private:
1899 string * make_debug_string () FINAL OVERRIDE;
1900 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1902 private:
1903 lvalue *m_lvalue;
1904 rvalue *m_rvalue;
1907 class assignment_op : public statement
1909 public:
1910 assignment_op (block *b,
1911 location *loc,
1912 lvalue *lvalue,
1913 enum gcc_jit_binary_op op,
1914 rvalue *rvalue)
1915 : statement (b, loc),
1916 m_lvalue (lvalue),
1917 m_op (op),
1918 m_rvalue (rvalue) {}
1920 void replay_into (replayer *r) FINAL OVERRIDE;
1922 private:
1923 string * make_debug_string () FINAL OVERRIDE;
1924 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1926 private:
1927 lvalue *m_lvalue;
1928 enum gcc_jit_binary_op m_op;
1929 rvalue *m_rvalue;
1932 class comment : public statement
1934 public:
1935 comment (block *b,
1936 location *loc,
1937 string *text)
1938 : statement (b, loc),
1939 m_text (text) {}
1941 void replay_into (replayer *r) FINAL OVERRIDE;
1943 private:
1944 string * make_debug_string () FINAL OVERRIDE;
1945 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1947 private:
1948 string *m_text;
1951 class conditional : public statement
1953 public:
1954 conditional (block *b,
1955 location *loc,
1956 rvalue *boolval,
1957 block *on_true,
1958 block *on_false)
1959 : statement (b, loc),
1960 m_boolval (boolval),
1961 m_on_true (on_true),
1962 m_on_false (on_false) {}
1964 void replay_into (replayer *r) FINAL OVERRIDE;
1966 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
1968 private:
1969 string * make_debug_string () FINAL OVERRIDE;
1970 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1972 private:
1973 rvalue *m_boolval;
1974 block *m_on_true;
1975 block *m_on_false;
1978 class jump : public statement
1980 public:
1981 jump (block *b,
1982 location *loc,
1983 block *target)
1984 : statement (b, loc),
1985 m_target (target) {}
1987 void replay_into (replayer *r) FINAL OVERRIDE;
1989 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
1991 private:
1992 string * make_debug_string () FINAL OVERRIDE;
1993 void write_reproducer (reproducer &r) FINAL OVERRIDE;
1995 private:
1996 block *m_target;
1999 class return_ : public statement
2001 public:
2002 return_ (block *b,
2003 location *loc,
2004 rvalue *rvalue)
2005 : statement (b, loc),
2006 m_rvalue (rvalue) {}
2008 void replay_into (replayer *r) FINAL OVERRIDE;
2010 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
2012 private:
2013 string * make_debug_string () FINAL OVERRIDE;
2014 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2016 private:
2017 rvalue *m_rvalue;
2020 class case_ : public memento
2022 public:
2023 case_ (context *ctxt,
2024 rvalue *min_value,
2025 rvalue *max_value,
2026 block *dest_block)
2027 : memento (ctxt),
2028 m_min_value (min_value),
2029 m_max_value (max_value),
2030 m_dest_block (dest_block)
2033 rvalue *get_min_value () const { return m_min_value; }
2034 rvalue *get_max_value () const { return m_max_value; }
2035 block *get_dest_block () const { return m_dest_block; }
2037 void replay_into (replayer *) FINAL OVERRIDE { /* empty */ }
2039 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2041 private:
2042 string * make_debug_string () FINAL OVERRIDE;
2044 private:
2045 rvalue *m_min_value;
2046 rvalue *m_max_value;
2047 block *m_dest_block;
2050 class switch_ : public statement
2052 public:
2053 switch_ (block *b,
2054 location *loc,
2055 rvalue *expr,
2056 block *default_block,
2057 int num_cases,
2058 case_ **cases);
2060 void replay_into (replayer *r) FINAL OVERRIDE;
2062 vec <block *> get_successor_blocks () const FINAL OVERRIDE;
2064 private:
2065 string * make_debug_string () FINAL OVERRIDE;
2066 void write_reproducer (reproducer &r) FINAL OVERRIDE;
2068 private:
2069 rvalue *m_expr;
2070 block *m_default_block;
2071 auto_vec <case_ *> m_cases;
2074 } // namespace gcc::jit::recording
2076 /* Create a recording::memento_of_new_rvalue_from_const instance and add
2077 it to this context's list of mementos.
2079 Implements the post-error-checking part of
2080 gcc_jit_context_new_rvalue_from_{int|long|double|ptr}. */
2082 template <typename HOST_TYPE>
2083 recording::rvalue *
2084 recording::context::new_rvalue_from_const (recording::type *type,
2085 HOST_TYPE value)
2087 recording::rvalue *result =
2088 new memento_of_new_rvalue_from_const <HOST_TYPE> (this, NULL, type, value);
2089 record (result);
2090 return result;
2093 } // namespace gcc::jit
2095 } // namespace gcc
2097 #endif /* JIT_RECORDING_H */