aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-10-28 10:13:12 +0000
committerGitHub <noreply@github.com>2021-10-28 10:13:12 +0000
commita2ce3ef6b024736dfcbfabb062100c685fa95c6b (patch)
tree41e1e2c804b45cf8d841456e3176b128b218362d /gcc/rust/backend
parente28c43f2f40cf405e89b3892aa65f6a06fa1c802 (diff)
parent0114e3e5b3b222c190a640bdeda8e781042389c4 (diff)
downloadgcc-a2ce3ef6b024736dfcbfabb062100c685fa95c6b.zip
gcc-a2ce3ef6b024736dfcbfabb062100c685fa95c6b.tar.gz
gcc-a2ce3ef6b024736dfcbfabb062100c685fa95c6b.tar.bz2
Merge #775
775: Support const within block-expr's r=philberty a=philberty This adds support for constant folding within block expr's and constant ArrayIndexExpression. Fixes #711 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-stmt.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h
index 1a2f02c..21e5814 100644
--- a/gcc/rust/backend/rust-compile-stmt.h
+++ b/gcc/rust/backend/rust-compile-stmt.h
@@ -48,6 +48,33 @@ public:
translated = CompileExpr::Compile (stmt.get_expr (), ctx);
}
+ void visit (HIR::ConstantItem &constant) override
+ {
+ TyTy::BaseType *resolved_type = nullptr;
+ bool ok
+ = ctx->get_tyctx ()->lookup_type (constant.get_mappings ().get_hirid (),
+ &resolved_type);
+ rust_assert (ok);
+
+ ::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
+ Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
+
+ const Resolver::CanonicalPath *canonical_path = nullptr;
+ rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ constant.get_mappings ().get_crate_num (),
+ constant.get_mappings ().get_nodeid (), &canonical_path));
+
+ std::string ident = canonical_path->get ();
+ Bexpression *const_expr
+ = ctx->get_backend ()->named_constant_expression (type, ident, value,
+ constant.get_locus ());
+
+ ctx->push_const (const_expr);
+ ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
+
+ translated = const_expr;
+ }
+
void visit (HIR::LetStmt &stmt) override
{
// nothing to do