diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-10 16:14:26 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-11 20:00:03 +0000 |
commit | 5a9ceba8fd21973118f1866686aca5622cc60ba2 (patch) | |
tree | ff3794551b143037a6aaf8b83658e0efaf322b36 /gcc/rust/backend/rust-compile-item.h | |
parent | 9a3ad294e0af5ed45b53c340382a7806fb150bdf (diff) | |
download | gcc-5a9ceba8fd21973118f1866686aca5622cc60ba2.zip gcc-5a9ceba8fd21973118f1866686aca5622cc60ba2.tar.gz gcc-5a9ceba8fd21973118f1866686aca5622cc60ba2.tar.bz2 |
Mark DECL_PUBLIC for main fn or functions with visibility.
This change will need more thought later when it comes to traits and
generics etc.
Fixes #136
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-item.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index e042ccb..c5fe9a2 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -138,10 +138,24 @@ public: // convert to the actual function type auto compiled_fn_type = TyTyCompile::compile (ctx->get_backend (), fnType); + unsigned int flags = 0; + bool is_main_fn = function.function_name.compare ("main") == 0; + + // if its the main fn or pub visibility mark its as DECL_PUBLIC + // please see https://github.com/Rust-GCC/gccrs/pull/137 + if (is_main_fn || function.has_visibility ()) + flags |= Backend::function_is_visible; + + std::string asm_name = function.function_name; + if (!is_main_fn) + { + // FIXME need name mangling + asm_name = "__" + function.function_name; + } + Bfunction *fndecl = ctx->get_backend ()->function (compiled_fn_type, function.function_name, - "" /* asm_name */, 0 /* flags */, - function.get_locus ()); + asm_name, flags, function.get_locus ()); ctx->insert_function_decl (function.get_mappings ().get_hirid (), fndecl); // setup the params |