OSDN Git Service

Start using backend interface separate from gofrontend.
[pf3gnuchains/gcc-fork.git] / gcc / go / go-gcc.cc
1 // go-gcc.cc -- Go frontend to gcc IR.
2 // Copyright (C) 2011 Free Software Foundation, Inc.
3 // Contributed by Ian Lance Taylor, Google.
4
5 // This file is part of GCC.
6
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
10 // version.
11
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
15 // for more details.
16
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/>.
20
21 #include "go-system.h"
22
23 // This has to be included outside of extern "C", so we have to
24 // include it here before tree.h includes it later.
25 #include <gmp.h>
26
27 #ifndef ENABLE_BUILD_WITH_CXX
28 extern "C"
29 {
30 #endif
31
32 #include "tree.h"
33
34 #ifndef ENABLE_BUILD_WITH_CXX
35 }
36 #endif
37
38 #include "backend.h"
39
40 // A class wrapping a tree.
41
42 class Gcc_tree
43 {
44  public:
45   Gcc_tree(tree t)
46     : t_(t)
47   { }
48
49   tree
50   get_tree()
51   { return this->t_; }
52
53  private:
54   tree t_;
55 };
56
57 // In gcc, types, expressions, and statements are all trees.
58 class Btype : public Gcc_tree
59 {
60  public:
61   Btype(tree t)
62     : Gcc_tree(t)
63   { }
64 };
65
66 class Bexpression : public Gcc_tree
67 {
68  public:
69   Bexpression(tree t)
70     : Gcc_tree(t)
71   { }
72 };
73
74 class Bstatement : public Gcc_tree
75 {
76  public:
77   Bstatement(tree t)
78     : Gcc_tree(t)
79   { }
80 };
81
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.
87
88 class Gcc_backend : public Backend
89 {
90  public:
91   // Types.
92
93   Btype*
94   error_type()
95   { gcc_unreachable(); }
96
97   Btype*
98   void_type()
99   { gcc_unreachable(); }
100
101   Btype*
102   bool_type()
103   { gcc_unreachable(); }
104
105   Btype*
106   integer_type(bool /* is_unsigned */, int /* bits */)
107   { gcc_unreachable(); }
108
109   Btype*
110   float_type(int /* bits */)
111   { gcc_unreachable(); }
112
113   Btype*
114   string_type()
115   { gcc_unreachable(); }
116
117   Btype*
118   function_type(const Function_type*, Btype* /* receiver */,
119                 const Btypes* /* parameters */,
120                 const Btypes* /* results */)
121   { gcc_unreachable(); }
122
123   Btype*
124   struct_type(const Struct_type*, const Btypes* /* field_types */)
125   { gcc_unreachable(); }
126
127   Btype*
128   array_type(const Btype* /* element_type */, const Bexpression* /* length */)
129   { gcc_unreachable(); }
130
131   Btype*
132   slice_type(const Btype* /* element_type */)
133   { gcc_unreachable(); }
134
135   Btype*
136   map_type(const Btype* /* key_type */, const Btype* /* value_type */,
137            source_location)
138   { gcc_unreachable(); }
139
140   Btype*
141   channel_type(const Btype* /* element_type */)
142   { gcc_unreachable(); }
143
144   Btype*
145   interface_type(const Interface_type*, const Btypes* /* method_types */)
146   { gcc_unreachable(); }
147
148   // Statements.
149
150   // Create an assignment statement.
151   Bstatement*
152   assignment(Bexpression* lhs, Bexpression* rhs,
153              source_location location);
154
155  private:
156   // Make a Bstatement from a tree.
157   Bstatement*
158   make_statement(tree t)
159   { return new Bstatement(t); }
160 };
161
162 // Assignment.
163
164 Bstatement*
165 Gcc_backend::assignment(Bexpression* lhs, Bexpression* rhs,
166                         source_location location)
167 {
168   return this->make_statement(fold_build2_loc(location, MODIFY_EXPR,
169                                               void_type_node,
170                                               lhs->get_tree(),
171                                               rhs->get_tree()));
172 }
173
174 // The single backend.
175
176 static Gcc_backend gcc_backend;
177
178 // Return the backend generator.
179
180 Backend*
181 go_get_backend()
182 {
183   return &gcc_backend;
184 }
185
186 // FIXME: Temporary functions while converting to the new backend
187 // interface.
188
189 Bexpression*
190 tree_to_expr(tree t)
191 {
192   return new Bexpression(t);
193 }
194
195 tree
196 statement_to_tree(Bstatement* bs)
197 {
198   return bs->get_tree();
199 }