diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-05 13:26:47 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-06 10:28:45 +0000 |
commit | c2cc8df0b5aacd448f464e5a927d03730698aba8 (patch) | |
tree | e6e833c0a14708a3e7f7b41061a7e9b2b2576c1d /gcc/rust/backend | |
parent | 82d80bf20ec46fc9a1e5b44a5f1231b584bcb28e (diff) | |
download | gcc-c2cc8df0b5aacd448f464e5a927d03730698aba8.zip gcc-c2cc8df0b5aacd448f464e5a927d03730698aba8.tar.gz gcc-c2cc8df0b5aacd448f464e5a927d03730698aba8.tar.bz2 |
Add in support to compile static variables. Still requires name mangling
for the ASM name similar to functions.
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-item.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index aa65962..90630bb 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -68,6 +68,34 @@ public: named_struct); } + void visit (HIR::StaticItem &var) + { + TyTy::TyBase *resolved_type = nullptr; + bool ok = ctx->get_tyctx ()->lookup_type (var.get_mappings ().get_hirid (), + &resolved_type); + rust_assert (ok); + + Btype *type = TyTyResolveCompile::compile (ctx, resolved_type); + Bexpression *value = CompileExpr::Compile (var.get_expr (), ctx); + + std::string name = var.get_identifier (); + // FIXME need name mangling + std::string asm_name = "__" + var.get_identifier (); + + bool is_external = false; + bool is_hidden = false; + bool in_unique_section = true; + + Bvariable *static_global + = ctx->get_backend ()->global_variable (name, asm_name, type, is_external, + is_hidden, in_unique_section, + var.get_locus ()); + ctx->get_backend ()->global_variable_set_init (static_global, value); + + ctx->insert_var_decl (var.get_mappings ().get_hirid (), static_global); + ctx->push_var (static_global); + } + void visit (HIR::ConstantItem &constant) { TyTy::TyBase *resolved_type = nullptr; |