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.
14 // Pointers to these types are created by the backend, passed to the
15 // frontend, and passed back to the backend. The types must be
16 // defined by the backend using these names.
18 // The backend representation of a type.
21 // The backend represention of an expression.
24 // The backend representation of a statement.
27 // The backend representation of a function definition.
30 // A list of backend types.
31 typedef std::vector<Btype*> Btypes;
33 // The backend interface. This is a pure abstract class that a
34 // specific backend will implement.
39 virtual ~Backend() { }
43 // Produce an error type. Actually the backend could probably just
44 // crash if this is called.
48 // Get a void type. This is used in (at least) two ways: 1) as the
49 // return type of a function with no result parameters; 2)
50 // unsafe.Pointer is represented as *void.
54 // Get the unnamed boolean type.
58 // Get an unnamed integer type with the given signedness and number
61 integer_type(bool is_unsigned, int bits) = 0;
63 // Get an unnamed floating point type with the given number of bits.
65 float_type(int bits) = 0;
67 // Get the unnamed string type.
71 // Get a function type. The receiver, parameter, and results are
72 // generated from the types in the Function_type. The Function_type
73 // is provided so that the names are available.
75 function_type(const Function_type*, Btype* receiver,
76 const Btypes* parameters,
77 const Btypes* results) = 0;
79 // Get a struct type. The Struct_type is provided to get the field
82 struct_type(const Struct_type*, const Btypes* field_types) = 0;
86 array_type(const Btype* element_type, const Bexpression* length) = 0;
90 slice_type(const Btype* element_type) = 0;
94 map_type(const Btype* key_type, const Btype* value_type, source_location) = 0;
96 // Get a channel type.
98 channel_type(const Btype* element_type) = 0;
100 // Get an interface type. The Interface_type is provided to get the
103 interface_type(const Interface_type*, const Btypes* method_types) = 0;
107 // Create an assignment statement.
109 assignment_statement(Bexpression* lhs, Bexpression* rhs,
110 source_location) = 0;
112 // Create a return statement, passing the representation of the
113 // function and the list of values to return.
115 return_statement(Bfunction*, const std::vector<Bexpression*>&,
116 source_location) = 0;
119 // The backend interface has to define this function.
121 extern Backend* go_get_backend();
123 // FIXME: Temporary helper functions while converting to new backend
126 extern Bexpression* tree_to_expr(tree);
127 extern Bfunction* tree_to_function(tree);
128 extern tree statement_to_tree(Bstatement*);
130 #endif // !defined(GO_BACKEND_H)