mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Initialize LLVM target and asmprinter for the native and extra targets.
Uses some CMake hackery to get the native LLVM target name, since it only provides a conveniance function for initializing the native target and not the native asmprinter.
This commit is contained in:
@@ -54,13 +54,6 @@ execute_process(
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
set(EXTRA_LLVM_MODULES "" CACHE STRING "extra llvm components to link in (see llvm-config --components)")
|
||||
execute_process(
|
||||
COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --libfiles bitwriter linker ipo instrumentation backend ${EXTRA_LLVM_MODULES}
|
||||
OUTPUT_VARIABLE LLVM_LIBS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
set(D_VERSION 1 CACHE STRING "D language version")
|
||||
set(PROGRAM_PREFIX CACHE STRING "prepended to ldc binary name")
|
||||
set(PROGRAM_SUFFIX CACHE STRING "appended to ldc binary name")
|
||||
@@ -135,6 +128,29 @@ set(DEFAULT_ALT_TARGET ${HOST_ALT_TARGET} CACHE STRING "default alt target")
|
||||
|
||||
include_directories(. ${DMDFE_PATH} ${DMDFE_PATH}/root ${PROJECT_BINARY_DIR}/${DMDFE_PATH} ${PROJECT_BINARY_DIR} ${LLVM_INSTDIR}/include)
|
||||
|
||||
set(EXTRA_LLVM_MODULES "" CACHE STRING "extra llvm components to link in (see llvm-config --components)")
|
||||
separate_arguments(EXTRA_LLVM_MODULES)
|
||||
execute_process(
|
||||
COMMAND ${PERL_EXECUTABLE} ${LLVM_CONFIG} --libfiles bitwriter linker ipo instrumentation backend ${EXTRA_LLVM_MODULES}
|
||||
OUTPUT_VARIABLE LLVM_LIBS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
# build a define that contains all LLVM targets required and is usable for
|
||||
# preprocessor code generation. start with the native target.
|
||||
file(STRINGS ${LLVM_INSTDIR}/include/llvm/Config/config.h LLVM_NATIVE_ARCH REGEX "^#define LLVM_NATIVE_ARCH")
|
||||
string(REGEX REPLACE "^#define LLVM_NATIVE_ARCH (.*)Target$" "\\1" LLVM_NATIVE_ARCH ${LLVM_NATIVE_ARCH})
|
||||
set(LLVM_MODULES_DEFINE "LLVM_TARGET(${LLVM_NATIVE_ARCH})")
|
||||
# chain the extra target list to the define
|
||||
foreach(EXTRA_TARGET ${EXTRA_LLVM_MODULES})
|
||||
set(LLVM_MODULES_DEFINE "${LLVM_MODULES_DEFINE} LLVM_TARGET(${EXTRA_TARGET})")
|
||||
endforeach(EXTRA_TARGET)
|
||||
set_source_files_properties(
|
||||
${PROJECT_SOURCE_DIR}/gen/main.cpp PROPERTIES
|
||||
COMPILE_DEFINITIONS LDC_TARGETS=${LLVM_MODULES_DEFINE}
|
||||
)
|
||||
|
||||
|
||||
file(GLOB FE_SRC ${DMDFE_PATH}/*.c)
|
||||
file(GLOB FE_SRC_ROOT ${DMDFE_PATH}/root/*.c)
|
||||
file(GLOB_RECURSE GEN_SRC gen/*.cpp)
|
||||
|
||||
17
gen/main.cpp
17
gen/main.cpp
@@ -4,6 +4,7 @@
|
||||
// which uses the llvm license
|
||||
|
||||
#include "gen/llvm.h"
|
||||
#include "gen/llvm-version.h"
|
||||
#include "llvm/LinkAllVMCore.h"
|
||||
#include "llvm/Linker.h"
|
||||
#include "llvm/System/Signals.h"
|
||||
@@ -11,6 +12,9 @@
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/Target/TargetMachineRegistry.h"
|
||||
#if LLVM_REV >= 73610
|
||||
#include "llvm/Target/TargetSelect.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -421,8 +425,17 @@ int main(int argc, char** argv)
|
||||
|
||||
mod.setTargetTriple(global.params.targetTriple);
|
||||
|
||||
// Allocate target machine. First, check whether the user has
|
||||
// explicitly specified an architecture to compile for.
|
||||
// Allocate target machine.
|
||||
|
||||
// first initialize llvm
|
||||
#if LLVM_REV >= 73610
|
||||
#define LLVM_TARGET(A) LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter();
|
||||
// this is defined to be LLVM_TARGET(target name 1) LLVM_TARGET(target name 2) ...
|
||||
LDC_TARGETS
|
||||
#undef LLVM_TARGET
|
||||
#endif
|
||||
|
||||
// Check whether the user has explicitly specified an architecture to compile for.
|
||||
if (mArch == 0)
|
||||
{
|
||||
std::string Err;
|
||||
|
||||
Reference in New Issue
Block a user