diff options
author | John Hodge <tpg@mutabah.net> | 2018-06-03 12:10:54 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-06-03 12:10:54 +0800 |
commit | 45023a8b4916de02a77abe23e2a800fc1d2e1d6a (patch) | |
tree | 8ba12fd5cb824de25a8ff208d6316d07a76f5613 | |
parent | b99e6d0a7581c626d6c31c37487548965df05735 (diff) | |
download | mrust-45023a8b4916de02a77abe23e2a800fc1d2e1d6a.tar.gz |
All - Move host target auto-detection to be common between compiler and minicargo
-rw-r--r-- | src/main.cpp | 66 | ||||
-rw-r--r-- | tools/common/target_detect.h | 66 | ||||
-rw-r--r-- | tools/minicargo/build.cpp | 14 | ||||
-rw-r--r-- | tools/minicargo/manifest.cpp | 2 |
4 files changed, 73 insertions, 75 deletions
diff --git a/src/main.cpp b/src/main.cpp index ca55d6ba..358de95e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,65 +26,7 @@ #include "trans/target.hpp" #include "expand/cfg.hpp" - -// Hacky default target detection -// - Windows (MSVC) -#ifdef _MSC_VER -# if defined(_WIN64) -# define DEFAULT_TARGET_NAME "x86_64-windows-msvc" -# else -# define DEFAULT_TARGET_NAME "x86-windows-msvc" -# endif -// - Linux -#elif defined(__linux__) -# if defined(__amd64__) -# define DEFAULT_TARGET_NAME "x86_64-linux-gnu" -# elif defined(__aarch64__) -# define DEFAULT_TARGET_NAME "aarch64-linux-gnu" -# elif defined(__arm__) -# define DEFAULT_TARGET_NAME "arm-linux-gnu" -# elif defined(__i386__) -# define DEFAULT_TARGET_NAME "i586-linux-gnu" -# else -# warning "Unable to detect a suitable default target (linux-gnu)" -# endif -// - MinGW -#elif defined(__MINGW32__) -# if defined(_WIN64) -# define DEFAULT_TARGET_NAME "x86_64-windows-gnu" -# else -# define DEFAULT_TARGET_NAME "i586-windows-gnu" -# endif -// - NetBSD -#elif defined(__NetBSD__) -# if defined(__amd64__) -# define DEFAULT_TARGET_NAME "x86_64-unknown-netbsd" -# else -# warning "Unable to detect a suitable default target (NetBSD)" -# endif -// - OpenBSD -#elif defined(__OpenBSD__) -# if defined(__amd64__) -# define DEFAULT_TARGET_NAME "x86_64-unknown-openbsd" -# elif defined(__aarch64__) -# define DEFAULT_TARGET_NAME "aarch64-unknown-openbsd" -# elif defined(__arm__) -# define DEFAULT_TARGET_NAME "arm-unknown-openbsd" -# elif defined(__i386__) -# define DEFAULT_TARGET_NAME "i686-unknown-openbsd" -# else -# warning "Unable to detect a suitable default target (OpenBSD)" -# endif -// - Apple devices -#elif defined(__APPLE__) -# define DEFAULT_TARGET_NAME "x86_64-apple-macosx" -// - Unknown -#else -# warning "Unable to detect a suitable default target" -#endif -#ifndef DEFAULT_TARGET_NAME -# define DEFAULT_TARGET_NAME "" -#endif +#include <target_detect.h> // tools/common/target_detect.h int g_debug_indent_level = 0; bool g_debug_enabled = true; @@ -929,7 +871,7 @@ ProgramParams::ProgramParams(int argc, char *argv[]) } else if( optname == "dump-hir" ) { no_optval(); - this->debug.dump_mir = true; + this->debug.dump_hir = true; } else if( optname == "dump-mir" ) { no_optval(); @@ -943,10 +885,10 @@ ProgramParams::ProgramParams(int argc, char *argv[]) this->last_stage = STAGE_EXPAND; else if( optval == "resolve" ) this->last_stage = STAGE_RESOLVE; + else if( optval == "typeck" ) + this->last_stage = STAGE_TYPECK; else if( optval == "mir" ) this->last_stage = STAGE_MIR; - else if( optval == "ALL" ) - this->last_stage = STAGE_ALL; else { ::std::cerr << "Unknown argument to -Z stop-after - '" << optval << "'" << ::std::endl; exit(1); diff --git a/tools/common/target_detect.h b/tools/common/target_detect.h new file mode 100644 index 00000000..995ab6a4 --- /dev/null +++ b/tools/common/target_detect.h @@ -0,0 +1,66 @@ +/* + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * common/target_detect.h + * - Auto-magical host target detection + */ +#pragma once + +// - Windows (MSVC) +#ifdef _MSC_VER +# if defined(_WIN64) +# define DEFAULT_TARGET_NAME "x86_64-windows-msvc" +# else +# define DEFAULT_TARGET_NAME "x86-windows-msvc" +# endif +// - Linux +#elif defined(__linux__) +# if defined(__amd64__) +# define DEFAULT_TARGET_NAME "x86_64-linux-gnu" +# elif defined(__aarch64__) +# define DEFAULT_TARGET_NAME "aarch64-linux-gnu" +# elif defined(__arm__) +# define DEFAULT_TARGET_NAME "arm-linux-gnu" +# elif defined(__i386__) +# define DEFAULT_TARGET_NAME "i586-linux-gnu" +# else +# warning "Unable to detect a suitable default target (linux-gnu)" +# endif +// - MinGW +#elif defined(__MINGW32__) +# if defined(_WIN64) +# define DEFAULT_TARGET_NAME "x86_64-windows-gnu" +# else +# define DEFAULT_TARGET_NAME "i586-windows-gnu" +# endif +// - NetBSD +#elif defined(__NetBSD__) +# if defined(__amd64__) +# define DEFAULT_TARGET_NAME "x86_64-unknown-netbsd" +# else +# warning "Unable to detect a suitable default target (NetBSD)" +# endif +// - OpenBSD +#elif defined(__OpenBSD__) +# if defined(__amd64__) +# define DEFAULT_TARGET_NAME "x86_64-unknown-openbsd" +# elif defined(__aarch64__) +# define DEFAULT_TARGET_NAME "aarch64-unknown-openbsd" +# elif defined(__arm__) +# define DEFAULT_TARGET_NAME "arm-unknown-openbsd" +# elif defined(__i386__) +# define DEFAULT_TARGET_NAME "i686-unknown-openbsd" +# else +# warning "Unable to detect a suitable default target (OpenBSD)" +# endif +// - Apple devices +#elif defined(__APPLE__) +# define DEFAULT_TARGET_NAME "x86_64-apple-macosx" +// - Unknown +#else +# warning "Unable to detect a suitable default target" +#endif +#ifndef DEFAULT_TARGET_NAME +# define DEFAULT_TARGET_NAME "" +#endif diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index 21d8d809..42e19552 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -51,18 +51,8 @@ extern int _putenv_s(const char*, const char*); #else # define EXESUF "" #endif -#ifdef _WIN32 -# ifdef _MSC_VER -# define HOST_TARGET "x86_64-windows-msvc" -# elif defined(__MINGW32__) -# define HOST_TARGET "x86_64-windows-gnu" -# else -# endif -#elif defined(__NetBSD__) -# define HOST_TARGET "x86_64-unknown-netbsd" -#else -# define HOST_TARGET "x86_64-unknown-linux-gnu" -#endif +#include <target_detect.h> // tools/common/target_detect.h +#define HOST_TARGET DEFAULT_TARGET_NAME /// Class abstracting access to the compiler class Builder diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp index 6e2bf451..687c3e2a 100644 --- a/tools/minicargo/manifest.cpp +++ b/tools/minicargo/manifest.cpp @@ -9,7 +9,7 @@ #include <cctype> // toupper #include "repository.h" - +// TODO: Extract this from the target at runtime #ifdef _WIN32 # define TARGET_NAME "i586-windows-msvc" # define CFG_UNIX false |