summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/trans/codegen.cpp20
-rw-r--r--src/trans/codegen.hpp4
-rw-r--r--src/trans/codegen_c.cpp13
-rw-r--r--src/trans/mangling.cpp2
4 files changed, 27 insertions, 12 deletions
diff --git a/src/trans/codegen.cpp b/src/trans/codegen.cpp
index 7989981b..a571b5e4 100644
--- a/src/trans/codegen.cpp
+++ b/src/trans/codegen.cpp
@@ -87,16 +87,18 @@ void Trans_Codegen(const ::std::string& outfile, const TransOptions& opt, const
{
DEBUG("FUNCTION " << ent.first);
assert( ent.second->ptr );
- if( ent.second->ptr->m_code.m_mir ) {
- codegen->emit_function_proto(ent.first, *ent.second->ptr, ent.second->pp);
+ const auto& fcn = *ent.second->ptr;
+ bool is_extern = ! static_cast<bool>(fcn.m_code);
+ if( fcn.m_code.m_mir ) {
+ codegen->emit_function_proto(ent.first, fcn, ent.second->pp, is_extern);
}
else {
// TODO: Why would an intrinsic be in the queue?
// - If it's exported it does.
- if( ent.second->ptr->m_abi == "rust-intrinsic" ) {
+ if( fcn.m_abi == "rust-intrinsic" ) {
}
else {
- codegen->emit_function_ext(ent.first, *ent.second->ptr, ent.second->pp);
+ codegen->emit_function_ext(ent.first, fcn, ent.second->pp);
}
}
}
@@ -148,7 +150,8 @@ void Trans_Codegen(const ::std::string& outfile, const TransOptions& opt, const
const auto& pp = ent.second->pp;
TRACE_FUNCTION_F(path);
DEBUG("FUNCTION CODE " << path);
- // TODO: If this is a provided trait method, it needs to be monomorphised too.
+ bool is_extern = ! static_cast<bool>(fcn.m_code);
+ // If this is a provided trait method, it needs to be monomorphised too.
bool is_method = ( fcn.m_args.size() > 0 && visit_ty_with(fcn.m_args[0].second, [&](const auto& x){return x == ::HIR::TypeRef("Self",0xFFFF);}) );
if( pp.has_types() || is_method )
{
@@ -164,11 +167,14 @@ void Trans_Codegen(const ::std::string& outfile, const TransOptions& opt, const
MIR_Cleanup(resolve, ip, *mir, args, ret_type);
MIR_Optimise(resolve, ip, *mir, args, ret_type);
MIR_Validate(resolve, ip, *mir, args, ret_type);
- codegen->emit_function_code(path, fcn, ent.second->pp, mir);
+ // TODO: Flag that this should be a weak (or weak-er) symbol?
+ // - If it's from an external crate, it should be weak
+ codegen->emit_function_code(path, fcn, ent.second->pp, is_extern, mir);
}
// TODO: Detect if the function was a #[inline] function from another crate, and don't emit if that is the case?
+ // - Emiting is nice, but it should be emitted as a weak symbol
else {
- codegen->emit_function_code(path, fcn, pp, fcn.m_code.m_mir);
+ codegen->emit_function_code(path, fcn, pp, is_extern, fcn.m_code.m_mir);
}
}
}
diff --git a/src/trans/codegen.hpp b/src/trans/codegen.hpp
index b317e632..65135d18 100644
--- a/src/trans/codegen.hpp
+++ b/src/trans/codegen.hpp
@@ -50,8 +50,8 @@ public:
virtual void emit_static_local(const ::HIR::Path& p, const ::HIR::Static& item, const Trans_Params& params) {}
virtual void emit_function_ext(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params) {}
- virtual void emit_function_proto(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params) {}
- virtual void emit_function_code(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params, const ::MIR::FunctionPointer& code) {}
+ virtual void emit_function_proto(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params, bool is_extern_def) {}
+ virtual void emit_function_code(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params, bool is_extern_def, const ::MIR::FunctionPointer& code) {}
};
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";
diff --git a/src/trans/mangling.cpp b/src/trans/mangling.cpp
index 4ea56581..0f3acfd9 100644
--- a/src/trans/mangling.cpp
+++ b/src/trans/mangling.cpp
@@ -148,7 +148,7 @@ namespace {
),
(Tuple,
return FMT_CB(ss,
- ss << "$T";
+ ss << "$T" << te.size();
for(const auto& t : te)
ss << "_" << Trans_Mangle(t);
);