aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2011-04-03 22:44:18 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-04-03 22:44:18 +0000
commita9ac13f7bf9f86977984590b32359f7f4742216f (patch)
tree9b87d695a50405dbc08b35a02db9db1e0ff0355f /gcc/go/gofrontend
parent3edf1dd5bd3a7893f130e69a72839ca3637196cc (diff)
downloadgcc-a9ac13f7bf9f86977984590b32359f7f4742216f.zip
gcc-a9ac13f7bf9f86977984590b32359f7f4742216f.tar.gz
gcc-a9ac13f7bf9f86977984590b32359f7f4742216f.tar.bz2
Start using backend interface separate from gofrontend.
* go-gcc.cc: New file. * Make-lang.in (GO_OBJS): Add go/go-gcc.o. (go/go-gcc.o): New target. (go/go.o): Depend on go/gofrontend/backend.h. (go/statements.o): Likewise. From-SVN: r171917
Diffstat (limited to 'gcc/go/gofrontend')
-rw-r--r--gcc/go/gofrontend/backend.h119
-rw-r--r--gcc/go/gofrontend/go.cc3
-rw-r--r--gcc/go/gofrontend/gogo.cc5
-rw-r--r--gcc/go/gofrontend/gogo.h24
-rw-r--r--gcc/go/gofrontend/statements.cc7
5 files changed, 148 insertions, 10 deletions
diff --git a/gcc/go/gofrontend/backend.h b/gcc/go/gofrontend/backend.h
new file mode 100644
index 0000000..babef83
--- /dev/null
+++ b/gcc/go/gofrontend/backend.h
@@ -0,0 +1,119 @@
+// backend.h -- Go frontend interface to backend -*- C++ -*-
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#ifndef GO_BACKEND_H
+#define GO_BACKEND_H
+
+class Function_type;
+class Struct_type;
+class Interface_type;
+
+// Pointers to these types are created by the backend, passed to the
+// frontend, and passed back to the backend. The types must be
+// defined by the backend using these names.
+
+// The backend representation of a type.
+class Btype;
+
+// The backend represention of an expression.
+class Bexpression;
+
+// The backend representation of a statement.
+class Bstatement;
+
+// A list of backend types.
+typedef std::vector<Btype*> Btypes;
+
+// The backend interface. This is a pure abstract class that a
+// specific backend will implement.
+
+class Backend
+{
+ public:
+ virtual ~Backend() { }
+
+ // Types.
+
+ // Produce an error type. Actually the backend could probably just
+ // crash if this is called.
+ virtual Btype*
+ error_type() = 0;
+
+ // Get a void type. This is used in (at least) two ways: 1) as the
+ // return type of a function with no result parameters; 2)
+ // unsafe.Pointer is represented as *void.
+ virtual Btype*
+ void_type() = 0;
+
+ // Get the unnamed boolean type.
+ virtual Btype*
+ bool_type() = 0;
+
+ // Get an unnamed integer type with the given signedness and number
+ // of bits.
+ virtual Btype*
+ integer_type(bool is_unsigned, int bits) = 0;
+
+ // Get an unnamed floating point type with the given number of bits.
+ virtual Btype*
+ float_type(int bits) = 0;
+
+ // Get the unnamed string type.
+ virtual Btype*
+ string_type() = 0;
+
+ // Get a function type. The receiver, parameter, and results are
+ // generated from the types in the Function_type. The Function_type
+ // is provided so that the names are available.
+ virtual Btype*
+ function_type(const Function_type*, Btype* receiver,
+ const Btypes* parameters,
+ const Btypes* results) = 0;
+
+ // Get a struct type. The Struct_type is provided to get the field
+ // names.
+ virtual Btype*
+ struct_type(const Struct_type*, const Btypes* field_types) = 0;
+
+ // Get an array type.
+ virtual Btype*
+ array_type(const Btype* element_type, const Bexpression* length) = 0;
+
+ // Get a slice type.
+ virtual Btype*
+ slice_type(const Btype* element_type) = 0;
+
+ // Get a map type.
+ virtual Btype*
+ map_type(const Btype* key_type, const Btype* value_type, source_location) = 0;
+
+ // Get a channel type.
+ virtual Btype*
+ channel_type(const Btype* element_type) = 0;
+
+ // Get an interface type. The Interface_type is provided to get the
+ // method names.
+ virtual Btype*
+ interface_type(const Interface_type*, const Btypes* method_types) = 0;
+
+ // Statements.
+
+ // Create an assignment statement.
+ virtual Bstatement*
+ assignment(Bexpression* lhs, Bexpression* rhs, source_location location) = 0;
+};
+
+// The backend interface has to define this function.
+
+extern Backend* go_get_backend();
+
+// FIXME: Temporary helper functions while converting to new backend
+// interface.
+
+extern Bexpression* tree_to_expr(tree);
+extern tree statement_to_tree(Bstatement*);
+
+#endif // !defined(GO_BACKEND_H)
diff --git a/gcc/go/gofrontend/go.cc b/gcc/go/gofrontend/go.cc
index 7b1fd7e..e872973 100644
--- a/gcc/go/gofrontend/go.cc
+++ b/gcc/go/gofrontend/go.cc
@@ -10,6 +10,7 @@
#include "lex.h"
#include "parse.h"
+#include "backend.h"
#include "gogo.h"
// The unique prefix to use for exported symbols. This is set during
@@ -27,7 +28,7 @@ void
go_create_gogo(int int_type_size, int pointer_size)
{
gcc_assert(::gogo == NULL);
- ::gogo = new Gogo(int_type_size, pointer_size);
+ ::gogo = new Gogo(go_get_backend(), int_type_size, pointer_size);
if (!unique_prefix.empty())
::gogo->set_unique_prefix(unique_prefix);
}
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 9001d2b..6450141 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -19,8 +19,9 @@
// Class Gogo.
-Gogo::Gogo(int int_type_size, int pointer_size)
- : package_(NULL),
+Gogo::Gogo(Backend* backend, int int_type_size, int pointer_size)
+ : backend_(backend),
+ package_(NULL),
functions_(),
globals_(new Bindings(NULL)),
imports_(),
diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h
index 365860d..b6b1f4d 100644
--- a/gcc/go/gofrontend/gogo.h
+++ b/gcc/go/gofrontend/gogo.h
@@ -37,6 +37,7 @@ class Methods;
class Named_object;
class Label;
class Translate_context;
+class Backend;
class Export;
class Import;
@@ -102,7 +103,12 @@ class Gogo
public:
// Create the IR, passing in the sizes of the types "int" and
// "uintptr" in bits.
- Gogo(int int_type_size, int pointer_size);
+ Gogo(Backend* backend, int int_type_size, int pointer_size);
+
+ // Get the backend generator.
+ Backend*
+ backend()
+ { return this->backend_; }
// Get the package name.
const std::string&
@@ -647,6 +653,8 @@ class Gogo
typedef Unordered_map_hash(const Type*, tree, Type_hash_identical,
Type_identical) Type_descriptor_decls;
+ // The backend generator.
+ Backend* backend_;
// The package we are compiling.
Package* package_;
// The list of currently open functions during parsing.
@@ -2451,16 +2459,16 @@ class Traverse
Expressions_seen* expressions_seen_;
};
-// When translating the gogo IR into trees, this is the context we
-// pass down the blocks and statements.
+// When translating the gogo IR into the backend data structure, this
+// is the context we pass down the blocks and statements.
class Translate_context
{
public:
Translate_context(Gogo* gogo, Named_object* function, Block* block,
tree block_tree)
- : gogo_(gogo), function_(function), block_(block), block_tree_(block_tree),
- is_const_(false)
+ : gogo_(gogo), backend_(gogo->backend()), function_(function),
+ block_(block), block_tree_(block_tree), is_const_(false)
{ }
// Accessors.
@@ -2469,6 +2477,10 @@ class Translate_context
gogo()
{ return this->gogo_; }
+ Backend*
+ backend()
+ { return this->backend_; }
+
Named_object*
function()
{ return this->function_; }
@@ -2493,6 +2505,8 @@ class Translate_context
private:
// The IR for the entire compilation unit.
Gogo* gogo_;
+ // The generator for the backend data structures.
+ Backend* backend_;
// The function we are currently translating.
Named_object* function_;
// The block we are currently translating.
diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc
index f57ada8..b1e7613 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -29,6 +29,7 @@ extern "C"
#include "types.h"
#include "expressions.h"
#include "gogo.h"
+#include "backend.h"
#include "statements.h"
// Class Statement.
@@ -560,8 +561,10 @@ Assignment_statement::do_get_tree(Translate_context* context)
if (rhs_tree == error_mark_node)
return error_mark_node;
- return fold_build2_loc(this->location(), MODIFY_EXPR, void_type_node,
- lhs_tree, rhs_tree);
+ Bstatement* ret = context->backend()->assignment(tree_to_expr(lhs_tree),
+ tree_to_expr(rhs_tree),
+ this->location());
+ return statement_to_tree(ret);
}
// Make an assignment statement.