[gcc r14-7965] gccrs: Move variable-related methods into base class Backend

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:09:22 GMT 2024


https://gcc.gnu.org/g:88045f3524d805f09ba24d07d54ba975f043ec93

commit r14-7965-g88045f3524d805f09ba24d07d54ba975f043ec93
Author: Owen Avery <powerboat9.gamer@gmail.com>
Date:   Thu Aug 31 11:39:51 2023 -0400

    gccrs: Move variable-related methods into base class Backend
    
    gcc/rust/ChangeLog:
    
            * rust-backend.h
            (Backend::global_variable): Make non-virtual.
            (Backend::global_variable_set_init): Likewise.
            (Backend::local_variable): Likewise.
            (Backend::parameter_variable): Likewise.
            (Backend::static_chain_variable): Likewise.
            (Backend::temporary_variable): Likewise.
    
            (Gcc_backend::global_variable): Remove.
            (Gcc_backend::global_variable_set_init): Remove.
            (Gcc_backend::local_variable): Remove.
            (Gcc_backend::parameter_variable): Remove.
            (Gcc_backend::static_chain_variable): Remove.
            (Gcc_backend::temporary_variable): Remove.
    
            (Gcc_backend::non_zero_size_type): Move to ...
            (Backend::non_zero_size_type): ... here.
            (Gcc_backend::convert_tree): Move to ...
            (Backend::convert_tree): ... here.
    
            * rust-gcc.cc
            (Gcc_backend::non_zero_size_type): Rename to ...
            (Backend::non_zero_size_type): ... here.
            (Gcc_backend::convert_tree): Rename to ...
            (Backend::convert_tree): ... here.
            (Gcc_backend::global_variable): Rename to ...
            (Backend::global_variable): ... here.
            (Gcc_backend::global_variable_set_init): Rename to ...
            (Backend::global_variable_set_init): ... here.
            (Gcc_backend::local_variable): Rename to ...
            (Backend::local_variable): ... here.
            (Gcc_backend::parameter_variable): Rename to ...
            (Backend::parameter_variable): ... here.
            (Gcc_backend::static_chain_variable): Rename to ...
            (Backend::static_chain_variable): ... here.
            (Gcc_backend::temporary_variable): Rename to ...
            (Backend::temporary_variable): ... here.
    
    Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>

Diff:
---
 gcc/rust/rust-backend.h | 64 ++++++++++++++-----------------------------------
 gcc/rust/rust-gcc.cc    | 33 +++++++++++++------------
 2 files changed, 34 insertions(+), 63 deletions(-)

diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index cb091b114bc..dd849b8abd9 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -351,11 +351,10 @@ public:
   // be put into a unique section if possible; this is intended to
   // permit the linker to garbage collect the variable if it is not
   // referenced.  LOCATION is where the variable was defined.
-  virtual Bvariable *
-  global_variable (const std::string &name, const std::string &asm_name,
-		   tree btype, bool is_external, bool is_hidden,
-		   bool in_unique_section, location_t location)
-    = 0;
+  Bvariable *global_variable (const std::string &name,
+			      const std::string &asm_name, tree btype,
+			      bool is_external, bool is_hidden,
+			      bool in_unique_section, location_t location);
 
   // A global variable will 1) be initialized to zero, or 2) be
   // initialized to a constant value, or 3) be initialized in the init
@@ -363,7 +362,7 @@ public:
   // global_variable_set_init to set the initial value.  If this is
   // not called, the backend should initialize a global variable to 0.
   // The init function may then assign a value to it.
-  virtual void global_variable_set_init (Bvariable *, tree) = 0;
+  void global_variable_set_init (Bvariable *, tree);
 
   // Create a local variable.  The frontend will create the local
   // variables first, and then create the block which contains them.
@@ -377,23 +376,18 @@ public:
   // the function, as otherwise the variable would be on the heap).
   // LOCATION is where the variable is defined.  For each local variable
   // the frontend will call init_statement to set the initial value.
-  virtual Bvariable *local_variable (tree function, const std::string &name,
-				     tree type, Bvariable *decl_var,
-				     location_t location)
-    = 0;
+  Bvariable *local_variable (tree function, const std::string &name, tree type,
+			     Bvariable *decl_var, location_t location);
 
   // Create a function parameter.  This is an incoming parameter, not
   // a result parameter (result parameters are treated as local
   // variables).  The arguments are as for local_variable.
-  virtual Bvariable *parameter_variable (tree function, const std::string &name,
-					 tree type, location_t location)
-    = 0;
+  Bvariable *parameter_variable (tree function, const std::string &name,
+				 tree type, location_t location);
 
   // Create a static chain parameter.  This is the closure parameter.
-  virtual Bvariable *static_chain_variable (tree function,
-					    const std::string &name, tree type,
-					    location_t location)
-    = 0;
+  Bvariable *static_chain_variable (tree function, const std::string &name,
+				    tree type, location_t location);
 
   // Create a temporary variable.  A temporary variable has no name,
   // just a type.  We pass in FUNCTION and BLOCK in case they are
@@ -406,10 +400,9 @@ public:
   // variable, and may not be very useful.  This function should
   // return a variable which can be referenced later and should set
   // *PSTATEMENT to a statement which initializes the variable.
-  virtual Bvariable *temporary_variable (tree fndecl, tree bind_tree, tree type,
-					 tree init, bool address_is_taken,
-					 location_t location, tree *pstatement)
-    = 0;
+  Bvariable *temporary_variable (tree fndecl, tree bind_tree, tree type,
+				 tree init, bool address_is_taken,
+				 location_t location, tree *pstatement);
 
   // Labels.
 
@@ -496,6 +489,10 @@ protected:
   tree fill_in_fields (tree, const std::vector<typed_identifier> &);
 
   tree fill_in_array (tree, tree, tree);
+
+  tree non_zero_size_type (tree);
+
+  tree convert_tree (tree, tree, location_t);
 };
 
 class Gcc_backend : public Backend
@@ -595,26 +592,6 @@ public:
 
   void block_add_statements (tree, const std::vector<tree> &);
 
-  // Variables.
-
-  Bvariable *global_variable (const std::string &var_name,
-			      const std::string &asm_name, tree type,
-			      bool is_external, bool is_hidden,
-			      bool in_unique_section, location_t location);
-
-  void global_variable_set_init (Bvariable *, tree);
-
-  Bvariable *local_variable (tree, const std::string &, tree, Bvariable *,
-			     location_t);
-
-  Bvariable *parameter_variable (tree, const std::string &, tree, location_t);
-
-  Bvariable *static_chain_variable (tree, const std::string &, tree,
-				    location_t);
-
-  Bvariable *temporary_variable (tree, tree, tree, tree, bool, location_t,
-				 tree *);
-
   // Functions.
 
   tree function (tree fntype, const std::string &name,
@@ -632,11 +609,6 @@ public:
 				 const std::vector<Bvariable *> &);
 
   void write_export_data (const char *bytes, unsigned int size);
-
-private:
-  tree non_zero_size_type (tree);
-
-  tree convert_tree (tree, tree, location_t);
 };
 
 #endif // RUST_BACKEND_H
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 5ed73066bea..eddcb0fc9d7 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -1951,7 +1951,7 @@ tree rust_non_zero_struct;
 // Return a type corresponding to TYPE with non-zero size.
 
 tree
-Gcc_backend::non_zero_size_type (tree type)
+Backend::non_zero_size_type (tree type)
 {
   if (int_size_in_bytes (type) != 0)
     return type;
@@ -2010,7 +2010,7 @@ Gcc_backend::non_zero_size_type (tree type)
 // representations.  Make sure this does not confuse the middle-end.
 
 tree
-Gcc_backend::convert_tree (tree type_tree, tree expr_tree, location_t location)
+Backend::convert_tree (tree type_tree, tree expr_tree, location_t location)
 {
   if (type_tree == TREE_TYPE (expr_tree))
     return expr_tree;
@@ -2041,10 +2041,10 @@ Gcc_backend::convert_tree (tree type_tree, tree expr_tree, location_t location)
 // Make a global variable.
 
 Bvariable *
-Gcc_backend::global_variable (const std::string &var_name,
-			      const std::string &asm_name, tree type_tree,
-			      bool is_external, bool is_hidden,
-			      bool in_unique_section, location_t location)
+Backend::global_variable (const std::string &var_name,
+			  const std::string &asm_name, tree type_tree,
+			  bool is_external, bool is_hidden,
+			  bool in_unique_section, location_t location)
 {
   if (type_tree == error_mark_node)
     return Bvariable::error_variable ();
@@ -2083,7 +2083,7 @@ Gcc_backend::global_variable (const std::string &var_name,
 // Set the initial value of a global variable.
 
 void
-Gcc_backend::global_variable_set_init (Bvariable *var, tree expr_tree)
+Backend::global_variable_set_init (Bvariable *var, tree expr_tree)
 {
   if (expr_tree == error_mark_node)
     return;
@@ -2107,9 +2107,8 @@ Gcc_backend::global_variable_set_init (Bvariable *var, tree expr_tree)
 // Make a local variable.
 
 Bvariable *
-Gcc_backend::local_variable (tree function, const std::string &name,
-			     tree type_tree, Bvariable *decl_var,
-			     location_t location)
+Backend::local_variable (tree function, const std::string &name, tree type_tree,
+			 Bvariable *decl_var, location_t location)
 {
   if (type_tree == error_mark_node)
     return Bvariable::error_variable ();
@@ -2129,8 +2128,8 @@ Gcc_backend::local_variable (tree function, const std::string &name,
 // Make a function parameter variable.
 
 Bvariable *
-Gcc_backend::parameter_variable (tree function, const std::string &name,
-				 tree type_tree, location_t location)
+Backend::parameter_variable (tree function, const std::string &name,
+			     tree type_tree, location_t location)
 {
   if (type_tree == error_mark_node)
     return Bvariable::error_variable ();
@@ -2146,8 +2145,8 @@ Gcc_backend::parameter_variable (tree function, const std::string &name,
 // Make a static chain variable.
 
 Bvariable *
-Gcc_backend::static_chain_variable (tree fndecl, const std::string &name,
-				    tree type_tree, location_t location)
+Backend::static_chain_variable (tree fndecl, const std::string &name,
+				tree type_tree, location_t location)
 {
   if (type_tree == error_mark_node)
     return Bvariable::error_variable ();
@@ -2178,9 +2177,9 @@ Gcc_backend::static_chain_variable (tree fndecl, const std::string &name,
 // Make a temporary variable.
 
 Bvariable *
-Gcc_backend::temporary_variable (tree fndecl, tree bind_tree, tree type_tree,
-				 tree init_tree, bool is_address_taken,
-				 location_t location, tree *pstatement)
+Backend::temporary_variable (tree fndecl, tree bind_tree, tree type_tree,
+			     tree init_tree, bool is_address_taken,
+			     location_t location, tree *pstatement)
 {
   gcc_assert (fndecl != NULL_TREE);
   if (type_tree == error_mark_node || init_tree == error_mark_node


More information about the Gcc-cvs mailing list