diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-21 14:02:16 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-26 11:59:23 +0000 |
commit | be371b9f49e0c4fd7752cad6708fed8b1f2719a3 (patch) | |
tree | 4cd49a36ce274aa268a816ab8c72abda84a08393 /gcc | |
parent | be10fafbb6e06aeb8a818e404ac512f2f1bfce30 (diff) | |
download | gcc-be371b9f49e0c4fd7752cad6708fed8b1f2719a3.zip gcc-be371b9f49e0c4fd7752cad6708fed8b1f2719a3.tar.gz gcc-be371b9f49e0c4fd7752cad6708fed8b1f2719a3.tar.bz2 |
Add backend support to create immutable types
GCC uses qualified types to create const immutability.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/rust-backend.h | 3 | ||||
-rw-r--r-- | gcc/rust/rust-gcc.cc | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h index 02c12ee..184f8fa 100644 --- a/gcc/rust/rust-backend.h +++ b/gcc/rust/rust-backend.h @@ -112,6 +112,9 @@ public: // Get a pointer type. virtual Btype *pointer_type (Btype *to_type) = 0; + // make type immutable + virtual Btype *immutable_type (Btype *base) = 0; + // Get a function type. The receiver, parameter, and results are // generated from the types in the Function_type. The Function_type // is provided so that the names are available. This should return diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc index 748aa5a..6f8dc46 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -173,6 +173,8 @@ public: Btype *pointer_type (Btype *); + Btype *immutable_type (Btype *); + Btype *function_type (const Btyped_identifier &, const std::vector<Btyped_identifier> &, const std::vector<Btyped_identifier> &, Btype *, @@ -848,6 +850,18 @@ Gcc_backend::pointer_type (Btype *to_type) return this->make_type (type); } +// Get immutable type + +Btype * +Gcc_backend::immutable_type (Btype *base) +{ + tree type_tree = base->get_tree (); + if (type_tree == error_mark_node) + return this->error_type (); + tree constified = build_qualified_type (type_tree, TYPE_QUAL_CONST); + return this->make_type (constified); +} + // Make a function type. Btype * |