Provide InitializeAllTargets and InitializeNativeTarget functions in the
authorBob Wilson <bob.wilson@apple.com>
Tue, 23 Jun 2009 23:59:40 +0000 (23:59 +0000)
committerBob Wilson <bob.wilson@apple.com>
Tue, 23 Jun 2009 23:59:40 +0000 (23:59 +0000)
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

25 files changed:
include/llvm-c/Target.h
include/llvm/Config/Targets.def.in
include/llvm/Target/TargetSelect.h
lib/Target/ARM/ARMTargetMachine.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
lib/Target/Alpha/AlphaTargetMachine.cpp
lib/Target/Alpha/AsmPrinter/AlphaAsmPrinter.cpp
lib/Target/CBackend/CBackend.cpp
lib/Target/CellSPU/AsmPrinter/SPUAsmPrinter.cpp
lib/Target/CellSPU/SPUTargetMachine.cpp
lib/Target/CppBackend/CPPBackend.cpp
lib/Target/IA64/AsmPrinter/IA64AsmPrinter.cpp
lib/Target/IA64/IA64TargetMachine.cpp
lib/Target/MSIL/MSILWriter.cpp
lib/Target/MSP430/MSP430TargetMachine.cpp
lib/Target/Mips/AsmPrinter/MipsAsmPrinter.cpp
lib/Target/Mips/MipsTargetMachine.cpp
lib/Target/PIC16/PIC16TargetMachine.cpp
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
lib/Target/PowerPC/PPCTargetMachine.cpp
lib/Target/Sparc/AsmPrinter/SparcAsmPrinter.cpp
lib/Target/Sparc/SparcTargetMachine.cpp
lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
lib/Target/X86/X86TargetMachine.cpp
lib/Target/XCore/XCoreTargetMachine.cpp

index 5de5bc78574330da9a6c19792cc910364e4171f1..bb423bbaadfc3bec18e8dc74ad55d8294a18f53e 100644 (file)
@@ -20,6 +20,7 @@
 #define LLVM_C_TARGET_H
 
 #include "llvm-c/Core.h"
+#include "llvm/Config/config.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -31,6 +32,34 @@ typedef int LLVMByteOrdering;
 typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef;
 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 -------------------------------------------------------===*/
 
index a3884729e118d6d1dd0b1b06cc6741ec9d96a74e..d589ecee12cc495404e4446967e51e8c5d1a56a0 100644 (file)
@@ -1,23 +1,23 @@
-//===- llvm/Config/Targets.def - LLVM Target Architectures ------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file enumerates all of the target architectures supported by
-// this build of LLVM. Clients of this file should define the
-// LLVM_TARGET macro to be a function-like macro with a single
-// parameter (the name of the target); including this file will then
-// enumerate all of the targets. 
-//
-// The set of targets supported by LLVM is generated at configuration
-// time, at which point this header is generated. Do not modify this
-// header directly.
-//
-//===----------------------------------------------------------------------===//
+/*===- llvm/Config/Targets.def - LLVM Target Architectures ------*- C++ -*-===*\
+|*                                                                            *|
+|*                     The LLVM Compiler Infrastructure                       *|
+|*                                                                            *|
+|* This file is distributed under the University of Illinois Open Source      *|
+|* License. See LICENSE.TXT for details.                                      *|
+|*                                                                            *|
+|*===----------------------------------------------------------------------===*|
+|*                                                                            *|
+|* This file enumerates all of the target architectures supported by          *|
+|* this build of LLVM. Clients of this file should define the                 *|
+|* LLVM_TARGET macro to be a function-like macro with a single                *|
+|* parameter (the name of the target); including this file will then          *|
+|* enumerate all of the targets.                                              *|
+|*                                                                            *|
+|* The set of targets supported by LLVM is generated at configuration         *|
+|* time, at which point this header is generated. Do not modify this          *|
+|* header directly.                                                           *|
+|*                                                                            *|
+\*===----------------------------------------------------------------------===*/
 
 #ifndef LLVM_TARGET
 #  error Please define the macro LLVM_TARGET(TargetName)
index 8aa314ac774733e2bf2cbc82dea8cd0c18c005b4..002d5fc70e5ea8c7d6abacdedab82ae1ee637bf8 100644 (file)
 
 #include "llvm/Config/config.h"
 
-namespace llvm {
+extern "C" {
   // 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"
   
   // Declare all of the available asm-printer initialization functions.
-  // Declare all of the target-initialization functions.
-#define LLVM_ASM_PRINTER(TargetName) void Initialize##TargetName##AsmPrinter();
+#define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
 #include "llvm/Config/AsmPrinters.def"
-  
+}
+
+namespace llvm {
   /// InitializeAllTargets - The main program should call this function if it
   /// wants to link in all available targets that LLVM is configured to support.
   inline void InitializeAllTargets() {
-#define LLVM_TARGET(TargetName) llvm::Initialize##TargetName##Target();
+#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
 #include "llvm/Config/Targets.def"
   }
   
@@ -39,18 +40,17 @@ namespace llvm {
   /// it wants all asm printers that LLVM is configured to support.  This will
   /// cause them to be linked into its executable.
   inline void InitializeAllAsmPrinters() {
-#define LLVM_ASM_PRINTER(TargetName) Initialize##TargetName##AsmPrinter();
+#define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
 #include "llvm/Config/AsmPrinters.def"
   }
   
-  
   /// InitializeNativeTarget - 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.
   inline bool InitializeNativeTarget() {
   // If we have a native target, initialize it to ensure it is linked in.
 #ifdef LLVM_NATIVE_ARCH
-#define DoInit2(TARG)   llvm::Initialize ## TARG ()
+#define DoInit2(TARG)   LLVMInitialize ## TARG ()
 #define DoInit(T) DoInit2(T)
     DoInit(LLVM_NATIVE_ARCH);
     return false;
index 8006b9be32ebe925c5f1ab75427319ffe0685043..35737e7800c2bae6c29fdfbda000aa9467beb098 100644 (file)
@@ -39,10 +39,8 @@ int ARMTargetMachineModule = 0;
 static RegisterTarget<ARMTargetMachine>   X("arm",   "ARM");
 static RegisterTarget<ThumbTargetMachine> Y("thumb", "Thumb");
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeARMTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeARMTarget() { }
 
 // No assembler printer by default
 ARMTargetMachine::AsmPrinterCtorFn ARMTargetMachine::AsmPrinterCtor = 0;
index fe1c9806cbb9f09962e090302b5e3a569fa39665..78d322437272f9b954e82e40ebc7b84b606d4db8 100644 (file)
@@ -1172,8 +1172,5 @@ namespace {
   } Registrator;
 }
 
-// Force static initialization when called from
-// llvm/InitializeAllAsmPrinters.h
-namespace llvm {
-  void InitializeARMAsmPrinter() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeARMAsmPrinter() { }
index cdd4fa4b2445adc265f60a4698ac3a96ec26dbf9..10952eb096ae78e9a94b1b04b4d5e8ed658797bc 100644 (file)
@@ -27,10 +27,8 @@ static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]");
 // No assembler printer by default
 AlphaTargetMachine::AsmPrinterCtorFn AlphaTargetMachine::AsmPrinterCtor = 0;
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeAlphaTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeAlphaTarget() { }
 
 const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const {
   return new AlphaTargetAsmInfo(*this);
index 7b73bb302c38e70edd857d28a9ed30c45f45c150..0c25c47cc097723ac50ba9b890dc2c71ed6af0d2 100644 (file)
@@ -304,11 +304,8 @@ bool AlphaAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
   return false;
 }
 
-// Force static initialization when called from
-// llvm/InitializeAllAsmPrinters.h
-namespace llvm {
-  void InitializeAlphaAsmPrinter() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeAlphaAsmPrinter() { }
 
 namespace {
   static struct Register {
index c3554f6b5734695c5ee6f8daddc9c26a24340498..9a08cad0c7801a3906429efc9700967d12440d57 100644 (file)
@@ -59,10 +59,8 @@ int CBackendTargetMachineModule = 0;
 // Register the target.
 static RegisterTarget<CTargetMachine> X("c", "C backend");
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeCBackendTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeCBackendTarget() { }
 
 namespace {
   /// CBackendNameAllUsedStructsAndMergeFunctions - This pass inserts names for
index 26a8ece21cf7a3aadbc98a5bca5e91a337697c89..896b8a302adce162b2b5c91d2c354b00a998d7b1 100644 (file)
@@ -617,11 +617,8 @@ FunctionPass *llvm::createSPUAsmPrinterPass(raw_ostream &o,
   return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo(), OptLevel, verbose);
 }
 
-// Force static initialization when called from
-// llvm/InitializeAllAsmPrinters.h
-namespace llvm {
-  void InitializeCellSPUAsmPrinter() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeCellSPUAsmPrinter() { }
 
 namespace {
   static struct Register {
index c675ebb09a619429e46bed7cc782c18fbbfb2382..256d63d520e91cb288faf62cab12092233e3515d 100644 (file)
@@ -32,10 +32,8 @@ namespace {
 // No assembler printer by default
 SPUTargetMachine::AsmPrinterCtorFn SPUTargetMachine::AsmPrinterCtor = 0;
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeCellSPUTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeCellSPUTarget() { }
 
 const std::pair<unsigned, int> *
 SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const {
index 1feea96e3d9df306e3b376b360fd868fed285ee3..44418f6e4361c0ac1dd930b1adf28f831ee90fbe 100644 (file)
@@ -82,10 +82,8 @@ int CppBackendTargetMachineModule = 0;
 // Register the target.
 static RegisterTarget<CPPTargetMachine> X("cpp", "C++ backend");
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeCppBackendTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeCppBackendTarget() { }
 
 namespace {
   typedef std::vector<const Type*> TypeList;
index 662c667037fc2127d33e4de0e3a06389b7ca4aef..9a0d134e3240df05facb586c4387dadbd3488f69 100644 (file)
@@ -384,8 +384,5 @@ namespace {
 }
 
 
-// Force static initialization when called from
-// llvm/InitializeAllAsmPrinters.h
-namespace llvm {
-  void InitializeIA64AsmPrinter() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeIA64AsmPrinter() { }
index 0b93ee5c4ae8d0bdd82fae5d490413d9cc03f25c..4b05e1dde37fb2197e4a029b99b153091f2ee919 100644 (file)
@@ -26,10 +26,8 @@ static RegisterTarget<IA64TargetMachine> X("ia64",
 // No assembler printer by default
 IA64TargetMachine::AsmPrinterCtorFn IA64TargetMachine::AsmPrinterCtor = 0;
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeIA64Target() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeIA64Target() { }
 
 const TargetAsmInfo *IA64TargetMachine::createTargetAsmInfo() const {
   return new IA64TargetAsmInfo(*this);
index 0aff14fee26c07fb94069513fa9732ee47628bfc..ee73c381cd4ace054132dc7102d86b49b68e2689 100644 (file)
@@ -55,10 +55,8 @@ int MSILTargetMachineModule = 0;
 
 static RegisterTarget<MSILTarget> X("msil", "MSIL backend");
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeMSILTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeMSILTarget() { }
 
 bool MSILModule::runOnModule(Module &M) {
   ModulePtr = &M;
index 0f5244d666fc75eefab1dee197ee64c054ce93d9..b1fe758c8f306950b214e30ac85bd87604c8dd03 100644 (file)
@@ -35,10 +35,8 @@ int MSP430TargetMachineModule = 0;
 static RegisterTarget<MSP430TargetMachine>
 X("msp430", "MSP430 [experimental]");
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeMSP430Target() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeMSP430Target() { }
 
 MSP430TargetMachine::MSP430TargetMachine(const Module &M,
                                          const std::string &FS) :
index 077ec96d17b757e32cd30b70bc427f189703c0a2..ea38b8aa7df1a21e99b36cf989c77ee04811983b 100644 (file)
@@ -587,8 +587,5 @@ namespace {
   } Registrator;
 }
 
-// Force static initialization when called from
-// llvm/InitializeAllAsmPrinters.h
-namespace llvm {
-  void InitializeMipsAsmPrinter() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeMipsAsmPrinter() { }
index 83b9b62e8ee86c6060ae383f75a88f1cc1a6a431..c5f117bccb984b1f24506f88c8d606d276745db3 100644 (file)
@@ -34,10 +34,8 @@ static RegisterTarget<MipselTargetMachine>  Y("mipsel", "Mipsel");
 MipsTargetMachine::AsmPrinterCtorFn MipsTargetMachine::AsmPrinterCtor = 0;
 
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeMipsTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeMipsTarget() { }
 
 const TargetAsmInfo *MipsTargetMachine::
 createTargetAsmInfo() const 
index d4f46a49449872191c2da2224912f967c131e3fe..43047327663ebbb8d1bd52e350a1c57897a97fc4 100644 (file)
@@ -37,10 +37,8 @@ X("pic16", "PIC16 14-bit [experimental].");
 static RegisterTarget<CooperTargetMachine> 
 Y("cooper", "PIC16 Cooper [experimental].");
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializePIC16Target() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializePIC16Target() { }
 
 // PIC16TargetMachine - Traditional PIC16 Machine.
 PIC16TargetMachine::PIC16TargetMachine(const Module &M, const std::string &FS,
index c7bfb6d1a1a34bb483fadd25a16d68a8f2ed3828..e97495f6a8532dccec0848fd7fc2064d7c240a7f 100644 (file)
@@ -1185,8 +1185,5 @@ namespace {
 extern "C" int PowerPCAsmPrinterForceLink;
 int PowerPCAsmPrinterForceLink = 0;
 
-// Force static initialization when called from
-// llvm/InitializeAllAsmPrinters.h
-namespace llvm {
-  void InitializePowerPCAsmPrinter() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializePowerPCAsmPrinter() { }
index 3e89885a77eb77e67a496d73fb1efda0625974b8..2f95d7e64c0d9886376d05893d2a85b6d7728ee0 100644 (file)
@@ -35,10 +35,8 @@ X("ppc32", "PowerPC 32");
 static RegisterTarget<PPC64TargetMachine>
 Y("ppc64", "PowerPC 64");
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializePowerPCTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializePowerPCTarget() { }
 
 // No assembler printer by default
 PPCTargetMachine::AsmPrinterCtorFn PPCTargetMachine::AsmPrinterCtor = 0;
index 6a2fdcac01d792ac3d239c3c48bec41141c7f468..a2147ddee45c3352bf13f9911b97acce602b0c02 100644 (file)
@@ -362,8 +362,5 @@ namespace {
   } Registrator;
 }
 
-// Force static initialization when called from
-// llvm/InitializeAllAsmPrinters.h
-namespace llvm {
-  void InitializeSparcAsmPrinter() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeSparcAsmPrinter() { }
index fd0f12429a04433d51f3af086116e723a8e111a9..aef238d896508a77b3779b987d19815a8225a5f1 100644 (file)
@@ -25,10 +25,8 @@ static RegisterTarget<SparcTargetMachine> X("sparc", "SPARC");
 SparcTargetMachine::AsmPrinterCtorFn SparcTargetMachine::AsmPrinterCtor = 0;
 
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeSparcTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeSparcTarget() { }
 
 const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
   // FIXME: Handle Solaris subtarget someday :)
index a39203b19c24b224f70986898c1c735bb0384ef6..d1623d62e6a1a666299c5508b43f5a69f7d4d2d5 100644 (file)
@@ -47,8 +47,5 @@ namespace {
 extern "C" int X86AsmPrinterForceLink;
 int X86AsmPrinterForceLink = 0;
 
-// Force static initialization when called from
-// llvm/InitializeAllAsmPrinters.h
-namespace llvm {
-  void InitializeX86AsmPrinter() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeX86AsmPrinter() { }
index 53c46c3595ed5ed96fafbb027e36dfd450691636..6bd9bbefc8dda38b8b57616a7f3bdfb117380864 100644 (file)
@@ -36,10 +36,8 @@ X("x86",    "32-bit X86: Pentium-Pro and above");
 static RegisterTarget<X86_64TargetMachine>
 Y("x86-64", "64-bit X86: EM64T and AMD64");
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeX86Target() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeX86Target() { }
 
 // No assembler printer by default
 X86TargetMachine::AsmPrinterCtorFn X86TargetMachine::AsmPrinterCtor = 0;
index cfd3cd3fe3bf9d146f91433c6c3666baf5335316..09227d94e2b934386b63e0e6b9f33e78d6053ab5 100644 (file)
@@ -31,10 +31,8 @@ namespace {
   RegisterTarget<XCoreTargetMachine> X("xcore", "XCore");
 }
 
-// Force static initialization when called from llvm/InitializeAllTargets.h
-namespace llvm {
-  void InitializeXCoreTarget() { }
-}
+// Force static initialization.
+extern "C" void LLVMInitializeXCoreTarget() { }
 
 const TargetAsmInfo *XCoreTargetMachine::createTargetAsmInfo() const {
   return new XCoreTargetAsmInfo(*this);