This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Go patch committed: Use backend interface for references to temps


This patch from Chris Manghane changes the Go frontend to use the
backend interface when building a reference to a temporary variable.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.8 branch.

Ian


2013-10-04  Chris Manghane  <cmang@google.com>

	* go-gcc.cc (Backend::convert_expression): New function.


Index: gcc/go/go-gcc.cc
===================================================================
--- gcc/go/go-gcc.cc	(revision 203037)
+++ gcc/go/go-gcc.cc	(revision 203038)
@@ -208,6 +208,16 @@ class Gcc_backend : public Backend
   Bexpression*
   zero_expression(Btype*);
 
+  Bexpression*
+  error_expression()
+  { return this->make_expression(error_mark_node); }
+
+  Bexpression*
+  var_expression(Bvariable* var, Location);
+
+  Bexpression*
+  indirect_expression(Bexpression* expr, bool known_valid, Location);
+
   // Statements.
 
   Bstatement*
@@ -848,6 +858,30 @@ Gcc_backend::zero_expression(Btype* btyp
   return tree_to_expr(ret);
 }
 
+// An expression that references a variable.
+
+Bexpression*
+Gcc_backend::var_expression(Bvariable* var, Location)
+{
+  tree ret = var->get_tree();
+  if (ret == error_mark_node)
+    return this->error_expression();
+  return tree_to_expr(ret);
+}
+
+// An expression that indirectly references an expression.
+
+Bexpression*
+Gcc_backend::indirect_expression(Bexpression* expr, bool known_valid,
+                                 Location location)
+{
+  tree ret = build_fold_indirect_ref_loc(location.gcc_location(),
+                                         expr->get_tree());
+  if (known_valid)
+    TREE_THIS_NOTRAP(ret) = 1;
+  return tree_to_expr(ret);
+}
+
 // An expression as a statement.
 
 Bstatement*
Index: gcc/go/gofrontend/backend.h
===================================================================
--- gcc/go/gofrontend/backend.h	(revision 203037)
+++ gcc/go/gofrontend/backend.h	(revision 203038)
@@ -231,6 +231,22 @@ class Backend
   virtual Bexpression*
   zero_expression(Btype*) = 0;
 
+  // Create an error expression. This is used for cases which should
+  // not occur in a correct program, in order to keep the compilation
+  // going without crashing.
+  virtual Bexpression*
+  error_expression() = 0;
+
+  // Create a reference to a variable.
+  virtual Bexpression*
+  var_expression(Bvariable* var, Location) = 0;
+
+  // Create an expression that indirects through the pointer expression EXPR
+  // (i.e., return the expression for *EXPR). KNOWN_VALID is true if the pointer
+  // is known to point to a valid memory location.
+  virtual Bexpression*
+  indirect_expression(Bexpression* expr, bool known_valid, Location) = 0;
+
   // Statements.
 
   // Create an error statement.  This is used for cases which should
Index: gcc/go/gofrontend/expressions.cc
===================================================================
--- gcc/go/gofrontend/expressions.cc	(revision 203037)
+++ gcc/go/gofrontend/expressions.cc	(revision 203038)
@@ -978,22 +978,19 @@ Var_expression::do_get_tree(Translate_co
 {
   Bvariable* bvar = this->variable_->get_backend_variable(context->gogo(),
 							  context->function());
-  tree ret = var_to_tree(bvar);
-  if (ret == error_mark_node)
-    return error_mark_node;
   bool is_in_heap;
+  Location loc = this->location();
   if (this->variable_->is_variable())
     is_in_heap = this->variable_->var_value()->is_in_heap();
   else if (this->variable_->is_result_variable())
     is_in_heap = this->variable_->result_var_value()->is_in_heap();
   else
     go_unreachable();
+
+  Bexpression* ret = context->backend()->var_expression(bvar, loc);
   if (is_in_heap)
-    {
-      ret = build_fold_indirect_ref_loc(this->location().gcc_location(), ret);
-      TREE_THIS_NOTRAP(ret) = 1;
-    }
-  return ret;
+    ret = context->backend()->indirect_expression(ret, true, loc);
+  return expr_to_tree(ret);
 }
 
 // Ast dump for variable expression.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]