diff options
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index d0c0b74..eb245dc 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -304,8 +304,7 @@ public: } return; - case HIR::Literal::STRING: - case HIR::Literal::BYTE_STRING: { + case HIR::Literal::STRING: { auto base = ctx->get_backend ()->string_constant_expression ( literal_value->as_string ()); translated @@ -313,6 +312,46 @@ public: } return; + case HIR::Literal::BYTE_STRING: { + TyTy::BaseType *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 array expr"); + return; + } + + // the type here is &[ty; capacity] + rust_assert (tyty->get_kind () == TyTy::TypeKind::REF); + auto ref_tyty = static_cast<TyTy::ReferenceType *> (tyty); + auto base_tyty = ref_tyty->get_base (); + rust_assert (base_tyty->get_kind () == TyTy::TypeKind::ARRAY); + auto array_tyty = static_cast<TyTy::ArrayType *> (base_tyty); + + std::string value_str = expr.get_literal ()->as_string (); + std::vector<Bexpression *> vals; + std::vector<unsigned long> indexes; + for (size_t i = 0; i < value_str.size (); i++) + { + char b = value_str.at (i); + Bexpression *bb + = ctx->get_backend ()->char_constant_expression (b); + vals.push_back (bb); + indexes.push_back (i); + } + + Btype *array_type = TyTyResolveCompile::compile (ctx, array_tyty); + Bexpression *constructed + = ctx->get_backend ()->array_constructor_expression ( + array_type, indexes, vals, expr.get_locus ()); + + translated + = ctx->get_backend ()->address_expression (constructed, + expr.get_locus ()); + } + return; + default: rust_fatal_error (expr.get_locus (), "unknown literal"); return; |