From: Ian Lance Taylor Date: Wed, 6 Apr 2011 15:46:53 +0000 (+0000) Subject: Use backend interface for if statements. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=db0adf823043571405db77196c8b8898212808ec;p=gcc.git Use backend interface for if statements. Rename some temporary conversion functions to shorter names. * go-gcc.cc (Gcc_backend::if_statement): New function. (tree_to_stat): New function. (expr_to_tree): Renamed from expression_to_tree. (stat_to_tree): Renamed from statement_to_tree. From-SVN: r172052 --- diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog index b83eae8cb26..ff56bfe9883 100644 --- a/gcc/go/ChangeLog +++ b/gcc/go/ChangeLog @@ -1,3 +1,10 @@ +2011-04-06 Ian Lance Taylor + + * go-gcc.cc (Gcc_backend::if_statement): New function. + (tree_to_stat): New function. + (expr_to_tree): Renamed from expression_to_tree. + (stat_to_tree): Renamed from statement_to_tree. + 2011-04-06 Ian Lance Taylor * go-gcc.cc (Gcc_backend::expression_statement): New function. diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc index ce26d4d844e..de689f8478e 100644 --- a/gcc/go/go-gcc.cc +++ b/gcc/go/go-gcc.cc @@ -176,6 +176,10 @@ class Gcc_backend : public Backend return_statement(Bfunction*, const std::vector&, source_location); + Bstatement* + if_statement(Bexpression* condition, Bstatement* then_block, + Bstatement* else_block, source_location); + // Labels. Blabel* @@ -293,6 +297,25 @@ Gcc_backend::return_statement(Bfunction* bfunction, return this->make_statement(ret); } +// If. + +Bstatement* +Gcc_backend::if_statement(Bexpression* condition, Bstatement* then_block, + Bstatement* else_block, source_location location) +{ + tree cond_tree = condition->get_tree(); + tree then_tree = then_block->get_tree(); + tree else_tree = else_block == NULL ? NULL_TREE : else_block->get_tree(); + if (cond_tree == error_mark_node + || then_tree == error_mark_node + || else_tree == error_mark_node) + return this->make_statement(error_mark_node); + tree ret = build3(COND_EXPR, void_type_node, cond_tree, then_tree, + else_tree); + SET_EXPR_LOCATION(ret, location); + return this->make_statement(ret); +} + // Make a label. Blabel* @@ -366,6 +389,12 @@ tree_to_expr(tree t) return new Bexpression(t); } +Bstatement* +tree_to_stat(tree t) +{ + return new Bstatement(t); +} + Bfunction* tree_to_function(tree t) { @@ -373,13 +402,13 @@ tree_to_function(tree t) } tree -expression_to_tree(Bexpression* be) +expr_to_tree(Bexpression* be) { return be->get_tree(); } tree -statement_to_tree(Bstatement* bs) +stat_to_tree(Bstatement* bs) { return bs->get_tree(); } diff --git a/gcc/go/gofrontend/backend.h b/gcc/go/gofrontend/backend.h index a84b9e84c69..a6c242680ff 100644 --- a/gcc/go/gofrontend/backend.h +++ b/gcc/go/gofrontend/backend.h @@ -122,6 +122,11 @@ class Backend return_statement(Bfunction*, const std::vector&, source_location) = 0; + // Create an if statement. ELSE_BLOCK may be NULL. + virtual Bstatement* + if_statement(Bexpression* condition, Bstatement* then_block, + Bstatement* else_block, source_location) = 0; + // Labels. // Create a new label. NAME will be empty if this is a label @@ -155,8 +160,9 @@ extern Backend* go_get_backend(); // interface. extern Bexpression* tree_to_expr(tree); +extern Bstatement* tree_to_stat(tree); extern Bfunction* tree_to_function(tree); -extern tree expression_to_tree(Bexpression*); -extern tree statement_to_tree(Bstatement*); +extern tree expr_to_tree(Bexpression*); +extern tree stat_to_tree(Bstatement*); #endif // !defined(GO_BACKEND_H) diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index afd2191e857..c516485f343 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -12598,8 +12598,7 @@ class Label_addr_expression : public Expression tree do_get_tree(Translate_context* context) { - return expression_to_tree(this->label_->get_addr(context, - this->location())); + return expr_to_tree(this->label_->get_addr(context, this->location())); } private: diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc index da29a35d00d..131001a9ce1 100644 --- a/gcc/go/gofrontend/statements.cc +++ b/gcc/go/gofrontend/statements.cc @@ -565,7 +565,7 @@ Assignment_statement::do_get_tree(Translate_context* context) ret = context->backend()->assignment_statement(tree_to_expr(lhs_tree), tree_to_expr(rhs_tree), this->location()); - return statement_to_tree(ret); + return stat_to_tree(ret); } // Make an assignment statement. @@ -1596,7 +1596,7 @@ Expression_statement::do_get_tree(Translate_context* context) tree expr_tree = this->expr_->get_tree(context); Bexpression* bexpr = tree_to_expr(expr_tree); Bstatement* ret = context->backend()->expression_statement(bexpr); - return statement_to_tree(ret); + return stat_to_tree(ret); } // Make an expression statement from an Expression. @@ -2593,7 +2593,7 @@ Return_statement::do_get_tree(Translate_context* context) Bstatement* ret; ret = context->backend()->return_statement(tree_to_function(fndecl), retvals, this->location()); - return statement_to_tree(ret); + return stat_to_tree(ret); } // Make a return statement. @@ -2631,8 +2631,7 @@ class Bc_statement : public Statement tree do_get_tree(Translate_context* context) { - return statement_to_tree(this->label_->get_goto(context, - this->location())); + return stat_to_tree(this->label_->get_goto(context, this->location())); } private: @@ -2710,7 +2709,7 @@ Goto_statement::do_get_tree(Translate_context* context) Blabel* blabel = this->label_->get_backend_label(context); Bstatement* statement = context->backend()->goto_statement(blabel, this->location()); - return statement_to_tree(statement); + return stat_to_tree(statement); } // Make a goto statement. @@ -2743,8 +2742,7 @@ class Goto_unnamed_statement : public Statement tree do_get_tree(Translate_context* context) { - return statement_to_tree(this->label_->get_goto(context, - this->location())); + return stat_to_tree(this->label_->get_goto(context, this->location())); } private: @@ -2778,7 +2776,7 @@ Label_statement::do_get_tree(Translate_context* context) Blabel* blabel = this->label_->get_backend_label(context); Bstatement* statement; statement = context->backend()->label_definition_statement(blabel); - return statement_to_tree(statement); + return stat_to_tree(statement); } // Make a label statement. @@ -2806,7 +2804,7 @@ class Unnamed_label_statement : public Statement tree do_get_tree(Translate_context* context) - { return statement_to_tree(this->label_->get_definition(context)); } + { return stat_to_tree(this->label_->get_definition(context)); } private: // The label. @@ -2914,14 +2912,17 @@ If_statement::do_get_tree(Translate_context* context) tree else_tree = (this->else_block_ == NULL ? NULL_TREE : this->else_block_->get_tree(context)); - if (cond_tree == error_mark_node - || then_tree == error_mark_node - || else_tree == error_mark_node) - return error_mark_node; - tree ret = build3(COND_EXPR, void_type_node, cond_tree, then_tree, - else_tree); - SET_EXPR_LOCATION(ret, this->location()); - return ret; + + Bexpression* cond_expr = tree_to_expr(cond_tree); + Bstatement* then_stat = tree_to_stat(then_tree); + Bstatement* else_stat = (else_tree == NULL_TREE + ? NULL + : tree_to_stat(else_tree)); + + Bstatement* ret = context->backend()->if_statement(cond_expr, then_stat, + else_stat, + this->location()); + return stat_to_tree(ret); } // Make an if statement. @@ -3158,7 +3159,7 @@ Case_clauses::Case_clause::get_constant_tree(Translate_context* context, if (!this->is_fallthrough_) { Bstatement* g = break_label->get_goto(context, this->location_); - append_to_statement_list(statement_to_tree(g), stmt_list); + append_to_statement_list(stat_to_tree(g), stmt_list); } } @@ -3413,7 +3414,7 @@ Constant_switch_statement::do_get_tree(Translate_context* context) append_to_statement_list(s, &stmt_list); Bstatement* ldef = break_label->get_definition(context); - append_to_statement_list(statement_to_tree(ldef), &stmt_list); + append_to_statement_list(stat_to_tree(ldef), &stmt_list); return stmt_list; } @@ -4272,7 +4273,7 @@ Select_clauses::get_tree(Translate_context* context, append_to_statement_list(default_clause->get_statements_tree(context), &stmt_list); Bstatement* ldef = break_label->get_definition(context); - append_to_statement_list(statement_to_tree(ldef), &stmt_list); + append_to_statement_list(stat_to_tree(ldef), &stmt_list); return stmt_list; } @@ -4364,7 +4365,7 @@ Select_clauses::get_tree(Translate_context* context, } Bstatement* ldef = break_label->get_definition(context); - append_to_statement_list(statement_to_tree(ldef), &stmt_list); + append_to_statement_list(stat_to_tree(ldef), &stmt_list); tree switch_stmt = build3(SWITCH_EXPR, sizetype, call, stmt_list, NULL_TREE); SET_EXPR_LOCATION(switch_stmt, location); @@ -4390,7 +4391,7 @@ Select_clauses::add_clause_tree(Translate_context* context, int case_index, ? clause->location() : clause->statements()->end_location()); Bstatement* g = bottom_label->get_goto(context, gloc); - append_to_statement_list(statement_to_tree(g), stmt_list); + append_to_statement_list(stat_to_tree(g), stmt_list); } // Class Select_statement.