Minor interface cleanups of libgccjit
[gcc.git] / gcc / jit / jit-recording.h
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>.
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21 #ifndef JIT_RECORDING_H
22 #define JIT_RECORDING_H
23
24 #include "jit-common.h"
25
26 namespace gcc {
27
28 namespace jit {
29
30 class result;
31 class dump;
32
33 /**********************************************************************
34 Recording.
35 **********************************************************************/
36
37 namespace recording {
38
39 playback::location *
40 playback_location (replayer *r, location *loc);
41
42 const char *
43 playback_string (string *str);
44
45 playback::block *
46 playback_block (block *b);
47
48 /* A recording of a call to gcc_jit_context_enable_dump. */
49 struct requested_dump
50 {
51 const char *m_dumpname;
52 char **m_out_ptr;
53 };
54
55 /* A JIT-compilation context. */
56 class context
57 {
58 public:
59 context (context *parent_ctxt);
60 ~context ();
61
62 builtins_manager *
63 get_builtins_manager ();
64
65 void record (memento *m);
66 void replay_into (replayer *r);
67 void disassociate_from_playback ();
68
69 string *
70 new_string (const char *text);
71
72 location *
73 new_location (const char *filename,
74 int line,
75 int column);
76
77 type *
78 get_type (enum gcc_jit_types type);
79
80 type *
81 get_int_type (int num_bytes, int is_signed);
82
83 type *
84 new_array_type (location *loc,
85 type *element_type,
86 int num_elements);
87
88 field *
89 new_field (location *loc,
90 type *type,
91 const char *name);
92
93 struct_ *
94 new_struct_type (location *loc,
95 const char *name);
96
97 union_ *
98 new_union_type (location *loc,
99 const char *name);
100
101 function_type *
102 new_function_type (type *return_type,
103 int num_params,
104 type **param_types,
105 int is_variadic);
106
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);
113
114 param *
115 new_param (location *loc,
116 type *type,
117 const char *name);
118
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);
128
129 function *
130 get_builtin_function (const char *name);
131
132 lvalue *
133 new_global (location *loc,
134 type *type,
135 const char *name);
136
137 rvalue *
138 new_rvalue_from_int (type *numeric_type,
139 int value);
140
141 rvalue *
142 new_rvalue_from_double (type *numeric_type,
143 double value);
144
145 rvalue *
146 new_rvalue_from_ptr (type *pointer_type,
147 void *value);
148
149 rvalue *
150 new_string_literal (const char *value);
151
152 rvalue *
153 new_unary_op (location *loc,
154 enum gcc_jit_unary_op op,
155 type *result_type,
156 rvalue *a);
157
158 rvalue *
159 new_binary_op (location *loc,
160 enum gcc_jit_binary_op op,
161 type *result_type,
162 rvalue *a, rvalue *b);
163
164 rvalue *
165 new_comparison (location *loc,
166 enum gcc_jit_comparison op,
167 rvalue *a, rvalue *b);
168
169 rvalue *
170 new_call (location *loc,
171 function *func,
172 int numargs, rvalue **args);
173
174 rvalue *
175 new_call_through_ptr (location *loc,
176 rvalue *fn_ptr,
177 int numargs, rvalue **args);
178
179 rvalue *
180 new_cast (location *loc,
181 rvalue *expr,
182 type *type_);
183
184 lvalue *
185 new_array_access (location *loc,
186 rvalue *ptr,
187 rvalue *index);
188
189 void
190 set_str_option (enum gcc_jit_str_option opt,
191 const char *value);
192
193 void
194 set_int_option (enum gcc_jit_int_option opt,
195 int value);
196
197 void
198 set_bool_option (enum gcc_jit_bool_option opt,
199 int value);
200
201 void
202 enable_dump (const char *dumpname,
203 char **out_ptr);
204
205 const char *
206 get_str_option (enum gcc_jit_str_option opt) const
207 {
208 return m_str_options[opt];
209 }
210
211 int
212 get_int_option (enum gcc_jit_int_option opt) const
213 {
214 return m_int_options[opt];
215 }
216
217 int
218 get_bool_option (enum gcc_jit_bool_option opt) const
219 {
220 return m_bool_options[opt];
221 }
222
223 result *
224 compile ();
225
226 void
227 add_error (location *loc, const char *fmt, ...)
228 GNU_PRINTF(3, 4);
229
230 void
231 add_error_va (location *loc, const char *fmt, va_list ap)
232 GNU_PRINTF(3, 0);
233
234 const char *
235 get_first_error () const;
236
237 bool errors_occurred () const
238 {
239 if (m_parent_ctxt)
240 if (m_parent_ctxt->errors_occurred ())
241 return true;
242 return m_error_count;
243 }
244
245 type *get_opaque_FILE_type ();
246
247 void dump_to_file (const char *path, bool update_locations);
248
249 void
250 get_all_requested_dumps (vec <recording::requested_dump> *out);
251
252 private:
253 void validate ();
254
255 private:
256 context *m_parent_ctxt;
257
258 int m_error_count;
259
260 char *m_first_error_str;
261 bool m_owns_first_error_str;
262
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];
266
267 /* Dumpfiles that were requested via gcc_jit_context_enable_dump. */
268 auto_vec<requested_dump> m_requested_dumps;
269
270 /* Recorded API usage. */
271 auto_vec<memento *> m_mementos;
272
273 /* Specific recordings, for use by dump_to_file. */
274 auto_vec<compound_type *> m_compound_types;
275 auto_vec<function *> m_functions;
276
277 type *m_basic_types[NUM_GCC_JIT_TYPES];
278 type *m_FILE_type;
279
280 builtins_manager *m_builtins_manager; // lazily created
281 };
282
283
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. */
287
288 class memento
289 {
290 public:
291 virtual ~memento () {}
292
293 /* Hook for replaying this. */
294 virtual void replay_into (replayer *r) = 0;
295
296 void set_playback_obj (void *obj) { m_playback_obj = obj; }
297
298
299 /* Get the context that owns this object.
300
301 Implements the post-error-checking part of
302 gcc_jit_object_get_context. */
303 context *get_context () { return m_ctxt; }
304
305 memento *
306 as_object () { return this; }
307
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 ();
313
314 virtual void write_to_dump (dump &d);
315
316 protected:
317 memento (context *ctxt)
318 : m_ctxt (ctxt),
319 m_playback_obj (NULL),
320 m_debug_string (NULL)
321 {
322 gcc_assert (ctxt);
323 }
324
325 string *new_string (const char *text) { return m_ctxt->new_string (text); }
326
327 private:
328 virtual string * make_debug_string () = 0;
329
330 public:
331 context *m_ctxt;
332
333 protected:
334 void *m_playback_obj;
335
336 private:
337 string *m_debug_string;
338 };
339
340 /* or just use std::string? */
341 class string : public memento
342 {
343 public:
344 string (context *ctxt, const char *text);
345 ~string ();
346
347 const char *c_str () { return m_buffer; }
348
349 static string * from_printf (context *ctxt, const char *fmt, ...)
350 GNU_PRINTF(2, 3);
351
352 void replay_into (replayer *) {}
353
354 private:
355 string * make_debug_string ();
356
357 private:
358 size_t m_len;
359 char *m_buffer;
360 };
361
362 class location : public memento
363 {
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)
370 {}
371
372 void replay_into (replayer *r);
373
374 playback::location *
375 playback_location (replayer *r)
376 {
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.
382
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.
388
389 In such circumstances, the statement is replayed *before* the location,
390 when the latter doesn't yet have a playback object.
391
392 Hence we need to ensure that locations have playback objects. */
393 if (!m_playback_obj)
394 {
395 replay_into (r);
396 }
397 gcc_assert (m_playback_obj);
398 return static_cast <playback::location *> (m_playback_obj);
399 }
400
401 private:
402 string * make_debug_string ();
403
404 private:
405 string *m_filename;
406 int m_line;
407 int m_column;
408 };
409
410 class type : public memento
411 {
412 public:
413 type *get_pointer ();
414 type *get_const ();
415 type *get_volatile ();
416
417 /* Get the type obtained when dereferencing this type.
418
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;
422
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; }
427
428 /* Is it typesafe to copy to this type from rtype? */
429 virtual bool accepts_writes_from (type *rtype)
430 {
431 gcc_assert (rtype);
432 return this == rtype->unqualified ();
433 }
434
435 /* Strip off "const" etc */
436 virtual type *unqualified ()
437 {
438 return this;
439 }
440
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;
446
447 bool is_numeric () const
448 {
449 return is_int () || is_float () || is_bool ();
450 }
451
452 playback::type *
453 playback_type ()
454 {
455 return static_cast <playback::type *> (m_playback_obj);
456 }
457
458 protected:
459 type (context *ctxt)
460 : memento (ctxt),
461 m_pointer_to_this_type (NULL)
462 {}
463
464 private:
465 type *m_pointer_to_this_type;
466 };
467
468 /* Result of "gcc_jit_type_get_type". */
469 class memento_of_get_type : public type
470 {
471 public:
472 memento_of_get_type (context *ctxt,
473 enum gcc_jit_types kind)
474 : type (ctxt),
475 m_kind (kind) {}
476
477 type *dereference ();
478
479 bool accepts_writes_from (type *rtype)
480 {
481 if (m_kind == GCC_JIT_TYPE_VOID_PTR)
482 if (rtype->is_pointer ())
483 {
484 /* LHS (this) is type (void *), and the RHS is a pointer:
485 accept it: */
486 return true;
487 }
488
489 return type::accepts_writes_from (rtype);
490 }
491
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; }
497
498 public:
499 void replay_into (replayer *r);
500
501 private:
502 string * make_debug_string ();
503
504 private:
505 enum gcc_jit_types m_kind;
506 };
507
508 /* Result of "gcc_jit_type_get_pointer". */
509 class memento_of_get_pointer : public type
510 {
511 public:
512 memento_of_get_pointer (type *other_type)
513 : type (other_type->m_ctxt),
514 m_other_type (other_type) {}
515
516 type *dereference () { return m_other_type; }
517
518 bool accepts_writes_from (type *rtype);
519
520 void replay_into (replayer *r);
521
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; }
527
528 private:
529 string * make_debug_string ();
530
531 private:
532 type *m_other_type;
533 };
534
535 /* Result of "gcc_jit_type_get_const". */
536 class memento_of_get_const : public type
537 {
538 public:
539 memento_of_get_const (type *other_type)
540 : type (other_type->m_ctxt),
541 m_other_type (other_type) {}
542
543 type *dereference () { return m_other_type->dereference (); }
544
545 bool accepts_writes_from (type */*rtype*/)
546 {
547 /* Can't write to a "const". */
548 return false;
549 }
550
551 /* Strip off the "const", giving the underlying type. */
552 type *unqualified () { return m_other_type; }
553
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 (); }
559
560 void replay_into (replayer *);
561
562 private:
563 string * make_debug_string ();
564
565 private:
566 type *m_other_type;
567 };
568
569 /* Result of "gcc_jit_type_get_volatile". */
570 class memento_of_get_volatile : public type
571 {
572 public:
573 memento_of_get_volatile (type *other_type)
574 : type (other_type->m_ctxt),
575 m_other_type (other_type) {}
576
577 type *dereference () { return m_other_type->dereference (); }
578
579 /* Strip off the "volatile", giving the underlying type. */
580 type *unqualified () { return m_other_type; }
581
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 (); }
587
588 void replay_into (replayer *);
589
590 private:
591 string * make_debug_string ();
592
593 private:
594 type *m_other_type;
595 };
596
597 class array_type : public type
598 {
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)
608 {}
609
610 type *dereference ();
611
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; }
617
618 void replay_into (replayer *);
619
620 private:
621 string * make_debug_string ();
622
623 private:
624 location *m_loc;
625 type *m_element_type;
626 int m_num_elements;
627 };
628
629 class function_type : public type
630 {
631 public:
632 function_type (context *ctxt,
633 type *return_type,
634 int num_params,
635 type **param_types,
636 int is_variadic);
637
638 type *dereference ();
639 function_type *dyn_cast_function_type () { return this; }
640 function_type *as_a_function_type () { return this; }
641
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; }
647
648 void replay_into (replayer *);
649
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; }
653
654 string * make_debug_string_with_ptr ();
655
656 private:
657 string * make_debug_string ();
658 string * make_debug_string_with (const char *);
659
660 private:
661 type *m_return_type;
662 auto_vec<type *> m_param_types;
663 int m_is_variadic;
664 };
665
666 class field : public memento
667 {
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)
678 {}
679
680 type * get_type () const { return m_type; }
681
682 compound_type * get_container () const { return m_container; }
683 void set_container (compound_type *c) { m_container = c; }
684
685 void replay_into (replayer *);
686
687 void write_to_dump (dump &d);
688
689 playback::field *
690 playback_field () const
691 {
692 return static_cast <playback::field *> (m_playback_obj);
693 }
694
695 private:
696 string * make_debug_string ();
697
698 private:
699 location *m_loc;
700 type *m_type;
701 string *m_name;
702 compound_type *m_container;
703 };
704
705 /* Base class for struct_ and union_ */
706 class compound_type : public type
707 {
708 public:
709 compound_type (context *ctxt,
710 location *loc,
711 string *name);
712
713 string *get_name () const { return m_name; }
714 location *get_loc () const { return m_loc; }
715 fields * get_fields () { return m_fields; }
716
717 void
718 set_fields (location *loc,
719 int num_fields,
720 field **fields);
721
722 type *dereference ();
723
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; }
729
730 playback::compound_type *
731 playback_compound_type ()
732 {
733 return static_cast <playback::compound_type *> (m_playback_obj);
734 }
735
736 private:
737 location *m_loc;
738 string *m_name;
739 fields *m_fields;
740 };
741
742 class struct_ : public compound_type
743 {
744 public:
745 struct_ (context *ctxt,
746 location *loc,
747 string *name);
748
749 struct_ *dyn_cast_struct () { return this; }
750
751 type *
752 as_type () { return this; }
753
754 void replay_into (replayer *r);
755
756 private:
757 string * make_debug_string ();
758
759 };
760
761 // memento of struct_::set_fields
762 class fields : public memento
763 {
764 public:
765 fields (compound_type *struct_or_union,
766 int num_fields,
767 field **fields);
768
769 void replay_into (replayer *r);
770
771 void write_to_dump (dump &d);
772
773 private:
774 string * make_debug_string ();
775
776 private:
777 compound_type *m_struct_or_union;
778 auto_vec<field *> m_fields;
779 };
780
781 class union_ : public compound_type
782 {
783 public:
784 union_ (context *ctxt,
785 location *loc,
786 string *name);
787
788 void replay_into (replayer *r);
789
790 private:
791 string * make_debug_string ();
792
793 private:
794 location *m_loc;
795 string *m_name;
796 fields *m_fields;
797 };
798
799 class rvalue : public memento
800 {
801 public:
802 rvalue (context *ctxt,
803 location *loc,
804 type *type_)
805 : memento (ctxt),
806 m_loc (loc),
807 m_type (type_)
808 {
809 gcc_assert (type_);
810 }
811
812 /* Get the recording::type of this rvalue.
813
814 Implements the post-error-checking part of
815 gcc_jit_rvalue_get_type. */
816 type * get_type () const { return m_type; }
817
818 playback::rvalue *
819 playback_rvalue () const
820 {
821 return static_cast <playback::rvalue *> (m_playback_obj);
822 }
823 rvalue *
824 access_field (location *loc,
825 field *field);
826
827 lvalue *
828 dereference_field (location *loc,
829 field *field);
830
831 lvalue *
832 dereference (location *loc);
833
834 protected:
835 location *m_loc;
836 type *m_type;
837 };
838
839 class lvalue : public rvalue
840 {
841 public:
842 lvalue (context *ctxt,
843 location *loc,
844 type *type_)
845 : rvalue (ctxt, loc, type_)
846 {}
847
848 playback::lvalue *
849 playback_lvalue () const
850 {
851 return static_cast <playback::lvalue *> (m_playback_obj);
852 }
853
854 lvalue *
855 access_field (location *loc,
856 field *field);
857
858 rvalue *
859 get_address (location *loc);
860
861 rvalue *
862 as_rvalue () { return this; }
863 };
864
865 class param : public lvalue
866 {
867 public:
868 param (context *ctxt,
869 location *loc,
870 type *type,
871 string *name)
872 : lvalue (ctxt, loc, type),
873 m_name (name) {}
874
875 lvalue *
876 as_lvalue () { return this; }
877
878 void replay_into (replayer *r);
879
880 playback::param *
881 playback_param () const
882 {
883 return static_cast <playback::param *> (m_playback_obj);
884 }
885
886 private:
887 string * make_debug_string () { return m_name; }
888
889 private:
890 string *m_name;
891 };
892
893 class function : public memento
894 {
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);
905
906 void replay_into (replayer *r);
907
908 playback::function *
909 playback_function () const
910 {
911 return static_cast <playback::function *> (m_playback_obj);
912 }
913
914 enum gcc_jit_function_kind get_kind () const { return m_kind; }
915
916 lvalue *
917 new_local (location *loc,
918 type *type,
919 const char *name);
920
921 block*
922 new_block (const char *name);
923
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; }
927
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]; }
932
933 bool is_variadic () const { return m_is_variadic; }
934
935 void write_to_dump (dump &d);
936
937 void validate ();
938
939 void dump_to_dot (const char *path);
940
941 private:
942 string * make_debug_string ();
943
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;
954 };
955
956 class block : public memento
957 {
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)
967 {
968 }
969
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; }
974
975 bool has_been_terminated () { return m_has_been_terminated; }
976 bool is_reachable () { return m_is_reachable; }
977
978 void
979 add_eval (location *loc,
980 rvalue *rvalue);
981
982 void
983 add_assignment (location *loc,
984 lvalue *lvalue,
985 rvalue *rvalue);
986
987 void
988 add_assignment_op (location *loc,
989 lvalue *lvalue,
990 enum gcc_jit_binary_op op,
991 rvalue *rvalue);
992
993 void
994 add_comment (location *loc,
995 const char *text);
996
997 void
998 end_with_conditional (location *loc,
999 rvalue *boolval,
1000 block *on_true,
1001 block *on_false);
1002
1003 void
1004 end_with_jump (location *loc,
1005 block *target);
1006
1007 void
1008 end_with_return (location *loc,
1009 rvalue *rvalue);
1010
1011 playback::block *
1012 playback_block () const
1013 {
1014 return static_cast <playback::block *> (m_playback_obj);
1015 }
1016
1017 void write_to_dump (dump &d);
1018
1019 bool validate ();
1020
1021 location *get_loc () const;
1022
1023 statement *get_first_statement () const;
1024 statement *get_last_statement () const;
1025
1026 int get_successor_blocks (block **next1, block **next2) const;
1027
1028 private:
1029 string * make_debug_string ();
1030
1031 void replay_into (replayer *r);
1032
1033 void dump_to_dot (pretty_printer *pp);
1034 void dump_edges_to_dot (pretty_printer *pp);
1035
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;
1043
1044 friend class function;
1045 };
1046
1047 class global : public lvalue
1048 {
1049 public:
1050 global (context *ctxt,
1051 location *loc,
1052 type *type,
1053 string *name)
1054 : lvalue (ctxt, loc, type),
1055 m_name (name)
1056 {}
1057
1058 void replay_into (replayer *);
1059
1060 private:
1061 string * make_debug_string () { return m_name; }
1062
1063 private:
1064 string *m_name;
1065 };
1066
1067 class memento_of_new_rvalue_from_int : public rvalue
1068 {
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) {}
1076
1077 void replay_into (replayer *r);
1078
1079 private:
1080 string * make_debug_string ();
1081
1082 private:
1083 int m_value;
1084 };
1085
1086 class memento_of_new_rvalue_from_double : public rvalue
1087 {
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)
1095 {}
1096
1097 void replay_into (replayer *);
1098
1099 private:
1100 string * make_debug_string ();
1101
1102 private:
1103 double m_value;
1104 };
1105
1106 class memento_of_new_rvalue_from_ptr : public rvalue
1107 {
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)
1115 {}
1116
1117 void replay_into (replayer *);
1118
1119 private:
1120 string * make_debug_string ();
1121
1122 private:
1123 void *m_value;
1124 };
1125
1126 class memento_of_new_string_literal : public rvalue
1127 {
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) {}
1134
1135 void replay_into (replayer *r);
1136
1137 private:
1138 string * make_debug_string ();
1139
1140 private:
1141 string *m_value;
1142 };
1143
1144 class unary_op : public rvalue
1145 {
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)
1155 {}
1156
1157 void replay_into (replayer *r);
1158
1159 private:
1160 string * make_debug_string ();
1161
1162 private:
1163 enum gcc_jit_unary_op m_op;
1164 rvalue *m_a;
1165 };
1166
1167 class binary_op : public rvalue
1168 {
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) {}
1179
1180 void replay_into (replayer *r);
1181
1182 private:
1183 string * make_debug_string ();
1184
1185 private:
1186 enum gcc_jit_binary_op m_op;
1187 rvalue *m_a;
1188 rvalue *m_b;
1189 };
1190
1191 class comparison : public rvalue
1192 {
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)
1202 {}
1203
1204 void replay_into (replayer *r);
1205
1206 private:
1207 string * make_debug_string ();
1208
1209 private:
1210 enum gcc_jit_comparison m_op;
1211 rvalue *m_a;
1212 rvalue *m_b;
1213 };
1214
1215 class cast : public rvalue
1216 {
1217 public:
1218 cast (context *ctxt,
1219 location *loc,
1220 rvalue *a,
1221 type *type_)
1222 : rvalue (ctxt, loc, type_),
1223 m_rvalue (a)
1224 {}
1225
1226 void replay_into (replayer *r);
1227
1228 private:
1229 string * make_debug_string ();
1230
1231 private:
1232 rvalue *m_rvalue;
1233 };
1234
1235 class call : public rvalue
1236 {
1237 public:
1238 call (context *ctxt,
1239 location *loc,
1240 function *func,
1241 int numargs,
1242 rvalue **args);
1243
1244 void replay_into (replayer *r);
1245
1246 private:
1247 string * make_debug_string ();
1248
1249 private:
1250 function *m_func;
1251 auto_vec<rvalue *> m_args;
1252 };
1253
1254 class call_through_ptr : public rvalue
1255 {
1256 public:
1257 call_through_ptr (context *ctxt,
1258 location *loc,
1259 rvalue *fn_ptr,
1260 int numargs,
1261 rvalue **args);
1262
1263 void replay_into (replayer *r);
1264
1265 private:
1266 string * make_debug_string ();
1267
1268 private:
1269 rvalue *m_fn_ptr;
1270 auto_vec<rvalue *> m_args;
1271 };
1272
1273 class array_access : public lvalue
1274 {
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)
1283 {}
1284
1285 void replay_into (replayer *r);
1286
1287 private:
1288 string * make_debug_string ();
1289
1290 private:
1291 rvalue *m_ptr;
1292 rvalue *m_index;
1293 };
1294
1295 class access_field_of_lvalue : public lvalue
1296 {
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)
1305 {}
1306
1307 void replay_into (replayer *r);
1308
1309 private:
1310 string * make_debug_string ();
1311
1312 private:
1313 lvalue *m_lvalue;
1314 field *m_field;
1315 };
1316
1317 class access_field_rvalue : public rvalue
1318 {
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)
1327 {}
1328
1329 void replay_into (replayer *r);
1330
1331 private:
1332 string * make_debug_string ();
1333
1334 private:
1335 rvalue *m_rvalue;
1336 field *m_field;
1337 };
1338
1339 class dereference_field_rvalue : public lvalue
1340 {
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)
1349 {}
1350
1351 void replay_into (replayer *r);
1352
1353 private:
1354 string * make_debug_string ();
1355
1356 private:
1357 rvalue *m_rvalue;
1358 field *m_field;
1359 };
1360
1361 class dereference_rvalue : public lvalue
1362 {
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) {}
1369
1370 void replay_into (replayer *r);
1371
1372 private:
1373 string * make_debug_string ();
1374
1375 private:
1376 rvalue *m_rvalue;
1377 };
1378
1379 class get_address_of_lvalue : public rvalue
1380 {
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)
1387 {}
1388
1389 void replay_into (replayer *r);
1390
1391 private:
1392 string * make_debug_string ();
1393
1394 private:
1395 lvalue *m_lvalue;
1396 };
1397
1398 class local : public lvalue
1399 {
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) {}
1405
1406 void replay_into (replayer *r);
1407
1408 void write_to_dump (dump &d);
1409
1410 private:
1411 string * make_debug_string () { return m_name; }
1412
1413 private:
1414 function *m_func;
1415 string *m_name;
1416 };
1417
1418 class statement : public memento
1419 {
1420 public:
1421 virtual int get_successor_blocks (block **out_next1,
1422 block **out_next2) const;
1423
1424 void write_to_dump (dump &d);
1425
1426 location *get_loc () const { return m_loc; }
1427
1428 protected:
1429 statement (block *b, location *loc)
1430 : memento (b->m_ctxt),
1431 m_block (b),
1432 m_loc (loc) {}
1433
1434 block *get_block () const { return m_block; }
1435
1436 playback::location *
1437 playback_location (replayer *r) const
1438 {
1439 return ::gcc::jit::recording::playback_location (r, m_loc);
1440 }
1441
1442 private:
1443 block *m_block;
1444 location *m_loc;
1445 };
1446
1447 class eval : public statement
1448 {
1449 public:
1450 eval (block *b,
1451 location *loc,
1452 rvalue *rvalue)
1453 : statement (b, loc),
1454 m_rvalue (rvalue) {}
1455
1456 void replay_into (replayer *r);
1457
1458 private:
1459 string * make_debug_string ();
1460
1461 private:
1462 rvalue *m_rvalue;
1463 };
1464
1465 class assignment : public statement
1466 {
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) {}
1475
1476 void replay_into (replayer *r);
1477
1478 private:
1479 string * make_debug_string ();
1480
1481 private:
1482 lvalue *m_lvalue;
1483 rvalue *m_rvalue;
1484 };
1485
1486 class assignment_op : public statement
1487 {
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) {}
1498
1499 void replay_into (replayer *r);
1500
1501 private:
1502 string * make_debug_string ();
1503
1504 private:
1505 lvalue *m_lvalue;
1506 enum gcc_jit_binary_op m_op;
1507 rvalue *m_rvalue;
1508 };
1509
1510 class comment : public statement
1511 {
1512 public:
1513 comment (block *b,
1514 location *loc,
1515 string *text)
1516 : statement (b, loc),
1517 m_text (text) {}
1518
1519 void replay_into (replayer *r);
1520
1521 private:
1522 string * make_debug_string ();
1523
1524 private:
1525 string *m_text;
1526 };
1527
1528 class conditional : public statement
1529 {
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) {}
1540
1541 void replay_into (replayer *r);
1542
1543 int get_successor_blocks (block **out_next1,
1544 block **out_next2) const;
1545
1546 private:
1547 string * make_debug_string ();
1548
1549 private:
1550 rvalue *m_boolval;
1551 block *m_on_true;
1552 block *m_on_false;
1553 };
1554
1555 class jump : public statement
1556 {
1557 public:
1558 jump (block *b,
1559 location *loc,
1560 block *target)
1561 : statement (b, loc),
1562 m_target (target) {}
1563
1564 void replay_into (replayer *r);
1565
1566 int get_successor_blocks (block **out_next1,
1567 block **out_next2) const;
1568
1569 private:
1570 string * make_debug_string ();
1571
1572 private:
1573 block *m_target;
1574 };
1575
1576 class return_ : public statement
1577 {
1578 public:
1579 return_ (block *b,
1580 location *loc,
1581 rvalue *rvalue)
1582 : statement (b, loc),
1583 m_rvalue (rvalue) {}
1584
1585 void replay_into (replayer *r);
1586
1587 int get_successor_blocks (block **out_next1,
1588 block **out_next2) const;
1589
1590 private:
1591 string * make_debug_string ();
1592
1593 private:
1594 rvalue *m_rvalue;
1595 };
1596
1597 } // namespace gcc::jit::recording
1598
1599 } // namespace gcc::jit
1600
1601 } // namespace gcc
1602
1603 #endif /* JIT_RECORDING_H */