diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-05 15:51:46 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-06 10:19:10 +0000 |
commit | aef9821d9b04fffadb4c0f9796652cec58da8902 (patch) | |
tree | 5bda63ded46482bd755fbdb0cac6be02e378f45a /gcc/rust/backend/rust-compile-expr.h | |
parent | 1a97dbc6b54cd77ba7c3f00cb8dd2e870017a83c (diff) | |
download | gcc-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/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 30 |
1 files changed, 30 insertions, 0 deletions
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; |