1 // go-gcc.cc -- Go frontend to gcc IR.
2 // Copyright (C) 2011 Free Software Foundation, Inc.
3 // Contributed by Ian Lance Taylor, Google.
5 // This file is part of GCC.
7 // GCC is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3, or (at your option) any later
12 // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 // You should have received a copy of the GNU General Public License
18 // along with GCC; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 #include "go-system.h"
23 // This has to be included outside of extern "C", so we have to
24 // include it here before tree.h includes it later.
27 #ifndef ENABLE_BUILD_WITH_CXX
34 #ifndef ENABLE_BUILD_WITH_CXX
40 // A class wrapping a tree.
57 // In gcc, types, expressions, and statements are all trees.
58 class Btype : public Gcc_tree
66 class Bexpression : public Gcc_tree
74 class Bstatement : public Gcc_tree
82 // This file implements the interface between the Go frontend proper
83 // and the gcc IR. This implements specific instantiations of
84 // abstract classes defined by the Go frontend proper. The Go
85 // frontend proper class methods of these classes to generate the
86 // backend representation.
88 class Gcc_backend : public Backend
95 { gcc_unreachable(); }
99 { gcc_unreachable(); }
103 { gcc_unreachable(); }
106 integer_type(bool /* is_unsigned */, int /* bits */)
107 { gcc_unreachable(); }
110 float_type(int /* bits */)
111 { gcc_unreachable(); }
115 { gcc_unreachable(); }
118 function_type(const Function_type*, Btype* /* receiver */,
119 const Btypes* /* parameters */,
120 const Btypes* /* results */)
121 { gcc_unreachable(); }
124 struct_type(const Struct_type*, const Btypes* /* field_types */)
125 { gcc_unreachable(); }
128 array_type(const Btype* /* element_type */, const Bexpression* /* length */)
129 { gcc_unreachable(); }
132 slice_type(const Btype* /* element_type */)
133 { gcc_unreachable(); }
136 map_type(const Btype* /* key_type */, const Btype* /* value_type */,
138 { gcc_unreachable(); }
141 channel_type(const Btype* /* element_type */)
142 { gcc_unreachable(); }
145 interface_type(const Interface_type*, const Btypes* /* method_types */)
146 { gcc_unreachable(); }
150 // Create an assignment statement.
152 assignment(Bexpression* lhs, Bexpression* rhs,
153 source_location location);
156 // Make a Bstatement from a tree.
158 make_statement(tree t)
159 { return new Bstatement(t); }
165 Gcc_backend::assignment(Bexpression* lhs, Bexpression* rhs,
166 source_location location)
168 return this->make_statement(fold_build2_loc(location, MODIFY_EXPR,
174 // The single backend.
176 static Gcc_backend gcc_backend;
178 // Return the backend generator.
186 // FIXME: Temporary functions while converting to the new backend
192 return new Bexpression(t);
196 statement_to_tree(Bstatement* bs)
198 return bs->get_tree();