From 08ab5d99ed8b7622440a8a33fed4a2475e5e714d Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 18 Feb 2018 12:14:06 +0800 Subject: Standalone MIRI (and mmir codegen) - Support external functions --- src/trans/codegen_mmir.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/trans/codegen_mmir.cpp b/src/trans/codegen_mmir.cpp index 345a5703..703ef44d 100644 --- a/src/trans/codegen_mmir.cpp +++ b/src/trans/codegen_mmir.cpp @@ -796,6 +796,30 @@ namespace m_mir_res = nullptr; } + void emit_function_ext(const ::HIR::Path& p, const ::HIR::Function& item, const Trans_Params& params) override + { + ::MIR::Function empty_fcn; + ::MIR::TypeResolve top_mir_res { sp, m_resolve, FMT_CB(ss, ss << "extern fn " << p;), ::HIR::TypeRef(), {}, empty_fcn }; + m_mir_res = &top_mir_res; + TRACE_FUNCTION_F(p); + + // If the function is a C external, emit as such + if( item.m_linkage.name != "" ) + { + ::HIR::TypeRef ret_type_tmp; + const auto& ret_type = monomorphise_fcn_return(ret_type_tmp, item, params); + + m_of << "fn " << p << "("; + for(unsigned int i = 0; i < item.m_args.size(); i ++) + { + if( i != 0 ) m_of << ", "; + m_of << params.monomorph(m_resolve, item.m_args[i].second); + } + m_of << "): " << ret_type << " = \"" << item.m_linkage.name << "\":\"" << item.m_abi << "\";\n"; + } + + m_mir_res = nullptr; + } 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); -- cgit v1.2.3