Implemented basic -m32 and -m64 options.

This commit is contained in:
Tomas Lindquist Olsen 2009-03-01 22:27:03 +01:00
parent 3d6b0b68d5
commit a71b028a0f
4 changed files with 34 additions and 5 deletions

View file

@ -23,6 +23,11 @@ execute_process(
OUTPUT_VARIABLE HOST_TARGET OUTPUT_VARIABLE HOST_TARGET
OUTPUT_STRIP_TRAILING_WHITESPACE 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( execute_process(
COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --cxxflags COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --cxxflags
OUTPUT_VARIABLE LLVM_CXXFLAGS OUTPUT_VARIABLE LLVM_CXXFLAGS
@ -105,6 +110,7 @@ set(LDC_GENERATED
# idgen and impcnvgen done # idgen and impcnvgen done
set(DEFAULT_TARGET ${HOST_TARGET} CACHE STRING "default target") 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) include_directories(. ${DMDFE_PATH} ${PROJECT_BINARY_DIR}/${DMDFE_PATH} ${LLVM_INSTDIR}/include)
@ -154,8 +160,10 @@ if(CMAKE_MINOR_VERSION LESS 6)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "output dir for built executables") 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") 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_TARGET_TRIPLE=\\"${DEFAULT_TARGET}\\")
add_definitions(-DDEFAULT_ALT_TARGET_TRIPLE=\\"${DEFAULT_ALT_TARGET}\\")
else(CMAKE_MINOR_VERSION LESS 6) else(CMAKE_MINOR_VERSION LESS 6)
add_definitions(-DDEFAULT_TARGET_TRIPLE="${DEFAULT_TARGET}") add_definitions(-DDEFAULT_TARGET_TRIPLE="${DEFAULT_TARGET}")
add_definitions(-DDEFAULT_ALT_TARGET_TRIPLE="${DEFAULT_ALT_TARGET}")
endif(CMAKE_MINOR_VERSION LESS 6) endif(CMAKE_MINOR_VERSION LESS 6)
add_executable(${LDC_EXE} ${LDC_SOURCE_FILES}) add_executable(${LDC_EXE} ${LDC_SOURCE_FILES})

View file

@ -225,10 +225,13 @@ cl::opt<const llvm::TargetMachineRegistry::entry*, false,
llvm::RegistryParser<llvm::TargetMachine> > mArch("march", llvm::RegistryParser<llvm::TargetMachine> > mArch("march",
cl::desc("Architecture to generate code for:")); cl::desc("Architecture to generate code for:"));
static cl::alias m("m", cl::opt<bool> m32bits("m32",
cl::desc("Alias for '-march' for backwards compatibility"), cl::desc("32 bit target"),
cl::Prefix, cl::ZeroOrMore);
cl::aliasopt(mArch));
cl::opt<bool> m64bits("m64",
cl::desc("64 bit target"),
cl::ZeroOrMore);
cl::opt<std::string> mCPU("mcpu", cl::opt<std::string> mCPU("mcpu",
cl::desc("Target a specific cpu type (-mcpu=help for details)"), cl::desc("Target a specific cpu type (-mcpu=help for details)"),

View file

@ -38,6 +38,8 @@ namespace opts {
extern cl::opt<const llvm::TargetMachineRegistry::entry*, false, extern cl::opt<const llvm::TargetMachineRegistry::entry*, false,
llvm::RegistryParser<llvm::TargetMachine> > mArch; llvm::RegistryParser<llvm::TargetMachine> > mArch;
extern cl::opt<bool> m32bits;
extern cl::opt<bool> m64bits;
extern cl::opt<std::string> mCPU; extern cl::opt<std::string> mCPU;
extern cl::list<std::string> mAttrs; extern cl::list<std::string> mAttrs;
extern cl::opt<std::string> mTargetTriple; extern cl::opt<std::string> mTargetTriple;

View file

@ -337,8 +337,24 @@ int main(int argc, char** argv)
} }
// create a proper target // 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"); 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? // did the user override the target triple?
if (mTargetTriple.empty()) if (mTargetTriple.empty())
{ {
@ -347,7 +363,7 @@ int main(int argc, char** argv)
error("you must specify a target triple as well with -mtriple when using the -march option"); error("you must specify a target triple as well with -mtriple when using the -march option");
fatal(); fatal();
} }
global.params.targetTriple = DEFAULT_TARGET_TRIPLE; global.params.targetTriple = defaultTriple;
} }
else else
{ {