aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-01-05 15:51:46 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-01-06 10:19:10 +0000
commitaef9821d9b04fffadb4c0f9796652cec58da8902 (patch)
tree5bda63ded46482bd755fbdb0cac6be02e378f45a /gcc/rust/backend
parent1a97dbc6b54cd77ba7c3f00cb8dd2e870017a83c (diff)
downloadgcc-aef9821d9b04fffadb4c0f9796652cec58da8902.zip
gcc-aef9821d9b04fffadb4c0f9796652cec58da8902.tar.gz
gcc-aef9821d9b04fffadb4c0f9796652cec58da8902.tar.bz2
Add in F32 and F64 types builtin types.
We need to ensure all suffix of literals are handled in a subsequent PR.
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-context.h8
-rw-r--r--gcc/rust/backend/rust-compile-expr.h30
-rw-r--r--gcc/rust/backend/rust-compile-tyty.h18
3 files changed, 56 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 9f1475a..d241921 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -272,6 +272,14 @@ public:
translated = compiled_type;
}
+ void visit (TyTy::FloatType &type) override
+ {
+ ::Btype *compiled_type = nullptr;
+ bool ok = ctx->lookup_compiled_types (type.get_ref (), &compiled_type);
+ rust_assert (ok);
+ translated = compiled_type;
+ }
+
private:
TyTyResolveCompile (Context *ctx) : ctx (ctx) {}
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 7b01e0e..9081000 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -155,6 +155,36 @@ public:
}
return;
+ case HIR::Literal::FLOAT: {
+ printf ("FLOATY BOYO: [%s]\n", expr.as_string ().c_str ());
+
+ mpfr_t fval;
+ if (mpfr_init_set_str (fval, expr.as_string ().c_str (), 10,
+ MPFR_RNDN)
+ != 0)
+ {
+ rust_fatal_error (expr.get_locus (),
+ "bad float number in literal");
+ return;
+ }
+
+ TyTy::TyBase *tyty = nullptr;
+ if (!ctx->get_tyctx ()->lookup_type (
+ expr.get_mappings ().get_hirid (), &tyty))
+ {
+ rust_fatal_error (expr.get_locus (),
+ "did not resolve type for this literal expr");
+ return;
+ }
+
+ printf ("tyty float is [%s]\n", tyty->as_string ().c_str ());
+
+ Btype *type = TyTyResolveCompile::compile (ctx, tyty);
+ translated
+ = ctx->get_backend ()->float_constant_expression (type, fval);
+ }
+ return;
+
default:
rust_fatal_error (expr.get_locus (), "unknown literal");
return;
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index f4e467a..e3c8a73 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -163,6 +163,24 @@ public:
gcc_unreachable ();
}
+ void visit (TyTy::FloatType &type) override
+ {
+ switch (type.get_kind ())
+ {
+ case TyTy::FloatType::F32:
+ translated = backend->named_type ("f32", backend->float_type (32),
+ Linemap::predeclared_location ());
+ return;
+
+ case TyTy::FloatType::F64:
+ translated = backend->named_type ("f32", backend->float_type (64),
+ Linemap::predeclared_location ());
+ return;
+ }
+
+ gcc_unreachable ();
+ }
+
private:
TyTyCompile (::Backend *backend)
: backend (backend), translated (nullptr),