public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7956] gccrs: Move type-related functions into base class Backend
@ 2024-01-16 18:08 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 18:08 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:fb14147b9f336d5467b3bb26afeab4ab925dd748
commit r14-7956-gfb14147b9f336d5467b3bb26afeab4ab925dd748
Author: Owen Avery <powerboat9.gamer@gmail.com>
Date: Thu Aug 31 11:15:43 2023 -0400
gccrs: Move type-related functions into base class Backend
gcc/rust/ChangeLog:
* rust-backend.h:
(Backend::wchar_type): Make non-virtual.
(Backend::get_pointer_size): Likewise.
(Backend::raw_str_type): Likewise.
(Backend::integer_type): Likewise.
(Backend::float_type): Likewise.
(Backend::complex_type): Likewise.
(Backend::pointer_type): Likewise.
(Backend::reference_type): Likewise.
(Backend::immutable_type): Likewise.
(Backend::function_type): Likewise.
(Backend::function_type_varadic): Likewise.
(Backend::function_ptr_type): Likewise.
(Backend::struct_type): Likewise.
(Backend::union_type): Likewise.
(Backend::array_type): Likewise.
(Backend::named_type): Likewise.
(Backend::type_size): Likewise.
(Backend::type_alignment): Likewise.
(Backend::type_field_alignment): Likewise.
(Backend::type_field_offset): Likewise.
(Gcc_backend::wchar_type): Remove.
(Gcc_backend::get_pointer_size): Remove.
(Gcc_backend::raw_str_type): Remove.
(Gcc_backend::integer_type): Remove.
(Gcc_backend::float_type): Remove.
(Gcc_backend::complex_type): Remove.
(Gcc_backend::pointer_type): Remove.
(Gcc_backend::reference_type): Remove.
(Gcc_backend::immutable_type): Remove.
(Gcc_backend::function_type): Remove.
(Gcc_backend::function_type_varadic): Remove.
(Gcc_backend::function_ptr_type): Remove.
(Gcc_backend::struct_type): Remove.
(Gcc_backend::union_type): Remove.
(Gcc_backend::array_type): Remove.
(Gcc_backend::named_type): Remove.
(Gcc_backend::type_size): Remove.
(Gcc_backend::type_alignment): Remove.
(Gcc_backend::type_field_alignment): Remove.
(Gcc_backend::type_field_offset): Remove.
(Gcc_backend::fill_in_fields): Move to ...
(Backend::fill_in_fields): ... here.
(Gcc_backend::fill_in_array): Move to ...
(Backend::fill_in_array): ... here.
* rust-gcc.cc
(Gcc_backend::wchar_type): Rename to ...
(Backend::wchar_type): ... here.
(Gcc_backend::get_pointer_size): Rename to ...
(Backend::get_pointer_size): ... here.
(Gcc_backend::raw_str_type): Rename to ...
(Backend::raw_str_type): ... here.
(Gcc_backend::integer_type): Rename to ...
(Backend::integer_type): ... here.
(Gcc_backend::float_type): Rename to ...
(Backend::float_type): ... here.
(Gcc_backend::complex_type): Rename to ...
(Backend::complex_type): ... here.
(Gcc_backend::pointer_type): Rename to ...
(Backend::pointer_type): ... here.
(Gcc_backend::reference_type): Rename to ...
(Backend::reference_type): ... here.
(Gcc_backend::immutable_type): Rename to ...
(Backend::immutable_type): ... here.
(Gcc_backend::function_type): Rename to ...
(Backend::function_type): ... here.
(Gcc_backend::function_type_varadic): Rename to ...
(Backend::function_type_varadic): ... here.
(Gcc_backend::function_ptr_type): Rename to ...
(Backend::function_ptr_type): ... here.
(Gcc_backend::struct_type): Rename to ...
(Backend::struct_type): ... here.
(Gcc_backend::union_type): Rename to ...
(Backend::union_type): ... here.
(Gcc_backend::fill_in_fields): Rename to ...
(Backend::fill_in_fields): ... here.
(Gcc_backend::array_type): Rename to ...
(Backend::array_type): ... here.
(Gcc_backend::fill_in_array): Rename to ...
(Backend::fill_in_array): ... here.
(Gcc_backend::named_type): Rename to ...
(Backend::named_type): ... here.
(Gcc_backend::type_size): Rename to ...
(Backend::type_size): ... here.
(Gcc_backend::type_alignment): Rename to ...
(Backend::type_alignment): ... here.
(Gcc_backend::type_field_alignment): Rename to ...
(Backend::type_field_alignment): ... here.
(Gcc_backend::type_field_offset): Rename to ...
(Backend::type_field_offset): ... here.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diff:
---
gcc/rust/rust-backend.h | 114 +++++++++++++-----------------------------------
gcc/rust/rust-gcc.cc | 62 +++++++++++++-------------
2 files changed, 61 insertions(+), 115 deletions(-)
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index e1c22e38a9f..1c81b20a870 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -71,33 +71,33 @@ public:
// Types.
// Get the wchar type
- virtual tree wchar_type () = 0;
+ tree wchar_type ();
// Get the Host pointer size in bits
- virtual int get_pointer_size () = 0;
+ int get_pointer_size ();
// Get the raw str type const char*
- virtual tree raw_str_type () = 0;
+ tree raw_str_type ();
// Get an unnamed integer type with the given signedness and number
// of bits.
- virtual tree integer_type (bool is_unsigned, int bits) = 0;
+ tree integer_type (bool is_unsigned, int bits);
// Get an unnamed floating point type with the given number of bits
// (32 or 64).
- virtual tree float_type (int bits) = 0;
+ tree float_type (int bits);
// Get an unnamed complex type with the given number of bits (64 or 128).
- virtual tree complex_type (int bits) = 0;
+ tree complex_type (int bits);
// Get a pointer type.
- virtual tree pointer_type (tree to_type) = 0;
+ tree pointer_type (tree to_type);
// Get a reference type.
- virtual tree reference_type (tree to_type) = 0;
+ tree reference_type (tree to_type);
// make type immutable
- virtual tree immutable_type (tree base) = 0;
+ tree immutable_type (tree base);
// Get a function type. The receiver, parameter, and results are
// generated from the types in the Function_type. The Function_type
@@ -108,54 +108,49 @@ public:
// one result, RESULT_STRUCT is a struct type to hold the results,
// and RESULTS may be ignored; if there are zero or one results,
// RESULT_STRUCT is NULL.
- virtual tree function_type (const typed_identifier &receiver,
+ tree function_type (const typed_identifier &receiver,
+ const std::vector<typed_identifier> ¶meters,
+ const std::vector<typed_identifier> &results,
+ tree result_struct, location_t location);
+
+ tree function_type_varadic (const typed_identifier &receiver,
const std::vector<typed_identifier> ¶meters,
const std::vector<typed_identifier> &results,
- tree result_struct, location_t location)
- = 0;
+ tree result_struct, location_t location);
- virtual tree
- function_type_varadic (const typed_identifier &receiver,
- const std::vector<typed_identifier> ¶meters,
- const std::vector<typed_identifier> &results,
- tree result_struct, location_t location)
- = 0;
-
- virtual tree function_ptr_type (tree result,
- const std::vector<tree> &praameters,
- location_t location)
- = 0;
+ tree function_ptr_type (tree result, const std::vector<tree> &praameters,
+ location_t location);
// Get a struct type.
- virtual tree struct_type (const std::vector<typed_identifier> &fields) = 0;
+ tree struct_type (const std::vector<typed_identifier> &fields);
// Get a union type.
- virtual tree union_type (const std::vector<typed_identifier> &fields) = 0;
+ tree union_type (const std::vector<typed_identifier> &fields);
// Get an array type.
- virtual tree array_type (tree element_type, tree length) = 0;
+ tree array_type (tree element_type, tree length);
// Return a named version of a type. The location is the location
// of the type definition. This will not be called for a type
// created via placeholder_pointer_type, placeholder_struct_type, or
// placeholder_array_type.. (It may be called for a pointer,
// struct, or array type in a case like "type P *byte; type Q P".)
- virtual tree named_type (const std::string &name, tree, location_t) = 0;
+ tree named_type (const std::string &name, tree, location_t);
// Return the size of a type.
- virtual int64_t type_size (tree) = 0;
+ int64_t type_size (tree);
// Return the alignment of a type.
- virtual int64_t type_alignment (tree) = 0;
+ int64_t type_alignment (tree);
// Return the alignment of a struct field of this type. This is
// normally the same as type_alignment, but not always.
- virtual int64_t type_field_alignment (tree) = 0;
+ int64_t type_field_alignment (tree);
// Return the offset of field INDEX in a struct type. INDEX is the
// entry in the FIELDS std::vector parameter of struct_type or
// set_placeholder_struct_type.
- virtual int64_t type_field_offset (tree, size_t index) = 0;
+ int64_t type_field_offset (tree, size_t index);
// Expressions.
@@ -496,6 +491,11 @@ public:
// Write SIZE bytes of export data from BYTES to the proper
// section in the output object file.
virtual void write_export_data (const char *bytes, unsigned int size) = 0;
+
+protected:
+ tree fill_in_fields (tree, const std::vector<typed_identifier> &);
+
+ tree fill_in_array (tree, tree, tree);
};
class Gcc_backend : public Backend
@@ -508,54 +508,6 @@ public:
tree get_identifier_node (const std::string &str);
- // Types.
-
- 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<typed_identifier> &,
- const std::vector<typed_identifier> &, tree,
- const location_t);
-
- tree function_type_varadic (const typed_identifier &,
- const std::vector<typed_identifier> &,
- const std::vector<typed_identifier> &, tree,
- const location_t);
-
- tree function_ptr_type (tree, const std::vector<tree> &, location_t);
-
- tree struct_type (const std::vector<typed_identifier> &);
-
- tree union_type (const std::vector<typed_identifier> &);
-
- 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);
@@ -697,10 +649,6 @@ public:
void write_export_data (const char *bytes, unsigned int size);
private:
- 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);
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 15ef0ed07e5..06bf7da246e 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -340,7 +340,7 @@ Gcc_backend::get_identifier_node (const std::string &str)
}
tree
-Gcc_backend::wchar_type ()
+Backend::wchar_type ()
{
tree wchar = make_unsigned_type (32);
TYPE_STRING_FLAG (wchar) = 1;
@@ -350,13 +350,13 @@ Gcc_backend::wchar_type ()
// Get an unnamed integer type.
int
-Gcc_backend::get_pointer_size ()
+Backend::get_pointer_size ()
{
return POINTER_SIZE;
}
tree
-Gcc_backend::raw_str_type ()
+Backend::raw_str_type ()
{
tree char_ptr = build_pointer_type (char_type_node);
tree const_char_type = build_qualified_type (char_ptr, TYPE_QUAL_CONST);
@@ -364,7 +364,7 @@ Gcc_backend::raw_str_type ()
}
tree
-Gcc_backend::integer_type (bool is_unsigned, int bits)
+Backend::integer_type (bool is_unsigned, int bits)
{
tree type;
if (is_unsigned)
@@ -399,7 +399,7 @@ Gcc_backend::integer_type (bool is_unsigned, int bits)
// Get an unnamed float type.
tree
-Gcc_backend::float_type (int bits)
+Backend::float_type (int bits)
{
tree type;
if (bits == FLOAT_TYPE_SIZE)
@@ -420,7 +420,7 @@ Gcc_backend::float_type (int bits)
// Get an unnamed complex type.
tree
-Gcc_backend::complex_type (int bits)
+Backend::complex_type (int bits)
{
tree type;
if (bits == FLOAT_TYPE_SIZE * 2)
@@ -442,7 +442,7 @@ Gcc_backend::complex_type (int bits)
// Get a pointer type.
tree
-Gcc_backend::pointer_type (tree to_type)
+Backend::pointer_type (tree to_type)
{
if (to_type == error_mark_node)
return error_mark_node;
@@ -453,7 +453,7 @@ Gcc_backend::pointer_type (tree to_type)
// Get a reference type.
tree
-Gcc_backend::reference_type (tree to_type)
+Backend::reference_type (tree to_type)
{
if (to_type == error_mark_node)
return error_mark_node;
@@ -464,7 +464,7 @@ Gcc_backend::reference_type (tree to_type)
// Get immutable type
tree
-Gcc_backend::immutable_type (tree base)
+Backend::immutable_type (tree base)
{
if (base == error_mark_node)
return error_mark_node;
@@ -475,10 +475,10 @@ Gcc_backend::immutable_type (tree base)
// Make a function type.
tree
-Gcc_backend::function_type (const typed_identifier &receiver,
- const std::vector<typed_identifier> ¶meters,
- const std::vector<typed_identifier> &results,
- tree result_struct, location_t)
+Backend::function_type (const typed_identifier &receiver,
+ const std::vector<typed_identifier> ¶meters,
+ const std::vector<typed_identifier> &results,
+ tree result_struct, location_t)
{
tree args = NULL_TREE;
tree *pp = &args;
@@ -526,10 +526,10 @@ Gcc_backend::function_type (const typed_identifier &receiver,
}
tree
-Gcc_backend::function_type_varadic (
- const typed_identifier &receiver,
- const std::vector<typed_identifier> ¶meters,
- const std::vector<typed_identifier> &results, tree result_struct, location_t)
+Backend::function_type_varadic (const typed_identifier &receiver,
+ const std::vector<typed_identifier> ¶meters,
+ const std::vector<typed_identifier> &results,
+ tree result_struct, location_t)
{
size_t n = parameters.size () + (receiver.type != NULL_TREE ? 1 : 0);
tree *args = XALLOCAVEC (tree, n);
@@ -574,9 +574,9 @@ Gcc_backend::function_type_varadic (
}
tree
-Gcc_backend::function_ptr_type (tree result_type,
- const std::vector<tree> ¶meters,
- location_t /* locus */)
+Backend::function_ptr_type (tree result_type,
+ const std::vector<tree> ¶meters,
+ location_t /* locus */)
{
tree args = NULL_TREE;
tree *pp = &args;
@@ -606,7 +606,7 @@ Gcc_backend::function_ptr_type (tree result_type,
// Make a struct type.
tree
-Gcc_backend::struct_type (const std::vector<typed_identifier> &fields)
+Backend::struct_type (const std::vector<typed_identifier> &fields)
{
return fill_in_fields (make_node (RECORD_TYPE), fields);
}
@@ -614,7 +614,7 @@ Gcc_backend::struct_type (const std::vector<typed_identifier> &fields)
// Make a union type.
tree
-Gcc_backend::union_type (const std::vector<typed_identifier> &fields)
+Backend::union_type (const std::vector<typed_identifier> &fields)
{
return fill_in_fields (make_node (UNION_TYPE), fields);
}
@@ -622,8 +622,7 @@ Gcc_backend::union_type (const std::vector<typed_identifier> &fields)
// Fill in the fields of a struct or union type.
tree
-Gcc_backend::fill_in_fields (tree fill,
- const std::vector<typed_identifier> &fields)
+Backend::fill_in_fields (tree fill, const std::vector<typed_identifier> &fields)
{
tree field_trees = NULL_TREE;
tree *pp = &field_trees;
@@ -654,7 +653,7 @@ Gcc_backend::fill_in_fields (tree fill,
// Make an array type.
tree
-Gcc_backend::array_type (tree element_type, tree length)
+Backend::array_type (tree element_type, tree length)
{
return fill_in_array (make_node (ARRAY_TYPE), element_type, length);
}
@@ -662,7 +661,7 @@ Gcc_backend::array_type (tree element_type, tree length)
// Fill in an array type.
tree
-Gcc_backend::fill_in_array (tree fill, tree element_type, tree length_tree)
+Backend::fill_in_array (tree fill, tree element_type, tree length_tree)
{
if (element_type == error_mark_node || length_tree == error_mark_node)
return error_mark_node;
@@ -694,8 +693,7 @@ Gcc_backend::fill_in_array (tree fill, tree element_type, tree length_tree)
// Return a named version of a type.
tree
-Gcc_backend::named_type (const std::string &name, tree type,
- location_t location)
+Backend::named_type (const std::string &name, tree type, location_t location)
{
if (type == error_mark_node)
return error_mark_node;
@@ -725,7 +723,7 @@ Gcc_backend::named_type (const std::string &name, tree type,
// Return the size of a type.
int64_t
-Gcc_backend::type_size (tree t)
+Backend::type_size (tree t)
{
if (t == error_mark_node)
return 1;
@@ -743,7 +741,7 @@ Gcc_backend::type_size (tree t)
// Return the alignment of a type.
int64_t
-Gcc_backend::type_alignment (tree t)
+Backend::type_alignment (tree t)
{
if (t == error_mark_node)
return 1;
@@ -753,7 +751,7 @@ Gcc_backend::type_alignment (tree t)
// Return the alignment of a struct field of type BTYPE.
int64_t
-Gcc_backend::type_field_alignment (tree t)
+Backend::type_field_alignment (tree t)
{
if (t == error_mark_node)
return 1;
@@ -763,7 +761,7 @@ Gcc_backend::type_field_alignment (tree t)
// Return the offset of a field in a struct.
int64_t
-Gcc_backend::type_field_offset (tree struct_tree, size_t index)
+Backend::type_field_offset (tree struct_tree, size_t index)
{
if (struct_tree == error_mark_node)
return 0;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 18:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 18:08 [gcc r14-7956] gccrs: Move type-related functions into base class Backend Arthur Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).