aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/rust-backend.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-04-20 15:19:33 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-04-20 18:56:53 +0100
commit393b783549e1247dfed5b86f098fb10d1eaf6659 (patch)
tree628921f4b47bc83ab588fa3f7109ddfd7702bfd6 /gcc/rust/rust-backend.h
parentee5afc03f94e8a76c1b1b9306849cd932d5d9090 (diff)
downloadgcc-393b783549e1247dfed5b86f098fb10d1eaf6659.zip
gcc-393b783549e1247dfed5b86f098fb10d1eaf6659.tar.gz
gcc-393b783549e1247dfed5b86f098fb10d1eaf6659.tar.bz2
Reuse fold-const.c from GCC to enforce const array capacities
Rust allows for constant eval for cases like array capacity, the initial version of this code forced the programmer to only use literals which was not correct but got the type system off the ground. This now takes advantage of the GCC backend object to offer 3 helpers. 1. check for constant Bexpression* are equal 2. extract a size_t constant value from the Bexpression* 3. to string the Bexpression constant We can get away with the extraction of the value here because we know its going to be a usize for array capacity but some thought is needed if these methods are to be reused in other cases. There is a new ConstFold namespace which should be extensible for const functions later on and const generics. Fixes: #296
Diffstat (limited to 'gcc/rust/rust-backend.h')
-rw-r--r--gcc/rust/rust-backend.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/rust/rust-backend.h b/gcc/rust/rust-backend.h
index 7c0ac6e..e71d81e 100644
--- a/gcc/rust/rust-backend.h
+++ b/gcc/rust/rust-backend.h
@@ -93,6 +93,11 @@ public:
virtual void debug (Bvariable *) = 0;
virtual void debug (Blabel *) = 0;
+ // const folder helpers
+ virtual bool const_size_cast (Bexpression *, size_t *) = 0;
+ virtual std::string const_size_val_to_string (Bexpression *) = 0;
+ virtual bool const_values_equal (Bexpression *, Bexpression *) = 0;
+
// Types.
// Produce an error type. Actually the backend could probably just
@@ -283,6 +288,9 @@ public:
// going without crashing.
virtual Bexpression *error_expression () = 0;
+ // return whether this is error_mark_node
+ virtual bool is_error_expression (Bexpression *) = 0;
+
// Create a nil pointer expression.
virtual Bexpression *nil_pointer_expression () = 0;