Index: docs/ReleaseNotes.rst =================================================================== --- docs/ReleaseNotes.rst +++ docs/ReleaseNotes.rst @@ -41,6 +41,10 @@ functionality, or simply have a lot to talk about), see the `NOTE` below for adding a new subsection. +* C APIs for ``LLVMInitializeAllTarget{s,Infos,MCs}`` and + ``LLVMInitializeAllAsm{Printers,Parsers}`` as well as their ``Native`` counterparts are not + ``static inline`` anymore allowing them to be used via FFI. + * ... next change ... .. NOTE Index: include/llvm-c/Target.h =================================================================== --- include/llvm-c/Target.h +++ include/llvm-c/Target.h @@ -20,11 +20,6 @@ #define LLVM_C_TARGET_H #include "llvm-c/Types.h" -#include "llvm/Config/llvm-config.h" - -#if defined(_MSC_VER) && !defined(inline) -#define inline __inline -#endif #ifdef __cplusplus extern "C" { @@ -48,7 +43,8 @@ #include "llvm/Config/Targets.def" #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ -#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void); +#define LLVM_TARGET(TargetName) \ + void LLVMInitialize##TargetName##Target(void); #include "llvm/Config/Targets.def" #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ @@ -78,108 +74,52 @@ /** LLVMInitializeAllTargetInfos - The main program should call this function if it wants access to all available targets that LLVM is configured to support. */ -static inline void LLVMInitializeAllTargetInfos(void) { -#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo(); -#include "llvm/Config/Targets.def" -#undef LLVM_TARGET /* Explicit undef to make SWIG happier */ -} +void LLVMInitializeAllTargetInfos(void); /** LLVMInitializeAllTargets - The main program should call this function if it wants to link in all available targets that LLVM is configured to support. */ -static inline void LLVMInitializeAllTargets(void) { -#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target(); -#include "llvm/Config/Targets.def" -#undef LLVM_TARGET /* Explicit undef to make SWIG happier */ -} +void LLVMInitializeAllTargets(void); /** LLVMInitializeAllTargetMCs - The main program should call this function if it wants access to all available target MC that LLVM is configured to support. */ -static inline void LLVMInitializeAllTargetMCs(void) { -#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC(); -#include "llvm/Config/Targets.def" -#undef LLVM_TARGET /* Explicit undef to make SWIG happier */ -} +void LLVMInitializeAllTargetMCs(void); /** LLVMInitializeAllAsmPrinters - The main program should call this function if it wants all asm printers that LLVM is configured to support, to make them available via the TargetRegistry. */ -static inline void LLVMInitializeAllAsmPrinters(void) { -#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter(); -#include "llvm/Config/AsmPrinters.def" -#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */ -} +void LLVMInitializeAllAsmPrinters(void); /** LLVMInitializeAllAsmParsers - The main program should call this function if it wants all asm parsers that LLVM is configured to support, to make them available via the TargetRegistry. */ -static inline void LLVMInitializeAllAsmParsers(void) { -#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser(); -#include "llvm/Config/AsmParsers.def" -#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */ -} +void LLVMInitializeAllAsmParsers(void); /** LLVMInitializeAllDisassemblers - The main program should call this function if it wants all disassemblers that LLVM is configured to support, to make them available via the TargetRegistry. */ -static inline void LLVMInitializeAllDisassemblers(void) { -#define LLVM_DISASSEMBLER(TargetName) \ - LLVMInitialize##TargetName##Disassembler(); -#include "llvm/Config/Disassemblers.def" -#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */ -} +void LLVMInitializeAllDisassemblers(void); /** LLVMInitializeNativeTarget - The main program should call this function to initialize the native target corresponding to the host. This is useful for JIT applications to ensure that the target gets linked in correctly. */ -static inline LLVMBool LLVMInitializeNativeTarget(void) { - /* If we have a native target, initialize it to ensure it is linked in. */ -#ifdef LLVM_NATIVE_TARGET - LLVM_NATIVE_TARGETINFO(); - LLVM_NATIVE_TARGET(); - LLVM_NATIVE_TARGETMC(); - return 0; -#else - return 1; -#endif -} +LLVMBool LLVMInitializeNativeTarget(void); /** LLVMInitializeNativeTargetAsmParser - The main program should call this function to initialize the parser for the native target corresponding to the host. */ -static inline LLVMBool LLVMInitializeNativeAsmParser(void) { -#ifdef LLVM_NATIVE_ASMPARSER - LLVM_NATIVE_ASMPARSER(); - return 0; -#else - return 1; -#endif -} +LLVMBool LLVMInitializeNativeAsmParser(void); /** LLVMInitializeNativeTargetAsmPrinter - The main program should call this function to initialize the printer for the native target corresponding to the host. */ -static inline LLVMBool LLVMInitializeNativeAsmPrinter(void) { -#ifdef LLVM_NATIVE_ASMPRINTER - LLVM_NATIVE_ASMPRINTER(); - return 0; -#else - return 1; -#endif -} +LLVMBool LLVMInitializeNativeAsmPrinter(void); /** LLVMInitializeNativeTargetDisassembler - The main program should call this function to initialize the disassembler for the native target corresponding to the host. */ -static inline LLVMBool LLVMInitializeNativeDisassembler(void) { -#ifdef LLVM_NATIVE_DISASSEMBLER - LLVM_NATIVE_DISASSEMBLER(); - return 0; -#else - return 1; -#endif -} +LLVMBool LLVMInitializeNativeDisassembler(void); /*===-- Target Data -------------------------------------------------------===*/ Index: lib/Target/AllTargets/AllTargets.cpp =================================================================== --- /dev/null +++ lib/Target/AllTargets/AllTargets.cpp @@ -0,0 +1,95 @@ +//===-- AllTargets.cpp --------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the C FFI bindings to utility functions which initialize +// all targets and utility functions which initialize “native” targets. This is +// a separate library from libLLVMTarget.a, so dependents on libLLVMTarget woudln’t +// pull in all the available backends. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Config/llvm-config.h" +#include "llvm-c/Target.h" +#include "llvm-c/Initialization.h" + +void LLVMInitializeAllTargets(void) { +#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target(); +#include "llvm/Config/Targets.def" +#undef LLVM_TARGET /* Explicit undef to make SWIG happier */ +} + +void LLVMInitializeAllTargetInfos(void) { +#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo(); +#include "llvm/Config/Targets.def" +#undef LLVM_TARGET /* Explicit undef to make SWIG happier */ +} + +void LLVMInitializeAllTargetMCs(void) { +#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC(); +#include "llvm/Config/Targets.def" +#undef LLVM_TARGET /* Explicit undef to make SWIG happier */ +} + +void LLVMInitializeAllAsmPrinters(void) { +#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter(); +#include "llvm/Config/AsmPrinters.def" +#undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */ +} + +void LLVMInitializeAllAsmParsers(void) { +#define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser(); +#include "llvm/Config/AsmParsers.def" +#undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */ +} + +void LLVMInitializeAllDisassemblers(void) { +#define LLVM_DISASSEMBLER(TargetName) \ + LLVMInitialize##TargetName##Disassembler(); +#include "llvm/Config/Disassemblers.def" +#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */ +} + +LLVMBool LLVMInitializeNativeTarget(void) { + /* If we have a native target, initialize it to ensure it is linked in. */ +#ifdef LLVM_NATIVE_TARGET + LLVM_NATIVE_TARGETINFO(); + LLVM_NATIVE_TARGET(); + LLVM_NATIVE_TARGETMC(); + return 0; +#else + return 1; +#endif +} + +LLVMBool LLVMInitializeNativeAsmParser(void) { +#ifdef LLVM_NATIVE_ASMPARSER + LLVM_NATIVE_ASMPARSER(); + return 0; +#else + return 1; +#endif +} + +LLVMBool LLVMInitializeNativeAsmPrinter(void) { +#ifdef LLVM_NATIVE_ASMPRINTER + LLVM_NATIVE_ASMPRINTER(); + return 0; +#else + return 1; +#endif +} + +LLVMBool LLVMInitializeNativeDisassembler(void) { +#ifdef LLVM_NATIVE_DISASSEMBLER + LLVM_NATIVE_DISASSEMBLER(); + return 0; +#else + return 1; +#endif +} Index: lib/Target/AllTargets/CMakeLists.txt =================================================================== --- /dev/null +++ lib/Target/AllTargets/CMakeLists.txt @@ -0,0 +1,9 @@ +add_llvm_library(LLVMAllTargets + AllTargets.cpp + + ADDITIONAL_HEADER_DIRS + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Target + ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/ + + LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} + ) Index: lib/Target/CMakeLists.txt =================================================================== --- lib/Target/CMakeLists.txt +++ lib/Target/CMakeLists.txt @@ -17,3 +17,5 @@ message(STATUS "Targeting ${t}") add_subdirectory(${t}) endforeach() + +add_subdirectory(AllTargets) Index: lib/Target/Target.cpp =================================================================== --- lib/Target/Target.cpp +++ lib/Target/Target.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file implements the common infrastructure (including C bindings) for +// This file implements the common infrastructure (including C bindings) for // libLLVMTarget.a, which implements target information. // //===----------------------------------------------------------------------===// Index: tools/llvm-c-test/CMakeLists.txt =================================================================== --- tools/llvm-c-test/CMakeLists.txt +++ tools/llvm-c-test/CMakeLists.txt @@ -1,4 +1,5 @@ set(LLVM_LINK_COMPONENTS + AllTargets ${LLVM_TARGETS_TO_BUILD} BitReader Core