* xvasprintf.c: New file.
[official-gcc.git] / gcc / jit / jit-recording.h
blobb3e52dc0f4f498e387bd92430d81bce15f0574fc
1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2014 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"
26 namespace gcc {
28 namespace jit {
30 class result;
31 class dump;
33 /**********************************************************************
34 Recording.
35 **********************************************************************/
37 namespace recording {
39 playback::location *
40 playback_location (replayer *r, location *loc);
42 const char *
43 playback_string (string *str);
45 playback::block *
46 playback_block (block *b);
48 /* A recording of a call to gcc_jit_context_enable_dump. */
49 struct requested_dump
51 const char *m_dumpname;
52 char **m_out_ptr;
55 /* A JIT-compilation context. */
56 class context
58 public:
59 context (context *parent_ctxt);
60 ~context ();
62 builtins_manager *
63 get_builtins_manager ();
65 void record (memento *m);
66 void replay_into (replayer *r);
67 void disassociate_from_playback ();
69 string *
70 new_string (const char *text);
72 location *
73 new_location (const char *filename,
74 int line,
75 int column);
77 type *
78 get_type (enum gcc_jit_types type);
80 type *
81 get_int_type (int num_bytes, int is_signed);
83 type *
84 new_array_type (location *loc,
85 type *element_type,
86 int num_elements);
88 field *
89 new_field (location *loc,
90 type *type,
91 const char *name);
93 struct_ *
94 new_struct_type (location *loc,
95 const char *name);
97 union_ *
98 new_union_type (location *loc,
99 const char *name);
101 function_type *
102 new_function_type (type *return_type,
103 int num_params,
104 type **param_types,
105 int is_variadic);
107 type *
108 new_function_ptr_type (location *loc,
109 type *return_type,
110 int num_params,
111 type **param_types,
112 int is_variadic);
114 param *
115 new_param (location *loc,
116 type *type,
117 const char *name);
119 function *
120 new_function (location *loc,
121 enum gcc_jit_function_kind kind,
122 type *return_type,
123 const char *name,
124 int num_params,
125 param **params,
126 int is_variadic,
127 enum built_in_function builtin_id);
129 function *
130 get_builtin_function (const char *name);
132 lvalue *
133 new_global (location *loc,
134 type *type,
135 const char *name);
137 rvalue *
138 new_rvalue_from_int (type *numeric_type,
139 int value);
141 rvalue *
142 new_rvalue_from_double (type *numeric_type,
143 double value);
145 rvalue *
146 new_rvalue_from_ptr (type *pointer_type,
147 void *value);
149 rvalue *
150 new_string_literal (const char *value);
152 rvalue *
153 new_unary_op (location *loc,
154 enum gcc_jit_unary_op op,
155 type *result_type,
156 rvalue *a);
158 rvalue *
159 new_binary_op (location *loc,
160 enum gcc_jit_binary_op op,
161 type *result_type,
162 rvalue *a, rvalue *b);
164 rvalue *
165 new_comparison (location *loc,
166 enum gcc_jit_comparison op,
167 rvalue *a, rvalue *b);
169 rvalue *
170 new_call (location *loc,
171 function *func,
172 int numargs, rvalue **args);
174 rvalue *
175 new_call_through_ptr (location *loc,
176 rvalue *fn_ptr,
177 int numargs, rvalue **args);
179 rvalue *
180 new_cast (location *loc,
181 rvalue *expr,
182 type *type_);
184 lvalue *
185 new_array_access (location *loc,
186 rvalue *ptr,
187 rvalue *index);
189 void
190 set_str_option (enum gcc_jit_str_option opt,
191 const char *value);
193 void
194 set_int_option (enum gcc_jit_int_option opt,
195 int value);
197 void
198 set_bool_option (enum gcc_jit_bool_option opt,
199 int value);
201 void
202 enable_dump (const char *dumpname,
203 char **out_ptr);
205 const char *
206 get_str_option (enum gcc_jit_str_option opt) const
208 return m_str_options[opt];
212 get_int_option (enum gcc_jit_int_option opt) const
214 return m_int_options[opt];
218 get_bool_option (enum gcc_jit_bool_option opt) const
220 return m_bool_options[opt];
223 result *
224 compile ();
226 void
227 add_error (location *loc, const char *fmt, ...)
228 GNU_PRINTF(3, 4);
230 void
231 add_error_va (location *loc, const char *fmt, va_list ap)
232 GNU_PRINTF(3, 0);
234 const char *
235 get_first_error () const;
237 bool errors_occurred () const
239 if (m_parent_ctxt)
240 if (m_parent_ctxt->errors_occurred ())
241 return true;
242 return m_error_count;
245 type *get_opaque_FILE_type ();
247 void dump_to_file (const char *path, bool update_locations);
249 void
250 get_all_requested_dumps (vec <recording::requested_dump> *out);
252 private:
253 void validate ();
255 private:
256 context *m_parent_ctxt;
258 int m_error_count;
260 char *m_first_error_str;
261 bool m_owns_first_error_str;
263 char *m_str_options[GCC_JIT_NUM_STR_OPTIONS];
264 int m_int_options[GCC_JIT_NUM_INT_OPTIONS];
265 bool m_bool_options[GCC_JIT_NUM_BOOL_OPTIONS];
267 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
268 auto_vec<requested_dump> m_requested_dumps;
270 /* Recorded API usage. */
271 auto_vec<memento *> m_mementos;
273 /* Specific recordings, for use by dump_to_file. */
274 auto_vec<compound_type *> m_compound_types;
275 auto_vec<function *> m_functions;
277 type *m_basic_types[NUM_GCC_JIT_TYPES];
278 type *m_FILE_type;
280 builtins_manager *m_builtins_manager; // lazily created
284 /* An object with lifetime managed by the context i.e.
285 it lives until the context is released, at which
286 point it itself is cleaned up. */
288 class memento
290 public:
291 virtual ~memento () {}
293 /* Hook for replaying this. */
294 virtual void replay_into (replayer *r) = 0;
296 void set_playback_obj (void *obj) { m_playback_obj = obj; }
299 /* Get the context that owns this object.
301 Implements the post-error-checking part of
302 gcc_jit_object_get_context. */
303 context *get_context () { return m_ctxt; }
305 memento *
306 as_object () { return this; }
308 /* Debugging hook, for use in generating error messages etc.
309 Implements the post-error-checking part of
310 gcc_jit_object_get_debug_string. */
311 const char *
312 get_debug_string ();
314 virtual void write_to_dump (dump &d);
316 protected:
317 memento (context *ctxt)
318 : m_ctxt (ctxt),
319 m_playback_obj (NULL),
320 m_debug_string (NULL)
322 gcc_assert (ctxt);
325 string *new_string (const char *text) { return m_ctxt->new_string (text); }
327 private:
328 virtual string * make_debug_string () = 0;
330 public:
331 context *m_ctxt;
333 protected:
334 void *m_playback_obj;
336 private:
337 string *m_debug_string;
340 /* or just use std::string? */
341 class string : public memento
343 public:
344 string (context *ctxt, const char *text);
345 ~string ();
347 const char *c_str () { return m_buffer; }
349 static string * from_printf (context *ctxt, const char *fmt, ...)
350 GNU_PRINTF(2, 3);
352 void replay_into (replayer *) {}
354 private:
355 string * make_debug_string ();
357 private:
358 size_t m_len;
359 char *m_buffer;
362 class location : public memento
364 public:
365 location (context *ctxt, string *filename, int line, int column)
366 : memento (ctxt),
367 m_filename (filename),
368 m_line (line),
369 m_column (column)
372 void replay_into (replayer *r);
374 playback::location *
375 playback_location (replayer *r)
377 /* Normally during playback, we can walk forwards through the list of
378 recording objects, playing them back. The ordering of recording
379 ensures that everything that a recording object refers to has
380 already been played back, so we can simply look up the relevant
381 m_playback_obj.
383 Locations are an exception, due to the "write_to_dump" method of
384 recording::statement. This method can set a new location on a
385 statement after the statement is created, and thus the location
386 appears in the context's memento list *after* the statement that
387 refers to it.
389 In such circumstances, the statement is replayed *before* the location,
390 when the latter doesn't yet have a playback object.
392 Hence we need to ensure that locations have playback objects. */
393 if (!m_playback_obj)
395 replay_into (r);
397 gcc_assert (m_playback_obj);
398 return static_cast <playback::location *> (m_playback_obj);
401 private:
402 string * make_debug_string ();
404 private:
405 string *m_filename;
406 int m_line;
407 int m_column;
410 class type : public memento
412 public:
413 type *get_pointer ();
414 type *get_const ();
415 type *get_volatile ();
417 /* Get the type obtained when dereferencing this type.
419 This will return NULL if it's not valid to dereference this type.
420 The caller is responsible for setting an error. */
421 virtual type *dereference () = 0;
423 /* Dynamic casts. */
424 virtual function_type *dyn_cast_function_type () { return NULL; }
425 virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
426 virtual struct_ *dyn_cast_struct () { return NULL; }
428 /* Is it typesafe to copy to this type from rtype? */
429 virtual bool accepts_writes_from (type *rtype)
431 gcc_assert (rtype);
432 return this == rtype->unqualified ();
435 /* Strip off "const" etc */
436 virtual type *unqualified ()
438 return this;
441 virtual bool is_int () const = 0;
442 virtual bool is_float () const = 0;
443 virtual bool is_bool () const = 0;
444 virtual type *is_pointer () = 0;
445 virtual type *is_array () = 0;
447 bool is_numeric () const
449 return is_int () || is_float () || is_bool ();
452 playback::type *
453 playback_type ()
455 return static_cast <playback::type *> (m_playback_obj);
458 protected:
459 type (context *ctxt)
460 : memento (ctxt),
461 m_pointer_to_this_type (NULL)
464 private:
465 type *m_pointer_to_this_type;
468 /* Result of "gcc_jit_type_get_type". */
469 class memento_of_get_type : public type
471 public:
472 memento_of_get_type (context *ctxt,
473 enum gcc_jit_types kind)
474 : type (ctxt),
475 m_kind (kind) {}
477 type *dereference ();
479 bool accepts_writes_from (type *rtype)
481 if (m_kind == GCC_JIT_TYPE_VOID_PTR)
482 if (rtype->is_pointer ())
484 /* LHS (this) is type (void *), and the RHS is a pointer:
485 accept it: */
486 return true;
489 return type::accepts_writes_from (rtype);
492 bool is_int () const;
493 bool is_float () const;
494 bool is_bool () const;
495 type *is_pointer () { return dereference (); }
496 type *is_array () { return NULL; }
498 public:
499 void replay_into (replayer *r);
501 private:
502 string * make_debug_string ();
504 private:
505 enum gcc_jit_types m_kind;
508 /* Result of "gcc_jit_type_get_pointer". */
509 class memento_of_get_pointer : public type
511 public:
512 memento_of_get_pointer (type *other_type)
513 : type (other_type->m_ctxt),
514 m_other_type (other_type) {}
516 type *dereference () { return m_other_type; }
518 bool accepts_writes_from (type *rtype);
520 void replay_into (replayer *r);
522 bool is_int () const { return false; }
523 bool is_float () const { return false; }
524 bool is_bool () const { return false; }
525 type *is_pointer () { return m_other_type; }
526 type *is_array () { return NULL; }
528 private:
529 string * make_debug_string ();
531 private:
532 type *m_other_type;
535 /* Result of "gcc_jit_type_get_const". */
536 class memento_of_get_const : public type
538 public:
539 memento_of_get_const (type *other_type)
540 : type (other_type->m_ctxt),
541 m_other_type (other_type) {}
543 type *dereference () { return m_other_type->dereference (); }
545 bool accepts_writes_from (type */*rtype*/)
547 /* Can't write to a "const". */
548 return false;
551 /* Strip off the "const", giving the underlying type. */
552 type *unqualified () { return m_other_type; }
554 bool is_int () const { return m_other_type->is_int (); }
555 bool is_float () const { return m_other_type->is_float (); }
556 bool is_bool () const { return m_other_type->is_bool (); }
557 type *is_pointer () { return m_other_type->is_pointer (); }
558 type *is_array () { return m_other_type->is_array (); }
560 void replay_into (replayer *);
562 private:
563 string * make_debug_string ();
565 private:
566 type *m_other_type;
569 /* Result of "gcc_jit_type_get_volatile". */
570 class memento_of_get_volatile : public type
572 public:
573 memento_of_get_volatile (type *other_type)
574 : type (other_type->m_ctxt),
575 m_other_type (other_type) {}
577 type *dereference () { return m_other_type->dereference (); }
579 /* Strip off the "volatile", giving the underlying type. */
580 type *unqualified () { return m_other_type; }
582 bool is_int () const { return m_other_type->is_int (); }
583 bool is_float () const { return m_other_type->is_float (); }
584 bool is_bool () const { return m_other_type->is_bool (); }
585 type *is_pointer () { return m_other_type->is_pointer (); }
586 type *is_array () { return m_other_type->is_array (); }
588 void replay_into (replayer *);
590 private:
591 string * make_debug_string ();
593 private:
594 type *m_other_type;
597 class array_type : public type
599 public:
600 array_type (context *ctxt,
601 location *loc,
602 type *element_type,
603 int num_elements)
604 : type (ctxt),
605 m_loc (loc),
606 m_element_type (element_type),
607 m_num_elements (num_elements)
610 type *dereference ();
612 bool is_int () const { return false; }
613 bool is_float () const { return false; }
614 bool is_bool () const { return false; }
615 type *is_pointer () { return NULL; }
616 type *is_array () { return m_element_type; }
618 void replay_into (replayer *);
620 private:
621 string * make_debug_string ();
623 private:
624 location *m_loc;
625 type *m_element_type;
626 int m_num_elements;
629 class function_type : public type
631 public:
632 function_type (context *ctxt,
633 type *return_type,
634 int num_params,
635 type **param_types,
636 int is_variadic);
638 type *dereference ();
639 function_type *dyn_cast_function_type () { return this; }
640 function_type *as_a_function_type () { return this; }
642 bool is_int () const { return false; }
643 bool is_float () const { return false; }
644 bool is_bool () const { return false; }
645 type *is_pointer () { return NULL; }
646 type *is_array () { return NULL; }
648 void replay_into (replayer *);
650 type * get_return_type () const { return m_return_type; }
651 const vec<type *> &get_param_types () const { return m_param_types; }
652 int is_variadic () const { return m_is_variadic; }
654 string * make_debug_string_with_ptr ();
656 private:
657 string * make_debug_string ();
658 string * make_debug_string_with (const char *);
660 private:
661 type *m_return_type;
662 auto_vec<type *> m_param_types;
663 int m_is_variadic;
666 class field : public memento
668 public:
669 field (context *ctxt,
670 location *loc,
671 type *type,
672 string *name)
673 : memento (ctxt),
674 m_loc (loc),
675 m_type (type),
676 m_name (name),
677 m_container (NULL)
680 type * get_type () const { return m_type; }
682 compound_type * get_container () const { return m_container; }
683 void set_container (compound_type *c) { m_container = c; }
685 void replay_into (replayer *);
687 void write_to_dump (dump &d);
689 playback::field *
690 playback_field () const
692 return static_cast <playback::field *> (m_playback_obj);
695 private:
696 string * make_debug_string ();
698 private:
699 location *m_loc;
700 type *m_type;
701 string *m_name;
702 compound_type *m_container;
705 /* Base class for struct_ and union_ */
706 class compound_type : public type
708 public:
709 compound_type (context *ctxt,
710 location *loc,
711 string *name);
713 string *get_name () const { return m_name; }
714 location *get_loc () const { return m_loc; }
715 fields * get_fields () { return m_fields; }
717 void
718 set_fields (location *loc,
719 int num_fields,
720 field **fields);
722 type *dereference ();
724 bool is_int () const { return false; }
725 bool is_float () const { return false; }
726 bool is_bool () const { return false; }
727 type *is_pointer () { return NULL; }
728 type *is_array () { return NULL; }
730 playback::compound_type *
731 playback_compound_type ()
733 return static_cast <playback::compound_type *> (m_playback_obj);
736 private:
737 location *m_loc;
738 string *m_name;
739 fields *m_fields;
742 class struct_ : public compound_type
744 public:
745 struct_ (context *ctxt,
746 location *loc,
747 string *name);
749 struct_ *dyn_cast_struct () { return this; }
751 type *
752 as_type () { return this; }
754 void replay_into (replayer *r);
756 private:
757 string * make_debug_string ();
761 // memento of struct_::set_fields
762 class fields : public memento
764 public:
765 fields (compound_type *struct_or_union,
766 int num_fields,
767 field **fields);
769 void replay_into (replayer *r);
771 void write_to_dump (dump &d);
773 private:
774 string * make_debug_string ();
776 private:
777 compound_type *m_struct_or_union;
778 auto_vec<field *> m_fields;
781 class union_ : public compound_type
783 public:
784 union_ (context *ctxt,
785 location *loc,
786 string *name);
788 void replay_into (replayer *r);
790 private:
791 string * make_debug_string ();
793 private:
794 location *m_loc;
795 string *m_name;
796 fields *m_fields;
799 class rvalue : public memento
801 public:
802 rvalue (context *ctxt,
803 location *loc,
804 type *type_)
805 : memento (ctxt),
806 m_loc (loc),
807 m_type (type_)
809 gcc_assert (type_);
812 /* Get the recording::type of this rvalue.
814 Implements the post-error-checking part of
815 gcc_jit_rvalue_get_type. */
816 type * get_type () const { return m_type; }
818 playback::rvalue *
819 playback_rvalue () const
821 return static_cast <playback::rvalue *> (m_playback_obj);
823 rvalue *
824 access_field (location *loc,
825 field *field);
827 lvalue *
828 dereference_field (location *loc,
829 field *field);
831 lvalue *
832 dereference (location *loc);
834 protected:
835 location *m_loc;
836 type *m_type;
839 class lvalue : public rvalue
841 public:
842 lvalue (context *ctxt,
843 location *loc,
844 type *type_)
845 : rvalue (ctxt, loc, type_)
848 playback::lvalue *
849 playback_lvalue () const
851 return static_cast <playback::lvalue *> (m_playback_obj);
854 lvalue *
855 access_field (location *loc,
856 field *field);
858 rvalue *
859 get_address (location *loc);
861 rvalue *
862 as_rvalue () { return this; }
865 class param : public lvalue
867 public:
868 param (context *ctxt,
869 location *loc,
870 type *type,
871 string *name)
872 : lvalue (ctxt, loc, type),
873 m_name (name) {}
875 lvalue *
876 as_lvalue () { return this; }
878 void replay_into (replayer *r);
880 playback::param *
881 playback_param () const
883 return static_cast <playback::param *> (m_playback_obj);
886 private:
887 string * make_debug_string () { return m_name; }
889 private:
890 string *m_name;
893 class function : public memento
895 public:
896 function (context *ctxt,
897 location *loc,
898 enum gcc_jit_function_kind kind,
899 type *return_type,
900 string *name,
901 int num_params,
902 param **params,
903 int is_variadic,
904 enum built_in_function builtin_id);
906 void replay_into (replayer *r);
908 playback::function *
909 playback_function () const
911 return static_cast <playback::function *> (m_playback_obj);
914 enum gcc_jit_function_kind get_kind () const { return m_kind; }
916 lvalue *
917 new_local (location *loc,
918 type *type,
919 const char *name);
921 block*
922 new_block (const char *name);
924 type *get_return_type () const { return m_return_type; }
925 string * get_name () const { return m_name; }
926 const vec<param *> &get_params () const { return m_params; }
928 /* Get the given param by index.
929 Implements the post-error-checking part of
930 gcc_jit_function_get_param. */
931 param *get_param (int i) const { return m_params[i]; }
933 bool is_variadic () const { return m_is_variadic; }
935 void write_to_dump (dump &d);
937 void validate ();
939 void dump_to_dot (const char *path);
941 private:
942 string * make_debug_string ();
944 private:
945 location *m_loc;
946 enum gcc_jit_function_kind m_kind;
947 type *m_return_type;
948 string *m_name;
949 auto_vec<param *> m_params;
950 int m_is_variadic;
951 enum built_in_function m_builtin_id;
952 auto_vec<local *> m_locals;
953 auto_vec<block *> m_blocks;
956 class block : public memento
958 public:
959 block (function *func, int index, string *name)
960 : memento (func->m_ctxt),
961 m_func (func),
962 m_index (index),
963 m_name (name),
964 m_statements (),
965 m_has_been_terminated (false),
966 m_is_reachable (false)
970 /* Get the recording::function containing this block.
971 Implements the post-error-checking part of
972 gcc_jit_block_get_function. */
973 function *get_function () { return m_func; }
975 bool has_been_terminated () { return m_has_been_terminated; }
976 bool is_reachable () { return m_is_reachable; }
978 void
979 add_eval (location *loc,
980 rvalue *rvalue);
982 void
983 add_assignment (location *loc,
984 lvalue *lvalue,
985 rvalue *rvalue);
987 void
988 add_assignment_op (location *loc,
989 lvalue *lvalue,
990 enum gcc_jit_binary_op op,
991 rvalue *rvalue);
993 void
994 add_comment (location *loc,
995 const char *text);
997 void
998 end_with_conditional (location *loc,
999 rvalue *boolval,
1000 block *on_true,
1001 block *on_false);
1003 void
1004 end_with_jump (location *loc,
1005 block *target);
1007 void
1008 end_with_return (location *loc,
1009 rvalue *rvalue);
1011 playback::block *
1012 playback_block () const
1014 return static_cast <playback::block *> (m_playback_obj);
1017 void write_to_dump (dump &d);
1019 bool validate ();
1021 location *get_loc () const;
1023 statement *get_first_statement () const;
1024 statement *get_last_statement () const;
1026 int get_successor_blocks (block **next1, block **next2) const;
1028 private:
1029 string * make_debug_string ();
1031 void replay_into (replayer *r);
1033 void dump_to_dot (pretty_printer *pp);
1034 void dump_edges_to_dot (pretty_printer *pp);
1036 private:
1037 function *m_func;
1038 int m_index;
1039 string *m_name;
1040 auto_vec<statement *> m_statements;
1041 bool m_has_been_terminated;
1042 bool m_is_reachable;
1044 friend class function;
1047 class global : public lvalue
1049 public:
1050 global (context *ctxt,
1051 location *loc,
1052 type *type,
1053 string *name)
1054 : lvalue (ctxt, loc, type),
1055 m_name (name)
1058 void replay_into (replayer *);
1060 private:
1061 string * make_debug_string () { return m_name; }
1063 private:
1064 string *m_name;
1067 class memento_of_new_rvalue_from_int : public rvalue
1069 public:
1070 memento_of_new_rvalue_from_int (context *ctxt,
1071 location *loc,
1072 type *numeric_type,
1073 int value)
1074 : rvalue (ctxt, loc, numeric_type),
1075 m_value (value) {}
1077 void replay_into (replayer *r);
1079 private:
1080 string * make_debug_string ();
1082 private:
1083 int m_value;
1086 class memento_of_new_rvalue_from_double : public rvalue
1088 public:
1089 memento_of_new_rvalue_from_double (context *ctxt,
1090 location *loc,
1091 type *numeric_type,
1092 double value)
1093 : rvalue (ctxt, loc, numeric_type),
1094 m_value (value)
1097 void replay_into (replayer *);
1099 private:
1100 string * make_debug_string ();
1102 private:
1103 double m_value;
1106 class memento_of_new_rvalue_from_ptr : public rvalue
1108 public:
1109 memento_of_new_rvalue_from_ptr (context *ctxt,
1110 location *loc,
1111 type *pointer_type,
1112 void *value)
1113 : rvalue (ctxt, loc, pointer_type),
1114 m_value (value)
1117 void replay_into (replayer *);
1119 private:
1120 string * make_debug_string ();
1122 private:
1123 void *m_value;
1126 class memento_of_new_string_literal : public rvalue
1128 public:
1129 memento_of_new_string_literal (context *ctxt,
1130 location *loc,
1131 string *value)
1132 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR)),
1133 m_value (value) {}
1135 void replay_into (replayer *r);
1137 private:
1138 string * make_debug_string ();
1140 private:
1141 string *m_value;
1144 class unary_op : public rvalue
1146 public:
1147 unary_op (context *ctxt,
1148 location *loc,
1149 enum gcc_jit_unary_op op,
1150 type *result_type,
1151 rvalue *a)
1152 : rvalue (ctxt, loc, result_type),
1153 m_op (op),
1154 m_a (a)
1157 void replay_into (replayer *r);
1159 private:
1160 string * make_debug_string ();
1162 private:
1163 enum gcc_jit_unary_op m_op;
1164 rvalue *m_a;
1167 class binary_op : public rvalue
1169 public:
1170 binary_op (context *ctxt,
1171 location *loc,
1172 enum gcc_jit_binary_op op,
1173 type *result_type,
1174 rvalue *a, rvalue *b)
1175 : rvalue (ctxt, loc, result_type),
1176 m_op (op),
1177 m_a (a),
1178 m_b (b) {}
1180 void replay_into (replayer *r);
1182 private:
1183 string * make_debug_string ();
1185 private:
1186 enum gcc_jit_binary_op m_op;
1187 rvalue *m_a;
1188 rvalue *m_b;
1191 class comparison : public rvalue
1193 public:
1194 comparison (context *ctxt,
1195 location *loc,
1196 enum gcc_jit_comparison op,
1197 rvalue *a, rvalue *b)
1198 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_BOOL)),
1199 m_op (op),
1200 m_a (a),
1201 m_b (b)
1204 void replay_into (replayer *r);
1206 private:
1207 string * make_debug_string ();
1209 private:
1210 enum gcc_jit_comparison m_op;
1211 rvalue *m_a;
1212 rvalue *m_b;
1215 class cast : public rvalue
1217 public:
1218 cast (context *ctxt,
1219 location *loc,
1220 rvalue *a,
1221 type *type_)
1222 : rvalue (ctxt, loc, type_),
1223 m_rvalue (a)
1226 void replay_into (replayer *r);
1228 private:
1229 string * make_debug_string ();
1231 private:
1232 rvalue *m_rvalue;
1235 class call : public rvalue
1237 public:
1238 call (context *ctxt,
1239 location *loc,
1240 function *func,
1241 int numargs,
1242 rvalue **args);
1244 void replay_into (replayer *r);
1246 private:
1247 string * make_debug_string ();
1249 private:
1250 function *m_func;
1251 auto_vec<rvalue *> m_args;
1254 class call_through_ptr : public rvalue
1256 public:
1257 call_through_ptr (context *ctxt,
1258 location *loc,
1259 rvalue *fn_ptr,
1260 int numargs,
1261 rvalue **args);
1263 void replay_into (replayer *r);
1265 private:
1266 string * make_debug_string ();
1268 private:
1269 rvalue *m_fn_ptr;
1270 auto_vec<rvalue *> m_args;
1273 class array_access : public lvalue
1275 public:
1276 array_access (context *ctxt,
1277 location *loc,
1278 rvalue *ptr,
1279 rvalue *index)
1280 : lvalue (ctxt, loc, ptr->get_type ()->dereference ()),
1281 m_ptr (ptr),
1282 m_index (index)
1285 void replay_into (replayer *r);
1287 private:
1288 string * make_debug_string ();
1290 private:
1291 rvalue *m_ptr;
1292 rvalue *m_index;
1295 class access_field_of_lvalue : public lvalue
1297 public:
1298 access_field_of_lvalue (context *ctxt,
1299 location *loc,
1300 lvalue *val,
1301 field *field)
1302 : lvalue (ctxt, loc, field->get_type ()),
1303 m_lvalue (val),
1304 m_field (field)
1307 void replay_into (replayer *r);
1309 private:
1310 string * make_debug_string ();
1312 private:
1313 lvalue *m_lvalue;
1314 field *m_field;
1317 class access_field_rvalue : public rvalue
1319 public:
1320 access_field_rvalue (context *ctxt,
1321 location *loc,
1322 rvalue *val,
1323 field *field)
1324 : rvalue (ctxt, loc, field->get_type ()),
1325 m_rvalue (val),
1326 m_field (field)
1329 void replay_into (replayer *r);
1331 private:
1332 string * make_debug_string ();
1334 private:
1335 rvalue *m_rvalue;
1336 field *m_field;
1339 class dereference_field_rvalue : public lvalue
1341 public:
1342 dereference_field_rvalue (context *ctxt,
1343 location *loc,
1344 rvalue *val,
1345 field *field)
1346 : lvalue (ctxt, loc, field->get_type ()),
1347 m_rvalue (val),
1348 m_field (field)
1351 void replay_into (replayer *r);
1353 private:
1354 string * make_debug_string ();
1356 private:
1357 rvalue *m_rvalue;
1358 field *m_field;
1361 class dereference_rvalue : public lvalue
1363 public:
1364 dereference_rvalue (context *ctxt,
1365 location *loc,
1366 rvalue *val)
1367 : lvalue (ctxt, loc, val->get_type ()->dereference ()),
1368 m_rvalue (val) {}
1370 void replay_into (replayer *r);
1372 private:
1373 string * make_debug_string ();
1375 private:
1376 rvalue *m_rvalue;
1379 class get_address_of_lvalue : public rvalue
1381 public:
1382 get_address_of_lvalue (context *ctxt,
1383 location *loc,
1384 lvalue *val)
1385 : rvalue (ctxt, loc, val->get_type ()->get_pointer ()),
1386 m_lvalue (val)
1389 void replay_into (replayer *r);
1391 private:
1392 string * make_debug_string ();
1394 private:
1395 lvalue *m_lvalue;
1398 class local : public lvalue
1400 public:
1401 local (function *func, location *loc, type *type_, string *name)
1402 : lvalue (func->m_ctxt, loc, type_),
1403 m_func (func),
1404 m_name (name) {}
1406 void replay_into (replayer *r);
1408 void write_to_dump (dump &d);
1410 private:
1411 string * make_debug_string () { return m_name; }
1413 private:
1414 function *m_func;
1415 string *m_name;
1418 class statement : public memento
1420 public:
1421 virtual int get_successor_blocks (block **out_next1,
1422 block **out_next2) const;
1424 void write_to_dump (dump &d);
1426 location *get_loc () const { return m_loc; }
1428 protected:
1429 statement (block *b, location *loc)
1430 : memento (b->m_ctxt),
1431 m_block (b),
1432 m_loc (loc) {}
1434 block *get_block () const { return m_block; }
1436 playback::location *
1437 playback_location (replayer *r) const
1439 return ::gcc::jit::recording::playback_location (r, m_loc);
1442 private:
1443 block *m_block;
1444 location *m_loc;
1447 class eval : public statement
1449 public:
1450 eval (block *b,
1451 location *loc,
1452 rvalue *rvalue)
1453 : statement (b, loc),
1454 m_rvalue (rvalue) {}
1456 void replay_into (replayer *r);
1458 private:
1459 string * make_debug_string ();
1461 private:
1462 rvalue *m_rvalue;
1465 class assignment : public statement
1467 public:
1468 assignment (block *b,
1469 location *loc,
1470 lvalue *lvalue,
1471 rvalue *rvalue)
1472 : statement (b, loc),
1473 m_lvalue (lvalue),
1474 m_rvalue (rvalue) {}
1476 void replay_into (replayer *r);
1478 private:
1479 string * make_debug_string ();
1481 private:
1482 lvalue *m_lvalue;
1483 rvalue *m_rvalue;
1486 class assignment_op : public statement
1488 public:
1489 assignment_op (block *b,
1490 location *loc,
1491 lvalue *lvalue,
1492 enum gcc_jit_binary_op op,
1493 rvalue *rvalue)
1494 : statement (b, loc),
1495 m_lvalue (lvalue),
1496 m_op (op),
1497 m_rvalue (rvalue) {}
1499 void replay_into (replayer *r);
1501 private:
1502 string * make_debug_string ();
1504 private:
1505 lvalue *m_lvalue;
1506 enum gcc_jit_binary_op m_op;
1507 rvalue *m_rvalue;
1510 class comment : public statement
1512 public:
1513 comment (block *b,
1514 location *loc,
1515 string *text)
1516 : statement (b, loc),
1517 m_text (text) {}
1519 void replay_into (replayer *r);
1521 private:
1522 string * make_debug_string ();
1524 private:
1525 string *m_text;
1528 class conditional : public statement
1530 public:
1531 conditional (block *b,
1532 location *loc,
1533 rvalue *boolval,
1534 block *on_true,
1535 block *on_false)
1536 : statement (b, loc),
1537 m_boolval (boolval),
1538 m_on_true (on_true),
1539 m_on_false (on_false) {}
1541 void replay_into (replayer *r);
1543 int get_successor_blocks (block **out_next1,
1544 block **out_next2) const;
1546 private:
1547 string * make_debug_string ();
1549 private:
1550 rvalue *m_boolval;
1551 block *m_on_true;
1552 block *m_on_false;
1555 class jump : public statement
1557 public:
1558 jump (block *b,
1559 location *loc,
1560 block *target)
1561 : statement (b, loc),
1562 m_target (target) {}
1564 void replay_into (replayer *r);
1566 int get_successor_blocks (block **out_next1,
1567 block **out_next2) const;
1569 private:
1570 string * make_debug_string ();
1572 private:
1573 block *m_target;
1576 class return_ : public statement
1578 public:
1579 return_ (block *b,
1580 location *loc,
1581 rvalue *rvalue)
1582 : statement (b, loc),
1583 m_rvalue (rvalue) {}
1585 void replay_into (replayer *r);
1587 int get_successor_blocks (block **out_next1,
1588 block **out_next2) const;
1590 private:
1591 string * make_debug_string ();
1593 private:
1594 rvalue *m_rvalue;
1597 } // namespace gcc::jit::recording
1599 } // namespace gcc::jit
1601 } // namespace gcc
1603 #endif /* JIT_RECORDING_H */