mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 17:43:35 +03:00
Implemented basic -m32 and -m64 options.
This commit is contained in:
parent
3d6b0b68d5
commit
a71b028a0f
4 changed files with 34 additions and 5 deletions
|
@ -23,6 +23,11 @@ execute_process(
|
|||
OUTPUT_VARIABLE HOST_TARGET
|
||||
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
|
||||
|
@ -105,6 +110,7 @@ set(LDC_GENERATED
|
|||
# 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 @@ if(CMAKE_MINOR_VERSION LESS 6)
|
|||
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})
|
||||
|
|
|
@ -225,10 +225,13 @@ cl::opt<const llvm::TargetMachineRegistry::entry*, false,
|
|||
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)"),
|
||||
|
|
|
@ -38,6 +38,8 @@ namespace opts {
|
|||
|
||||
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;
|
||||
|
|
18
gen/main.cpp
18
gen/main.cpp
|
@ -337,8 +337,24 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
// 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 @@ int main(int argc, char** argv)
|
|||
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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue