diff options
Diffstat (limited to 'src/trans/codegen.cpp')
-rw-r--r-- | src/trans/codegen.cpp | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/trans/codegen.cpp b/src/trans/codegen.cpp index 12252465..9e93caba 100644 --- a/src/trans/codegen.cpp +++ b/src/trans/codegen.cpp @@ -168,29 +168,18 @@ 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); + // `is_extern` is set if there's no HIR (i.e. this function is from an external crate) 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 ) { - ::StaticTraitResolve resolve { crate }; - auto ret_type = pp.monomorph(resolve, fcn.m_return); - ::HIR::Function::args_t args; - for(const auto& a : fcn.m_args) - args.push_back(::std::make_pair( ::HIR::Pattern{}, pp.monomorph(resolve, a.second) )); - auto mir = Trans_Monomorphise(resolve, pp, fcn.m_code.m_mir); - ::std::string s = FMT(path); - ::HIR::ItemPath ip(s); - MIR_Validate(resolve, ip, *mir, args, ret_type); - MIR_Cleanup(resolve, ip, *mir, args, ret_type); - MIR_Optimise(resolve, ip, *mir, args, ret_type); - MIR_Validate(resolve, ip, *mir, args, ret_type); + ASSERT_BUG(sp, ent.second->monomorphised.code, "Function that required monomorphisation wasn't monomorphised"); + // 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); + // - If it's from an external crate, it should be weak, but what about local ones? + codegen->emit_function_code(path, fcn, ent.second->pp, is_extern, ent.second->monomorphised.code); } - // 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, is_extern, fcn.m_code.m_mir); } |