aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-item.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2020-12-24 21:26:26 +0000
committerPhilip Herron <herron.philip@googlemail.com>2020-12-25 18:23:22 +0000
commit467141184aa274126ff7e2a41d08bb621b7a3fdf (patch)
treef15fd81fb434787967d3837651891bfaa73fee80 /gcc/rust/backend/rust-compile-item.h
parent8d34ac3c1602d8506ae4b65d92075be86f5a6c9a (diff)
downloadgcc-467141184aa274126ff7e2a41d08bb621b7a3fdf.zip
gcc-467141184aa274126ff7e2a41d08bb621b7a3fdf.tar.gz
gcc-467141184aa274126ff7e2a41d08bb621b7a3fdf.tar.bz2
Implement constant expressions
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.h')
-rw-r--r--gcc/rust/backend/rust-compile-item.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index f131a89..10bdce0 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -23,6 +23,7 @@
#include "rust-compile-tyty.h"
#include "rust-compile-var-decl.h"
#include "rust-compile-stmt.h"
+#include "rust-compile-expr.h"
namespace Rust {
namespace Compile {
@@ -38,6 +39,24 @@ public:
virtual ~CompileItem () {}
+ void visit (HIR::ConstantItem &constant)
+ {
+ TyTy::TyBase *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);
+
+ Bexpression *const_expr = ctx->get_backend ()->named_constant_expression (
+ type, constant.get_identifier (), value, constant.get_locus ());
+
+ ctx->push_const (const_expr);
+ ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
+ }
+
void visit (HIR::Function &function)
{
// items can be forward compiled which means we may not need to invoke this