aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-01-25 13:27:50 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-01-26 11:59:39 +0000
commit854aad3b58e747cad3e46b522c9ef765bdfadca4 (patch)
treee7c0943131d46cb1b9f2faaa4edfd6a5ede3c172 /gcc/rust/backend
parent0817c29a423aca1c4c3f9ba812f67df35f36fc65 (diff)
downloadgcc-854aad3b58e747cad3e46b522c9ef765bdfadca4.zip
gcc-854aad3b58e747cad3e46b522c9ef765bdfadca4.tar.gz
gcc-854aad3b58e747cad3e46b522c9ef765bdfadca4.tar.bz2
Add usize and isize types
Arrays can only be indexed by usize and this enforces that rule. These types are sized based on the pointer size of the host arch. Fixes #87
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-context.h16
-rw-r--r--gcc/rust/backend/rust-compile-tyty.h14
2 files changed, 30 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index ed03f02..034568f 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -374,6 +374,22 @@ public:
translated = compiled_type;
}
+ void visit (TyTy::USizeType &type) override
+ {
+ ::Btype *compiled_type = nullptr;
+ bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
+ rust_assert (ok);
+ translated = compiled_type;
+ }
+
+ void visit (TyTy::ISizeType &type) override
+ {
+ ::Btype *compiled_type = nullptr;
+ bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &compiled_type);
+ rust_assert (ok);
+ translated = compiled_type;
+ }
+
private:
TyTyResolveCompile (Context *ctx) : ctx (ctx) {}
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index b6794bc..2c54b17 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -190,6 +190,20 @@ public:
gcc_unreachable ();
}
+ void visit (TyTy::USizeType &type) override
+ {
+ translated = backend->named_type (
+ "usize", backend->integer_type (true, backend->get_pointer_size ()),
+ Linemap::predeclared_location ());
+ }
+
+ void visit (TyTy::ISizeType &type) override
+ {
+ translated = backend->named_type (
+ "isize", backend->integer_type (false, backend->get_pointer_size ()),
+ Linemap::predeclared_location ());
+ }
+
private:
TyTyCompile (::Backend *backend)
: backend (backend), translated (nullptr),