summaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/gogo.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2011-04-19 18:20:05 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-04-19 18:20:05 +0000
commit5ad7db5fa38f86e095645296a5c1832fa088aa84 (patch)
treebd78a56617f782bc1b6bc7acb061e27f107b8285 /gcc/go/gofrontend/gogo.cc
parentf7d2e5d418d88cccfd1d54daebd57de464d9bd92 (diff)
downloadgcc-5ad7db5fa38f86e095645296a5c1832fa088aa84.tar.gz
Use backend interface for blocks.
* go-gcc.cc (class Bblock): Define. (Gcc_backend::if_statement): Change then_block and else_block to Bblock*. (Gcc_backend::block): New function. (Gcc_backend::block_add_statements): New function. (Gcc_backend::block_statement): New function. (tree_to_block, block_to_tree): New functions. From-SVN: r172731
Diffstat (limited to 'gcc/go/gofrontend/gogo.cc')
-rw-r--r--gcc/go/gofrontend/gogo.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index 8f0d3288694..be945c5ced9 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -3285,6 +3285,48 @@ Block::may_fall_through() const
return this->statements_.back()->may_fall_through();
}
+// Convert a block to the backend representation.
+
+Bblock*
+Block::get_backend(Translate_context* context)
+{
+ Gogo* gogo = context->gogo();
+ Named_object* function = context->function();
+ std::vector<Bvariable*> vars;
+ vars.reserve(this->bindings_->size_definitions());
+ for (Bindings::const_definitions_iterator pv =
+ this->bindings_->begin_definitions();
+ pv != this->bindings_->end_definitions();
+ ++pv)
+ {
+ if ((*pv)->is_variable() && !(*pv)->var_value()->is_parameter())
+ vars.push_back((*pv)->get_backend_variable(gogo, function));
+ }
+
+ // FIXME: Permitting FUNCTION to be NULL here is a temporary measure
+ // until we have a proper representation of the init function.
+ Bfunction* bfunction;
+ if (function == NULL)
+ bfunction = NULL;
+ else
+ bfunction = tree_to_function(function->func_value()->get_decl());
+ Bblock* ret = context->backend()->block(bfunction, context->bblock(),
+ vars, this->start_location_,
+ this->end_location_);
+
+ Translate_context subcontext(gogo, function, this, ret);
+ std::vector<Bstatement*> bstatements;
+ bstatements.reserve(this->statements_.size());
+ for (std::vector<Statement*>::const_iterator p = this->statements_.begin();
+ p != this->statements_.end();
+ ++p)
+ bstatements.push_back(tree_to_stat((*p)->get_tree(&subcontext)));
+
+ context->backend()->block_add_statements(ret, bstatements);
+
+ return ret;
+}
+
// Class Variable.
Variable::Variable(Type* type, Expression* init, bool is_global,