diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-06-04 15:24:10 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-06-04 15:24:10 +0800 |
commit | 64ad08b84bef88228e8f6cc07803a7f644f7b22b (patch) | |
tree | d0b73c62c2b9d5e934ffe25c64678ef1c723d5fd /src/trans/codegen_c.cpp | |
parent | 828a19bd28eb39da6108545175bbb4427aaf2a4e (diff) | |
download | mrust-64ad08b84bef88228e8f6cc07803a7f644f7b22b.tar.gz |
Trans - Emit monomorphised/inlined functions as `static`
Diffstat (limited to 'src/trans/codegen_c.cpp')
-rw-r--r-- | src/trans/codegen_c.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 07736df3..946c7fac 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -426,6 +426,8 @@ namespace { ::std::vector< ::std::pair<::HIR::Pattern,::HIR::TypeRef> > args; if( item.m_markings.has_drop_impl ) { + if( p.m_path.m_crate_name != m_crate.m_crate_name ) + m_of << "static "; m_of << "tUNIT " << Trans_Mangle( ::HIR::Path(struct_ty.clone(), m_resolve.m_lang_Drop, "drop") ) << "("; emit_ctype(struct_ty_ptr, FMT_CB(ss, ss << "rv";)); m_of << ");\n"; } else if( m_resolve.is_type_owned_box(struct_ty) ) @@ -1255,7 +1257,7 @@ namespace { m_mir_res = nullptr; } - void emit_function_proto(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params) override + void emit_function_proto(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params, bool is_extern_def) override { ::MIR::TypeResolve top_mir_res { sp, m_resolve, FMT_CB(ss, ss << "/*proto*/ fn " << p;), ::HIR::TypeRef(), {}, *(::MIR::Function*)nullptr }; m_mir_res = &top_mir_res; @@ -1265,12 +1267,16 @@ namespace { { m_of << "#define " << Trans_Mangle(p) << " " << item.m_linkage.name << "\n"; } + if( is_extern_def ) + { + m_of << "static "; + } emit_function_header(p, item, params); m_of << ";\n"; m_mir_res = nullptr; } - void emit_function_code(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params, const ::MIR::FunctionPointer& code) override + void emit_function_code(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params, bool is_extern_def, const ::MIR::FunctionPointer& code) override { TRACE_FUNCTION_F(p); @@ -1285,6 +1291,9 @@ namespace { m_mir_res = &mir_res; m_of << "// " << p << "\n"; + if( is_extern_def ) { + m_of << "static "; + } emit_function_header(p, item, params); m_of << "\n"; m_of << "{\n"; |