annotate gcc/go/gofrontend/backend.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // backend.h -- Go frontend interface to backend -*- C++ -*-
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 // Copyright 2011 The Go Authors. All rights reserved.
kono
parents:
diff changeset
4 // Use of this source code is governed by a BSD-style
kono
parents:
diff changeset
5 // license that can be found in the LICENSE file.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 #ifndef GO_BACKEND_H
kono
parents:
diff changeset
8 #define GO_BACKEND_H
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 #include <gmp.h>
kono
parents:
diff changeset
11 #include <mpfr.h>
kono
parents:
diff changeset
12 #include <mpc.h>
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 #include "operator.h"
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 // Pointers to these types are created by the backend, passed to the
kono
parents:
diff changeset
17 // frontend, and passed back to the backend. The types must be
kono
parents:
diff changeset
18 // defined by the backend using these names.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 // The backend representation of a type.
kono
parents:
diff changeset
21 class Btype;
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 // The backend represention of an expression.
kono
parents:
diff changeset
24 class Bexpression;
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 // The backend representation of a statement.
kono
parents:
diff changeset
27 class Bstatement;
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 // The backend representation of a function definition or declaration.
kono
parents:
diff changeset
30 class Bfunction;
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 // The backend representation of a block.
kono
parents:
diff changeset
33 class Bblock;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 // The backend representation of a variable.
kono
parents:
diff changeset
36 class Bvariable;
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 // The backend representation of a label.
kono
parents:
diff changeset
39 class Blabel;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 // The backend interface. This is a pure abstract class that a
kono
parents:
diff changeset
42 // specific backend will implement.
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 class Backend
kono
parents:
diff changeset
45 {
kono
parents:
diff changeset
46 public:
kono
parents:
diff changeset
47 virtual ~Backend() { }
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 // Name/type/location. Used for function parameters, struct fields,
kono
parents:
diff changeset
50 // interface methods.
kono
parents:
diff changeset
51 struct Btyped_identifier
kono
parents:
diff changeset
52 {
kono
parents:
diff changeset
53 std::string name;
kono
parents:
diff changeset
54 Btype* btype;
kono
parents:
diff changeset
55 Location location;
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 Btyped_identifier()
kono
parents:
diff changeset
58 : name(), btype(NULL), location(Linemap::unknown_location())
kono
parents:
diff changeset
59 { }
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 Btyped_identifier(const std::string& a_name, Btype* a_btype,
kono
parents:
diff changeset
62 Location a_location)
kono
parents:
diff changeset
63 : name(a_name), btype(a_btype), location(a_location)
kono
parents:
diff changeset
64 { }
kono
parents:
diff changeset
65 };
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 // Types.
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 // Produce an error type. Actually the backend could probably just
kono
parents:
diff changeset
70 // crash if this is called.
kono
parents:
diff changeset
71 virtual Btype*
kono
parents:
diff changeset
72 error_type() = 0;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 // Get a void type. This is used in (at least) two ways: 1) as the
kono
parents:
diff changeset
75 // return type of a function with no result parameters; 2)
kono
parents:
diff changeset
76 // unsafe.Pointer is represented as *void.
kono
parents:
diff changeset
77 virtual Btype*
kono
parents:
diff changeset
78 void_type() = 0;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 // Get the unnamed boolean type.
kono
parents:
diff changeset
81 virtual Btype*
kono
parents:
diff changeset
82 bool_type() = 0;
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 // Get an unnamed integer type with the given signedness and number
kono
parents:
diff changeset
85 // of bits.
kono
parents:
diff changeset
86 virtual Btype*
kono
parents:
diff changeset
87 integer_type(bool is_unsigned, int bits) = 0;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 // Get an unnamed floating point type with the given number of bits
kono
parents:
diff changeset
90 // (32 or 64).
kono
parents:
diff changeset
91 virtual Btype*
kono
parents:
diff changeset
92 float_type(int bits) = 0;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 // Get an unnamed complex type with the given number of bits (64 or 128).
kono
parents:
diff changeset
95 virtual Btype*
kono
parents:
diff changeset
96 complex_type(int bits) = 0;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 // Get a pointer type.
kono
parents:
diff changeset
99 virtual Btype*
kono
parents:
diff changeset
100 pointer_type(Btype* to_type) = 0;
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 // Get a function type. The receiver, parameter, and results are
kono
parents:
diff changeset
103 // generated from the types in the Function_type. The Function_type
kono
parents:
diff changeset
104 // is provided so that the names are available. This should return
kono
parents:
diff changeset
105 // not the type of a Go function (which is a pointer to a struct)
kono
parents:
diff changeset
106 // but the type of a C function pointer (which will be used as the
kono
parents:
diff changeset
107 // type of the first field of the struct). If there is more than
kono
parents:
diff changeset
108 // one result, RESULT_STRUCT is a struct type to hold the results,
kono
parents:
diff changeset
109 // and RESULTS may be ignored; if there are zero or one results,
kono
parents:
diff changeset
110 // RESULT_STRUCT is NULL.
kono
parents:
diff changeset
111 virtual Btype*
kono
parents:
diff changeset
112 function_type(const Btyped_identifier& receiver,
kono
parents:
diff changeset
113 const std::vector<Btyped_identifier>& parameters,
kono
parents:
diff changeset
114 const std::vector<Btyped_identifier>& results,
kono
parents:
diff changeset
115 Btype* result_struct,
kono
parents:
diff changeset
116 Location location) = 0;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 // Get a struct type.
kono
parents:
diff changeset
119 virtual Btype*
kono
parents:
diff changeset
120 struct_type(const std::vector<Btyped_identifier>& fields) = 0;
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 // Get an array type.
kono
parents:
diff changeset
123 virtual Btype*
kono
parents:
diff changeset
124 array_type(Btype* element_type, Bexpression* length) = 0;
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 // Create a placeholder pointer type. This is used for a named
kono
parents:
diff changeset
127 // pointer type, since in Go a pointer type may refer to itself.
kono
parents:
diff changeset
128 // NAME is the name of the type, and the location is where the named
kono
parents:
diff changeset
129 // type is defined. This function is also used for unnamed function
kono
parents:
diff changeset
130 // types with multiple results, in which case the type has no name
kono
parents:
diff changeset
131 // and NAME will be empty. FOR_FUNCTION is true if this is for a C
kono
parents:
diff changeset
132 // pointer to function type. A Go func type is represented as a
kono
parents:
diff changeset
133 // pointer to a struct, and the first field of the struct is a C
kono
parents:
diff changeset
134 // pointer to function. The return value will later be passed as
kono
parents:
diff changeset
135 // the first parameter to set_placeholder_pointer_type or
kono
parents:
diff changeset
136 // set_placeholder_function_type.
kono
parents:
diff changeset
137 virtual Btype*
kono
parents:
diff changeset
138 placeholder_pointer_type(const std::string& name, Location,
kono
parents:
diff changeset
139 bool for_function) = 0;
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 // Fill in a placeholder pointer type as a pointer. This takes a
kono
parents:
diff changeset
142 // type returned by placeholder_pointer_type and arranges for it to
kono
parents:
diff changeset
143 // point to the type that TO_TYPE points to (that is, PLACEHOLDER
kono
parents:
diff changeset
144 // becomes the same type as TO_TYPE). Returns true on success,
kono
parents:
diff changeset
145 // false on failure.
kono
parents:
diff changeset
146 virtual bool
kono
parents:
diff changeset
147 set_placeholder_pointer_type(Btype* placeholder, Btype* to_type) = 0;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 // Fill in a placeholder pointer type as a function. This takes a
kono
parents:
diff changeset
150 // type returned by placeholder_pointer_type and arranges for it to
kono
parents:
diff changeset
151 // become a real Go function type (which corresponds to a C/C++
kono
parents:
diff changeset
152 // pointer to function type). FT will be something returned by the
kono
parents:
diff changeset
153 // function_type method. Returns true on success, false on failure.
kono
parents:
diff changeset
154 virtual bool
kono
parents:
diff changeset
155 set_placeholder_function_type(Btype* placeholder, Btype* ft) = 0;
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 // Create a placeholder struct type. This is used for a named
kono
parents:
diff changeset
158 // struct type, as with placeholder_pointer_type. It is also used
kono
parents:
diff changeset
159 // for interface types, in which case NAME will be the empty string.
kono
parents:
diff changeset
160 virtual Btype*
kono
parents:
diff changeset
161 placeholder_struct_type(const std::string& name, Location) = 0;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 // Fill in a placeholder struct type. This takes a type returned by
kono
parents:
diff changeset
164 // placeholder_struct_type and arranges for it to become a real
kono
parents:
diff changeset
165 // struct type. The parameter is as for struct_type. Returns true
kono
parents:
diff changeset
166 // on success, false on failure.
kono
parents:
diff changeset
167 virtual bool
kono
parents:
diff changeset
168 set_placeholder_struct_type(Btype* placeholder,
kono
parents:
diff changeset
169 const std::vector<Btyped_identifier>& fields)
kono
parents:
diff changeset
170 = 0;
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 // Create a placeholder array type. This is used for a named array
kono
parents:
diff changeset
173 // type, as with placeholder_pointer_type, to handle cases like
kono
parents:
diff changeset
174 // type A []*A.
kono
parents:
diff changeset
175 virtual Btype*
kono
parents:
diff changeset
176 placeholder_array_type(const std::string& name, Location) = 0;
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 // Fill in a placeholder array type. This takes a type returned by
kono
parents:
diff changeset
179 // placeholder_array_type and arranges for it to become a real array
kono
parents:
diff changeset
180 // type. The parameters are as for array_type. Returns true on
kono
parents:
diff changeset
181 // success, false on failure.
kono
parents:
diff changeset
182 virtual bool
kono
parents:
diff changeset
183 set_placeholder_array_type(Btype* placeholder, Btype* element_type,
kono
parents:
diff changeset
184 Bexpression* length) = 0;
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 // Return a named version of a type. The location is the location
kono
parents:
diff changeset
187 // of the type definition. This will not be called for a type
kono
parents:
diff changeset
188 // created via placeholder_pointer_type, placeholder_struct_type, or
kono
parents:
diff changeset
189 // placeholder_array_type.. (It may be called for a pointer,
kono
parents:
diff changeset
190 // struct, or array type in a case like "type P *byte; type Q P".)
kono
parents:
diff changeset
191 virtual Btype*
kono
parents:
diff changeset
192 named_type(const std::string& name, Btype*, Location) = 0;
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 // Create a marker for a circular pointer type. Go pointer and
kono
parents:
diff changeset
195 // function types can refer to themselves in ways that are not
kono
parents:
diff changeset
196 // permitted in C/C++. When a circular type is found, this function
kono
parents:
diff changeset
197 // is called for the circular reference. This permits the backend
kono
parents:
diff changeset
198 // to decide how to handle such a type. PLACEHOLDER is the
kono
parents:
diff changeset
199 // placeholder type which has already been created; if the backend
kono
parents:
diff changeset
200 // is prepared to handle a circular pointer type, it may simply
kono
parents:
diff changeset
201 // return PLACEHOLDER. FOR_FUNCTION is true if this is for a
kono
parents:
diff changeset
202 // function type.
kono
parents:
diff changeset
203 //
kono
parents:
diff changeset
204 // For "type P *P" the sequence of calls will be
kono
parents:
diff changeset
205 // bt1 = placeholder_pointer_type();
kono
parents:
diff changeset
206 // bt2 = circular_pointer_type(bt1, false);
kono
parents:
diff changeset
207 // set_placeholder_pointer_type(bt1, bt2);
kono
parents:
diff changeset
208 virtual Btype*
kono
parents:
diff changeset
209 circular_pointer_type(Btype* placeholder, bool for_function) = 0;
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 // Return whether the argument could be a special type created by
kono
parents:
diff changeset
212 // circular_pointer_type. This is used to introduce explicit type
kono
parents:
diff changeset
213 // conversions where needed. If circular_pointer_type returns its
kono
parents:
diff changeset
214 // PLACEHOLDER parameter, this may safely always return false.
kono
parents:
diff changeset
215 virtual bool
kono
parents:
diff changeset
216 is_circular_pointer_type(Btype*) = 0;
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 // Return the size of a type.
kono
parents:
diff changeset
219 virtual int64_t
kono
parents:
diff changeset
220 type_size(Btype*) = 0;
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 // Return the alignment of a type.
kono
parents:
diff changeset
223 virtual int64_t
kono
parents:
diff changeset
224 type_alignment(Btype*) = 0;
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 // Return the alignment of a struct field of this type. This is
kono
parents:
diff changeset
227 // normally the same as type_alignment, but not always.
kono
parents:
diff changeset
228 virtual int64_t
kono
parents:
diff changeset
229 type_field_alignment(Btype*) = 0;
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 // Return the offset of field INDEX in a struct type. INDEX is the
kono
parents:
diff changeset
232 // entry in the FIELDS std::vector parameter of struct_type or
kono
parents:
diff changeset
233 // set_placeholder_struct_type.
kono
parents:
diff changeset
234 virtual int64_t
kono
parents:
diff changeset
235 type_field_offset(Btype*, size_t index) = 0;
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 // Expressions.
kono
parents:
diff changeset
238
kono
parents:
diff changeset
239 // Return an expression for a zero value of the given type. This is
kono
parents:
diff changeset
240 // used for cases such as local variable initialization and
kono
parents:
diff changeset
241 // converting nil to other types.
kono
parents:
diff changeset
242 virtual Bexpression*
kono
parents:
diff changeset
243 zero_expression(Btype*) = 0;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 // Create an error expression. This is used for cases which should
kono
parents:
diff changeset
246 // not occur in a correct program, in order to keep the compilation
kono
parents:
diff changeset
247 // going without crashing.
kono
parents:
diff changeset
248 virtual Bexpression*
kono
parents:
diff changeset
249 error_expression() = 0;
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 // Create a nil pointer expression.
kono
parents:
diff changeset
252 virtual Bexpression*
kono
parents:
diff changeset
253 nil_pointer_expression() = 0;
kono
parents:
diff changeset
254
kono
parents:
diff changeset
255 // Create a reference to a variable.
kono
parents:
diff changeset
256 virtual Bexpression*
kono
parents:
diff changeset
257 var_expression(Bvariable* var, Varexpr_context in_lvalue_pos, Location) = 0;
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 // Create an expression that indirects through the pointer expression EXPR
kono
parents:
diff changeset
260 // (i.e., return the expression for *EXPR). KNOWN_VALID is true if the pointer
kono
parents:
diff changeset
261 // is known to point to a valid memory location. BTYPE is the expected type
kono
parents:
diff changeset
262 // of the indirected EXPR.
kono
parents:
diff changeset
263 virtual Bexpression*
kono
parents:
diff changeset
264 indirect_expression(Btype* btype, Bexpression* expr, bool known_valid,
kono
parents:
diff changeset
265 Location) = 0;
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 // Return an expression that declares a constant named NAME with the
kono
parents:
diff changeset
268 // constant value VAL in BTYPE.
kono
parents:
diff changeset
269 virtual Bexpression*
kono
parents:
diff changeset
270 named_constant_expression(Btype* btype, const std::string& name,
kono
parents:
diff changeset
271 Bexpression* val, Location) = 0;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 // Return an expression for the multi-precision integer VAL in BTYPE.
kono
parents:
diff changeset
274 virtual Bexpression*
kono
parents:
diff changeset
275 integer_constant_expression(Btype* btype, mpz_t val) = 0;
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 // Return an expression for the floating point value VAL in BTYPE.
kono
parents:
diff changeset
278 virtual Bexpression*
kono
parents:
diff changeset
279 float_constant_expression(Btype* btype, mpfr_t val) = 0;
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 // Return an expression for the complex value VAL in BTYPE.
kono
parents:
diff changeset
282 virtual Bexpression*
kono
parents:
diff changeset
283 complex_constant_expression(Btype* btype, mpc_t val) = 0;
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 // Return an expression for the string value VAL.
kono
parents:
diff changeset
286 virtual Bexpression*
kono
parents:
diff changeset
287 string_constant_expression(const std::string& val) = 0;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 // Return an expression for the boolean value VAL.
kono
parents:
diff changeset
290 virtual Bexpression*
kono
parents:
diff changeset
291 boolean_constant_expression(bool val) = 0;
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 // Return an expression for the real part of BCOMPLEX.
kono
parents:
diff changeset
294 virtual Bexpression*
kono
parents:
diff changeset
295 real_part_expression(Bexpression* bcomplex, Location) = 0;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 // Return an expression for the imaginary part of BCOMPLEX.
kono
parents:
diff changeset
298 virtual Bexpression*
kono
parents:
diff changeset
299 imag_part_expression(Bexpression* bcomplex, Location) = 0;
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 // Return an expression for the complex number (BREAL, BIMAG).
kono
parents:
diff changeset
302 virtual Bexpression*
kono
parents:
diff changeset
303 complex_expression(Bexpression* breal, Bexpression* bimag, Location) = 0;
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 // Return an expression that converts EXPR to TYPE.
kono
parents:
diff changeset
306 virtual Bexpression*
kono
parents:
diff changeset
307 convert_expression(Btype* type, Bexpression* expr, Location) = 0;
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 // Create an expression for the address of a function. This is used to
kono
parents:
diff changeset
310 // get the address of the code for a function.
kono
parents:
diff changeset
311 virtual Bexpression*
kono
parents:
diff changeset
312 function_code_expression(Bfunction*, Location) = 0;
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 // Create an expression that takes the address of an expression.
kono
parents:
diff changeset
315 virtual Bexpression*
kono
parents:
diff changeset
316 address_expression(Bexpression*, Location) = 0;
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 // Return an expression for the field at INDEX in BSTRUCT.
kono
parents:
diff changeset
319 virtual Bexpression*
kono
parents:
diff changeset
320 struct_field_expression(Bexpression* bstruct, size_t index, Location) = 0;
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 // Create an expression that executes BSTAT before BEXPR.
kono
parents:
diff changeset
323 virtual Bexpression*
kono
parents:
diff changeset
324 compound_expression(Bstatement* bstat, Bexpression* bexpr, Location) = 0;
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 // Return an expression that executes THEN_EXPR if CONDITION is true, or
kono
parents:
diff changeset
327 // ELSE_EXPR otherwise and returns the result as type BTYPE, within the
kono
parents:
diff changeset
328 // specified function FUNCTION. ELSE_EXPR may be NULL. BTYPE may be NULL.
kono
parents:
diff changeset
329 virtual Bexpression*
kono
parents:
diff changeset
330 conditional_expression(Bfunction* function, Btype* btype,
kono
parents:
diff changeset
331 Bexpression* condition, Bexpression* then_expr,
kono
parents:
diff changeset
332 Bexpression* else_expr, Location) = 0;
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 // Return an expression for the unary operation OP EXPR.
kono
parents:
diff changeset
335 // Supported values of OP are (from operators.h):
kono
parents:
diff changeset
336 // MINUS, NOT, XOR.
kono
parents:
diff changeset
337 virtual Bexpression*
kono
parents:
diff changeset
338 unary_expression(Operator op, Bexpression* expr, Location) = 0;
kono
parents:
diff changeset
339
kono
parents:
diff changeset
340 // Return an expression for the binary operation LEFT OP RIGHT.
kono
parents:
diff changeset
341 // Supported values of OP are (from operators.h):
kono
parents:
diff changeset
342 // EQEQ, NOTEQ, LT, LE, GT, GE, PLUS, MINUS, OR, XOR, MULT, DIV, MOD,
kono
parents:
diff changeset
343 // LSHIFT, RSHIFT, AND, NOT.
kono
parents:
diff changeset
344 virtual Bexpression*
kono
parents:
diff changeset
345 binary_expression(Operator op, Bexpression* left, Bexpression* right,
kono
parents:
diff changeset
346 Location) = 0;
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 // Return an expression that constructs BTYPE with VALS. BTYPE must be the
kono
parents:
diff changeset
349 // backend representation a of struct. VALS must be in the same order as the
kono
parents:
diff changeset
350 // corresponding fields in BTYPE.
kono
parents:
diff changeset
351 virtual Bexpression*
kono
parents:
diff changeset
352 constructor_expression(Btype* btype, const std::vector<Bexpression*>& vals,
kono
parents:
diff changeset
353 Location) = 0;
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 // Return an expression that constructs an array of BTYPE with INDEXES and
kono
parents:
diff changeset
356 // VALS. INDEXES and VALS must have the same amount of elements. Each index
kono
parents:
diff changeset
357 // in INDEXES must be in the same order as the corresponding value in VALS.
kono
parents:
diff changeset
358 virtual Bexpression*
kono
parents:
diff changeset
359 array_constructor_expression(Btype* btype,
kono
parents:
diff changeset
360 const std::vector<unsigned long>& indexes,
kono
parents:
diff changeset
361 const std::vector<Bexpression*>& vals,
kono
parents:
diff changeset
362 Location) = 0;
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 // Return an expression for the address of BASE[INDEX].
kono
parents:
diff changeset
365 // BASE has a pointer type. This is used for slice indexing.
kono
parents:
diff changeset
366 virtual Bexpression*
kono
parents:
diff changeset
367 pointer_offset_expression(Bexpression* base, Bexpression* index,
kono
parents:
diff changeset
368 Location) = 0;
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 // Return an expression for ARRAY[INDEX] as an l-value. ARRAY is a valid
kono
parents:
diff changeset
371 // fixed-length array, not a slice.
kono
parents:
diff changeset
372 virtual Bexpression*
kono
parents:
diff changeset
373 array_index_expression(Bexpression* array, Bexpression* index, Location) = 0;
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 // Create an expression for a call to FN with ARGS, taking place within
kono
parents:
diff changeset
376 // caller CALLER.
kono
parents:
diff changeset
377 virtual Bexpression*
kono
parents:
diff changeset
378 call_expression(Bfunction *caller, Bexpression* fn,
kono
parents:
diff changeset
379 const std::vector<Bexpression*>& args,
kono
parents:
diff changeset
380 Bexpression* static_chain, Location) = 0;
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 // Return an expression that allocates SIZE bytes on the stack.
kono
parents:
diff changeset
383 virtual Bexpression*
kono
parents:
diff changeset
384 stack_allocation_expression(int64_t size, Location) = 0;
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 // Statements.
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 // Create an error statement. This is used for cases which should
kono
parents:
diff changeset
389 // not occur in a correct program, in order to keep the compilation
kono
parents:
diff changeset
390 // going without crashing.
kono
parents:
diff changeset
391 virtual Bstatement*
kono
parents:
diff changeset
392 error_statement() = 0;
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 // Create an expression statement within the specified function.
kono
parents:
diff changeset
395 virtual Bstatement*
kono
parents:
diff changeset
396 expression_statement(Bfunction*, Bexpression*) = 0;
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 // Create a variable initialization statement in the specified
kono
parents:
diff changeset
399 // function. This initializes a local variable at the point in the
kono
parents:
diff changeset
400 // program flow where it is declared.
kono
parents:
diff changeset
401 virtual Bstatement*
kono
parents:
diff changeset
402 init_statement(Bfunction*, Bvariable* var, Bexpression* init) = 0;
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 // Create an assignment statement within the specified function.
kono
parents:
diff changeset
405 virtual Bstatement*
kono
parents:
diff changeset
406 assignment_statement(Bfunction*, Bexpression* lhs, Bexpression* rhs,
kono
parents:
diff changeset
407 Location) = 0;
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 // Create a return statement, passing the representation of the
kono
parents:
diff changeset
410 // function and the list of values to return.
kono
parents:
diff changeset
411 virtual Bstatement*
kono
parents:
diff changeset
412 return_statement(Bfunction*, const std::vector<Bexpression*>&,
kono
parents:
diff changeset
413 Location) = 0;
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 // Create an if statement within a function. ELSE_BLOCK may be NULL.
kono
parents:
diff changeset
416 virtual Bstatement*
kono
parents:
diff changeset
417 if_statement(Bfunction*, Bexpression* condition,
kono
parents:
diff changeset
418 Bblock* then_block, Bblock* else_block,
kono
parents:
diff changeset
419 Location) = 0;
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 // Create a switch statement where the case values are constants.
kono
parents:
diff changeset
422 // CASES and STATEMENTS must have the same number of entries. If
kono
parents:
diff changeset
423 // VALUE matches any of the list in CASES[i], which will all be
kono
parents:
diff changeset
424 // integers, then STATEMENTS[i] is executed. STATEMENTS[i] will
kono
parents:
diff changeset
425 // either end with a goto statement or will fall through into
kono
parents:
diff changeset
426 // STATEMENTS[i + 1]. CASES[i] is empty for the default clause,
kono
parents:
diff changeset
427 // which need not be last. FUNCTION is the current function.
kono
parents:
diff changeset
428 virtual Bstatement*
kono
parents:
diff changeset
429 switch_statement(Bfunction* function, Bexpression* value,
kono
parents:
diff changeset
430 const std::vector<std::vector<Bexpression*> >& cases,
kono
parents:
diff changeset
431 const std::vector<Bstatement*>& statements,
kono
parents:
diff changeset
432 Location) = 0;
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 // Create a single statement from two statements.
kono
parents:
diff changeset
435 virtual Bstatement*
kono
parents:
diff changeset
436 compound_statement(Bstatement*, Bstatement*) = 0;
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 // Create a single statement from a list of statements.
kono
parents:
diff changeset
439 virtual Bstatement*
kono
parents:
diff changeset
440 statement_list(const std::vector<Bstatement*>&) = 0;
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 // Create a statement that attempts to execute BSTAT and calls EXCEPT_STMT if
kono
parents:
diff changeset
443 // an exception occurs. EXCEPT_STMT may be NULL. FINALLY_STMT may be NULL and
kono
parents:
diff changeset
444 // if not NULL, it will always be executed. This is used for handling defers
kono
parents:
diff changeset
445 // in Go functions. In C++, the resulting code is of this form:
kono
parents:
diff changeset
446 // try { BSTAT; } catch { EXCEPT_STMT; } finally { FINALLY_STMT; }
kono
parents:
diff changeset
447 virtual Bstatement*
kono
parents:
diff changeset
448 exception_handler_statement(Bstatement* bstat, Bstatement* except_stmt,
kono
parents:
diff changeset
449 Bstatement* finally_stmt, Location) = 0;
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 // Blocks.
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 // Create a block. The frontend will call this function when it
kono
parents:
diff changeset
454 // starts converting a block within a function. FUNCTION is the
kono
parents:
diff changeset
455 // current function. ENCLOSING is the enclosing block; it will be
kono
parents:
diff changeset
456 // NULL for the top-level block in a function. VARS is the list of
kono
parents:
diff changeset
457 // local variables defined within this block; each entry will be
kono
parents:
diff changeset
458 // created by the local_variable function. START_LOCATION is the
kono
parents:
diff changeset
459 // location of the start of the block, more or less the location of
kono
parents:
diff changeset
460 // the initial curly brace. END_LOCATION is the location of the end
kono
parents:
diff changeset
461 // of the block, more or less the location of the final curly brace.
kono
parents:
diff changeset
462 // The statements will be added after the block is created.
kono
parents:
diff changeset
463 virtual Bblock*
kono
parents:
diff changeset
464 block(Bfunction* function, Bblock* enclosing,
kono
parents:
diff changeset
465 const std::vector<Bvariable*>& vars,
kono
parents:
diff changeset
466 Location start_location, Location end_location) = 0;
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 // Add the statements to a block. The block is created first. Then
kono
parents:
diff changeset
469 // the statements are created. Then the statements are added to the
kono
parents:
diff changeset
470 // block. This will called exactly once per block. The vector may
kono
parents:
diff changeset
471 // be empty if there are no statements.
kono
parents:
diff changeset
472 virtual void
kono
parents:
diff changeset
473 block_add_statements(Bblock*, const std::vector<Bstatement*>&) = 0;
kono
parents:
diff changeset
474
kono
parents:
diff changeset
475 // Return the block as a statement. This is used to include a block
kono
parents:
diff changeset
476 // in a list of statements.
kono
parents:
diff changeset
477 virtual Bstatement*
kono
parents:
diff changeset
478 block_statement(Bblock*) = 0;
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 // Variables.
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 // Create an error variable. This is used for cases which should
kono
parents:
diff changeset
483 // not occur in a correct program, in order to keep the compilation
kono
parents:
diff changeset
484 // going without crashing.
kono
parents:
diff changeset
485 virtual Bvariable*
kono
parents:
diff changeset
486 error_variable() = 0;
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 // Create a global variable. NAME is the package-qualified name of
kono
parents:
diff changeset
489 // the variable. ASM_NAME is the encoded identifier for the
kono
parents:
diff changeset
490 // variable, incorporating the package, and made safe for the
kono
parents:
diff changeset
491 // assembler. BTYPE is the type of the variable. IS_EXTERNAL is
kono
parents:
diff changeset
492 // true if the variable is defined in some other package. IS_HIDDEN
kono
parents:
diff changeset
493 // is true if the variable is not exported (name begins with a lower
kono
parents:
diff changeset
494 // case letter). IN_UNIQUE_SECTION is true if the variable should
kono
parents:
diff changeset
495 // be put into a unique section if possible; this is intended to
kono
parents:
diff changeset
496 // permit the linker to garbage collect the variable if it is not
kono
parents:
diff changeset
497 // referenced. LOCATION is where the variable was defined.
kono
parents:
diff changeset
498 virtual Bvariable*
kono
parents:
diff changeset
499 global_variable(const std::string& name,
kono
parents:
diff changeset
500 const std::string& asm_name,
kono
parents:
diff changeset
501 Btype* btype,
kono
parents:
diff changeset
502 bool is_external,
kono
parents:
diff changeset
503 bool is_hidden,
kono
parents:
diff changeset
504 bool in_unique_section,
kono
parents:
diff changeset
505 Location location) = 0;
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 // A global variable will 1) be initialized to zero, or 2) be
kono
parents:
diff changeset
508 // initialized to a constant value, or 3) be initialized in the init
kono
parents:
diff changeset
509 // function. In case 2, the frontend will call
kono
parents:
diff changeset
510 // global_variable_set_init to set the initial value. If this is
kono
parents:
diff changeset
511 // not called, the backend should initialize a global variable to 0.
kono
parents:
diff changeset
512 // The init function may then assign a value to it.
kono
parents:
diff changeset
513 virtual void
kono
parents:
diff changeset
514 global_variable_set_init(Bvariable*, Bexpression*) = 0;
kono
parents:
diff changeset
515
kono
parents:
diff changeset
516 // Create a local variable. The frontend will create the local
kono
parents:
diff changeset
517 // variables first, and then create the block which contains them.
kono
parents:
diff changeset
518 // FUNCTION is the function in which the variable is defined. NAME
kono
parents:
diff changeset
519 // is the name of the variable. TYPE is the type. IS_ADDRESS_TAKEN
kono
parents:
diff changeset
520 // is true if the address of this variable is taken (this implies
kono
parents:
diff changeset
521 // that the address does not escape the function, as otherwise the
kono
parents:
diff changeset
522 // variable would be on the heap). LOCATION is where the variable
kono
parents:
diff changeset
523 // is defined. For each local variable the frontend will call
kono
parents:
diff changeset
524 // init_statement to set the initial value.
kono
parents:
diff changeset
525 virtual Bvariable*
kono
parents:
diff changeset
526 local_variable(Bfunction* function, const std::string& name, Btype* type,
kono
parents:
diff changeset
527 bool is_address_taken, Location location) = 0;
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 // Create a function parameter. This is an incoming parameter, not
kono
parents:
diff changeset
530 // a result parameter (result parameters are treated as local
kono
parents:
diff changeset
531 // variables). The arguments are as for local_variable.
kono
parents:
diff changeset
532 virtual Bvariable*
kono
parents:
diff changeset
533 parameter_variable(Bfunction* function, const std::string& name,
kono
parents:
diff changeset
534 Btype* type, bool is_address_taken,
kono
parents:
diff changeset
535 Location location) = 0;
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 // Create a static chain parameter. This is the closure parameter.
kono
parents:
diff changeset
538 virtual Bvariable*
kono
parents:
diff changeset
539 static_chain_variable(Bfunction* function, const std::string& name,
kono
parents:
diff changeset
540 Btype* type, Location location) = 0;
kono
parents:
diff changeset
541
kono
parents:
diff changeset
542 // Create a temporary variable. A temporary variable has no name,
kono
parents:
diff changeset
543 // just a type. We pass in FUNCTION and BLOCK in case they are
kono
parents:
diff changeset
544 // needed. If INIT is not NULL, the variable should be initialized
kono
parents:
diff changeset
545 // to that value. Otherwise the initial value is irrelevant--the
kono
parents:
diff changeset
546 // backend does not have to explicitly initialize it to zero.
kono
parents:
diff changeset
547 // ADDRESS_IS_TAKEN is true if the programs needs to take the
kono
parents:
diff changeset
548 // address of this temporary variable. LOCATION is the location of
kono
parents:
diff changeset
549 // the statement or expression which requires creating the temporary
kono
parents:
diff changeset
550 // variable, and may not be very useful. This function should
kono
parents:
diff changeset
551 // return a variable which can be referenced later and should set
kono
parents:
diff changeset
552 // *PSTATEMENT to a statement which initializes the variable.
kono
parents:
diff changeset
553 virtual Bvariable*
kono
parents:
diff changeset
554 temporary_variable(Bfunction*, Bblock*, Btype*, Bexpression* init,
kono
parents:
diff changeset
555 bool address_is_taken, Location location,
kono
parents:
diff changeset
556 Bstatement** pstatement) = 0;
kono
parents:
diff changeset
557
kono
parents:
diff changeset
558 // Create an implicit variable that is compiler-defined. This is
kono
parents:
diff changeset
559 // used when generating GC data and roots, when storing the values
kono
parents:
diff changeset
560 // of a slice constructor, and for the zero value of types. This returns a
kono
parents:
diff changeset
561 // Bvariable because it corresponds to an initialized variable in C.
kono
parents:
diff changeset
562 //
kono
parents:
diff changeset
563 // NAME is the name to use for the initialized variable this will create.
kono
parents:
diff changeset
564 //
kono
parents:
diff changeset
565 // ASM_NAME is encoded assembler-friendly version of the name, or the
kono
parents:
diff changeset
566 // empty string if no encoding is needed.
kono
parents:
diff changeset
567 //
kono
parents:
diff changeset
568 // TYPE is the type of the implicit variable.
kono
parents:
diff changeset
569 //
kono
parents:
diff changeset
570 // IS_HIDDEN will be true if the descriptor should only be visible
kono
parents:
diff changeset
571 // within the current object.
kono
parents:
diff changeset
572 //
kono
parents:
diff changeset
573 // IS_CONSTANT is true if the implicit variable should be treated like it is
kono
parents:
diff changeset
574 // immutable. For slice initializers, if the values must be copied to the
kono
parents:
diff changeset
575 // heap, the variable IS_CONSTANT.
kono
parents:
diff changeset
576 //
kono
parents:
diff changeset
577 // IS_COMMON is true if the implicit variable should
kono
parents:
diff changeset
578 // be treated as a common variable (multiple definitions with
kono
parents:
diff changeset
579 // different sizes permitted in different object files, all merged
kono
parents:
diff changeset
580 // into the largest definition at link time); this will be true for
kono
parents:
diff changeset
581 // the zero value. IS_HIDDEN and IS_COMMON will never both be true.
kono
parents:
diff changeset
582 //
kono
parents:
diff changeset
583 // If ALIGNMENT is not zero, it is the desired alignment of the variable.
kono
parents:
diff changeset
584 virtual Bvariable*
kono
parents:
diff changeset
585 implicit_variable(const std::string& name, const std::string& asm_name,
kono
parents:
diff changeset
586 Btype* type, bool is_hidden, bool is_constant,
kono
parents:
diff changeset
587 bool is_common, int64_t alignment) = 0;
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 // Set the initial value of a variable created by implicit_variable.
kono
parents:
diff changeset
591 // This must be called even if there is no initializer, i.e., INIT is NULL.
kono
parents:
diff changeset
592 // The NAME, TYPE, IS_HIDDEN, IS_CONSTANT, and IS_COMMON parameters are
kono
parents:
diff changeset
593 // the same ones passed to implicit_variable. INIT will be a composite
kono
parents:
diff changeset
594 // literal of type TYPE. It will not contain any function calls or anything
kono
parents:
diff changeset
595 // else that can not be put into a read-only data section.
kono
parents:
diff changeset
596 // It may contain the address of variables created by implicit_variable.
kono
parents:
diff changeset
597 //
kono
parents:
diff changeset
598 // If IS_COMMON is true, INIT will be NULL, and the
kono
parents:
diff changeset
599 // variable should be initialized to all zeros.
kono
parents:
diff changeset
600 virtual void
kono
parents:
diff changeset
601 implicit_variable_set_init(Bvariable*, const std::string& name, Btype* type,
kono
parents:
diff changeset
602 bool is_hidden, bool is_constant, bool is_common,
kono
parents:
diff changeset
603 Bexpression* init) = 0;
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 // Create a reference to a named implicit variable defined in some
kono
parents:
diff changeset
606 // other package. This will be a variable created by a call to
kono
parents:
diff changeset
607 // implicit_variable with the same NAME, ASM_NAME and TYPE and with
kono
parents:
diff changeset
608 // IS_COMMON passed as false. This corresponds to an extern global
kono
parents:
diff changeset
609 // variable in C.
kono
parents:
diff changeset
610 virtual Bvariable*
kono
parents:
diff changeset
611 implicit_variable_reference(const std::string& name,
kono
parents:
diff changeset
612 const std::string& asm_name,
kono
parents:
diff changeset
613 Btype* type) = 0;
kono
parents:
diff changeset
614
kono
parents:
diff changeset
615 // Create a named immutable initialized data structure. This is
kono
parents:
diff changeset
616 // used for type descriptors, map descriptors, and function
kono
parents:
diff changeset
617 // descriptors. This returns a Bvariable because it corresponds to
kono
parents:
diff changeset
618 // an initialized const variable in C.
kono
parents:
diff changeset
619 //
kono
parents:
diff changeset
620 // NAME is the name to use for the initialized global variable which
kono
parents:
diff changeset
621 // this call will create.
kono
parents:
diff changeset
622 //
kono
parents:
diff changeset
623 // ASM_NAME is the encoded, assembler-friendly version of NAME, or
kono
parents:
diff changeset
624 // the empty string if no encoding is needed.
kono
parents:
diff changeset
625 //
kono
parents:
diff changeset
626 // IS_HIDDEN will be true if the descriptor should only be visible
kono
parents:
diff changeset
627 // within the current object.
kono
parents:
diff changeset
628 //
kono
parents:
diff changeset
629 // IS_COMMON is true if NAME may be defined by several packages, and
kono
parents:
diff changeset
630 // the linker should merge all such definitions. If IS_COMMON is
kono
parents:
diff changeset
631 // false, NAME should be defined in only one file. In general
kono
parents:
diff changeset
632 // IS_COMMON will be true for the type descriptor of an unnamed type
kono
parents:
diff changeset
633 // or a builtin type. IS_HIDDEN and IS_COMMON will never both be
kono
parents:
diff changeset
634 // true.
kono
parents:
diff changeset
635 //
kono
parents:
diff changeset
636 // TYPE will be a struct type; the type of the returned expression
kono
parents:
diff changeset
637 // must be a pointer to this struct type.
kono
parents:
diff changeset
638 //
kono
parents:
diff changeset
639 // We must create the named structure before we know its
kono
parents:
diff changeset
640 // initializer, because the initializer may refer to its own
kono
parents:
diff changeset
641 // address. After calling this the frontend will call
kono
parents:
diff changeset
642 // immutable_struct_set_init.
kono
parents:
diff changeset
643 virtual Bvariable*
kono
parents:
diff changeset
644 immutable_struct(const std::string& name,
kono
parents:
diff changeset
645 const std::string& asm_name,
kono
parents:
diff changeset
646 bool is_hidden, bool is_common,
kono
parents:
diff changeset
647 Btype* type, Location) = 0;
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 // Set the initial value of a variable created by immutable_struct.
kono
parents:
diff changeset
650 // The NAME, IS_HIDDEN, IS_COMMON, TYPE, and location parameters are
kono
parents:
diff changeset
651 // the same ones passed to immutable_struct. INITIALIZER will be a
kono
parents:
diff changeset
652 // composite literal of type TYPE. It will not contain any function
kono
parents:
diff changeset
653 // calls or anything else that can not be put into a read-only data
kono
parents:
diff changeset
654 // section. It may contain the address of variables created by
kono
parents:
diff changeset
655 // immutable_struct.
kono
parents:
diff changeset
656 virtual void
kono
parents:
diff changeset
657 immutable_struct_set_init(Bvariable*, const std::string& name,
kono
parents:
diff changeset
658 bool is_hidden, bool is_common, Btype* type,
kono
parents:
diff changeset
659 Location, Bexpression* initializer) = 0;
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 // Create a reference to a named immutable initialized data
kono
parents:
diff changeset
662 // structure defined in some other package. This will be a
kono
parents:
diff changeset
663 // structure created by a call to immutable_struct with the same
kono
parents:
diff changeset
664 // NAME, ASM_NAME and TYPE and with IS_COMMON passed as false. This
kono
parents:
diff changeset
665 // corresponds to an extern const global variable in C.
kono
parents:
diff changeset
666 virtual Bvariable*
kono
parents:
diff changeset
667 immutable_struct_reference(const std::string& name,
kono
parents:
diff changeset
668 const std::string& asm_name,
kono
parents:
diff changeset
669 Btype* type, Location) = 0;
kono
parents:
diff changeset
670
kono
parents:
diff changeset
671 // Labels.
kono
parents:
diff changeset
672
kono
parents:
diff changeset
673 // Create a new label. NAME will be empty if this is a label
kono
parents:
diff changeset
674 // created by the frontend for a loop construct. The location is
kono
parents:
diff changeset
675 // where the label is defined.
kono
parents:
diff changeset
676 virtual Blabel*
kono
parents:
diff changeset
677 label(Bfunction*, const std::string& name, Location) = 0;
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 // Create a statement which defines a label. This statement will be
kono
parents:
diff changeset
680 // put into the codestream at the point where the label should be
kono
parents:
diff changeset
681 // defined.
kono
parents:
diff changeset
682 virtual Bstatement*
kono
parents:
diff changeset
683 label_definition_statement(Blabel*) = 0;
kono
parents:
diff changeset
684
kono
parents:
diff changeset
685 // Create a goto statement to a label.
kono
parents:
diff changeset
686 virtual Bstatement*
kono
parents:
diff changeset
687 goto_statement(Blabel*, Location) = 0;
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 // Create an expression for the address of a label. This is used to
kono
parents:
diff changeset
690 // get the return address of a deferred function which may call
kono
parents:
diff changeset
691 // recover.
kono
parents:
diff changeset
692 virtual Bexpression*
kono
parents:
diff changeset
693 label_address(Blabel*, Location) = 0;
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 // Functions.
kono
parents:
diff changeset
696
kono
parents:
diff changeset
697 // Create an error function. This is used for cases which should
kono
parents:
diff changeset
698 // not occur in a correct program, in order to keep the compilation
kono
parents:
diff changeset
699 // going without crashing.
kono
parents:
diff changeset
700 virtual Bfunction*
kono
parents:
diff changeset
701 error_function() = 0;
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 // Declare or define a function of FNTYPE.
kono
parents:
diff changeset
704 // NAME is the Go name of the function. ASM_NAME, if not the empty string, is
kono
parents:
diff changeset
705 // the name that should be used in the symbol table; this will be non-empty if
kono
parents:
diff changeset
706 // a magic extern comment is used.
kono
parents:
diff changeset
707 // IS_VISIBLE is true if this function should be visible outside of the
kono
parents:
diff changeset
708 // current compilation unit. IS_DECLARATION is true if this is a function
kono
parents:
diff changeset
709 // declaration rather than a definition; the function definition will be in
kono
parents:
diff changeset
710 // another compilation unit.
kono
parents:
diff changeset
711 // IS_INLINABLE is true if the function can be inlined.
kono
parents:
diff changeset
712 // DISABLE_SPLIT_STACK is true if this function may not split the stack; this
kono
parents:
diff changeset
713 // is used for the implementation of recover.
kono
parents:
diff changeset
714 // IN_UNIQUE_SECTION is true if this function should be put into a unique
kono
parents:
diff changeset
715 // location if possible; this is used for field tracking.
kono
parents:
diff changeset
716 virtual Bfunction*
kono
parents:
diff changeset
717 function(Btype* fntype, const std::string& name, const std::string& asm_name,
kono
parents:
diff changeset
718 bool is_visible, bool is_declaration, bool is_inlinable,
kono
parents:
diff changeset
719 bool disable_split_stack, bool in_unique_section, Location) = 0;
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 // Create a statement that runs all deferred calls for FUNCTION. This should
kono
parents:
diff changeset
722 // be a statement that looks like this in C++:
kono
parents:
diff changeset
723 // finish:
kono
parents:
diff changeset
724 // try { DEFER_RETURN; } catch { CHECK_DEFER; goto finish; }
kono
parents:
diff changeset
725 virtual Bstatement*
kono
parents:
diff changeset
726 function_defer_statement(Bfunction* function, Bexpression* undefer,
kono
parents:
diff changeset
727 Bexpression* check_defer, Location) = 0;
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 // Record PARAM_VARS as the variables to use for the parameters of FUNCTION.
kono
parents:
diff changeset
730 // This will only be called for a function definition. Returns true on
kono
parents:
diff changeset
731 // success, false on failure.
kono
parents:
diff changeset
732 virtual bool
kono
parents:
diff changeset
733 function_set_parameters(Bfunction* function,
kono
parents:
diff changeset
734 const std::vector<Bvariable*>& param_vars) = 0;
kono
parents:
diff changeset
735
kono
parents:
diff changeset
736 // Set the function body for FUNCTION using the code in CODE_STMT. Returns
kono
parents:
diff changeset
737 // true on success, false on failure.
kono
parents:
diff changeset
738 virtual bool
kono
parents:
diff changeset
739 function_set_body(Bfunction* function, Bstatement* code_stmt) = 0;
kono
parents:
diff changeset
740
kono
parents:
diff changeset
741 // Look up a named built-in function in the current backend implementation.
kono
parents:
diff changeset
742 // Returns NULL if no built-in function by that name exists.
kono
parents:
diff changeset
743 virtual Bfunction*
kono
parents:
diff changeset
744 lookup_builtin(const std::string&) = 0;
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746 // Utility.
kono
parents:
diff changeset
747
kono
parents:
diff changeset
748 // Write the definitions for all TYPE_DECLS, CONSTANT_DECLS,
kono
parents:
diff changeset
749 // FUNCTION_DECLS, and VARIABLE_DECLS declared globally.
kono
parents:
diff changeset
750 virtual void
kono
parents:
diff changeset
751 write_global_definitions(const std::vector<Btype*>& type_decls,
kono
parents:
diff changeset
752 const std::vector<Bexpression*>& constant_decls,
kono
parents:
diff changeset
753 const std::vector<Bfunction*>& function_decls,
kono
parents:
diff changeset
754 const std::vector<Bvariable*>& variable_decls) = 0;
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 // Write SIZE bytes of export data from BYTES to the proper
kono
parents:
diff changeset
757 // section in the output object file.
kono
parents:
diff changeset
758 virtual void
kono
parents:
diff changeset
759 write_export_data(const char* bytes, unsigned int size) = 0;
kono
parents:
diff changeset
760 };
kono
parents:
diff changeset
761
kono
parents:
diff changeset
762 #endif // !defined(GO_BACKEND_H)