Mercurial > projects > ldc
changeset 1021:d1ec9ff0e9ba
Implemented basic -m32 and -m64 options.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Sun, 01 Mar 2009 22:27:03 +0100 |
parents | 474d7dd54d43 |
children | 6fccb5a036e4 |
files | CMakeLists.txt gen/cl_options.cpp gen/cl_options.h gen/main.cpp |
diffstat | 4 files changed, 34 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Sun Mar 01 20:22:10 2009 +0100 +++ b/CMakeLists.txt Sun Mar 01 22:27:03 2009 +0100 @@ -24,6 +24,11 @@ OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( + COMMAND /bin/sh ${PROJECT_SOURCE_DIR}/find-alt-triple.sh ${HOST_TARGET} + OUTPUT_VARIABLE HOST_ALT_TARGET + OUTPUT_STRIP_TRAILING_WHITESPACE +) +execute_process( COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --cxxflags OUTPUT_VARIABLE LLVM_CXXFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE @@ -105,6 +110,7 @@ # idgen and impcnvgen done set(DEFAULT_TARGET ${HOST_TARGET} CACHE STRING "default target") +set(DEFAULT_ALT_TARGET ${HOST_ALT_TARGET} CACHE STRING "default alt target") include_directories(. ${DMDFE_PATH} ${PROJECT_BINARY_DIR}/${DMDFE_PATH} ${LLVM_INSTDIR}/include) @@ -154,8 +160,10 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "output dir for built executables") set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib CACHE PATH "output dir for built libraries") add_definitions(-DDEFAULT_TARGET_TRIPLE=\\"${DEFAULT_TARGET}\\") + add_definitions(-DDEFAULT_ALT_TARGET_TRIPLE=\\"${DEFAULT_ALT_TARGET}\\") else(CMAKE_MINOR_VERSION LESS 6) add_definitions(-DDEFAULT_TARGET_TRIPLE="${DEFAULT_TARGET}") + add_definitions(-DDEFAULT_ALT_TARGET_TRIPLE="${DEFAULT_ALT_TARGET}") endif(CMAKE_MINOR_VERSION LESS 6) add_executable(${LDC_EXE} ${LDC_SOURCE_FILES})
--- a/gen/cl_options.cpp Sun Mar 01 20:22:10 2009 +0100 +++ b/gen/cl_options.cpp Sun Mar 01 22:27:03 2009 +0100 @@ -225,10 +225,13 @@ llvm::RegistryParser<llvm::TargetMachine> > mArch("march", cl::desc("Architecture to generate code for:")); -static cl::alias m("m", - cl::desc("Alias for '-march' for backwards compatibility"), - cl::Prefix, - cl::aliasopt(mArch)); +cl::opt<bool> m32bits("m32", + cl::desc("32 bit target"), + cl::ZeroOrMore); + +cl::opt<bool> m64bits("m64", + cl::desc("64 bit target"), + cl::ZeroOrMore); cl::opt<std::string> mCPU("mcpu", cl::desc("Target a specific cpu type (-mcpu=help for details)"),
--- a/gen/cl_options.h Sun Mar 01 20:22:10 2009 +0100 +++ b/gen/cl_options.h Sun Mar 01 22:27:03 2009 +0100 @@ -38,6 +38,8 @@ extern cl::opt<const llvm::TargetMachineRegistry::entry*, false, llvm::RegistryParser<llvm::TargetMachine> > mArch; + extern cl::opt<bool> m32bits; + extern cl::opt<bool> m64bits; extern cl::opt<std::string> mCPU; extern cl::list<std::string> mAttrs; extern cl::opt<std::string> mTargetTriple;
--- a/gen/main.cpp Sun Mar 01 20:22:10 2009 +0100 +++ b/gen/main.cpp Sun Mar 01 22:27:03 2009 +0100 @@ -337,8 +337,24 @@ } // create a proper target + + // check -m32/64 sanity + if (m32bits && m64bits) + error("cannot use both -m32 and -m64 options"); + else if ((m32bits || m64bits) && (mArch != 0 || !mTargetTriple.empty())) + error("-m32 and -m64 switches cannot be used together with -march and -mtriple switches"); + if (global.errors) + fatal(); + llvm::Module mod("dummy"); + // override triple if needed + const char* defaultTriple = DEFAULT_TARGET_TRIPLE; + if ((sizeof(void*) == 4 && m64bits) || (sizeof(void*) == 8 && m32bits)) + { + defaultTriple = DEFAULT_ALT_TARGET_TRIPLE; + } + // did the user override the target triple? if (mTargetTriple.empty()) { @@ -347,7 +363,7 @@ error("you must specify a target triple as well with -mtriple when using the -march option"); fatal(); } - global.params.targetTriple = DEFAULT_TARGET_TRIPLE; + global.params.targetTriple = defaultTriple; } else {