Provide InitializeAllTargets and InitializeNativeTarget functions in the

C bindings.  Change all the backend "Initialize" functions to have C linkage.
Change the "llvm/Config/Targets.def" header to use C-style comments to avoid
compile warnings.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74026 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bob Wilson 2009-06-23 23:59:40 +00:00
parent ba1da8a7b1
commit a96751fc8f
25 changed files with 102 additions and 125 deletions

View File

@ -20,6 +20,7 @@
#define LLVM_C_TARGET_H #define LLVM_C_TARGET_H
#include "llvm-c/Core.h" #include "llvm-c/Core.h"
#include "llvm/Config/config.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -31,6 +32,34 @@ typedef int LLVMByteOrdering;
typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef; typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
typedef struct LLVMStructLayout *LLVMStructLayoutRef; typedef struct LLVMStructLayout *LLVMStructLayoutRef;
/* Declare all of the target-initialization functions that are available. */
#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
#include "llvm/Config/Targets.def"
/** 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() {
#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
#include "llvm/Config/Targets.def"
}
/** 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 int LLVMInitializeNativeTarget() {
/* If we have a native target, initialize it to ensure it is linked in. */
#ifdef LLVM_NATIVE_ARCH
#define DoInit2(TARG) LLVMInitialize ## TARG ()
#define DoInit(T) DoInit2(T)
DoInit(LLVM_NATIVE_ARCH);
return 0;
#undef DoInit
#undef DoInit2
#else
return 1;
#endif
}
/*===-- Target Data -------------------------------------------------------===*/ /*===-- Target Data -------------------------------------------------------===*/

View File

@ -1,23 +1,23 @@
//===- llvm/Config/Targets.def - LLVM Target Architectures ------*- C++ -*-===// /*===- llvm/Config/Targets.def - LLVM Target Architectures ------*- C++ -*-===*\
// |* *|
// The LLVM Compiler Infrastructure |* The LLVM Compiler Infrastructure *|
// |* *|
// This file is distributed under the University of Illinois Open Source |* This file is distributed under the University of Illinois Open Source *|
// License. See LICENSE.TXT for details. |* License. See LICENSE.TXT for details. *|
// |* *|
//===----------------------------------------------------------------------===// |*===----------------------------------------------------------------------===*|
// |* *|
// This file enumerates all of the target architectures supported by |* This file enumerates all of the target architectures supported by *|
// this build of LLVM. Clients of this file should define the |* this build of LLVM. Clients of this file should define the *|
// LLVM_TARGET macro to be a function-like macro with a single |* LLVM_TARGET macro to be a function-like macro with a single *|
// parameter (the name of the target); including this file will then |* parameter (the name of the target); including this file will then *|
// enumerate all of the targets. |* enumerate all of the targets. *|
// |* *|
// The set of targets supported by LLVM is generated at configuration |* The set of targets supported by LLVM is generated at configuration *|
// time, at which point this header is generated. Do not modify this |* time, at which point this header is generated. Do not modify this *|
// header directly. |* header directly. *|
// |* *|
//===----------------------------------------------------------------------===// \*===----------------------------------------------------------------------===*/
#ifndef LLVM_TARGET #ifndef LLVM_TARGET
# error Please define the macro LLVM_TARGET(TargetName) # error Please define the macro LLVM_TARGET(TargetName)

View File

@ -18,20 +18,21 @@
#include "llvm/Config/config.h" #include "llvm/Config/config.h"
namespace llvm { extern "C" {
// Declare all of the target-initialization functions that are available. // Declare all of the target-initialization functions that are available.
#define LLVM_TARGET(TargetName) void Initialize##TargetName##Target(); #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
#include "llvm/Config/Targets.def" #include "llvm/Config/Targets.def"
// Declare all of the available asm-printer initialization functions. // Declare all of the available asm-printer initialization functions.
// Declare all of the target-initialization functions. #define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
#define LLVM_ASM_PRINTER(TargetName) void Initialize##TargetName##AsmPrinter();
#include "llvm/Config/AsmPrinters.def" #include "llvm/Config/AsmPrinters.def"
}
namespace llvm {
/// InitializeAllTargets - The main program should call this function if it /// InitializeAllTargets - The main program should call this function if it
/// wants to link in all available targets that LLVM is configured to support. /// wants to link in all available targets that LLVM is configured to support.
inline void InitializeAllTargets() { inline void InitializeAllTargets() {
#define LLVM_TARGET(TargetName) llvm::Initialize##TargetName##Target(); #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
#include "llvm/Config/Targets.def" #include "llvm/Config/Targets.def"
} }
@ -39,18 +40,17 @@ namespace llvm {
/// it wants all asm printers that LLVM is configured to support. This will /// it wants all asm printers that LLVM is configured to support. This will
/// cause them to be linked into its executable. /// cause them to be linked into its executable.
inline void InitializeAllAsmPrinters() { inline void InitializeAllAsmPrinters() {
#define LLVM_ASM_PRINTER(TargetName) Initialize##TargetName##AsmPrinter(); #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
#include "llvm/Config/AsmPrinters.def" #include "llvm/Config/AsmPrinters.def"
} }
/// InitializeNativeTarget - The main program should call this function to /// InitializeNativeTarget - 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
/// for JIT applications to ensure that the target gets linked in correctly. /// for JIT applications to ensure that the target gets linked in correctly.
inline bool InitializeNativeTarget() { inline bool InitializeNativeTarget() {
// If we have a native target, initialize it to ensure it is linked in. // If we have a native target, initialize it to ensure it is linked in.
#ifdef LLVM_NATIVE_ARCH #ifdef LLVM_NATIVE_ARCH
#define DoInit2(TARG) llvm::Initialize ## TARG () #define DoInit2(TARG) LLVMInitialize ## TARG ()
#define DoInit(T) DoInit2(T) #define DoInit(T) DoInit2(T)
DoInit(LLVM_NATIVE_ARCH); DoInit(LLVM_NATIVE_ARCH);
return false; return false;

View File

@ -39,10 +39,8 @@ int ARMTargetMachineModule = 0;
static RegisterTarget<ARMTargetMachine> X("arm", "ARM"); static RegisterTarget<ARMTargetMachine> X("arm", "ARM");
static RegisterTarget<ThumbTargetMachine> Y("thumb", "Thumb"); static RegisterTarget<ThumbTargetMachine> Y("thumb", "Thumb");
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeARMTarget() { }
void InitializeARMTarget() { }
}
// No assembler printer by default // No assembler printer by default
ARMTargetMachine::AsmPrinterCtorFn ARMTargetMachine::AsmPrinterCtor = 0; ARMTargetMachine::AsmPrinterCtorFn ARMTargetMachine::AsmPrinterCtor = 0;

View File

@ -1172,8 +1172,5 @@ namespace {
} Registrator; } Registrator;
} }
// Force static initialization when called from // Force static initialization.
// llvm/InitializeAllAsmPrinters.h extern "C" void LLVMInitializeARMAsmPrinter() { }
namespace llvm {
void InitializeARMAsmPrinter() { }
}

View File

@ -27,10 +27,8 @@ static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");
// No assembler printer by default // No assembler printer by default
AlphaTargetMachine::AsmPrinterCtorFn AlphaTargetMachine::AsmPrinterCtor = 0; AlphaTargetMachine::AsmPrinterCtorFn AlphaTargetMachine::AsmPrinterCtor = 0;
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeAlphaTarget() { }
void InitializeAlphaTarget() { }
}
const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const { const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
return new AlphaTargetAsmInfo(*this); return new AlphaTargetAsmInfo(*this);

View File

@ -304,11 +304,8 @@ bool AlphaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
return false; return false;
} }
// Force static initialization when called from // Force static initialization.
// llvm/InitializeAllAsmPrinters.h extern "C" void LLVMInitializeAlphaAsmPrinter() { }
namespace llvm {
void InitializeAlphaAsmPrinter() { }
}
namespace { namespace {
static struct Register { static struct Register {

View File

@ -59,10 +59,8 @@ int CBackendTargetMachineModule = 0;
// Register the target. // Register the target.
static RegisterTarget<CTargetMachine> X("c", "C backend"); static RegisterTarget<CTargetMachine> X("c", "C backend");
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeCBackendTarget() { }
void InitializeCBackendTarget() { }
}
namespace { namespace {
/// CBackendNameAllUsedStructsAndMergeFunctions - This pass inserts names for /// CBackendNameAllUsedStructsAndMergeFunctions - This pass inserts names for

View File

@ -617,11 +617,8 @@ FunctionPass *llvm::createSPUAsmPrinterPass(raw_ostream &o,
return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo(), OptLevel, verbose); return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo(), OptLevel, verbose);
} }
// Force static initialization when called from // Force static initialization.
// llvm/InitializeAllAsmPrinters.h extern "C" void LLVMInitializeCellSPUAsmPrinter() { }
namespace llvm {
void InitializeCellSPUAsmPrinter() { }
}
namespace { namespace {
static struct Register { static struct Register {

View File

@ -32,10 +32,8 @@ namespace {
// No assembler printer by default // No assembler printer by default
SPUTargetMachine::AsmPrinterCtorFn SPUTargetMachine::AsmPrinterCtor = 0; SPUTargetMachine::AsmPrinterCtorFn SPUTargetMachine::AsmPrinterCtor = 0;
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeCellSPUTarget() { }
void InitializeCellSPUTarget() { }
}
const std::pair<unsigned, int> * const std::pair<unsigned, int> *
SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const { SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const {

View File

@ -82,10 +82,8 @@ int CppBackendTargetMachineModule = 0;
// Register the target. // Register the target.
static RegisterTarget<CPPTargetMachine> X("cpp", "C++ backend"); static RegisterTarget<CPPTargetMachine> X("cpp", "C++ backend");
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeCppBackendTarget() { }
void InitializeCppBackendTarget() { }
}
namespace { namespace {
typedef std::vector<const Type*> TypeList; typedef std::vector<const Type*> TypeList;

View File

@ -384,8 +384,5 @@ namespace {
} }
// Force static initialization when called from // Force static initialization.
// llvm/InitializeAllAsmPrinters.h extern "C" void LLVMInitializeIA64AsmPrinter() { }
namespace llvm {
void InitializeIA64AsmPrinter() { }
}

View File

@ -26,10 +26,8 @@ static RegisterTarget<IA64TargetMachine> X("ia64",
// No assembler printer by default // No assembler printer by default
IA64TargetMachine::AsmPrinterCtorFn IA64TargetMachine::AsmPrinterCtor = 0; IA64TargetMachine::AsmPrinterCtorFn IA64TargetMachine::AsmPrinterCtor = 0;
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeIA64Target() { }
void InitializeIA64Target() { }
}
const TargetAsmInfo *IA64TargetMachine::createTargetAsmInfo() const { const TargetAsmInfo *IA64TargetMachine::createTargetAsmInfo() const {
return new IA64TargetAsmInfo(*this); return new IA64TargetAsmInfo(*this);

View File

@ -55,10 +55,8 @@ int MSILTargetMachineModule = 0;
static RegisterTarget<MSILTarget> X("msil", "MSIL backend"); static RegisterTarget<MSILTarget> X("msil", "MSIL backend");
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeMSILTarget() { }
void InitializeMSILTarget() { }
}
bool MSILModule::runOnModule(Module &M) { bool MSILModule::runOnModule(Module &M) {
ModulePtr = &M; ModulePtr = &M;

View File

@ -35,10 +35,8 @@ int MSP430TargetMachineModule = 0;
static RegisterTarget<MSP430TargetMachine> static RegisterTarget<MSP430TargetMachine>
X("msp430", "MSP430 [experimental]"); X("msp430", "MSP430 [experimental]");
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeMSP430Target() { }
void InitializeMSP430Target() { }
}
MSP430TargetMachine::MSP430TargetMachine(const Module &M, MSP430TargetMachine::MSP430TargetMachine(const Module &M,
const std::string &FS) : const std::string &FS) :

View File

@ -587,8 +587,5 @@ namespace {
} Registrator; } Registrator;
} }
// Force static initialization when called from // Force static initialization.
// llvm/InitializeAllAsmPrinters.h extern "C" void LLVMInitializeMipsAsmPrinter() { }
namespace llvm {
void InitializeMipsAsmPrinter() { }
}

View File

@ -34,10 +34,8 @@ static RegisterTarget<MipselTargetMachine> Y("mipsel", "Mipsel");
MipsTargetMachine::AsmPrinterCtorFn MipsTargetMachine::AsmPrinterCtor = 0; MipsTargetMachine::AsmPrinterCtorFn MipsTargetMachine::AsmPrinterCtor = 0;
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeMipsTarget() { }
void InitializeMipsTarget() { }
}
const TargetAsmInfo *MipsTargetMachine:: const TargetAsmInfo *MipsTargetMachine::
createTargetAsmInfo() const createTargetAsmInfo() const

View File

@ -37,10 +37,8 @@ X("pic16", "PIC16 14-bit [experimental].");
static RegisterTarget<CooperTargetMachine> static RegisterTarget<CooperTargetMachine>
Y("cooper", "PIC16 Cooper [experimental]."); Y("cooper", "PIC16 Cooper [experimental].");
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializePIC16Target() { }
void InitializePIC16Target() { }
}
// PIC16TargetMachine - Traditional PIC16 Machine. // PIC16TargetMachine - Traditional PIC16 Machine.
PIC16TargetMachine::PIC16TargetMachine(const Module &M, const std::string &FS, PIC16TargetMachine::PIC16TargetMachine(const Module &M, const std::string &FS,

View File

@ -1185,8 +1185,5 @@ namespace {
extern "C" int PowerPCAsmPrinterForceLink; extern "C" int PowerPCAsmPrinterForceLink;
int PowerPCAsmPrinterForceLink = 0; int PowerPCAsmPrinterForceLink = 0;
// Force static initialization when called from // Force static initialization.
// llvm/InitializeAllAsmPrinters.h extern "C" void LLVMInitializePowerPCAsmPrinter() { }
namespace llvm {
void InitializePowerPCAsmPrinter() { }
}

View File

@ -35,10 +35,8 @@ X("ppc32", "PowerPC 32");
static RegisterTarget<PPC64TargetMachine> static RegisterTarget<PPC64TargetMachine>
Y("ppc64", "PowerPC 64"); Y("ppc64", "PowerPC 64");
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializePowerPCTarget() { }
void InitializePowerPCTarget() { }
}
// No assembler printer by default // No assembler printer by default
PPCTargetMachine::AsmPrinterCtorFn PPCTargetMachine::AsmPrinterCtor = 0; PPCTargetMachine::AsmPrinterCtorFn PPCTargetMachine::AsmPrinterCtor = 0;

View File

@ -362,8 +362,5 @@ namespace {
} Registrator; } Registrator;
} }
// Force static initialization when called from // Force static initialization.
// llvm/InitializeAllAsmPrinters.h extern "C" void LLVMInitializeSparcAsmPrinter() { }
namespace llvm {
void InitializeSparcAsmPrinter() { }
}

View File

@ -25,10 +25,8 @@ static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");
SparcTargetMachine::AsmPrinterCtorFn SparcTargetMachine::AsmPrinterCtor = 0; SparcTargetMachine::AsmPrinterCtorFn SparcTargetMachine::AsmPrinterCtor = 0;
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeSparcTarget() { }
void InitializeSparcTarget() { }
}
const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const { const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
// FIXME: Handle Solaris subtarget someday :) // FIXME: Handle Solaris subtarget someday :)

View File

@ -47,8 +47,5 @@ namespace {
extern "C" int X86AsmPrinterForceLink; extern "C" int X86AsmPrinterForceLink;
int X86AsmPrinterForceLink = 0; int X86AsmPrinterForceLink = 0;
// Force static initialization when called from // Force static initialization.
// llvm/InitializeAllAsmPrinters.h extern "C" void LLVMInitializeX86AsmPrinter() { }
namespace llvm {
void InitializeX86AsmPrinter() { }
}

View File

@ -36,10 +36,8 @@ X("x86", "32-bit X86: Pentium-Pro and above");
static RegisterTarget<X86_64TargetMachine> static RegisterTarget<X86_64TargetMachine>
Y("x86-64", "64-bit X86: EM64T and AMD64"); Y("x86-64", "64-bit X86: EM64T and AMD64");
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeX86Target() { }
void InitializeX86Target() { }
}
// No assembler printer by default // No assembler printer by default
X86TargetMachine::AsmPrinterCtorFn X86TargetMachine::AsmPrinterCtor = 0; X86TargetMachine::AsmPrinterCtorFn X86TargetMachine::AsmPrinterCtor = 0;

View File

@ -31,10 +31,8 @@ namespace {
RegisterTarget<XCoreTargetMachine> X("xcore", "XCore"); RegisterTarget<XCoreTargetMachine> X("xcore", "XCore");
} }
// Force static initialization when called from llvm/InitializeAllTargets.h // Force static initialization.
namespace llvm { extern "C" void LLVMInitializeXCoreTarget() { }
void InitializeXCoreTarget() { }
}
const TargetAsmInfo *XCoreTargetMachine::createTargetAsmInfo() const { const TargetAsmInfo *XCoreTargetMachine::createTargetAsmInfo() const {
return new XCoreTargetAsmInfo(*this); return new XCoreTargetAsmInfo(*this);