]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/jit/jit-common.h
tree-core.h: Include symtab.h.
[thirdparty/gcc.git] / gcc / jit / jit-common.h
1 /* Core of implementation of libgccjit.so
2 Copyright (C) 2013-2015 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_COMMON_H
22 #define JIT_COMMON_H
23
24 #include "libgccjit.h"
25
26 #include "vec.h"
27 #include "flags.h"
28 #include "tree.h"
29 #include "inchash.h"
30 #include "tree-iterator.h"
31
32 #ifdef GCC_VERSION
33 #if GCC_VERSION >= 4001
34 #define GNU_PRINTF(M, N) __attribute__ ((format (gnu_printf, (M), (N))))
35 #else
36 #define GNU_PRINTF(M, N)
37 #endif
38 #endif
39
40 const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE + 1;
41
42 /* This comment is included by the docs.
43
44 In order to allow jit objects to be usable outside of a compile
45 whilst working with the existing structure of GCC's code the
46 C API is implemented in terms of a gcc::jit::recording::context,
47 which records the calls made to it.
48
49 When a gcc_jit_context is compiled, the recording context creates a
50 playback context. The playback context invokes the bulk of the GCC
51 code, and within the "frontend" parsing hook, plays back the recorded
52 API calls, creating GCC tree objects.
53
54 So there are two parallel families of classes: those relating to
55 recording, and those relating to playback:
56
57 * Visibility: recording objects are exposed back to client code,
58 whereas playback objects are internal to the library.
59
60 * Lifetime: recording objects have a lifetime equal to that of the
61 recording context that created them, whereas playback objects only
62 exist within the frontend hook.
63
64 * Memory allocation: recording objects are allocated by the recording
65 context, and automatically freed by it when the context is released,
66 whereas playback objects are allocated within the GC heap, and
67 garbage-collected; they can own GC-references.
68
69 * Integration with rest of GCC: recording objects are unrelated to the
70 rest of GCC, whereas playback objects are wrappers around "tree"
71 instances. Hence you can't ask a recording rvalue or lvalue what its
72 type is, whereas you can for a playback rvalue of lvalue (since it
73 can work with the underlying GCC tree nodes).
74
75 * Instancing: There can be multiple recording contexts "alive" at once
76 (albeit it only one compiling at once), whereas there can only be one
77 playback context alive at one time (since it interacts with the GC).
78
79 Ultimately if GCC could support multiple GC heaps and contexts, and
80 finer-grained initialization, then this recording vs playback
81 distinction could be eliminated.
82
83 During a playback, we associate objects from the recording with
84 their counterparts during this playback. For simplicity, we store this
85 within the recording objects, as ``void *m_playback_obj``, casting it to
86 the appropriate playback object subclass. For these casts to make
87 sense, the two class hierarchies need to have the same structure.
88
89 Note that the playback objects that ``m_playback_obj`` points to are
90 GC-allocated, but the recording objects don't own references:
91 these associations only exist within a part of the code where
92 the GC doesn't collect, and are set back to NULL before the GC can
93 run.
94
95 End of comment for inclusion in the docs. */
96
97 namespace gcc {
98
99 namespace jit {
100
101 class result;
102 class dump;
103 class logger;
104 class builtins_manager; // declared within jit-builtins.h
105 class tempdir;
106
107 namespace recording {
108
109 /* Recording types. */
110
111 /* Indentation indicates inheritance: */
112 class context;
113 class memento;
114 class string;
115 class location;
116 class type;
117 class function_type;
118 class compound_type;
119 class struct_;
120 class union_;
121 class field;
122 class fields;
123 class function;
124 class block;
125 class rvalue;
126 class lvalue;
127 class local;
128 class global;
129 class param;
130 class statement;
131 class case_;
132
133 /* End of recording types. */
134 }
135
136 namespace playback {
137 /* Playback types. */
138
139 /* Indentation indicates inheritance: */
140 class context;
141 class wrapper;
142 class type;
143 class compound_type;
144 class field;
145 class function;
146 class block;
147 class rvalue;
148 class lvalue;
149 class param;
150 class source_file;
151 class source_line;
152 class location;
153 class case_;
154
155 /* End of playback types. */
156 }
157
158 typedef playback::context replayer;
159
160 class dump
161 {
162 public:
163 dump (recording::context &ctxt,
164 const char *filename,
165 bool update_locations);
166 ~dump ();
167
168 recording::context &get_context () { return m_ctxt; }
169
170 void write (const char *fmt, ...)
171 GNU_PRINTF(2, 3);
172
173 bool update_locations () const { return m_update_locations; }
174
175 recording::location *
176 make_location () const;
177
178 FILE *get_file () const { return m_file; }
179
180 private:
181 recording::context &m_ctxt;
182 const char *m_filename;
183 bool m_update_locations;
184 int m_line;
185 int m_column;
186 FILE *m_file;
187 };
188
189 /* A hidden enum of boolean options that are only exposed via API
190 entrypoints, rather than via gcc_jit_context_set_bool_option. */
191
192 enum inner_bool_option
193 {
194 INNER_BOOL_OPTION_ALLOW_UNREACHABLE_BLOCKS,
195
196 NUM_INNER_BOOL_OPTIONS
197 };
198
199 } // namespace gcc::jit
200
201 } // namespace gcc
202
203 #endif /* JIT_COMMON_H */