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 descriptors


This patch from Chris Manghane changes the Go frontend to use the
backend interface for map and type descriptors.  Bootstrapped and ran Go
testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian


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

	* go-gcc.cc (Gcc_backend::address_expression): New function.


Index: gcc/go/go-gcc.cc
===================================================================
--- gcc/go/go-gcc.cc	(revision 203578)
+++ gcc/go/go-gcc.cc	(revision 203579)
@@ -235,6 +235,9 @@ class Gcc_backend : public Backend
   Bexpression*
   function_code_expression(Bfunction*, Location);
 
+  Bexpression*
+  address_expression(Bexpression*, Location);
+
   // Statements.
 
   Bstatement*
@@ -997,6 +1000,19 @@ Gcc_backend::function_code_expression(Bf
   return this->make_expression(ret);
 }
 
+// Get the address of an expression.
+
+Bexpression*
+Gcc_backend::address_expression(Bexpression* bexpr, Location location)
+{
+  tree expr = bexpr->get_tree();
+  if (expr == error_mark_node)
+    return this->error_expression();
+
+  tree ret = build_fold_addr_expr_loc(location.gcc_location(), expr);
+  return this->make_expression(ret);
+}
+
 // An expression as a statement.
 
 Bstatement*
Index: gcc/go/gofrontend/types.h
===================================================================
--- gcc/go/gofrontend/types.h	(revision 203578)
+++ gcc/go/gofrontend/types.h	(revision 203579)
@@ -901,7 +901,7 @@ class Type
   // Build a type descriptor entry for this type.  Return a pointer to
   // it.  The location is the location which causes us to need the
   // entry.
-  tree
+  Bexpression*
   type_descriptor_pointer(Gogo* gogo, Location);
 
   // Return the type reflection string for this type.
@@ -2401,7 +2401,7 @@ class Map_type : public Type
   // Build a map descriptor for this type.  Return a pointer to it.
   // The location is the location which causes us to need the
   // descriptor.
-  tree
+  Bexpression*
   map_descriptor_pointer(Gogo* gogo, Location);
 
  protected:
Index: gcc/go/gofrontend/gogo-tree.cc
===================================================================
--- gcc/go/gofrontend/gogo-tree.cc	(revision 203578)
+++ gcc/go/gofrontend/gogo-tree.cc	(revision 203579)
@@ -2107,8 +2107,10 @@ Gogo::interface_method_table_for_type(co
     td_type = type;
   else
     td_type = Type::make_pointer_type(type);
-  tree tdp = td_type->type_descriptor_pointer(this,
-                                              Linemap::predeclared_location());
+
+  Location loc = Linemap::predeclared_location();
+  Bexpression* tdp_bexpr = td_type->type_descriptor_pointer(this, loc);
+  tree tdp = expr_to_tree(tdp_bexpr);
   elt->value = fold_convert(const_ptr_type_node, tdp);
 
   Named_type* nt = type->named_type();
Index: gcc/go/gofrontend/backend.h
===================================================================
--- gcc/go/gofrontend/backend.h	(revision 203578)
+++ gcc/go/gofrontend/backend.h	(revision 203579)
@@ -271,6 +271,10 @@ class Backend
   virtual Bexpression*
   function_code_expression(Bfunction*, Location) = 0;
 
+  // Create an expression that takes the address of an expression.
+  virtual Bexpression*
+  address_expression(Bexpression*, Location) = 0;
+
   // Statements.
 
   // Create an error statement.  This is used for cases which should
Index: gcc/go/gofrontend/types.cc
===================================================================
--- gcc/go/gofrontend/types.cc	(revision 203578)
+++ gcc/go/gofrontend/types.cc	(revision 203579)
@@ -1204,7 +1204,7 @@ Type::finish_backend(Gogo* gogo, Btype *
 
 // Return a pointer to the type descriptor for this type.
 
-tree
+Bexpression*
 Type::type_descriptor_pointer(Gogo* gogo, Location location)
 {
   Type* t = this->forwarded();
@@ -1215,10 +1215,9 @@ Type::type_descriptor_pointer(Gogo* gogo
       t->make_type_descriptor_var(gogo);
       go_assert(t->type_descriptor_var_ != NULL);
     }
-  tree var_tree = var_to_tree(t->type_descriptor_var_);
-  if (var_tree == error_mark_node)
-    return error_mark_node;
-  return build_fold_addr_expr_loc(location.gcc_location(), var_tree);
+  Bexpression* var_expr =
+      gogo->backend()->var_expression(t->type_descriptor_var_, location);
+  return gogo->backend()->address_expression(var_expr, location);
 }
 
 // A mapping from unnamed types to type descriptor variables.
@@ -6250,14 +6249,12 @@ Map_type::Map_descriptors Map_type::map_
 
 // Build a map descriptor for this type.  Return a pointer to it.
 
-tree
+Bexpression*
 Map_type::map_descriptor_pointer(Gogo* gogo, Location location)
 {
   Bvariable* bvar = this->map_descriptor(gogo);
-  tree var_tree = var_to_tree(bvar);
-  if (var_tree == error_mark_node)
-    return error_mark_node;
-  return build_fold_addr_expr_loc(location.gcc_location(), var_tree);
+  Bexpression* var_expr = gogo->backend()->var_expression(bvar, location);
+  return gogo->backend()->address_expression(var_expr, location);
 }
 
 // Build a map descriptor for this type.
Index: gcc/go/gofrontend/expressions.cc
===================================================================
--- gcc/go/gofrontend/expressions.cc	(revision 203578)
+++ gcc/go/gofrontend/expressions.cc	(revision 203579)
@@ -286,7 +286,11 @@ Expression::convert_type_to_interface(Tr
   // Otherwise it is the interface method table for RHS_TYPE.
   tree first_field_value;
   if (lhs_is_empty)
-    first_field_value = rhs_type->type_descriptor_pointer(gogo, location);
+    {
+      Bexpression* rhs_bexpr =
+          rhs_type->type_descriptor_pointer(gogo, location);
+      first_field_value = expr_to_tree(rhs_bexpr);
+    }
   else
     {
       // Build the interface method table for this interface and this
@@ -457,8 +461,9 @@ Expression::convert_interface_to_interfa
   if (for_type_guard)
     {
       // A type assertion fails when converting a nil interface.
-      tree lhs_type_descriptor = lhs_type->type_descriptor_pointer(gogo,
-								   location);
+      Bexpression* lhs_type_expr = lhs_type->type_descriptor_pointer(gogo,
+                                                                     location);
+      tree lhs_type_descriptor = expr_to_tree(lhs_type_expr);
       static tree assert_interface_decl;
       tree call = Gogo::call_builtin(&assert_interface_decl,
 				     location,
@@ -491,8 +496,10 @@ Expression::convert_interface_to_interfa
       // type assertion converting nil will always succeed.
       go_assert(strcmp(IDENTIFIER_POINTER(DECL_NAME(field)), "__methods")
 		 == 0);
-      tree lhs_type_descriptor = lhs_type->type_descriptor_pointer(gogo,
-								   location);
+      Bexpression* lhs_type_expr = lhs_type->type_descriptor_pointer(gogo,
+                                                                     location);
+      tree lhs_type_descriptor = expr_to_tree(lhs_type_expr);
+
       static tree convert_interface_decl;
       tree call = Gogo::call_builtin(&convert_interface_decl,
 				     location,
@@ -546,8 +553,9 @@ Expression::convert_interface_to_type(Tr
   // Call a function to check that the type is valid.  The function
   // will panic with an appropriate runtime type error if the type is
   // not valid.
-
-  tree lhs_type_descriptor = lhs_type->type_descriptor_pointer(gogo, location);
+  Bexpression* lhs_type_expr = lhs_type->type_descriptor_pointer(gogo,
+                                                                 location);
+  tree lhs_type_descriptor = expr_to_tree(lhs_type_expr);
 
   if (!DECL_P(rhs_tree))
     rhs_tree = save_expr(rhs_tree);
@@ -556,8 +564,9 @@ Expression::convert_interface_to_type(Tr
     Expression::get_interface_type_descriptor(context, rhs_type, rhs_tree,
 					      location);
 
-  tree rhs_inter_descriptor = rhs_type->type_descriptor_pointer(gogo,
-								location);
+  Bexpression* rhs_inter_expr = rhs_type->type_descriptor_pointer(gogo,
+                                                                  location);
+  tree rhs_inter_descriptor = expr_to_tree(rhs_inter_expr);
 
   static tree check_interface_type_decl;
   tree call = Gogo::call_builtin(&check_interface_type_decl,
@@ -6500,8 +6509,9 @@ Expression::comparison_tree(Translate_co
 	}
       arg = fold_convert_loc(location.gcc_location(), ptr_type_node, arg);
 
-      tree descriptor = right_type->type_descriptor_pointer(context->gogo(),
-							    location);
+      Bexpression* descriptor_bexpr =
+          right_type->type_descriptor_pointer(context->gogo(), location);
+      tree descriptor = expr_to_tree(descriptor_bexpr);
 
       if (left_type->interface_type()->is_empty())
 	{
@@ -13256,7 +13266,8 @@ Map_construction_expression::do_get_tree
       valaddr = build_fold_addr_expr(tmp);
     }
 
-  tree descriptor = mt->map_descriptor_pointer(gogo, loc);
+  Bexpression* bdescriptor = mt->map_descriptor_pointer(gogo, loc);
+  tree descriptor = expr_to_tree(bdescriptor);
 
   tree type_tree = type_to_tree(this->type_->get_backend(gogo));
   if (type_tree == error_mark_node)
@@ -14312,8 +14323,9 @@ class Type_descriptor_expression : publi
   tree
   do_get_tree(Translate_context* context)
   {
-    return this->type_->type_descriptor_pointer(context->gogo(),
-						this->location());
+    Bexpression* ret = this->type_->type_descriptor_pointer(context->gogo(),
+                                                            this->location());
+    return expr_to_tree(ret);
   }
 
   void
@@ -14568,8 +14580,9 @@ class Map_descriptor_expression : public
   tree
   do_get_tree(Translate_context* context)
   {
-    return this->type_->map_descriptor_pointer(context->gogo(),
-					       this->location());
+    Bexpression* ret = this->type_->map_descriptor_pointer(context->gogo(),
+                                                           this->location());
+    return expr_to_tree(ret);
   }
 
   void

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