jit: New API entrypoint: gcc_jit_context_get_last_error
[official-gcc.git] / gcc / jit / jit-recording.h
blob94179938d414d0077f4ea15dbc40bfee436b0f59
1 /* Internals of libgccjit: classes for recording calls made to the JIT API.
2 Copyright (C) 2013-2015 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 namespace gcc {
29 namespace jit {
31 class result;
32 class dump;
34 /**********************************************************************
35 Recording.
36 **********************************************************************/
38 namespace recording {
40 playback::location *
41 playback_location (replayer *r, location *loc);
43 const char *
44 playback_string (string *str);
46 playback::block *
47 playback_block (block *b);
49 /* A recording of a call to gcc_jit_context_enable_dump. */
50 struct requested_dump
52 const char *m_dumpname;
53 char **m_out_ptr;
56 /* A JIT-compilation context. */
57 class context : public log_user
59 public:
60 context (context *parent_ctxt);
61 ~context ();
63 builtins_manager *
64 get_builtins_manager ();
66 void record (memento *m);
67 void replay_into (replayer *r);
68 void disassociate_from_playback ();
70 string *
71 new_string (const char *text);
73 location *
74 new_location (const char *filename,
75 int line,
76 int column);
78 type *
79 get_type (enum gcc_jit_types type);
81 type *
82 get_int_type (int num_bytes, int is_signed);
84 type *
85 new_array_type (location *loc,
86 type *element_type,
87 int num_elements);
89 field *
90 new_field (location *loc,
91 type *type,
92 const char *name);
94 struct_ *
95 new_struct_type (location *loc,
96 const char *name);
98 union_ *
99 new_union_type (location *loc,
100 const char *name);
102 function_type *
103 new_function_type (type *return_type,
104 int num_params,
105 type **param_types,
106 int is_variadic);
108 type *
109 new_function_ptr_type (location *loc,
110 type *return_type,
111 int num_params,
112 type **param_types,
113 int is_variadic);
115 param *
116 new_param (location *loc,
117 type *type,
118 const char *name);
120 function *
121 new_function (location *loc,
122 enum gcc_jit_function_kind kind,
123 type *return_type,
124 const char *name,
125 int num_params,
126 param **params,
127 int is_variadic,
128 enum built_in_function builtin_id);
130 function *
131 get_builtin_function (const char *name);
133 lvalue *
134 new_global (location *loc,
135 type *type,
136 const char *name);
138 rvalue *
139 new_rvalue_from_int (type *numeric_type,
140 int value);
142 rvalue *
143 new_rvalue_from_double (type *numeric_type,
144 double value);
146 rvalue *
147 new_rvalue_from_ptr (type *pointer_type,
148 void *value);
150 rvalue *
151 new_string_literal (const char *value);
153 rvalue *
154 new_unary_op (location *loc,
155 enum gcc_jit_unary_op op,
156 type *result_type,
157 rvalue *a);
159 rvalue *
160 new_binary_op (location *loc,
161 enum gcc_jit_binary_op op,
162 type *result_type,
163 rvalue *a, rvalue *b);
165 rvalue *
166 new_comparison (location *loc,
167 enum gcc_jit_comparison op,
168 rvalue *a, rvalue *b);
170 rvalue *
171 new_call (location *loc,
172 function *func,
173 int numargs, rvalue **args);
175 rvalue *
176 new_call_through_ptr (location *loc,
177 rvalue *fn_ptr,
178 int numargs, rvalue **args);
180 rvalue *
181 new_cast (location *loc,
182 rvalue *expr,
183 type *type_);
185 lvalue *
186 new_array_access (location *loc,
187 rvalue *ptr,
188 rvalue *index);
190 void
191 set_str_option (enum gcc_jit_str_option opt,
192 const char *value);
194 void
195 set_int_option (enum gcc_jit_int_option opt,
196 int value);
198 void
199 set_bool_option (enum gcc_jit_bool_option opt,
200 int value);
202 void
203 enable_dump (const char *dumpname,
204 char **out_ptr);
206 const char *
207 get_str_option (enum gcc_jit_str_option opt) const
209 return m_str_options[opt];
213 get_int_option (enum gcc_jit_int_option opt) const
215 return m_int_options[opt];
219 get_bool_option (enum gcc_jit_bool_option opt) const
221 return m_bool_options[opt];
224 result *
225 compile ();
227 void
228 add_error (location *loc, const char *fmt, ...)
229 GNU_PRINTF(3, 4);
231 void
232 add_error_va (location *loc, const char *fmt, va_list ap)
233 GNU_PRINTF(3, 0);
235 const char *
236 get_first_error () const;
238 const char *
239 get_last_error () const;
241 bool errors_occurred () const
243 if (m_parent_ctxt)
244 if (m_parent_ctxt->errors_occurred ())
245 return true;
246 return m_error_count;
249 type *get_opaque_FILE_type ();
251 void dump_to_file (const char *path, bool update_locations);
253 void
254 get_all_requested_dumps (vec <recording::requested_dump> *out);
256 private:
257 void validate ();
259 private:
260 context *m_parent_ctxt;
262 int m_error_count;
264 char *m_first_error_str;
265 bool m_owns_first_error_str;
267 char *m_last_error_str;
268 bool m_owns_last_error_str;
270 char *m_str_options[GCC_JIT_NUM_STR_OPTIONS];
271 int m_int_options[GCC_JIT_NUM_INT_OPTIONS];
272 bool m_bool_options[GCC_JIT_NUM_BOOL_OPTIONS];
274 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
275 auto_vec<requested_dump> m_requested_dumps;
277 /* Recorded API usage. */
278 auto_vec<memento *> m_mementos;
280 /* Specific recordings, for use by dump_to_file. */
281 auto_vec<compound_type *> m_compound_types;
282 auto_vec<function *> m_functions;
284 type *m_basic_types[NUM_GCC_JIT_TYPES];
285 type *m_FILE_type;
287 builtins_manager *m_builtins_manager; // lazily created
291 /* An object with lifetime managed by the context i.e.
292 it lives until the context is released, at which
293 point it itself is cleaned up. */
295 class memento
297 public:
298 virtual ~memento () {}
300 /* Hook for replaying this. */
301 virtual void replay_into (replayer *r) = 0;
303 void set_playback_obj (void *obj) { m_playback_obj = obj; }
306 /* Get the context that owns this object.
308 Implements the post-error-checking part of
309 gcc_jit_object_get_context. */
310 context *get_context () { return m_ctxt; }
312 memento *
313 as_object () { return this; }
315 /* Debugging hook, for use in generating error messages etc.
316 Implements the post-error-checking part of
317 gcc_jit_object_get_debug_string. */
318 const char *
319 get_debug_string ();
321 virtual void write_to_dump (dump &d);
323 protected:
324 memento (context *ctxt)
325 : m_ctxt (ctxt),
326 m_playback_obj (NULL),
327 m_debug_string (NULL)
329 gcc_assert (ctxt);
332 string *new_string (const char *text) { return m_ctxt->new_string (text); }
334 private:
335 virtual string * make_debug_string () = 0;
337 public:
338 context *m_ctxt;
340 protected:
341 void *m_playback_obj;
343 private:
344 string *m_debug_string;
347 /* or just use std::string? */
348 class string : public memento
350 public:
351 string (context *ctxt, const char *text);
352 ~string ();
354 const char *c_str () { return m_buffer; }
356 static string * from_printf (context *ctxt, const char *fmt, ...)
357 GNU_PRINTF(2, 3);
359 void replay_into (replayer *) {}
361 private:
362 string * make_debug_string ();
364 private:
365 size_t m_len;
366 char *m_buffer;
369 class location : public memento
371 public:
372 location (context *ctxt, string *filename, int line, int column)
373 : memento (ctxt),
374 m_filename (filename),
375 m_line (line),
376 m_column (column)
379 void replay_into (replayer *r);
381 playback::location *
382 playback_location (replayer *r)
384 /* Normally during playback, we can walk forwards through the list of
385 recording objects, playing them back. The ordering of recording
386 ensures that everything that a recording object refers to has
387 already been played back, so we can simply look up the relevant
388 m_playback_obj.
390 Locations are an exception, due to the "write_to_dump" method of
391 recording::statement. This method can set a new location on a
392 statement after the statement is created, and thus the location
393 appears in the context's memento list *after* the statement that
394 refers to it.
396 In such circumstances, the statement is replayed *before* the location,
397 when the latter doesn't yet have a playback object.
399 Hence we need to ensure that locations have playback objects. */
400 if (!m_playback_obj)
402 replay_into (r);
404 gcc_assert (m_playback_obj);
405 return static_cast <playback::location *> (m_playback_obj);
408 private:
409 string * make_debug_string ();
411 private:
412 string *m_filename;
413 int m_line;
414 int m_column;
417 class type : public memento
419 public:
420 type *get_pointer ();
421 type *get_const ();
422 type *get_volatile ();
424 /* Get the type obtained when dereferencing this type.
426 This will return NULL if it's not valid to dereference this type.
427 The caller is responsible for setting an error. */
428 virtual type *dereference () = 0;
430 /* Dynamic casts. */
431 virtual function_type *dyn_cast_function_type () { return NULL; }
432 virtual function_type *as_a_function_type() { gcc_unreachable (); return NULL; }
433 virtual struct_ *dyn_cast_struct () { return NULL; }
435 /* Is it typesafe to copy to this type from rtype? */
436 virtual bool accepts_writes_from (type *rtype)
438 gcc_assert (rtype);
439 return this == rtype->unqualified ();
442 /* Strip off "const" etc */
443 virtual type *unqualified ()
445 return this;
448 virtual bool is_int () const = 0;
449 virtual bool is_float () const = 0;
450 virtual bool is_bool () const = 0;
451 virtual type *is_pointer () = 0;
452 virtual type *is_array () = 0;
453 virtual bool is_void () const { return false; }
455 bool is_numeric () const
457 return is_int () || is_float () || is_bool ();
460 playback::type *
461 playback_type ()
463 return static_cast <playback::type *> (m_playback_obj);
466 protected:
467 type (context *ctxt)
468 : memento (ctxt),
469 m_pointer_to_this_type (NULL)
472 private:
473 type *m_pointer_to_this_type;
476 /* Result of "gcc_jit_context_get_type". */
477 class memento_of_get_type : public type
479 public:
480 memento_of_get_type (context *ctxt,
481 enum gcc_jit_types kind)
482 : type (ctxt),
483 m_kind (kind) {}
485 type *dereference ();
487 bool accepts_writes_from (type *rtype)
489 if (m_kind == GCC_JIT_TYPE_VOID_PTR)
490 if (rtype->is_pointer ())
492 /* LHS (this) is type (void *), and the RHS is a pointer:
493 accept it: */
494 return true;
497 return type::accepts_writes_from (rtype);
500 bool is_int () const;
501 bool is_float () const;
502 bool is_bool () const;
503 type *is_pointer () { return dereference (); }
504 type *is_array () { return NULL; }
505 bool is_void () const { return m_kind == GCC_JIT_TYPE_VOID; }
507 public:
508 void replay_into (replayer *r);
510 private:
511 string * make_debug_string ();
513 private:
514 enum gcc_jit_types m_kind;
517 /* Result of "gcc_jit_type_get_pointer". */
518 class memento_of_get_pointer : public type
520 public:
521 memento_of_get_pointer (type *other_type)
522 : type (other_type->m_ctxt),
523 m_other_type (other_type) {}
525 type *dereference () { return m_other_type; }
527 bool accepts_writes_from (type *rtype);
529 void replay_into (replayer *r);
531 bool is_int () const { return false; }
532 bool is_float () const { return false; }
533 bool is_bool () const { return false; }
534 type *is_pointer () { return m_other_type; }
535 type *is_array () { return NULL; }
537 private:
538 string * make_debug_string ();
540 private:
541 type *m_other_type;
544 /* Result of "gcc_jit_type_get_const". */
545 class memento_of_get_const : public type
547 public:
548 memento_of_get_const (type *other_type)
549 : type (other_type->m_ctxt),
550 m_other_type (other_type) {}
552 type *dereference () { return m_other_type->dereference (); }
554 bool accepts_writes_from (type */*rtype*/)
556 /* Can't write to a "const". */
557 return false;
560 /* Strip off the "const", giving the underlying type. */
561 type *unqualified () { return m_other_type; }
563 bool is_int () const { return m_other_type->is_int (); }
564 bool is_float () const { return m_other_type->is_float (); }
565 bool is_bool () const { return m_other_type->is_bool (); }
566 type *is_pointer () { return m_other_type->is_pointer (); }
567 type *is_array () { return m_other_type->is_array (); }
569 void replay_into (replayer *);
571 private:
572 string * make_debug_string ();
574 private:
575 type *m_other_type;
578 /* Result of "gcc_jit_type_get_volatile". */
579 class memento_of_get_volatile : public type
581 public:
582 memento_of_get_volatile (type *other_type)
583 : type (other_type->m_ctxt),
584 m_other_type (other_type) {}
586 type *dereference () { return m_other_type->dereference (); }
588 /* Strip off the "volatile", giving the underlying type. */
589 type *unqualified () { return m_other_type; }
591 bool is_int () const { return m_other_type->is_int (); }
592 bool is_float () const { return m_other_type->is_float (); }
593 bool is_bool () const { return m_other_type->is_bool (); }
594 type *is_pointer () { return m_other_type->is_pointer (); }
595 type *is_array () { return m_other_type->is_array (); }
597 void replay_into (replayer *);
599 private:
600 string * make_debug_string ();
602 private:
603 type *m_other_type;
606 class array_type : public type
608 public:
609 array_type (context *ctxt,
610 location *loc,
611 type *element_type,
612 int num_elements)
613 : type (ctxt),
614 m_loc (loc),
615 m_element_type (element_type),
616 m_num_elements (num_elements)
619 type *dereference ();
621 bool is_int () const { return false; }
622 bool is_float () const { return false; }
623 bool is_bool () const { return false; }
624 type *is_pointer () { return NULL; }
625 type *is_array () { return m_element_type; }
627 void replay_into (replayer *);
629 private:
630 string * make_debug_string ();
632 private:
633 location *m_loc;
634 type *m_element_type;
635 int m_num_elements;
638 class function_type : public type
640 public:
641 function_type (context *ctxt,
642 type *return_type,
643 int num_params,
644 type **param_types,
645 int is_variadic);
647 type *dereference ();
648 function_type *dyn_cast_function_type () { return this; }
649 function_type *as_a_function_type () { return this; }
651 bool is_int () const { return false; }
652 bool is_float () const { return false; }
653 bool is_bool () const { return false; }
654 type *is_pointer () { return NULL; }
655 type *is_array () { return NULL; }
657 void replay_into (replayer *);
659 type * get_return_type () const { return m_return_type; }
660 const vec<type *> &get_param_types () const { return m_param_types; }
661 int is_variadic () const { return m_is_variadic; }
663 string * make_debug_string_with_ptr ();
665 private:
666 string * make_debug_string ();
667 string * make_debug_string_with (const char *);
669 private:
670 type *m_return_type;
671 auto_vec<type *> m_param_types;
672 int m_is_variadic;
675 class field : public memento
677 public:
678 field (context *ctxt,
679 location *loc,
680 type *type,
681 string *name)
682 : memento (ctxt),
683 m_loc (loc),
684 m_type (type),
685 m_name (name),
686 m_container (NULL)
689 type * get_type () const { return m_type; }
691 compound_type * get_container () const { return m_container; }
692 void set_container (compound_type *c) { m_container = c; }
694 void replay_into (replayer *);
696 void write_to_dump (dump &d);
698 playback::field *
699 playback_field () const
701 return static_cast <playback::field *> (m_playback_obj);
704 private:
705 string * make_debug_string ();
707 private:
708 location *m_loc;
709 type *m_type;
710 string *m_name;
711 compound_type *m_container;
714 /* Base class for struct_ and union_ */
715 class compound_type : public type
717 public:
718 compound_type (context *ctxt,
719 location *loc,
720 string *name);
722 string *get_name () const { return m_name; }
723 location *get_loc () const { return m_loc; }
724 fields * get_fields () { return m_fields; }
726 void
727 set_fields (location *loc,
728 int num_fields,
729 field **fields);
731 type *dereference ();
733 bool is_int () const { return false; }
734 bool is_float () const { return false; }
735 bool is_bool () const { return false; }
736 type *is_pointer () { return NULL; }
737 type *is_array () { return NULL; }
739 playback::compound_type *
740 playback_compound_type ()
742 return static_cast <playback::compound_type *> (m_playback_obj);
745 private:
746 location *m_loc;
747 string *m_name;
748 fields *m_fields;
751 class struct_ : public compound_type
753 public:
754 struct_ (context *ctxt,
755 location *loc,
756 string *name);
758 struct_ *dyn_cast_struct () { return this; }
760 type *
761 as_type () { return this; }
763 void replay_into (replayer *r);
765 private:
766 string * make_debug_string ();
770 // memento of struct_::set_fields
771 class fields : public memento
773 public:
774 fields (compound_type *struct_or_union,
775 int num_fields,
776 field **fields);
778 void replay_into (replayer *r);
780 void write_to_dump (dump &d);
782 private:
783 string * make_debug_string ();
785 private:
786 compound_type *m_struct_or_union;
787 auto_vec<field *> m_fields;
790 class union_ : public compound_type
792 public:
793 union_ (context *ctxt,
794 location *loc,
795 string *name);
797 void replay_into (replayer *r);
799 private:
800 string * make_debug_string ();
802 private:
803 location *m_loc;
804 string *m_name;
805 fields *m_fields;
808 class rvalue : public memento
810 public:
811 rvalue (context *ctxt,
812 location *loc,
813 type *type_)
814 : memento (ctxt),
815 m_loc (loc),
816 m_type (type_)
818 gcc_assert (type_);
821 /* Get the recording::type of this rvalue.
823 Implements the post-error-checking part of
824 gcc_jit_rvalue_get_type. */
825 type * get_type () const { return m_type; }
827 playback::rvalue *
828 playback_rvalue () const
830 return static_cast <playback::rvalue *> (m_playback_obj);
832 rvalue *
833 access_field (location *loc,
834 field *field);
836 lvalue *
837 dereference_field (location *loc,
838 field *field);
840 lvalue *
841 dereference (location *loc);
843 protected:
844 location *m_loc;
845 type *m_type;
848 class lvalue : public rvalue
850 public:
851 lvalue (context *ctxt,
852 location *loc,
853 type *type_)
854 : rvalue (ctxt, loc, type_)
857 playback::lvalue *
858 playback_lvalue () const
860 return static_cast <playback::lvalue *> (m_playback_obj);
863 lvalue *
864 access_field (location *loc,
865 field *field);
867 rvalue *
868 get_address (location *loc);
870 rvalue *
871 as_rvalue () { return this; }
874 class param : public lvalue
876 public:
877 param (context *ctxt,
878 location *loc,
879 type *type,
880 string *name)
881 : lvalue (ctxt, loc, type),
882 m_name (name) {}
884 lvalue *
885 as_lvalue () { return this; }
887 void replay_into (replayer *r);
889 playback::param *
890 playback_param () const
892 return static_cast <playback::param *> (m_playback_obj);
895 private:
896 string * make_debug_string () { return m_name; }
898 private:
899 string *m_name;
902 class function : public memento
904 public:
905 function (context *ctxt,
906 location *loc,
907 enum gcc_jit_function_kind kind,
908 type *return_type,
909 string *name,
910 int num_params,
911 param **params,
912 int is_variadic,
913 enum built_in_function builtin_id);
915 void replay_into (replayer *r);
917 playback::function *
918 playback_function () const
920 return static_cast <playback::function *> (m_playback_obj);
923 enum gcc_jit_function_kind get_kind () const { return m_kind; }
925 lvalue *
926 new_local (location *loc,
927 type *type,
928 const char *name);
930 block*
931 new_block (const char *name);
933 type *get_return_type () const { return m_return_type; }
934 string * get_name () const { return m_name; }
935 const vec<param *> &get_params () const { return m_params; }
937 /* Get the given param by index.
938 Implements the post-error-checking part of
939 gcc_jit_function_get_param. */
940 param *get_param (int i) const { return m_params[i]; }
942 bool is_variadic () const { return m_is_variadic; }
944 void write_to_dump (dump &d);
946 void validate ();
948 void dump_to_dot (const char *path);
950 private:
951 string * make_debug_string ();
953 private:
954 location *m_loc;
955 enum gcc_jit_function_kind m_kind;
956 type *m_return_type;
957 string *m_name;
958 auto_vec<param *> m_params;
959 int m_is_variadic;
960 enum built_in_function m_builtin_id;
961 auto_vec<local *> m_locals;
962 auto_vec<block *> m_blocks;
965 class block : public memento
967 public:
968 block (function *func, int index, string *name)
969 : memento (func->m_ctxt),
970 m_func (func),
971 m_index (index),
972 m_name (name),
973 m_statements (),
974 m_has_been_terminated (false),
975 m_is_reachable (false)
979 /* Get the recording::function containing this block.
980 Implements the post-error-checking part of
981 gcc_jit_block_get_function. */
982 function *get_function () { return m_func; }
984 bool has_been_terminated () { return m_has_been_terminated; }
985 bool is_reachable () { return m_is_reachable; }
987 void
988 add_eval (location *loc,
989 rvalue *rvalue);
991 void
992 add_assignment (location *loc,
993 lvalue *lvalue,
994 rvalue *rvalue);
996 void
997 add_assignment_op (location *loc,
998 lvalue *lvalue,
999 enum gcc_jit_binary_op op,
1000 rvalue *rvalue);
1002 void
1003 add_comment (location *loc,
1004 const char *text);
1006 void
1007 end_with_conditional (location *loc,
1008 rvalue *boolval,
1009 block *on_true,
1010 block *on_false);
1012 void
1013 end_with_jump (location *loc,
1014 block *target);
1016 void
1017 end_with_return (location *loc,
1018 rvalue *rvalue);
1020 playback::block *
1021 playback_block () const
1023 return static_cast <playback::block *> (m_playback_obj);
1026 void write_to_dump (dump &d);
1028 bool validate ();
1030 location *get_loc () const;
1032 statement *get_first_statement () const;
1033 statement *get_last_statement () const;
1035 int get_successor_blocks (block **next1, block **next2) const;
1037 private:
1038 string * make_debug_string ();
1040 void replay_into (replayer *r);
1042 void dump_to_dot (pretty_printer *pp);
1043 void dump_edges_to_dot (pretty_printer *pp);
1045 private:
1046 function *m_func;
1047 int m_index;
1048 string *m_name;
1049 auto_vec<statement *> m_statements;
1050 bool m_has_been_terminated;
1051 bool m_is_reachable;
1053 friend class function;
1056 class global : public lvalue
1058 public:
1059 global (context *ctxt,
1060 location *loc,
1061 type *type,
1062 string *name)
1063 : lvalue (ctxt, loc, type),
1064 m_name (name)
1067 void replay_into (replayer *);
1069 private:
1070 string * make_debug_string () { return m_name; }
1072 private:
1073 string *m_name;
1076 class memento_of_new_rvalue_from_int : public rvalue
1078 public:
1079 memento_of_new_rvalue_from_int (context *ctxt,
1080 location *loc,
1081 type *numeric_type,
1082 int value)
1083 : rvalue (ctxt, loc, numeric_type),
1084 m_value (value) {}
1086 void replay_into (replayer *r);
1088 private:
1089 string * make_debug_string ();
1091 private:
1092 int m_value;
1095 class memento_of_new_rvalue_from_double : public rvalue
1097 public:
1098 memento_of_new_rvalue_from_double (context *ctxt,
1099 location *loc,
1100 type *numeric_type,
1101 double value)
1102 : rvalue (ctxt, loc, numeric_type),
1103 m_value (value)
1106 void replay_into (replayer *);
1108 private:
1109 string * make_debug_string ();
1111 private:
1112 double m_value;
1115 class memento_of_new_rvalue_from_ptr : public rvalue
1117 public:
1118 memento_of_new_rvalue_from_ptr (context *ctxt,
1119 location *loc,
1120 type *pointer_type,
1121 void *value)
1122 : rvalue (ctxt, loc, pointer_type),
1123 m_value (value)
1126 void replay_into (replayer *);
1128 private:
1129 string * make_debug_string ();
1131 private:
1132 void *m_value;
1135 class memento_of_new_string_literal : public rvalue
1137 public:
1138 memento_of_new_string_literal (context *ctxt,
1139 location *loc,
1140 string *value)
1141 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_CONST_CHAR_PTR)),
1142 m_value (value) {}
1144 void replay_into (replayer *r);
1146 private:
1147 string * make_debug_string ();
1149 private:
1150 string *m_value;
1153 class unary_op : public rvalue
1155 public:
1156 unary_op (context *ctxt,
1157 location *loc,
1158 enum gcc_jit_unary_op op,
1159 type *result_type,
1160 rvalue *a)
1161 : rvalue (ctxt, loc, result_type),
1162 m_op (op),
1163 m_a (a)
1166 void replay_into (replayer *r);
1168 private:
1169 string * make_debug_string ();
1171 private:
1172 enum gcc_jit_unary_op m_op;
1173 rvalue *m_a;
1176 class binary_op : public rvalue
1178 public:
1179 binary_op (context *ctxt,
1180 location *loc,
1181 enum gcc_jit_binary_op op,
1182 type *result_type,
1183 rvalue *a, rvalue *b)
1184 : rvalue (ctxt, loc, result_type),
1185 m_op (op),
1186 m_a (a),
1187 m_b (b) {}
1189 void replay_into (replayer *r);
1191 private:
1192 string * make_debug_string ();
1194 private:
1195 enum gcc_jit_binary_op m_op;
1196 rvalue *m_a;
1197 rvalue *m_b;
1200 class comparison : public rvalue
1202 public:
1203 comparison (context *ctxt,
1204 location *loc,
1205 enum gcc_jit_comparison op,
1206 rvalue *a, rvalue *b)
1207 : rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_BOOL)),
1208 m_op (op),
1209 m_a (a),
1210 m_b (b)
1213 void replay_into (replayer *r);
1215 private:
1216 string * make_debug_string ();
1218 private:
1219 enum gcc_jit_comparison m_op;
1220 rvalue *m_a;
1221 rvalue *m_b;
1224 class cast : public rvalue
1226 public:
1227 cast (context *ctxt,
1228 location *loc,
1229 rvalue *a,
1230 type *type_)
1231 : rvalue (ctxt, loc, type_),
1232 m_rvalue (a)
1235 void replay_into (replayer *r);
1237 private:
1238 string * make_debug_string ();
1240 private:
1241 rvalue *m_rvalue;
1244 class call : public rvalue
1246 public:
1247 call (context *ctxt,
1248 location *loc,
1249 function *func,
1250 int numargs,
1251 rvalue **args);
1253 void replay_into (replayer *r);
1255 private:
1256 string * make_debug_string ();
1258 private:
1259 function *m_func;
1260 auto_vec<rvalue *> m_args;
1263 class call_through_ptr : public rvalue
1265 public:
1266 call_through_ptr (context *ctxt,
1267 location *loc,
1268 rvalue *fn_ptr,
1269 int numargs,
1270 rvalue **args);
1272 void replay_into (replayer *r);
1274 private:
1275 string * make_debug_string ();
1277 private:
1278 rvalue *m_fn_ptr;
1279 auto_vec<rvalue *> m_args;
1282 class array_access : public lvalue
1284 public:
1285 array_access (context *ctxt,
1286 location *loc,
1287 rvalue *ptr,
1288 rvalue *index)
1289 : lvalue (ctxt, loc, ptr->get_type ()->dereference ()),
1290 m_ptr (ptr),
1291 m_index (index)
1294 void replay_into (replayer *r);
1296 private:
1297 string * make_debug_string ();
1299 private:
1300 rvalue *m_ptr;
1301 rvalue *m_index;
1304 class access_field_of_lvalue : public lvalue
1306 public:
1307 access_field_of_lvalue (context *ctxt,
1308 location *loc,
1309 lvalue *val,
1310 field *field)
1311 : lvalue (ctxt, loc, field->get_type ()),
1312 m_lvalue (val),
1313 m_field (field)
1316 void replay_into (replayer *r);
1318 private:
1319 string * make_debug_string ();
1321 private:
1322 lvalue *m_lvalue;
1323 field *m_field;
1326 class access_field_rvalue : public rvalue
1328 public:
1329 access_field_rvalue (context *ctxt,
1330 location *loc,
1331 rvalue *val,
1332 field *field)
1333 : rvalue (ctxt, loc, field->get_type ()),
1334 m_rvalue (val),
1335 m_field (field)
1338 void replay_into (replayer *r);
1340 private:
1341 string * make_debug_string ();
1343 private:
1344 rvalue *m_rvalue;
1345 field *m_field;
1348 class dereference_field_rvalue : public lvalue
1350 public:
1351 dereference_field_rvalue (context *ctxt,
1352 location *loc,
1353 rvalue *val,
1354 field *field)
1355 : lvalue (ctxt, loc, field->get_type ()),
1356 m_rvalue (val),
1357 m_field (field)
1360 void replay_into (replayer *r);
1362 private:
1363 string * make_debug_string ();
1365 private:
1366 rvalue *m_rvalue;
1367 field *m_field;
1370 class dereference_rvalue : public lvalue
1372 public:
1373 dereference_rvalue (context *ctxt,
1374 location *loc,
1375 rvalue *val)
1376 : lvalue (ctxt, loc, val->get_type ()->dereference ()),
1377 m_rvalue (val) {}
1379 void replay_into (replayer *r);
1381 private:
1382 string * make_debug_string ();
1384 private:
1385 rvalue *m_rvalue;
1388 class get_address_of_lvalue : public rvalue
1390 public:
1391 get_address_of_lvalue (context *ctxt,
1392 location *loc,
1393 lvalue *val)
1394 : rvalue (ctxt, loc, val->get_type ()->get_pointer ()),
1395 m_lvalue (val)
1398 void replay_into (replayer *r);
1400 private:
1401 string * make_debug_string ();
1403 private:
1404 lvalue *m_lvalue;
1407 class local : public lvalue
1409 public:
1410 local (function *func, location *loc, type *type_, string *name)
1411 : lvalue (func->m_ctxt, loc, type_),
1412 m_func (func),
1413 m_name (name) {}
1415 void replay_into (replayer *r);
1417 void write_to_dump (dump &d);
1419 private:
1420 string * make_debug_string () { return m_name; }
1422 private:
1423 function *m_func;
1424 string *m_name;
1427 class statement : public memento
1429 public:
1430 virtual int get_successor_blocks (block **out_next1,
1431 block **out_next2) const;
1433 void write_to_dump (dump &d);
1435 location *get_loc () const { return m_loc; }
1437 protected:
1438 statement (block *b, location *loc)
1439 : memento (b->m_ctxt),
1440 m_block (b),
1441 m_loc (loc) {}
1443 block *get_block () const { return m_block; }
1445 playback::location *
1446 playback_location (replayer *r) const
1448 return ::gcc::jit::recording::playback_location (r, m_loc);
1451 private:
1452 block *m_block;
1453 location *m_loc;
1456 class eval : public statement
1458 public:
1459 eval (block *b,
1460 location *loc,
1461 rvalue *rvalue)
1462 : statement (b, loc),
1463 m_rvalue (rvalue) {}
1465 void replay_into (replayer *r);
1467 private:
1468 string * make_debug_string ();
1470 private:
1471 rvalue *m_rvalue;
1474 class assignment : public statement
1476 public:
1477 assignment (block *b,
1478 location *loc,
1479 lvalue *lvalue,
1480 rvalue *rvalue)
1481 : statement (b, loc),
1482 m_lvalue (lvalue),
1483 m_rvalue (rvalue) {}
1485 void replay_into (replayer *r);
1487 private:
1488 string * make_debug_string ();
1490 private:
1491 lvalue *m_lvalue;
1492 rvalue *m_rvalue;
1495 class assignment_op : public statement
1497 public:
1498 assignment_op (block *b,
1499 location *loc,
1500 lvalue *lvalue,
1501 enum gcc_jit_binary_op op,
1502 rvalue *rvalue)
1503 : statement (b, loc),
1504 m_lvalue (lvalue),
1505 m_op (op),
1506 m_rvalue (rvalue) {}
1508 void replay_into (replayer *r);
1510 private:
1511 string * make_debug_string ();
1513 private:
1514 lvalue *m_lvalue;
1515 enum gcc_jit_binary_op m_op;
1516 rvalue *m_rvalue;
1519 class comment : public statement
1521 public:
1522 comment (block *b,
1523 location *loc,
1524 string *text)
1525 : statement (b, loc),
1526 m_text (text) {}
1528 void replay_into (replayer *r);
1530 private:
1531 string * make_debug_string ();
1533 private:
1534 string *m_text;
1537 class conditional : public statement
1539 public:
1540 conditional (block *b,
1541 location *loc,
1542 rvalue *boolval,
1543 block *on_true,
1544 block *on_false)
1545 : statement (b, loc),
1546 m_boolval (boolval),
1547 m_on_true (on_true),
1548 m_on_false (on_false) {}
1550 void replay_into (replayer *r);
1552 int get_successor_blocks (block **out_next1,
1553 block **out_next2) const;
1555 private:
1556 string * make_debug_string ();
1558 private:
1559 rvalue *m_boolval;
1560 block *m_on_true;
1561 block *m_on_false;
1564 class jump : public statement
1566 public:
1567 jump (block *b,
1568 location *loc,
1569 block *target)
1570 : statement (b, loc),
1571 m_target (target) {}
1573 void replay_into (replayer *r);
1575 int get_successor_blocks (block **out_next1,
1576 block **out_next2) const;
1578 private:
1579 string * make_debug_string ();
1581 private:
1582 block *m_target;
1585 class return_ : public statement
1587 public:
1588 return_ (block *b,
1589 location *loc,
1590 rvalue *rvalue)
1591 : statement (b, loc),
1592 m_rvalue (rvalue) {}
1594 void replay_into (replayer *r);
1596 int get_successor_blocks (block **out_next1,
1597 block **out_next2) const;
1599 private:
1600 string * make_debug_string ();
1602 private:
1603 rvalue *m_rvalue;
1606 } // namespace gcc::jit::recording
1608 } // namespace gcc::jit
1610 } // namespace gcc
1612 #endif /* JIT_RECORDING_H */