llvm-c: Make target initializer functions external functions in lib.

Making them proper functions defined in the (shared)lib instead of
static inlines defined in the header files makes it possible to
actually distribute a binary compiled against the shared library
without having to worry about getting undefined symbol errors when
calling e.g LLVMInitializeAllTargetInfos because the shared library on
the other system was compiled with different targets.

Differential Revision: http://llvm-reviews.chandlerc.com/D1714



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192316 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anders Waldenborg 2013-10-09 19:02:09 +00:00
parent 5e5d494ce0
commit 9360e64e60
3 changed files with 55 additions and 36 deletions

View File

@ -75,57 +75,32 @@ typedef struct LLVMStructLayout *LLVMStructLayoutRef;
/** LLVMInitializeAllTargetInfos - The main program should call this function if /** LLVMInitializeAllTargetInfos - The main program should call this function if
it wants access to all available targets that LLVM is configured to it wants access to all available targets that LLVM is configured to
support. */ support. */
static inline void LLVMInitializeAllTargetInfos(void) { void LLVMInitializeAllTargetInfos(void);
#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
}
/** LLVMInitializeAllTargets - The main program should call this function if it /** LLVMInitializeAllTargets - The main program should call this function if it
wants to link in all available targets that LLVM is configured to wants to link in all available targets that LLVM is configured to
support. */ support. */
static inline void LLVMInitializeAllTargets(void) { void LLVMInitializeAllTargets(void);
#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
}
/** LLVMInitializeAllTargetMCs - The main program should call this function if /** LLVMInitializeAllTargetMCs - The main program should call this function if
it wants access to all available target MC that LLVM is configured to it wants access to all available target MC that LLVM is configured to
support. */ support. */
static inline void LLVMInitializeAllTargetMCs(void) { void LLVMInitializeAllTargetMCs(void);
#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET /* Explicit undef to make SWIG happier */
}
/** LLVMInitializeAllAsmPrinters - The main program should call this function if /** LLVMInitializeAllAsmPrinters - The main program should call this function if
it wants all asm printers that LLVM is configured to support, to make them it wants all asm printers that LLVM is configured to support, to make them
available via the TargetRegistry. */ available via the TargetRegistry. */
static inline void LLVMInitializeAllAsmPrinters(void) { 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 */
}
/** LLVMInitializeAllAsmParsers - The main program should call this function if /** LLVMInitializeAllAsmParsers - The main program should call this function if
it wants all asm parsers that LLVM is configured to support, to make them it wants all asm parsers that LLVM is configured to support, to make them
available via the TargetRegistry. */ available via the TargetRegistry. */
static inline void LLVMInitializeAllAsmParsers(void) { 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 */
}
/** LLVMInitializeAllDisassemblers - The main program should call this function /** LLVMInitializeAllDisassemblers - The main program should call this function
if it wants all disassemblers that LLVM is configured to support, to make if it wants all disassemblers that LLVM is configured to support, to make
them available via the TargetRegistry. */ them available via the TargetRegistry. */
static inline void LLVMInitializeAllDisassemblers(void) { void LLVMInitializeAllDisassemblers(void);
#define LLVM_DISASSEMBLER(TargetName) \
LLVMInitialize##TargetName##Disassembler();
#include "llvm/Config/Disassemblers.def"
#undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */
}
/** LLVMInitializeNativeTarget - The main program should call this function to /** LLVMInitializeNativeTarget - The main program should call this function to
initialize the native target corresponding to the host. This is useful initialize the native target corresponding to the host. This is useful

43
lib/Target/AllTargets.cpp Normal file
View File

@ -0,0 +1,43 @@
//===-- 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 functions for initialization of different
// aspects of all configured targets. When calling any of these
// functions all configured targets must be linked in.
//
//===----------------------------------------------------------------------===//
#include "llvm-c/Target.h"
#include "llvm/Support/TargetSelect.h"
using namespace llvm;
void LLVMInitializeAllTargetInfos(void) {
InitializeAllTargetInfos();
}
void LLVMInitializeAllTargets(void) {
InitializeAllTargets();
}
void LLVMInitializeAllTargetMCs(void) {
InitializeAllTargetMCs();
}
void LLVMInitializeAllAsmPrinters(void) {
InitializeAllAsmPrinters();
}
void LLVMInitializeAllAsmParsers(void) {
InitializeAllAsmParsers();
}
void LLVMInitializeAllDisassemblers(void) {
InitializeAllDisassemblers();
}

View File

@ -1,4 +1,5 @@
add_llvm_library(LLVMTarget add_llvm_library(LLVMTarget
AllTargets.cpp
Mangler.cpp Mangler.cpp
Target.cpp Target.cpp
TargetIntrinsicInfo.cpp TargetIntrinsicInfo.cpp