Commit da55a299 by Than McIntosh Committed by Ian Lance Taylor

compiler: add calling Bfunction Backend::call_expression

    
    Pass in the calling (containing) Bfunction when invoking the Backend
    method call_expression(), so as to handle the case where generation of
    the call forces the creation of a temp var within the calling
    function.
    
    Reviewed-on: https://go-review.googlesource.com/43270

From-SVN: r247981
parent 9dd19976
2017-05-12 Than McIntosh <thanm@google.com>
* go-gcc.cc (Gcc_backend::call_expression): Add caller parameter.
2017-05-11 Ian Lance Taylor <iant@google.com> 2017-05-11 Ian Lance Taylor <iant@google.com>
PR go/64238 PR go/64238
......
...@@ -348,7 +348,8 @@ class Gcc_backend : public Backend ...@@ -348,7 +348,8 @@ class Gcc_backend : public Backend
array_index_expression(Bexpression* array, Bexpression* index, Location); array_index_expression(Bexpression* array, Bexpression* index, Location);
Bexpression* Bexpression*
call_expression(Bexpression* fn, const std::vector<Bexpression*>& args, call_expression(Bfunction* caller, Bexpression* fn,
const std::vector<Bexpression*>& args,
Bexpression* static_chain, Location); Bexpression* static_chain, Location);
Bexpression* Bexpression*
...@@ -1892,9 +1893,11 @@ Gcc_backend::array_index_expression(Bexpression* array, Bexpression* index, ...@@ -1892,9 +1893,11 @@ Gcc_backend::array_index_expression(Bexpression* array, Bexpression* index,
// Create an expression for a call to FN_EXPR with FN_ARGS. // Create an expression for a call to FN_EXPR with FN_ARGS.
Bexpression* Bexpression*
Gcc_backend::call_expression(Bexpression* fn_expr, Gcc_backend::call_expression(Bfunction*, // containing fcn for call
Bexpression* fn_expr,
const std::vector<Bexpression*>& fn_args, const std::vector<Bexpression*>& fn_args,
Bexpression* chain_expr, Location location) Bexpression* chain_expr,
Location location)
{ {
tree fn = fn_expr->get_tree(); tree fn = fn_expr->get_tree();
if (fn == error_mark_node || TREE_TYPE(fn) == error_mark_node) if (fn == error_mark_node || TREE_TYPE(fn) == error_mark_node)
......
d5bfa6cebb19a154cbfbc53f6e647d2ca7adef68 2f21020c9f61b31bd04d5b814aaa27bf976bf07a
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -372,9 +372,11 @@ class Backend ...@@ -372,9 +372,11 @@ class Backend
virtual Bexpression* virtual Bexpression*
array_index_expression(Bexpression* array, Bexpression* index, Location) = 0; array_index_expression(Bexpression* array, Bexpression* index, Location) = 0;
// Create an expression for a call to FN with ARGS. // Create an expression for a call to FN with ARGS, taking place within
// caller CALLER.
virtual Bexpression* virtual Bexpression*
call_expression(Bexpression* fn, const std::vector<Bexpression*>& args, call_expression(Bfunction *caller, Bexpression* fn,
const std::vector<Bexpression*>& args,
Bexpression* static_chain, Location) = 0; Bexpression* static_chain, Location) = 0;
// Return an expression that allocates SIZE bytes on the stack. // Return an expression that allocates SIZE bytes on the stack.
......
...@@ -10290,13 +10290,16 @@ Call_expression::do_get_backend(Translate_context* context) ...@@ -10290,13 +10290,16 @@ Call_expression::do_get_backend(Translate_context* context)
bfn = gogo->backend()->convert_expression(bft, bfn, location); bfn = gogo->backend()->convert_expression(bft, bfn, location);
} }
Bexpression* call = gogo->backend()->call_expression(bfn, fn_args, Bfunction* bfunction = NULL;
bclosure, location); if (context->function())
bfunction = context->function()->func_value()->get_decl();
Bexpression* call = gogo->backend()->call_expression(bfunction, bfn,
fn_args, bclosure,
location);
if (this->results_ != NULL) if (this->results_ != NULL)
{ {
Bexpression* bcall_ref = this->call_result_ref(context); Bexpression* bcall_ref = this->call_result_ref(context);
Bfunction* bfunction = context->function()->func_value()->get_decl();
Bstatement* assn_stmt = Bstatement* assn_stmt =
gogo->backend()->assignment_statement(bfunction, gogo->backend()->assignment_statement(bfunction,
bcall_ref, call, location); bcall_ref, call, location);
......
...@@ -708,8 +708,8 @@ Gogo::init_imports(std::vector<Bstatement*>& init_stmts, Bfunction *bfunction) ...@@ -708,8 +708,8 @@ Gogo::init_imports(std::vector<Bstatement*>& init_stmts, Bfunction *bfunction)
Bexpression* pfunc_code = Bexpression* pfunc_code =
this->backend()->function_code_expression(pfunc, unknown_loc); this->backend()->function_code_expression(pfunc, unknown_loc);
Bexpression* pfunc_call = Bexpression* pfunc_call =
this->backend()->call_expression(pfunc_code, empty_args, this->backend()->call_expression(bfunction, pfunc_code, empty_args,
NULL, unknown_loc); NULL, unknown_loc);
init_stmts.push_back(this->backend()->expression_statement(bfunction, init_stmts.push_back(this->backend()->expression_statement(bfunction,
pfunc_call)); pfunc_call));
} }
...@@ -1498,7 +1498,7 @@ Gogo::write_globals() ...@@ -1498,7 +1498,7 @@ Gogo::write_globals()
Bfunction* initfn = func->get_or_make_decl(this, *p); Bfunction* initfn = func->get_or_make_decl(this, *p);
Bexpression* func_code = Bexpression* func_code =
this->backend()->function_code_expression(initfn, func_loc); this->backend()->function_code_expression(initfn, func_loc);
Bexpression* call = this->backend()->call_expression(func_code, Bexpression* call = this->backend()->call_expression(initfn, func_code,
empty_args, empty_args,
NULL, func_loc); NULL, func_loc);
Bstatement* ist = this->backend()->expression_statement(initfn, call); Bstatement* ist = this->backend()->expression_statement(initfn, call);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment