]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/jit/jit-common.h
New jit API entrypoint: gcc_jit_context_set_logfile
[thirdparty/gcc.git] / gcc / jit / jit-common.h
CommitLineData
35485da9 1/* Core of implementation of libgccjit.so
1e3b6a3d 2 Copyright (C) 2013-2015 Free Software Foundation, Inc.
35485da9
DM
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along 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 "tree.h"
27#include "tree-iterator.h"
28
29#ifdef GCC_VERSION
30#if GCC_VERSION >= 4001
31#define GNU_PRINTF(M, N) __attribute__ ((format (gnu_printf, (M), (N))))
32#else
33#define GNU_PRINTF(M, N)
34#endif
35#endif
36
eeafb319 37const int NUM_GCC_JIT_TYPES = GCC_JIT_TYPE_COMPLEX_LONG_DOUBLE + 1;
35485da9
DM
38
39/* This comment is included by the docs.
40
41 In order to allow jit objects to be usable outside of a compile
42 whilst working with the existing structure of GCC's code the
43 C API is implemented in terms of a gcc::jit::recording::context,
44 which records the calls made to it.
45
46 When a gcc_jit_context is compiled, the recording context creates a
47 playback context. The playback context invokes the bulk of the GCC
48 code, and within the "frontend" parsing hook, plays back the recorded
49 API calls, creating GCC tree objects.
50
51 So there are two parallel families of classes: those relating to
52 recording, and those relating to playback:
53
54 * Visibility: recording objects are exposed back to client code,
55 whereas playback objects are internal to the library.
56
57 * Lifetime: recording objects have a lifetime equal to that of the
58 recording context that created them, whereas playback objects only
59 exist within the frontend hook.
60
61 * Memory allocation: recording objects are allocated by the recording
62 context, and automatically freed by it when the context is released,
63 whereas playback objects are allocated within the GC heap, and
64 garbage-collected; they can own GC-references.
65
66 * Integration with rest of GCC: recording objects are unrelated to the
67 rest of GCC, whereas playback objects are wrappers around "tree"
68 instances. Hence you can't ask a recording rvalue or lvalue what its
69 type is, whereas you can for a playback rvalue of lvalue (since it
70 can work with the underlying GCC tree nodes).
71
72 * Instancing: There can be multiple recording contexts "alive" at once
73 (albeit it only one compiling at once), whereas there can only be one
74 playback context alive at one time (since it interacts with the GC).
75
76 Ultimately if GCC could support multiple GC heaps and contexts, and
77 finer-grained initialization, then this recording vs playback
78 distinction could be eliminated.
79
80 During a playback, we associate objects from the recording with
81 their counterparts during this playback. For simplicity, we store this
82 within the recording objects, as ``void *m_playback_obj``, casting it to
83 the appropriate playback object subclass. For these casts to make
84 sense, the two class hierarchies need to have the same structure.
85
86 Note that the playback objects that ``m_playback_obj`` points to are
87 GC-allocated, but the recording objects don't own references:
88 these associations only exist within a part of the code where
89 the GC doesn't collect, and are set back to NULL before the GC can
90 run.
91
92 End of comment for inclusion in the docs. */
93
94namespace gcc {
95
96namespace jit {
97
98class result;
99class dump;
eb4c16eb 100class logger;
eeafb319 101class builtins_manager; // declared within jit-builtins.h
d1e5f2c7 102class tempdir;
35485da9
DM
103
104namespace recording {
105
106 /* Recording types. */
107
108 /* Indentation indicates inheritance: */
109 class context;
35485da9
DM
110 class memento;
111 class string;
112 class location;
113 class type;
114 class function_type;
115 class compound_type;
116 class struct_;
117 class union_;
118 class field;
119 class fields;
120 class function;
121 class block;
122 class rvalue;
123 class lvalue;
124 class local;
125 class global;
126 class param;
127 class statement;
128
129 /* End of recording types. */
130}
131
132namespace playback {
133 /* Playback types. */
134
135 /* Indentation indicates inheritance: */
136 class context;
137 class wrapper;
138 class type;
139 class compound_type;
140 class field;
141 class function;
142 class block;
143 class rvalue;
144 class lvalue;
145 class param;
146 class source_file;
147 class source_line;
148 class location;
149
150 /* End of playback types. */
151}
152
153typedef playback::context replayer;
154
155class dump
156{
157public:
158 dump (recording::context &ctxt,
159 const char *filename,
160 bool update_locations);
161 ~dump ();
162
163 void write (const char *fmt, ...)
164 GNU_PRINTF(2, 3);
165
166 bool update_locations () const { return m_update_locations; }
167
168 recording::location *
169 make_location () const;
170
171private:
172 recording::context &m_ctxt;
173 const char *m_filename;
174 bool m_update_locations;
175 int m_line;
176 int m_column;
177 FILE *m_file;
178};
179
180} // namespace gcc::jit
181
182} // namespace gcc
183
184#endif /* JIT_COMMON_H */