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