From 561d2ddc8e67277dbe12216f9a365d65ec3f5c2c Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 12 May 2018 22:09:41 +0800 Subject: Trans - Support NonZero optimisation for Box --- src/trans/codegen_c.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/trans/codegen_c.cpp') diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 5df20334..59687636 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -1127,6 +1127,12 @@ namespace { m_of << ".PTR"; } } + else if( const auto* te = ty->m_data.opt_Pointer() ) + { + if( metadata_type(*te->inner) != MetadataType::None ) { + m_of << ".PTR"; + } + } } void emit_enum(const Span& sp, const ::HIR::GenericPath& p, const ::HIR::Enum& item) override -- cgit v1.2.3 From 84392bea7f6f0754f61d5b424129eb5fa809674d Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 26 May 2018 16:51:43 +0800 Subject: Codegen C - Don't emit destructor when type doesn't need it --- src/trans/codegen_c.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/trans/codegen_c.cpp') diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 59687636..187485dc 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -4670,6 +4670,11 @@ namespace { void emit_destructor_call(const ::MIR::LValue& slot, const ::HIR::TypeRef& ty, bool unsized_valid, unsigned indent_level) { + // If the type doesn't need dropping, don't try. + if( !m_resolve.type_needs_drop_glue(sp, ty) ) + { + return ; + } auto indent = RepeatLitStr { "\t", static_cast(indent_level) }; TU_MATCHA( (ty.m_data), (te), // Impossible -- cgit v1.2.3 From 30783d1e61a83bb680f1231af32004f4c994fea3 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 27 May 2018 11:34:36 +0800 Subject: Trans - Plannin for dynamic library support --- src/main.cpp | 107 ++++++++++++++++++++++++-------------------- src/trans/codegen_c.cpp | 1 + src/trans/main_bindings.hpp | 7 +++ 3 files changed, 67 insertions(+), 48 deletions(-) (limited to 'src/trans/codegen_c.cpp') diff --git a/src/main.cpp b/src/main.cpp index 0f325230..f3b5a2cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -670,72 +670,83 @@ int main(int argc, char *argv[]) // If the test harness is enabled, override crate type to "Executable" crate_type = ::AST::Crate::Type::Executable; } - switch( crate_type ) + + // Enumerate items to be passed to codegen + TransList items = CompilePhase("Trans Enumerate", [&]() { + switch( crate_type ) + { + case ::AST::Crate::Type::Unknown: + ::std::cerr << "BUG? Unknown crate type" << ::std::endl; + exit(1); + break; + case ::AST::Crate::Type::RustLib: + case ::AST::Crate::Type::RustDylib: + case ::AST::Crate::Type::CDylib: + return Trans_Enumerate_Public(*hir_crate); + case ::AST::Crate::Type::ProcMacro: + // TODO: proc macros enumerate twice, once as a library (why?) and again as an executable + return Trans_Enumerate_Public(*hir_crate); + case ::AST::Crate::Type::Executable: + return Trans_Enumerate_Main(*hir_crate); + } + throw ::std::runtime_error("Invalid crate_type value"); + }); + // - Generate monomorphised versions of all functions + CompilePhaseV("Trans Monomorph", [&]() { Trans_Monomorphise_List(*hir_crate, items); }); + // - Do post-monomorph inlining + CompilePhaseV("MIR Optimise Inline", [&]() { MIR_OptimiseCrate_Inlining(*hir_crate, items); }); + // - Clean up no-unused functions + //CompilePhaseV("Trans Enumerate Cleanup", [&]() { Trans_Enumerate_Cleanup(*hir_crate, items); }); + + switch(crate_type) { case ::AST::Crate::Type::Unknown: - // ERROR? - break; - case ::AST::Crate::Type::RustLib: { - #if 1 - // Generate a .o - TransList items = CompilePhase("Trans Enumerate", [&]() { return Trans_Enumerate_Public(*hir_crate); }); - CompilePhaseV("Trans Monomorph", [&]() { Trans_Monomorphise_List(*hir_crate, items); }); - CompilePhaseV("MIR Optimise Inline", [&]() { MIR_OptimiseCrate_Inlining(*hir_crate, items); }); - //CompilePhaseV("Trans Enumerate Cleanup", [&]() { Trans_Enumerate_Cleanup(*hir_crate, items); }); - CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile + ".o", trans_opt, *hir_crate, items, false); }); - #endif - + throw ""; + case ::AST::Crate::Type::RustLib: + // Generate a loadable .o + CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile + ".o", trans_opt, *hir_crate, items, /*is_executable=*/false); }); // Save a loadable HIR dump - CompilePhaseV("HIR Serialise", [&]() { - //HIR_Serialise(params.outfile + ".meta", *hir_crate); - HIR_Serialise(params.outfile, *hir_crate); - }); - - // Link metatdata and object into a .rlib - break; } - case ::AST::Crate::Type::RustDylib: { - #if 1 - // Generate a .o - TransList items = CompilePhase("Trans Enumerate", [&]() { return Trans_Enumerate_Public(*hir_crate); }); - CompilePhaseV("Trans Monomorph", [&]() { Trans_Monomorphise_List(*hir_crate, items); }); - CompilePhaseV("MIR Optimise Inline", [&]() { MIR_OptimiseCrate_Inlining(*hir_crate, items); }); - CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile + ".o", trans_opt, *hir_crate, items, false); }); - #endif + CompilePhaseV("HIR Serialise", [&]() { HIR_Serialise(params.outfile, *hir_crate); }); + // TODO: Link metatdata and object into a .rlib + //Trans_Link(params.outfile, params.outfile + ".hir", params.outfile + ".o", CodegenOutput::StaticLibrary); + break; + case ::AST::Crate::Type::RustDylib: + // Generate a .so + //CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile + ".so", trans_opt, *hir_crate, items, CodegenOutput::DynamicLibrary); }); + CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile + ".o", trans_opt, *hir_crate, items, /*is_executable=*/false); }); // Save a loadable HIR dump CompilePhaseV("HIR Serialise", [&]() { HIR_Serialise(params.outfile, *hir_crate); }); - - // Generate a .so/.dll - // TODO: Codegen and include the metadata in a non-loadable segment - break; } + // TODO: Add the metadata to the .so as a non-loadable segment + //Trans_Link(params.outfile, params.outfile + ".hir", params.outfile + ".o", CodegenOutput::DynamicLibrary); + break; case ::AST::Crate::Type::CDylib: // Generate a .so/.dll + CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile, trans_opt, *hir_crate, items, /*is_executable=*/false); }); + // - No metadata file + //Trans_Link(params.outfile, "", params.outfile + ".o", CodegenOutput::DynamicLibrary); break; case ::AST::Crate::Type::ProcMacro: { // Needs: An executable (the actual macro handler), metadata (for `extern crate foo;`) - // Can just emit the metadata and do miri? - // - Requires MIR for EVERYTHING, not feasable. - TransList items = CompilePhase("Trans Enumerate", [&]() { return Trans_Enumerate_Public(*hir_crate); }); - CompilePhaseV("Trans Monomorph", [&]() { Trans_Monomorphise_List(*hir_crate, items); }); - CompilePhaseV("MIR Optimise Inline", [&]() { MIR_OptimiseCrate_Inlining(*hir_crate, items); }); - CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile + ".o", trans_opt, *hir_crate, items, false); }); + // 1. Generate code for the .o file + // TODO: Is the .o actually needed for proc macros? + CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile + ".o", trans_opt, *hir_crate, items, /*is_executable=*/false); }); + + // 2. Generate code for the plugin itself TransList items2 = CompilePhase("Trans Enumerate", [&]() { return Trans_Enumerate_Main(*hir_crate); }); CompilePhaseV("Trans Monomorph", [&]() { Trans_Monomorphise_List(*hir_crate, items2); }); CompilePhaseV("MIR Optimise Inline", [&]() { MIR_OptimiseCrate_Inlining(*hir_crate, items2); }); - CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile + "-plugin", trans_opt, *hir_crate, items2, true); }); + CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile + "-plugin", trans_opt, *hir_crate, items2, /*is_executable=*/true); }); - hir_crate->m_lang_items.clear(); // Make sure that we're not exporting any lang items + // - Save a very basic HIR dump, making sure that there's no lang items in it (e.g. `mrustc-main`) + hir_crate->m_lang_items.clear(); CompilePhaseV("HIR Serialise", [&]() { HIR_Serialise(params.outfile, *hir_crate); }); + //Trans_Link(params.outfile, params.outfile + ".hir", params.outfile + ".o", CodegenOutput::StaticLibrary); + //Trans_Link(params.outfile+"-plugin", "", params.outfile + "-plugin.o", CodegenOutput::StaticLibrary); break; } case ::AST::Crate::Type::Executable: - // Generate a binary - // - Enumerate items for translation - TransList items = CompilePhase("Trans Enumerate", [&]() { return Trans_Enumerate_Main(*hir_crate); }); - // - Monomorphise - CompilePhaseV("Trans Monomorph", [&]() { Trans_Monomorphise_List(*hir_crate, items); }); - CompilePhaseV("MIR Optimise Inline", [&]() { MIR_OptimiseCrate_Inlining(*hir_crate, items); }); - // - Perform codegen - CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile, trans_opt, *hir_crate, items, true); }); + CompilePhaseV("Trans Codegen", [&]() { Trans_Codegen(params.outfile, trans_opt, *hir_crate, items, /*is_executable=*/true); }); + //Trans_Link(params.outfile, "", params.outfile + ".o", CodegenOutput::Executable); break; } } diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 187485dc..f891d267 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -510,6 +510,7 @@ namespace { emit_box_drop_glue( mv$(e.first), *e.second ); } + // TODO: Define this function in MIR. if( is_executable ) { m_of << "int main(int argc, const char* argv[]) {\n"; diff --git a/src/trans/main_bindings.hpp b/src/trans/main_bindings.hpp index 46d2cdb1..b938e8bf 100644 --- a/src/trans/main_bindings.hpp +++ b/src/trans/main_bindings.hpp @@ -24,6 +24,13 @@ struct TransOptions ::std::vector< ::std::string> libraries; }; +enum class CodegenOutput { + Object, // .o + StaticLibrary, // .a + DynamicLibrary, // .so + Executable, // no suffix, includes main stub (TODO: Can't that just be added earlier?) +}; + extern TransList Trans_Enumerate_Main(const ::HIR::Crate& crate); // NOTE: This also sets the saveout flags extern TransList Trans_Enumerate_Public(::HIR::Crate& crate); -- cgit v1.2.3 From 1c25575621e53757234c1033d3e3ccddc5d86aa6 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 3 Jun 2018 11:02:21 +0800 Subject: Trans - Fix some minor errors from building with clang --- src/trans/codegen_c.cpp | 6 ++++++ src/trans/enumerate.cpp | 5 +++++ 2 files changed, 11 insertions(+) (limited to 'src/trans/codegen_c.cpp') diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index f891d267..a4b0387a 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -196,6 +196,7 @@ namespace { } m_options; ::std::vector< ::std::pair< ::HIR::GenericPath, const ::HIR::Struct*> > m_box_glue_todo; + ::std::set< ::HIR::TypeRef> m_emitted_fn_types; public: CodeGenerator_C(const ::HIR::Crate& crate, const ::std::string& outfile): m_crate(crate), @@ -819,6 +820,11 @@ namespace { } void emit_type_fn(const ::HIR::TypeRef& ty) { + if( m_emitted_fn_types.count(ty) ) { + return ; + } + m_emitted_fn_types.insert(ty.clone()); + const auto& te = ty.m_data.as_Function(); m_of << "typedef "; // TODO: ABI marker, need an ABI enum? diff --git a/src/trans/enumerate.cpp b/src/trans/enumerate.cpp index fbf747f8..4e04ddf9 100644 --- a/src/trans/enumerate.cpp +++ b/src/trans/enumerate.cpp @@ -518,6 +518,11 @@ namespace { TU_MATCH_DEF(::HIR::TypeRef::Data, (ty.m_data), (te), ( ), + (Function, + visit_type(*te.m_rettype, Mode::Shallow); + for(const auto& sty : te.m_arg_types) + visit_type(sty, Mode::Shallow); + ), (Pointer, visit_type(*te.inner, Mode::Shallow); ), -- cgit v1.2.3 From 50ab851adfda92d2ccc3ff8d0f8c6a5bf37ed484 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 3 Jun 2018 14:48:39 +0800 Subject: Trans C - Add configuration for linker args --- src/trans/codegen_c.cpp | 28 ++++++++----- src/trans/target.cpp | 104 ++++++++++++++++++++++++++++++++++++++++-------- src/trans/target.hpp | 12 +++++- 3 files changed, 114 insertions(+), 30 deletions(-) (limited to 'src/trans/codegen_c.cpp') diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index a4b0387a..c30657bf 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -205,7 +205,7 @@ namespace { m_outfile_path_c(outfile + ".c"), m_of(m_outfile_path_c) { - switch(Target_GetCurSpec().m_codegen_mode) + switch(Target_GetCurSpec().m_backend_c.m_codegen_mode) { case CodegenMode::Gnu11: m_compiler = Compiler::Gcc; @@ -303,7 +303,7 @@ namespace { << "\treturn ((v&0xFFFFFFFF) == 0 ? __builtin_ctz(v>>32) + 32 : __builtin_ctz(v));\n" << "}\n" ; - break; + break; case Compiler::Msvc: m_of << "static inline uint64_t __builtin_popcount(uint64_t v) {\n" @@ -567,7 +567,7 @@ namespace { // - `gcc-${TRIPLE}` (if available) // - `gcc` as fallback { - ::std::string varname = "CC-" + Target_GetCurSpec().m_c_compiler; + ::std::string varname = "CC-" + Target_GetCurSpec().m_backend_c.m_c_compiler; if( getenv(varname.c_str()) ) { args.push_back( getenv(varname.c_str()) ); } @@ -576,12 +576,14 @@ namespace { } else { // TODO: Determine if the compiler can't be found, and fall back to `gcc` if that's the case - args.push_back( Target_GetCurSpec().m_c_compiler + "-gcc" ); + args.push_back( Target_GetCurSpec().m_backend_c.m_c_compiler + "-gcc" ); //args.push_back( "gcc" ); } } - args.push_back("-ffunction-sections"); - args.push_back("-pthread"); + for( const auto& a : Target_GetCurSpec().m_backend_c.m_compiler_opts ) + { + args.push_back( a.c_str() ); + } switch(opt.opt_level) { case 0: break; @@ -624,7 +626,10 @@ namespace { { args.push_back("-l"); args.push_back(path.c_str()); } - args.push_back("-Wl,--gc-sections"); + for( const auto& a : Target_GetCurSpec().m_backend_c.m_linker_opts ) + { + args.push_back( a.c_str() ); + } } else { @@ -633,8 +638,9 @@ namespace { break; case Compiler::Msvc: // TODO: Look up these paths in the registry and use CreateProcess instead of system + // - OR, run `vcvarsall` and get the required environment variables and PATH from it? args.push_back(detect_msvc().path_vcvarsall); - args.push_back( Target_GetCurSpec().m_c_compiler ); + args.push_back( Target_GetCurSpec().m_backend_c.m_c_compiler ); args.push_back("&"); args.push_back("cl.exe"); args.push_back("/nologo"); @@ -680,9 +686,9 @@ namespace { } args.push_back("kernel32.lib"); // Needed for Interlocked* - // Command-line specified linker search directories args.push_back("/link"); - //args.push_back("/verbose"); + + // Command-line specified linker search directories for(const auto& path : link_dirs ) { args.push_back(FMT("/LIBPATH:" << path)); @@ -3569,7 +3575,7 @@ namespace { #endif } - if( Target_GetCurSpec().m_c_compiler == "amd64" ) { + if( Target_GetCurSpec().m_backend_c.m_c_compiler == "amd64" ) { MIR_TODO(mir_res, "MSVC amd64 doesn't support inline assembly, need to have a transform for '" << e.tpl << "'"); } m_of << indent << "__asm {\n"; diff --git a/src/trans/target.cpp b/src/trans/target.cpp index 87b5aa1d..1727cdba 100644 --- a/src/trans/target.cpp +++ b/src/trans/target.cpp @@ -133,11 +133,11 @@ namespace check_path_length(key_val, 3); if( key_val.value.as_string() == "msvc" ) { - rv.m_codegen_mode = CodegenMode::Msvc; + rv.m_backend_c.m_codegen_mode = CodegenMode::Msvc; } else if( key_val.value.as_string() == "gnu" ) { - rv.m_codegen_mode = CodegenMode::Gnu11; + rv.m_backend_c.m_codegen_mode = CodegenMode::Gnu11; } else { @@ -148,7 +148,23 @@ namespace else if( key_val.path[2] == "target" ) { check_path_length(key_val, 3); - rv.m_c_compiler = key_val.value.as_string(); + rv.m_backend_c.m_c_compiler = key_val.value.as_string(); + } + else if( key_val.path[2] == "compiler-opts" ) + { + check_path_length(key_val, 3); + for(const auto& v : key_val.value.as_list()) + { + rv.m_backend_c.m_compiler_opts.push_back( v.as_string() ); + } + } + else if( key_val.path[2] == "linker-opts" ) + { + check_path_length(key_val, 3); + for(const auto& v : key_val.value.as_list()) + { + rv.m_backend_c.m_linker_opts.push_back( v.as_string() ); + } } else { @@ -233,8 +249,56 @@ namespace return rv; } + void save_spec_to_file(const ::std::string& filename, const TargetSpec& spec) + { + // TODO: Have a round-trip unit test + ::std::ofstream of(filename); + + struct H + { + static const char* tfstr(bool v) + { + return v ? "true" : "false"; + } + static const char* c_variant_name(const CodegenMode m) + { + switch(m) + { + case CodegenMode::Gnu11: return "gnu"; + case CodegenMode::Msvc: return "msvc"; + } + return ""; + } + }; + + of + << "[target]\n" + << "family = \"" << spec.m_family << "\"\n" + << "os-name = \"" << spec.m_os_name << "\"\n" + << "env-name = \"" << spec.m_env_name << "\"\n" + //<< "arch = \"" << spec.m_arch.m_name << "\"\n" + << "\n" + << "[backend.c]\n" + << "variant = \"" << H::c_variant_name(spec.m_backend_c.m_codegen_mode) << "\"\n" + << "target = \"" << spec.m_backend_c.m_c_compiler << "\"\n" + << "compiler-opts = [" << spec.m_backend_c.m_compiler_opts << "]\n" + << "linker-opts = [" << spec.m_backend_c.m_linker_opts << "]\n" + << "\n" + << "[arch]" + << "name = \"" << spec.m_arch.m_name << "\"\n" + << "pointer-bits = " << spec.m_arch.m_pointer_bits << "\n" + << "is-big-endian = " << H::tfstr(spec.m_arch.m_big_endian) << "\n" + << "has-atomic-u8 = " << H::tfstr(spec.m_arch.m_atomics.u8) << "\n" + << "has-atomic-u16 = " << H::tfstr(spec.m_arch.m_atomics.u16) << "\n" + << "has-atomic-u32 = " << H::tfstr(spec.m_arch.m_atomics.u32) << "\n" + << "has-atomic-u64 = " << H::tfstr(spec.m_arch.m_atomics.u64) << "\n" + << "has-atomic-ptr = " << H::tfstr(spec.m_arch.m_atomics.ptr) << "\n" + ; + } TargetSpec init_from_spec_name(const ::std::string& target_name) { + // Options for all the fully-GNU environments + #define BACKEND_C_OPTS_GNU {"-ffunction-sections", "-pthread"}, {"-Wl,--gc-sections"} // If there's a '/' or a '\' in the filename, open it as a path, otherwise assume it's a triple. if( target_name.find('/') != ::std::string::npos || target_name.find('\\') != ::std::string::npos ) { @@ -243,98 +307,100 @@ namespace else if(target_name == "i586-linux-gnu") { return TargetSpec { - "unix", "linux", "gnu", CodegenMode::Gnu11, "i586-linux-gnu", + "unix", "linux", "gnu", {CodegenMode::Gnu11, "i586-linux-gnu", BACKEND_C_OPTS_GNU}, ARCH_X86 }; } else if(target_name == "x86_64-linux-gnu") { return TargetSpec { - "unix", "linux", "gnu", CodegenMode::Gnu11, "x86_64-linux-gnu", + "unix", "linux", "gnu", {CodegenMode::Gnu11, "x86_64-linux-gnu", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } else if(target_name == "arm-linux-gnu") { return TargetSpec { - "unix", "linux", "gnu", CodegenMode::Gnu11, "arm-elf-eabi", + "unix", "linux", "gnu", {CodegenMode::Gnu11, "arm-elf-eabi", BACKEND_C_OPTS_GNU}, ARCH_ARM32 }; } else if(target_name == "aarch64-linux-gnu") { return TargetSpec { - "unix", "linux", "gnu", CodegenMode::Gnu11, "aarch64-linux-gnu", + "unix", "linux", "gnu", {CodegenMode::Gnu11, "aarch64-linux-gnu", BACKEND_C_OPTS_GNU}, ARCH_ARM64 }; } else if(target_name == "i586-windows-gnu") { return TargetSpec { - "windows", "windows", "gnu", CodegenMode::Gnu11, "mingw32", + "windows", "windows", "gnu", {CodegenMode::Gnu11, "mingw32", BACKEND_C_OPTS_GNU}, ARCH_X86 }; } else if(target_name == "x86_64-windows-gnu") { return TargetSpec { - "windows", "windows", "gnu", CodegenMode::Gnu11, "x86_64-w64-mingw32", + "windows", "windows", "gnu", {CodegenMode::Gnu11, "x86_64-w64-mingw32", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } else if (target_name == "x86-windows-msvc") { + // TODO: Should this include the "kernel32.lib" inclusion? return TargetSpec { - "windows", "windows", "msvc", CodegenMode::Msvc, "x86", + "windows", "windows", "msvc", {CodegenMode::Msvc, "x86", {}, {}}, ARCH_X86 }; } else if (target_name == "x86_64-windows-msvc") { return TargetSpec { - "windows", "windows", "msvc", CodegenMode::Msvc, "amd64", + "windows", "windows", "msvc", {CodegenMode::Msvc, "amd64", {}, {}}, ARCH_X86_64 }; } else if(target_name == "x86_64-unknown-netbsd") { return TargetSpec { - "unix", "netbsd", "gnu", CodegenMode::Gnu11, "x86_64-unknown-netbsd", + "unix", "netbsd", "gnu", {CodegenMode::Gnu11, "x86_64-unknown-netbsd", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } else if(target_name == "i686-unknown-openbsd") { return TargetSpec { - "unix", "openbsd", "gnu", CodegenMode::Gnu11, "i686-unknown-openbsd", + "unix", "openbsd", "gnu", {CodegenMode::Gnu11, "i686-unknown-openbsd", BACKEND_C_OPTS_GNU}, ARCH_X86 }; } else if(target_name == "x86_64-unknown-openbsd") { return TargetSpec { - "unix", "openbsd", "gnu", CodegenMode::Gnu11, "x86_64-unknown-openbsd", + "unix", "openbsd", "gnu", {CodegenMode::Gnu11, "x86_64-unknown-openbsd", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } else if(target_name == "arm-unknown-openbsd") { return TargetSpec { - "unix", "openbsd", "gnu", CodegenMode::Gnu11, "arm-unknown-openbsd", + "unix", "openbsd", "gnu", {CodegenMode::Gnu11, "arm-unknown-openbsd", BACKEND_C_OPTS_GNU}, ARCH_ARM32 }; } else if(target_name == "aarch64-unknown-openbsd") { return TargetSpec { - "unix", "openbsd", "gnu", CodegenMode::Gnu11, "aarch64-unknown-openbsd", + "unix", "openbsd", "gnu", {CodegenMode::Gnu11, "aarch64-unknown-openbsd", BACKEND_C_OPTS_GNU}, ARCH_ARM64 }; } else if(target_name == "x86_64-apple-macosx") { + // NOTE: OSX uses clang and lld, which don't fully support the defaults used for GNU targets return TargetSpec { - "unix", "macos", "gnu", CodegenMode::Gnu11, "x86_64-apple-darwin", + "unix", "macos", "gnu", {CodegenMode::Gnu11, "x86_64-apple-darwin", {}, {}}, ARCH_X86_64 }; } @@ -351,6 +417,10 @@ const TargetSpec& Target_GetCurSpec() { return g_target; } +void Target_ExportCurSpec(const ::std::string& filename) +{ + save_spec_to_file(filename, g_target); +} void Target_SetCfg(const ::std::string& target_name) { g_target = init_from_spec_name(target_name); diff --git a/src/trans/target.hpp b/src/trans/target.hpp index 81205831..b1ed9456 100644 --- a/src/trans/target.hpp +++ b/src/trans/target.hpp @@ -31,14 +31,20 @@ struct TargetArch bool ptr; } m_atomics; }; +struct BackendOptsC +{ + CodegenMode m_codegen_mode; + ::std::string m_c_compiler; // MSVC arch / GNU triplet + ::std::vector< ::std::string> m_compiler_opts; + ::std::vector< ::std::string> m_linker_opts; +}; struct TargetSpec { ::std::string m_family; ::std::string m_os_name; ::std::string m_env_name; - CodegenMode m_codegen_mode; - ::std::string m_c_compiler; // MSVC arch / GNU triplet + BackendOptsC m_backend_c; TargetArch m_arch; }; @@ -96,6 +102,8 @@ struct TypeRepr extern const TargetSpec& Target_GetCurSpec(); extern void Target_SetCfg(const ::std::string& target_name); +extern void Target_ExportCurSpec(const ::std::string& filename); + extern bool Target_GetSizeOf(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty, size_t& out_size); extern bool Target_GetAlignOf(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty, size_t& out_align); extern bool Target_GetSizeAndAlignOf(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty, size_t& out_size, size_t& out_align); -- cgit v1.2.3