From 2b00b13d309f600fee94cc911a99362e0451cbaa Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Fri, 14 Jul 2023 15:39:14 -0400 Subject: [PATCH] gccrs: Move Gcc_backend declaration to header file gcc/rust/ChangeLog: * rust-backend.h: Include "rust-gcc.h". (class Gcc_backend): Move to ... * rust-gcc.cc (class Gcc_backend): ... here. Signed-off-by: Owen Avery --- gcc/rust/rust-backend.h | 215 ++++++++++++++++++++++++++++++++++++++++ gcc/rust/rust-gcc.cc | 214 --------------------------------------- 2 files changed, 215 insertions(+), 214 deletions(-) diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h index d4679ca9d86..66d17b338f7 100644 --- a/gcc/rust/rust-backend.h +++ b/gcc/rust/rust-backend.h @@ -28,6 +28,7 @@ #include "rust-diagnostics.h" #include "util/rust-operators.h" #include "tree.h" +#include "rust-gcc.h" // Pointers to these types are created by the backend, passed to the // frontend, and passed back to the backend. The types must be @@ -508,4 +509,218 @@ public: virtual void write_export_data (const char *bytes, unsigned int size) = 0; }; +class Gcc_backend : public Backend +{ +public: + Gcc_backend (); + + void debug (tree t); + void debug (Bvariable *t); + + tree get_identifier_node (const std::string &str); + + // Types. + + tree bool_type () { return boolean_type_node; } + + tree char_type () { return char_type_node; } + + tree wchar_type (); + + int get_pointer_size (); + + tree raw_str_type (); + + tree integer_type (bool, int); + + tree float_type (int); + + tree complex_type (int); + + tree pointer_type (tree); + + tree reference_type (tree); + + tree immutable_type (tree); + + tree function_type (const typed_identifier &, + const std::vector &, + const std::vector &, tree, + const location_t); + + tree function_type_varadic (const typed_identifier &, + const std::vector &, + const std::vector &, tree, + const location_t); + + tree function_ptr_type (tree, const std::vector &, location_t); + + tree struct_type (const std::vector &); + + tree union_type (const std::vector &); + + tree array_type (tree, tree); + + tree named_type (const std::string &, tree, location_t); + + int64_t type_size (tree); + + int64_t type_alignment (tree); + + int64_t type_field_alignment (tree); + + int64_t type_field_offset (tree, size_t index); + + // Expressions. + + tree zero_expression (tree); + + tree var_expression (Bvariable *var, location_t); + + tree integer_constant_expression (tree type, mpz_t val); + + tree float_constant_expression (tree type, mpfr_t val); + + tree complex_constant_expression (tree type, mpc_t val); + + tree string_constant_expression (const std::string &val); + + tree wchar_constant_expression (wchar_t c); + + tree char_constant_expression (char c); + + tree boolean_constant_expression (bool val); + + tree real_part_expression (tree bcomplex, location_t); + + tree imag_part_expression (tree bcomplex, location_t); + + tree complex_expression (tree breal, tree bimag, location_t); + + tree convert_expression (tree type, tree expr, location_t); + + tree struct_field_expression (tree, size_t, location_t); + + tree compound_expression (tree, tree, location_t); + + tree conditional_expression (tree, tree, tree, tree, tree, location_t); + + tree negation_expression (NegationOperator op, tree expr, location_t); + + tree arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op, + tree left, tree right, location_t); + + tree arithmetic_or_logical_expression_checked (ArithmeticOrLogicalOperator op, + tree left, tree right, + location_t, + Bvariable *receiver); + + tree comparison_expression (ComparisonOperator op, tree left, tree right, + location_t); + + tree lazy_boolean_expression (LazyBooleanOperator op, tree left, tree right, + location_t); + + tree constructor_expression (tree, bool, const std::vector &, int, + location_t); + + tree array_constructor_expression (tree, const std::vector &, + const std::vector &, location_t); + + tree array_initializer (tree, tree, tree, tree, tree, tree *, location_t); + + tree array_index_expression (tree array, tree index, location_t); + + tree call_expression (tree fn, const std::vector &args, + tree static_chain, location_t); + + // Statements. + + tree init_statement (tree, Bvariable *var, tree init); + + tree assignment_statement (tree lhs, tree rhs, location_t); + + tree return_statement (tree fndecl, tree val, location_t locus); + + tree if_statement (tree, tree condition, tree then_block, tree else_block, + location_t); + + tree compound_statement (tree, tree); + + tree statement_list (const std::vector &); + + tree exception_handler_statement (tree bstat, tree except_stmt, + tree finally_stmt, location_t); + + tree loop_expression (tree body, location_t); + + tree exit_expression (tree condition, location_t); + + // Blocks. + + tree block (tree, tree, const std::vector &, location_t, + location_t); + + void block_add_statements (tree, const std::vector &); + + // Variables. + + Bvariable *error_variable () { return new Bvariable (error_mark_node); } + + 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 *); + + // Labels. + + tree label (tree, const std::string &name, location_t); + + tree label_definition_statement (tree); + + tree goto_statement (tree, location_t); + + tree label_address (tree, location_t); + + // Functions. + + tree function (tree fntype, const std::string &name, + const std::string &asm_name, unsigned int flags, location_t); + + tree function_defer_statement (tree function, tree undefer, tree defer, + location_t); + + bool function_set_parameters (tree function, + const std::vector &); + + void write_global_definitions (const std::vector &, + const std::vector &, + const std::vector &, + const std::vector &); + + void write_export_data (const char *bytes, unsigned int size); + +private: + tree fill_in_fields (tree, const std::vector &); + + tree fill_in_array (tree, tree, tree); + + 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 a6a67bbb159..ced1e5471af 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -83,220 +83,6 @@ Bvariable::get_tree (location_t location) const // frontend proper class methods of these classes to generate the // backend representation. -class Gcc_backend : public Backend -{ -public: - Gcc_backend (); - - void debug (tree t); - void debug (Bvariable *t); - - tree get_identifier_node (const std::string &str); - - // Types. - - tree bool_type () { return boolean_type_node; } - - tree char_type () { return char_type_node; } - - tree wchar_type (); - - int get_pointer_size (); - - tree raw_str_type (); - - tree integer_type (bool, int); - - tree float_type (int); - - tree complex_type (int); - - tree pointer_type (tree); - - tree reference_type (tree); - - tree immutable_type (tree); - - tree function_type (const typed_identifier &, - const std::vector &, - const std::vector &, tree, - const location_t); - - tree function_type_varadic (const typed_identifier &, - const std::vector &, - const std::vector &, tree, - const location_t); - - tree function_ptr_type (tree, const std::vector &, location_t); - - tree struct_type (const std::vector &); - - tree union_type (const std::vector &); - - tree array_type (tree, tree); - - tree named_type (const std::string &, tree, location_t); - - int64_t type_size (tree); - - int64_t type_alignment (tree); - - int64_t type_field_alignment (tree); - - int64_t type_field_offset (tree, size_t index); - - // Expressions. - - tree zero_expression (tree); - - tree var_expression (Bvariable *var, location_t); - - tree integer_constant_expression (tree type, mpz_t val); - - tree float_constant_expression (tree type, mpfr_t val); - - tree complex_constant_expression (tree type, mpc_t val); - - tree string_constant_expression (const std::string &val); - - tree wchar_constant_expression (wchar_t c); - - tree char_constant_expression (char c); - - tree boolean_constant_expression (bool val); - - tree real_part_expression (tree bcomplex, location_t); - - tree imag_part_expression (tree bcomplex, location_t); - - tree complex_expression (tree breal, tree bimag, location_t); - - tree convert_expression (tree type, tree expr, location_t); - - tree struct_field_expression (tree, size_t, location_t); - - tree compound_expression (tree, tree, location_t); - - tree conditional_expression (tree, tree, tree, tree, tree, location_t); - - tree negation_expression (NegationOperator op, tree expr, location_t); - - tree arithmetic_or_logical_expression (ArithmeticOrLogicalOperator op, - tree left, tree right, location_t); - - tree arithmetic_or_logical_expression_checked (ArithmeticOrLogicalOperator op, - tree left, tree right, - location_t, - Bvariable *receiver); - - tree comparison_expression (ComparisonOperator op, tree left, tree right, - location_t); - - tree lazy_boolean_expression (LazyBooleanOperator op, tree left, tree right, - location_t); - - tree constructor_expression (tree, bool, const std::vector &, int, - location_t); - - tree array_constructor_expression (tree, const std::vector &, - const std::vector &, location_t); - - tree array_initializer (tree, tree, tree, tree, tree, tree *, location_t); - - tree array_index_expression (tree array, tree index, location_t); - - tree call_expression (tree fn, const std::vector &args, - tree static_chain, location_t); - - // Statements. - - tree init_statement (tree, Bvariable *var, tree init); - - tree assignment_statement (tree lhs, tree rhs, location_t); - - tree return_statement (tree fndecl, tree val, location_t locus); - - tree if_statement (tree, tree condition, tree then_block, tree else_block, - location_t); - - tree compound_statement (tree, tree); - - tree statement_list (const std::vector &); - - tree exception_handler_statement (tree bstat, tree except_stmt, - tree finally_stmt, location_t); - - tree loop_expression (tree body, location_t); - - tree exit_expression (tree condition, location_t); - - // Blocks. - - tree block (tree, tree, const std::vector &, location_t, - location_t); - - void block_add_statements (tree, const std::vector &); - - // Variables. - - Bvariable *error_variable () { return new Bvariable (error_mark_node); } - - 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 *); - - // Labels. - - tree label (tree, const std::string &name, location_t); - - tree label_definition_statement (tree); - - tree goto_statement (tree, location_t); - - tree label_address (tree, location_t); - - // Functions. - - tree function (tree fntype, const std::string &name, - const std::string &asm_name, unsigned int flags, location_t); - - tree function_defer_statement (tree function, tree undefer, tree defer, - location_t); - - bool function_set_parameters (tree function, - const std::vector &); - - void write_global_definitions (const std::vector &, - const std::vector &, - const std::vector &, - const std::vector &); - - void write_export_data (const char *bytes, unsigned int size); - -private: - tree fill_in_fields (tree, const std::vector &); - - tree fill_in_array (tree, tree, tree); - - tree non_zero_size_type (tree); - - tree convert_tree (tree, tree, location_t); -}; - // A helper function to create a GCC identifier from a C++ string. static inline tree