diff options
Diffstat (limited to 'src/trans/codegen_c.cpp')
-rw-r--r-- | src/trans/codegen_c.cpp | 90 |
1 files changed, 79 insertions, 11 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index b942dae7..1ec2d2cd 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -520,7 +520,10 @@ namespace { is_windows = true; // TODO: Look up these paths in the registry and use CreateProcess instead of system args.push_back(cache_str( detect_msvc().path_vcvarsall )); - //args.push_back("amd64"); + if( Target_GetCurSpec().m_arch.m_pointer_bits == 64 ) + { + args.push_back("amd64"); // NOTE: Doesn't support inline assembly, only works with overrides + } args.push_back("&"); args.push_back("cl.exe"); args.push_back("/nologo"); @@ -584,6 +587,10 @@ namespace { cmd_ss << "&"; } else { + if( is_windows && strchr(arg, ' ') == nullptr ) { + cmd_ss << arg << " "; + continue ; + } cmd_ss << "\"" << FmtShell(arg, is_windows) << "\" "; } } @@ -628,7 +635,15 @@ namespace { void emit_type_id(const ::HIR::TypeRef& ty) override { - m_of << "tTYPEID __typeid_" << Trans_Mangle(ty) << " __attribute__((weak));\n"; + switch(m_compiler) + { + case Compiler::Gcc: + m_of << "tTYPEID __typeid_" << Trans_Mangle(ty) << " __attribute__((weak));\n"; + break; + case Compiler::Msvc: + m_of << "__declspec(selectany) tTYPEID __typeid_" << Trans_Mangle(ty) << ";\n"; + break; + } } void emit_type_proto(const ::HIR::TypeRef& ty) override { @@ -673,7 +688,21 @@ namespace { m_of << "typedef "; // TODO: ABI marker, need an ABI enum? // TODO: Better emit_ctype call for return type. - emit_ctype(*te.m_rettype); m_of << " (*"; emit_ctype(ty); m_of << ")("; + emit_ctype(*te.m_rettype); m_of << " ("; + if( m_compiler == Compiler::Msvc ) + { + if( te.m_abi == ABI_RUST ) + { + } + else if( te.m_abi == "system" ) + { + m_of << "__stdcall"; + } + else + { + } + } + m_of << "*"; emit_ctype(ty); m_of << ")("; if( te.m_arg_types.size() == 0 ) { m_of << "void)"; @@ -843,8 +872,16 @@ namespace { ::std::vector< ::std::pair<::HIR::Pattern,::HIR::TypeRef> > args; if( item.m_markings.has_drop_impl ) { + // If the type is defined outside the current crate, define as static (to avoid conflicts when we define it) if( p.m_path.m_crate_name != m_crate.m_crate_name ) - m_of << "static "; + { + if( item.m_params.m_types.size() > 0 ) { + m_of << "static "; + } + else { + m_of << "extern "; + } + } 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) ) @@ -1433,6 +1470,8 @@ namespace { m_of << " "; emit_literal(get_inner_type(0, i), e[i], params); } + if(ty.m_data.is_Path() && e.size() == 0 && m_options.disallow_empty_structs) + m_of << "0"; m_of << " }"; if( ty.m_data.is_Array() ) m_of << "}"; @@ -1460,25 +1499,25 @@ namespace { } else { - m_of << "{" << e.idx << ", { "; + m_of << "{" << e.idx; if( e.vals.empty() ) { if( m_options.disallow_empty_structs && !enm.m_variants.at(e.idx).second.is_Unit() ) { - m_of << ".var_" << e.idx << " = {0} "; + m_of << ", { .var_" << e.idx << " = {0} }"; } } else { - m_of << ".var_" << e.idx << " = {"; + m_of << ", { .var_" << e.idx << " = {"; for(unsigned int i = 0; i < e.vals.size(); i ++) { if(i != 0) m_of << ","; m_of << " "; emit_literal(get_inner_type(e.idx, i), e.vals[i], params); } - m_of << "} "; + m_of << "} }"; } - m_of << "}}"; + m_of << "}"; } ), (Integer, @@ -1752,7 +1791,7 @@ namespace { } } - m_of << "// extern \"" << item.m_abi << "\" " << p << "\n"; + m_of << "// EXTERN extern \"" << item.m_abi << "\" " << p << "\n"; m_of << "extern "; emit_function_header(p, item, params); if( item.m_linkage.name != "" && m_compiler == Compiler::Gcc) @@ -1769,6 +1808,7 @@ namespace { m_mir_res = &top_mir_res; TRACE_FUNCTION_F(p); + m_of << "// PROTO extern \"" << item.m_abi << "\" " << p << "\n"; if( item.m_linkage.name != "" ) { m_of << "#define " << Trans_Mangle(p) << " " << item.m_linkage.name << "\n"; @@ -2942,9 +2982,37 @@ namespace { { auto indent = RepeatLitStr{ "\t", static_cast<int>(indent_level) }; + if( e.tpl == "fnstcw $0" ) + { + // HARD CODE: `fnstcw` -> _control87 + if( !(e.inputs.size() == 0 && e.outputs.size() == 1 && e.outputs[0].first == "=*m") ) + MIR_BUG(mir_res, "Hard-coded asm translation doesn't apply - `" << e.tpl << "` inputs=" << e.inputs << " outputs=" << e.outputs); + m_of << indent << "*("; emit_lvalue(e.outputs[0].second); m_of << ") = _control87(0,0);\n"; + return ; + } + else if( e.tpl == "fldcw $0" ) + { + // HARD CODE: `fldcw` -> _control87 + if( !(e.inputs.size() == 1 && e.inputs[0].first == "m" && e.outputs.size() == 0) ) + MIR_BUG(mir_res, "Hard-coded asm translation doesn't apply - `" << e.tpl << "` inputs=" << e.inputs << " outputs=" << e.outputs); + m_of << indent << "_control87("; emit_lvalue(e.inputs[0].second); m_of << ", 0xFFFF);\n"; + return ; + } + else if( e.tpl == "int $$0x29" ) + { + if( !(e.inputs.size() == 1 && e.inputs[0].first == "{ecx}" && e.outputs.size() == 0) ) + MIR_BUG(mir_res, "Hard-coded asm translation doesn't apply - `" << e.tpl << "` inputs=" << e.inputs << " outputs=" << e.outputs); + m_of << indent << "__fastfail("; emit_lvalue(e.inputs[0].second); m_of << ");\n"; + return ; + } + else + { + // No hard-coded translations. + } + if( !e.inputs.empty() || !e.outputs.empty() ) { - MIR_TODO(mir_res, "Inputs/outputs in msvc inline assembly"); + MIR_TODO(mir_res, "Inputs/outputs in msvc inline assembly - `" << e.tpl << "` inputs=" << e.inputs << " outputs=" << e.outputs); #if 0 m_of << indent << "{\n"; for(size_t i = 0; i < e.inputs.size(); i ++) |