Home | History | Annotate | Line # | Download | only in jit
jit-playback.h revision 1.6
      1  1.1  mrg /* Internals of libgccjit: classes for playing back recorded API calls.
      2  1.6  mrg    Copyright (C) 2013-2020 Free Software Foundation, Inc.
      3  1.1  mrg    Contributed by David Malcolm <dmalcolm (at) redhat.com>.
      4  1.1  mrg 
      5  1.1  mrg This file is part of GCC.
      6  1.1  mrg 
      7  1.1  mrg GCC is free software; you can redistribute it and/or modify it
      8  1.1  mrg under the terms of the GNU General Public License as published by
      9  1.1  mrg the Free Software Foundation; either version 3, or (at your option)
     10  1.1  mrg any later version.
     11  1.1  mrg 
     12  1.1  mrg GCC is distributed in the hope that it will be useful, but
     13  1.1  mrg WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  1.1  mrg General Public License for more details.
     16  1.1  mrg 
     17  1.1  mrg You should have received a copy of the GNU General Public License
     18  1.1  mrg along with GCC; see the file COPYING3.  If not see
     19  1.1  mrg <http://www.gnu.org/licenses/>.  */
     20  1.1  mrg 
     21  1.1  mrg #ifndef JIT_PLAYBACK_H
     22  1.1  mrg #define JIT_PLAYBACK_H
     23  1.1  mrg 
     24  1.1  mrg #include <utility> // for std::pair
     25  1.1  mrg 
     26  1.1  mrg #include "timevar.h"
     27  1.1  mrg 
     28  1.1  mrg #include "jit-recording.h"
     29  1.1  mrg 
     30  1.3  mrg struct diagnostic_context;
     31  1.3  mrg struct diagnostic_info;
     32  1.3  mrg 
     33  1.1  mrg namespace gcc {
     34  1.1  mrg 
     35  1.1  mrg namespace jit {
     36  1.1  mrg 
     37  1.1  mrg /**********************************************************************
     38  1.1  mrg  Playback.
     39  1.1  mrg  **********************************************************************/
     40  1.1  mrg 
     41  1.1  mrg namespace playback {
     42  1.1  mrg 
     43  1.1  mrg /* playback::context is an abstract base class.
     44  1.1  mrg 
     45  1.1  mrg    The two concrete subclasses are:
     46  1.1  mrg    - playback::compile_to_memory
     47  1.1  mrg    - playback::compile_to_file.  */
     48  1.1  mrg 
     49  1.1  mrg class context : public log_user
     50  1.1  mrg {
     51  1.1  mrg public:
     52  1.1  mrg   context (::gcc::jit::recording::context *ctxt);
     53  1.1  mrg   ~context ();
     54  1.1  mrg 
     55  1.1  mrg   void gt_ggc_mx ();
     56  1.1  mrg 
     57  1.1  mrg   void replay ();
     58  1.1  mrg 
     59  1.1  mrg   location *
     60  1.1  mrg   new_location (recording::location *rloc,
     61  1.1  mrg 		const char *filename,
     62  1.1  mrg 		int line,
     63  1.1  mrg 		int column);
     64  1.1  mrg 
     65  1.1  mrg   type *
     66  1.1  mrg   get_type (enum gcc_jit_types type);
     67  1.1  mrg 
     68  1.1  mrg   type *
     69  1.1  mrg   new_array_type (location *loc,
     70  1.1  mrg 		  type *element_type,
     71  1.1  mrg 		  int num_elements);
     72  1.1  mrg 
     73  1.1  mrg   field *
     74  1.1  mrg   new_field (location *loc,
     75  1.1  mrg 	     type *type,
     76  1.1  mrg 	     const char *name);
     77  1.1  mrg 
     78  1.6  mrg   field *
     79  1.6  mrg   new_bitfield (location *loc,
     80  1.6  mrg 		type *type,
     81  1.6  mrg 		int width,
     82  1.6  mrg 		const char *name);
     83  1.6  mrg 
     84  1.1  mrg   compound_type *
     85  1.1  mrg   new_compound_type (location *loc,
     86  1.1  mrg 		     const char *name,
     87  1.1  mrg 		     bool is_struct); /* else is union */
     88  1.1  mrg 
     89  1.1  mrg   type *
     90  1.1  mrg   new_function_type (type *return_type,
     91  1.1  mrg 		     const auto_vec<type *> *param_types,
     92  1.1  mrg 		     int is_variadic);
     93  1.1  mrg 
     94  1.1  mrg   param *
     95  1.1  mrg   new_param (location *loc,
     96  1.1  mrg 	     type *type,
     97  1.1  mrg 	     const char *name);
     98  1.1  mrg 
     99  1.1  mrg   function *
    100  1.1  mrg   new_function (location *loc,
    101  1.1  mrg 		enum gcc_jit_function_kind kind,
    102  1.1  mrg 		type *return_type,
    103  1.1  mrg 		const char *name,
    104  1.1  mrg 		const auto_vec<param *> *params,
    105  1.1  mrg 		int is_variadic,
    106  1.1  mrg 		enum built_in_function builtin_id);
    107  1.1  mrg 
    108  1.1  mrg   lvalue *
    109  1.1  mrg   new_global (location *loc,
    110  1.1  mrg 	      enum gcc_jit_global_kind kind,
    111  1.1  mrg 	      type *type,
    112  1.1  mrg 	      const char *name);
    113  1.1  mrg 
    114  1.1  mrg   template <typename HOST_TYPE>
    115  1.1  mrg   rvalue *
    116  1.1  mrg   new_rvalue_from_const (type *type,
    117  1.1  mrg 			 HOST_TYPE value);
    118  1.1  mrg 
    119  1.1  mrg   rvalue *
    120  1.1  mrg   new_string_literal (const char *value);
    121  1.1  mrg 
    122  1.1  mrg   rvalue *
    123  1.4  mrg   new_rvalue_from_vector (location *loc,
    124  1.4  mrg 			  type *type,
    125  1.4  mrg 			  const auto_vec<rvalue *> &elements);
    126  1.4  mrg 
    127  1.4  mrg   rvalue *
    128  1.1  mrg   new_unary_op (location *loc,
    129  1.1  mrg 		enum gcc_jit_unary_op op,
    130  1.1  mrg 		type *result_type,
    131  1.1  mrg 		rvalue *a);
    132  1.1  mrg 
    133  1.1  mrg   rvalue *
    134  1.1  mrg   new_binary_op (location *loc,
    135  1.1  mrg 		 enum gcc_jit_binary_op op,
    136  1.1  mrg 		 type *result_type,
    137  1.1  mrg 		 rvalue *a, rvalue *b);
    138  1.1  mrg 
    139  1.1  mrg   rvalue *
    140  1.1  mrg   new_comparison (location *loc,
    141  1.1  mrg 		  enum gcc_jit_comparison op,
    142  1.1  mrg 		  rvalue *a, rvalue *b);
    143  1.1  mrg 
    144  1.1  mrg   rvalue *
    145  1.1  mrg   new_call (location *loc,
    146  1.1  mrg 	    function *func,
    147  1.3  mrg 	    const auto_vec<rvalue *> *args,
    148  1.3  mrg 	    bool require_tail_call);
    149  1.1  mrg 
    150  1.1  mrg   rvalue *
    151  1.1  mrg   new_call_through_ptr (location *loc,
    152  1.1  mrg 			rvalue *fn_ptr,
    153  1.3  mrg 			const auto_vec<rvalue *> *args,
    154  1.3  mrg 			bool require_tail_call);
    155  1.1  mrg 
    156  1.1  mrg   rvalue *
    157  1.1  mrg   new_cast (location *loc,
    158  1.1  mrg 	    rvalue *expr,
    159  1.1  mrg 	    type *type_);
    160  1.1  mrg 
    161  1.1  mrg   lvalue *
    162  1.1  mrg   new_array_access (location *loc,
    163  1.1  mrg 		    rvalue *ptr,
    164  1.1  mrg 		    rvalue *index);
    165  1.1  mrg 
    166  1.1  mrg   void
    167  1.1  mrg   set_str_option (enum gcc_jit_str_option opt,
    168  1.1  mrg 		  const char *value);
    169  1.1  mrg 
    170  1.1  mrg   void
    171  1.1  mrg   set_int_option (enum gcc_jit_int_option opt,
    172  1.1  mrg 		  int value);
    173  1.1  mrg 
    174  1.1  mrg   void
    175  1.1  mrg   set_bool_option (enum gcc_jit_bool_option opt,
    176  1.1  mrg 		   int value);
    177  1.1  mrg 
    178  1.1  mrg   const char *
    179  1.1  mrg   get_str_option (enum gcc_jit_str_option opt) const
    180  1.1  mrg   {
    181  1.1  mrg     return m_recording_ctxt->get_str_option (opt);
    182  1.1  mrg   }
    183  1.1  mrg 
    184  1.1  mrg   int
    185  1.1  mrg   get_int_option (enum gcc_jit_int_option opt) const
    186  1.1  mrg   {
    187  1.1  mrg     return m_recording_ctxt->get_int_option (opt);
    188  1.1  mrg   }
    189  1.1  mrg 
    190  1.1  mrg   int
    191  1.1  mrg   get_bool_option (enum gcc_jit_bool_option opt) const
    192  1.1  mrg   {
    193  1.1  mrg     return m_recording_ctxt->get_bool_option (opt);
    194  1.1  mrg   }
    195  1.1  mrg 
    196  1.3  mrg   int
    197  1.3  mrg   get_inner_bool_option (enum inner_bool_option opt) const
    198  1.3  mrg   {
    199  1.3  mrg     return m_recording_ctxt->get_inner_bool_option (opt);
    200  1.3  mrg   }
    201  1.3  mrg 
    202  1.1  mrg   builtins_manager *get_builtins_manager () const
    203  1.1  mrg   {
    204  1.1  mrg     return m_recording_ctxt->get_builtins_manager ();
    205  1.1  mrg   }
    206  1.1  mrg 
    207  1.1  mrg   void
    208  1.1  mrg   compile ();
    209  1.1  mrg 
    210  1.1  mrg   void
    211  1.1  mrg   add_error (location *loc, const char *fmt, ...)
    212  1.1  mrg       GNU_PRINTF(3, 4);
    213  1.1  mrg 
    214  1.1  mrg   void
    215  1.1  mrg   add_error_va (location *loc, const char *fmt, va_list ap)
    216  1.1  mrg       GNU_PRINTF(3, 0);
    217  1.1  mrg 
    218  1.1  mrg   const char *
    219  1.1  mrg   get_first_error () const;
    220  1.1  mrg 
    221  1.1  mrg   void
    222  1.3  mrg   add_diagnostic (struct diagnostic_context *context,
    223  1.3  mrg 		  struct diagnostic_info *diagnostic);
    224  1.3  mrg 
    225  1.3  mrg   void
    226  1.1  mrg   set_tree_location (tree t, location *loc);
    227  1.1  mrg 
    228  1.1  mrg   tree
    229  1.1  mrg   new_field_access (location *loc,
    230  1.1  mrg 		    tree datum,
    231  1.1  mrg 		    field *field);
    232  1.1  mrg 
    233  1.1  mrg   tree
    234  1.1  mrg   new_dereference (tree ptr, location *loc);
    235  1.1  mrg 
    236  1.1  mrg   tree
    237  1.1  mrg   as_truth_value (tree expr, location *loc);
    238  1.1  mrg 
    239  1.1  mrg   bool errors_occurred () const
    240  1.1  mrg   {
    241  1.1  mrg     return m_recording_ctxt->errors_occurred ();
    242  1.1  mrg   }
    243  1.1  mrg 
    244  1.3  mrg   timer *get_timer () const { return m_recording_ctxt->get_timer (); }
    245  1.1  mrg 
    246  1.1  mrg private:
    247  1.1  mrg   void dump_generated_code ();
    248  1.1  mrg 
    249  1.1  mrg   rvalue *
    250  1.1  mrg   build_call (location *loc,
    251  1.1  mrg 	      tree fn_ptr,
    252  1.3  mrg 	      const auto_vec<rvalue *> *args,
    253  1.3  mrg 	      bool require_tail_call);
    254  1.1  mrg 
    255  1.1  mrg   tree
    256  1.1  mrg   build_cast (location *loc,
    257  1.1  mrg 	      rvalue *expr,
    258  1.1  mrg 	      type *type_);
    259  1.1  mrg 
    260  1.1  mrg   source_file *
    261  1.1  mrg   get_source_file (const char *filename);
    262  1.1  mrg 
    263  1.1  mrg   void handle_locations ();
    264  1.1  mrg 
    265  1.1  mrg   const char * get_path_c_file () const;
    266  1.1  mrg   const char * get_path_s_file () const;
    267  1.1  mrg   const char * get_path_so_file () const;
    268  1.1  mrg 
    269  1.1  mrg private:
    270  1.1  mrg 
    271  1.1  mrg   /* Functions for implementing "compile".  */
    272  1.1  mrg 
    273  1.1  mrg   void acquire_mutex ();
    274  1.1  mrg   void release_mutex ();
    275  1.1  mrg 
    276  1.1  mrg   void
    277  1.1  mrg   make_fake_args (vec <char *> *argvec,
    278  1.1  mrg 		  const char *ctxt_progname,
    279  1.1  mrg 		  vec <recording::requested_dump> *requested_dumps);
    280  1.1  mrg 
    281  1.1  mrg   void
    282  1.1  mrg   extract_any_requested_dumps
    283  1.1  mrg     (vec <recording::requested_dump> *requested_dumps);
    284  1.1  mrg 
    285  1.1  mrg   char *
    286  1.1  mrg   read_dump_file (const char *path);
    287  1.1  mrg 
    288  1.1  mrg   virtual void postprocess (const char *ctxt_progname) = 0;
    289  1.1  mrg 
    290  1.1  mrg protected:
    291  1.1  mrg   tempdir *get_tempdir () { return m_tempdir; }
    292  1.1  mrg 
    293  1.1  mrg   void
    294  1.1  mrg   convert_to_dso (const char *ctxt_progname);
    295  1.1  mrg 
    296  1.1  mrg   void
    297  1.1  mrg   invoke_driver (const char *ctxt_progname,
    298  1.1  mrg 		 const char *input_file,
    299  1.1  mrg 		 const char *output_file,
    300  1.1  mrg 		 timevar_id_t tv_id,
    301  1.1  mrg 		 bool shared,
    302  1.1  mrg 		 bool run_linker);
    303  1.1  mrg 
    304  1.1  mrg   void
    305  1.1  mrg   add_multilib_driver_arguments (vec <char *> *argvec);
    306  1.1  mrg 
    307  1.1  mrg   result *
    308  1.1  mrg   dlopen_built_dso ();
    309  1.1  mrg 
    310  1.3  mrg  private:
    311  1.3  mrg   void
    312  1.3  mrg   invoke_embedded_driver (const vec <char *> *argvec);
    313  1.3  mrg 
    314  1.3  mrg   void
    315  1.3  mrg   invoke_external_driver (const char *ctxt_progname,
    316  1.3  mrg 			  vec <char *> *argvec);
    317  1.3  mrg 
    318  1.1  mrg private:
    319  1.1  mrg   ::gcc::jit::recording::context *m_recording_ctxt;
    320  1.1  mrg 
    321  1.1  mrg   tempdir *m_tempdir;
    322  1.1  mrg 
    323  1.1  mrg   auto_vec<function *> m_functions;
    324  1.1  mrg   auto_vec<tree> m_globals;
    325  1.1  mrg   tree m_const_char_ptr;
    326  1.1  mrg 
    327  1.1  mrg   /* Source location handling.  */
    328  1.1  mrg   auto_vec<source_file *> m_source_files;
    329  1.1  mrg 
    330  1.1  mrg   auto_vec<std::pair<tree, location *> > m_cached_locations;
    331  1.1  mrg };
    332  1.1  mrg 
    333  1.1  mrg class compile_to_memory : public context
    334  1.1  mrg {
    335  1.1  mrg  public:
    336  1.1  mrg   compile_to_memory (recording::context *ctxt);
    337  1.3  mrg   void postprocess (const char *ctxt_progname) FINAL OVERRIDE;
    338  1.1  mrg 
    339  1.1  mrg   result *get_result_obj () const { return m_result; }
    340  1.1  mrg 
    341  1.1  mrg  private:
    342  1.1  mrg   result *m_result;
    343  1.1  mrg };
    344  1.1  mrg 
    345  1.1  mrg class compile_to_file : public context
    346  1.1  mrg {
    347  1.1  mrg  public:
    348  1.1  mrg   compile_to_file (recording::context *ctxt,
    349  1.1  mrg 		   enum gcc_jit_output_kind output_kind,
    350  1.1  mrg 		   const char *output_path);
    351  1.3  mrg   void postprocess (const char *ctxt_progname) FINAL OVERRIDE;
    352  1.1  mrg 
    353  1.1  mrg  private:
    354  1.1  mrg   void
    355  1.1  mrg   copy_file (const char *src_path,
    356  1.1  mrg 	     const char *dst_path);
    357  1.1  mrg 
    358  1.1  mrg  private:
    359  1.1  mrg   enum gcc_jit_output_kind m_output_kind;
    360  1.1  mrg   const char *m_output_path;
    361  1.1  mrg };
    362  1.1  mrg 
    363  1.1  mrg 
    364  1.1  mrg /* A temporary wrapper object.
    365  1.1  mrg    These objects are (mostly) only valid during replay.
    366  1.1  mrg    We allocate them on the GC heap, so that they will be cleaned
    367  1.1  mrg    the next time the GC collects.
    368  1.1  mrg    The exception is the "function" class, which is tracked and marked by
    369  1.1  mrg    the jit::context, since it needs to stay alive during post-processing
    370  1.1  mrg    (when the GC could run). */
    371  1.1  mrg class wrapper
    372  1.1  mrg {
    373  1.1  mrg public:
    374  1.1  mrg   /* Allocate in the GC heap.  */
    375  1.1  mrg   void *operator new (size_t sz);
    376  1.1  mrg 
    377  1.1  mrg   /* Some wrapper subclasses contain vec<> and so need to
    378  1.1  mrg      release them when they are GC-ed.  */
    379  1.1  mrg   virtual void finalizer () { }
    380  1.1  mrg 
    381  1.1  mrg };
    382  1.1  mrg 
    383  1.1  mrg class type : public wrapper
    384  1.1  mrg {
    385  1.1  mrg public:
    386  1.1  mrg   type (tree inner)
    387  1.1  mrg     : m_inner(inner)
    388  1.1  mrg   {}
    389  1.1  mrg 
    390  1.1  mrg   tree as_tree () const { return m_inner; }
    391  1.1  mrg 
    392  1.1  mrg   type *get_pointer () const { return new type (build_pointer_type (m_inner)); }
    393  1.1  mrg 
    394  1.1  mrg   type *get_const () const
    395  1.1  mrg   {
    396  1.1  mrg     return new type (build_qualified_type (m_inner, TYPE_QUAL_CONST));
    397  1.1  mrg   }
    398  1.1  mrg 
    399  1.1  mrg   type *get_volatile () const
    400  1.1  mrg   {
    401  1.1  mrg     return new type (build_qualified_type (m_inner, TYPE_QUAL_VOLATILE));
    402  1.1  mrg   }
    403  1.1  mrg 
    404  1.4  mrg   type *get_aligned (size_t alignment_in_bytes) const;
    405  1.4  mrg   type *get_vector (size_t num_units) const;
    406  1.4  mrg 
    407  1.1  mrg private:
    408  1.1  mrg   tree m_inner;
    409  1.1  mrg };
    410  1.1  mrg 
    411  1.1  mrg class compound_type : public type
    412  1.1  mrg {
    413  1.1  mrg public:
    414  1.1  mrg   compound_type (tree inner)
    415  1.1  mrg     : type (inner)
    416  1.1  mrg   {}
    417  1.1  mrg 
    418  1.1  mrg   void set_fields (const auto_vec<field *> *fields);
    419  1.1  mrg };
    420  1.1  mrg 
    421  1.1  mrg class field : public wrapper
    422  1.1  mrg {
    423  1.1  mrg public:
    424  1.1  mrg   field (tree inner)
    425  1.1  mrg     : m_inner(inner)
    426  1.1  mrg   {}
    427  1.1  mrg 
    428  1.1  mrg   tree as_tree () const { return m_inner; }
    429  1.1  mrg 
    430  1.1  mrg private:
    431  1.1  mrg   tree m_inner;
    432  1.1  mrg };
    433  1.1  mrg 
    434  1.6  mrg class bitfield : public field {};
    435  1.6  mrg 
    436  1.1  mrg class function : public wrapper
    437  1.1  mrg {
    438  1.1  mrg public:
    439  1.1  mrg   function(context *ctxt, tree fndecl, enum gcc_jit_function_kind kind);
    440  1.1  mrg 
    441  1.1  mrg   void gt_ggc_mx ();
    442  1.3  mrg   void finalizer () FINAL OVERRIDE;
    443  1.1  mrg 
    444  1.1  mrg   tree get_return_type_as_tree () const;
    445  1.1  mrg 
    446  1.1  mrg   tree as_fndecl () const { return m_inner_fndecl; }
    447  1.1  mrg 
    448  1.1  mrg   enum gcc_jit_function_kind get_kind () const { return m_kind; }
    449  1.1  mrg 
    450  1.1  mrg   lvalue *
    451  1.1  mrg   new_local (location *loc,
    452  1.1  mrg 	     type *type,
    453  1.1  mrg 	     const char *name);
    454  1.1  mrg 
    455  1.1  mrg   block*
    456  1.1  mrg   new_block (const char *name);
    457  1.1  mrg 
    458  1.4  mrg   rvalue *
    459  1.4  mrg   get_address (location *loc);
    460  1.4  mrg 
    461  1.1  mrg   void
    462  1.1  mrg   build_stmt_list ();
    463  1.1  mrg 
    464  1.1  mrg   void
    465  1.1  mrg   postprocess ();
    466  1.1  mrg 
    467  1.1  mrg public:
    468  1.1  mrg   context *m_ctxt;
    469  1.1  mrg 
    470  1.1  mrg public:
    471  1.1  mrg   void
    472  1.1  mrg   set_tree_location (tree t, location *loc)
    473  1.1  mrg   {
    474  1.1  mrg     m_ctxt->set_tree_location (t, loc);
    475  1.1  mrg   }
    476  1.1  mrg 
    477  1.1  mrg private:
    478  1.1  mrg   tree m_inner_fndecl;
    479  1.1  mrg   tree m_inner_block;
    480  1.1  mrg   tree m_inner_bind_expr;
    481  1.1  mrg   enum gcc_jit_function_kind m_kind;
    482  1.1  mrg   tree m_stmt_list;
    483  1.1  mrg   tree_stmt_iterator m_stmt_iter;
    484  1.1  mrg   vec<block *> m_blocks;
    485  1.1  mrg };
    486  1.1  mrg 
    487  1.1  mrg struct case_
    488  1.1  mrg {
    489  1.1  mrg   case_ (rvalue *min_value, rvalue *max_value, block *dest_block)
    490  1.1  mrg   : m_min_value (min_value),
    491  1.1  mrg     m_max_value (max_value),
    492  1.1  mrg     m_dest_block (dest_block)
    493  1.1  mrg   {}
    494  1.1  mrg 
    495  1.1  mrg   rvalue *m_min_value;
    496  1.1  mrg   rvalue *m_max_value;
    497  1.1  mrg   block *m_dest_block;
    498  1.1  mrg };
    499  1.1  mrg 
    500  1.1  mrg class block : public wrapper
    501  1.1  mrg {
    502  1.1  mrg public:
    503  1.1  mrg   block (function *func,
    504  1.1  mrg 	 const char *name);
    505  1.1  mrg 
    506  1.3  mrg   void finalizer () FINAL OVERRIDE;
    507  1.1  mrg 
    508  1.1  mrg   tree as_label_decl () const { return m_label_decl; }
    509  1.1  mrg 
    510  1.1  mrg   function *get_function () const { return m_func; }
    511  1.1  mrg 
    512  1.1  mrg   void
    513  1.1  mrg   add_eval (location *loc,
    514  1.1  mrg 	    rvalue *rvalue);
    515  1.1  mrg 
    516  1.1  mrg   void
    517  1.1  mrg   add_assignment (location *loc,
    518  1.1  mrg 		  lvalue *lvalue,
    519  1.1  mrg 		  rvalue *rvalue);
    520  1.1  mrg 
    521  1.1  mrg   void
    522  1.1  mrg   add_comment (location *loc,
    523  1.1  mrg 	       const char *text);
    524  1.1  mrg 
    525  1.1  mrg   void
    526  1.1  mrg   add_conditional (location *loc,
    527  1.1  mrg 		   rvalue *boolval,
    528  1.1  mrg 		   block *on_true,
    529  1.1  mrg 		   block *on_false);
    530  1.1  mrg 
    531  1.1  mrg   block *
    532  1.1  mrg   add_block (location *loc,
    533  1.1  mrg 	     const char *name);
    534  1.1  mrg 
    535  1.1  mrg   void
    536  1.1  mrg   add_jump (location *loc,
    537  1.1  mrg 	    block *target);
    538  1.1  mrg 
    539  1.1  mrg   void
    540  1.1  mrg   add_return (location *loc,
    541  1.1  mrg 	      rvalue *rvalue);
    542  1.1  mrg 
    543  1.1  mrg   void
    544  1.1  mrg   add_switch (location *loc,
    545  1.1  mrg 	      rvalue *expr,
    546  1.1  mrg 	      block *default_block,
    547  1.1  mrg 	      const auto_vec <case_> *cases);
    548  1.1  mrg 
    549  1.1  mrg private:
    550  1.1  mrg   void
    551  1.1  mrg   set_tree_location (tree t, location *loc)
    552  1.1  mrg   {
    553  1.1  mrg     m_func->set_tree_location (t, loc);
    554  1.1  mrg   }
    555  1.1  mrg 
    556  1.1  mrg   void add_stmt (tree stmt)
    557  1.1  mrg   {
    558  1.1  mrg     /* TODO: use one stmt_list per block.  */
    559  1.1  mrg     m_stmts.safe_push (stmt);
    560  1.1  mrg   }
    561  1.1  mrg 
    562  1.1  mrg private:
    563  1.1  mrg   function *m_func;
    564  1.1  mrg   tree m_label_decl;
    565  1.1  mrg   vec<tree> m_stmts;
    566  1.1  mrg 
    567  1.1  mrg public: // for now
    568  1.1  mrg   tree m_label_expr;
    569  1.1  mrg 
    570  1.1  mrg   friend class function;
    571  1.1  mrg };
    572  1.1  mrg 
    573  1.1  mrg class rvalue : public wrapper
    574  1.1  mrg {
    575  1.1  mrg public:
    576  1.1  mrg   rvalue (context *ctxt, tree inner)
    577  1.1  mrg     : m_ctxt (ctxt),
    578  1.1  mrg       m_inner (inner)
    579  1.1  mrg   {}
    580  1.1  mrg 
    581  1.1  mrg   rvalue *
    582  1.1  mrg   as_rvalue () { return this; }
    583  1.1  mrg 
    584  1.1  mrg   tree as_tree () const { return m_inner; }
    585  1.1  mrg 
    586  1.1  mrg   context *get_context () const { return m_ctxt; }
    587  1.1  mrg 
    588  1.1  mrg   type *
    589  1.1  mrg   get_type () { return new type (TREE_TYPE (m_inner)); }
    590  1.1  mrg 
    591  1.1  mrg   rvalue *
    592  1.1  mrg   access_field (location *loc,
    593  1.1  mrg 		field *field);
    594  1.1  mrg 
    595  1.1  mrg   lvalue *
    596  1.1  mrg   dereference_field (location *loc,
    597  1.1  mrg 		     field *field);
    598  1.1  mrg 
    599  1.1  mrg   lvalue *
    600  1.1  mrg   dereference (location *loc);
    601  1.1  mrg 
    602  1.1  mrg private:
    603  1.1  mrg   context *m_ctxt;
    604  1.1  mrg   tree m_inner;
    605  1.1  mrg };
    606  1.1  mrg 
    607  1.1  mrg class lvalue : public rvalue
    608  1.1  mrg {
    609  1.1  mrg public:
    610  1.1  mrg   lvalue (context *ctxt, tree inner)
    611  1.1  mrg     : rvalue(ctxt, inner)
    612  1.1  mrg   {}
    613  1.1  mrg 
    614  1.1  mrg   lvalue *
    615  1.1  mrg   as_lvalue () { return this; }
    616  1.1  mrg 
    617  1.1  mrg   lvalue *
    618  1.1  mrg   access_field (location *loc,
    619  1.1  mrg 		field *field);
    620  1.1  mrg 
    621  1.1  mrg   rvalue *
    622  1.1  mrg   get_address (location *loc);
    623  1.1  mrg 
    624  1.6  mrg private:
    625  1.6  mrg   bool mark_addressable (location *loc);
    626  1.1  mrg };
    627  1.1  mrg 
    628  1.1  mrg class param : public lvalue
    629  1.1  mrg {
    630  1.1  mrg public:
    631  1.1  mrg   param (context *ctxt, tree inner)
    632  1.1  mrg     : lvalue(ctxt, inner)
    633  1.1  mrg   {}
    634  1.1  mrg };
    635  1.1  mrg 
    636  1.1  mrg /* Dealing with the linemap API.
    637  1.1  mrg 
    638  1.1  mrg    It appears that libcpp requires locations to be created as if by
    639  1.1  mrg    a tokenizer, creating them by filename, in ascending order of
    640  1.1  mrg    line/column, whereas our API doesn't impose any such constraints:
    641  1.1  mrg    we allow client code to create locations in arbitrary orders.
    642  1.1  mrg 
    643  1.1  mrg    To square this circle, we need to cache all location creation,
    644  1.1  mrg    grouping things up by filename/line, and then creating the linemap
    645  1.1  mrg    entries in a post-processing phase.  */
    646  1.1  mrg 
    647  1.1  mrg /* A set of locations, all sharing a filename */
    648  1.1  mrg class source_file : public wrapper
    649  1.1  mrg {
    650  1.1  mrg public:
    651  1.1  mrg   source_file (tree filename);
    652  1.3  mrg   void finalizer () FINAL OVERRIDE;
    653  1.1  mrg 
    654  1.1  mrg   source_line *
    655  1.1  mrg   get_source_line (int line_num);
    656  1.1  mrg 
    657  1.1  mrg   tree filename_as_tree () const { return m_filename; }
    658  1.1  mrg 
    659  1.1  mrg   const char*
    660  1.1  mrg   get_filename () const { return IDENTIFIER_POINTER (m_filename); }
    661  1.1  mrg 
    662  1.1  mrg   vec<source_line *> m_source_lines;
    663  1.1  mrg 
    664  1.1  mrg private:
    665  1.1  mrg   tree m_filename;
    666  1.1  mrg };
    667  1.1  mrg 
    668  1.1  mrg /* A source line, with one or more locations of interest.  */
    669  1.1  mrg class source_line : public wrapper
    670  1.1  mrg {
    671  1.1  mrg public:
    672  1.1  mrg   source_line (source_file *file, int line_num);
    673  1.3  mrg   void finalizer () FINAL OVERRIDE;
    674  1.1  mrg 
    675  1.1  mrg   location *
    676  1.1  mrg   get_location (recording::location *rloc, int column_num);
    677  1.1  mrg 
    678  1.1  mrg   int get_line_num () const { return m_line_num; }
    679  1.1  mrg 
    680  1.1  mrg   vec<location *> m_locations;
    681  1.1  mrg 
    682  1.1  mrg private:
    683  1.1  mrg   source_file *m_source_file;
    684  1.1  mrg   int m_line_num;
    685  1.1  mrg };
    686  1.1  mrg 
    687  1.1  mrg /* A specific location on a source line.  This is what we expose
    688  1.1  mrg    to the client API.  */
    689  1.1  mrg class location : public wrapper
    690  1.1  mrg {
    691  1.1  mrg public:
    692  1.1  mrg   location (recording::location *loc, source_line *line, int column_num);
    693  1.1  mrg 
    694  1.1  mrg   int get_column_num () const { return m_column_num; }
    695  1.1  mrg 
    696  1.1  mrg   recording::location *get_recording_loc () const { return m_recording_loc; }
    697  1.1  mrg 
    698  1.5  mrg   location_t m_srcloc;
    699  1.1  mrg 
    700  1.1  mrg private:
    701  1.1  mrg   recording::location *m_recording_loc;
    702  1.1  mrg   source_line *m_line;
    703  1.1  mrg   int m_column_num;
    704  1.1  mrg };
    705  1.1  mrg 
    706  1.1  mrg } // namespace gcc::jit::playback
    707  1.1  mrg 
    708  1.1  mrg extern playback::context *active_playback_ctxt;
    709  1.1  mrg 
    710  1.1  mrg } // namespace gcc::jit
    711  1.1  mrg 
    712  1.1  mrg } // namespace gcc
    713  1.1  mrg 
    714  1.1  mrg #endif /* JIT_PLAYBACK_H */
    715