Use InstrSlots::NUM rather than pre-dividing by four. Also, mark this const.
[oota-llvm.git] / include / llvm / System / IncludeFile.h
index 8e96f7571f630495e9fef3f5940875cf721115f0..6103e44e4cfcf948a983817129548b165c58fe6a 100644 (file)
@@ -1,9 +1,9 @@
-//===- llvm/Support/IncludeFile.h - Ensure Linking Of Library ---*- C++ -*-===//
+//===- llvm/System/IncludeFile.h - Ensure Linking Of Library ---*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Reid Spencer and is distributed under the 
-// University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -12,8 +12,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_SUPPORT_INCLUDEFILE_H
-#define LLVM_SUPPORT_INCLUDEFILE_H
+#ifndef LLVM_SYSTEM_INCLUDEFILE_H
+#define LLVM_SYSTEM_INCLUDEFILE_H
 
 /// This macro is the public interface that IncludeFile.h exports. This gives
 /// us the option to implement the "link the definition" capability in any 
 /// 
 /// And, foo.cp would use:<br/>
 /// <tt>DEFINING_FILE_FOR(foo)</tt><br/>
+#ifdef __GNUC__
+// If the `used' attribute is available, use it to create a variable
+// with an initializer that will force the linking of the defining file.
 #define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
-  extern char name ## LinkVar; \
-  static IncludeFile name ## LinkObj ( &name ## LinkVar )
+  namespace llvm { \
+    extern const char name ## LinkVar; \
+    __attribute__((used)) static const char *const name ## LinkObj = \
+      &name ## LinkVar; \
+  } 
+#else
+// Otherwise use a constructor call.
+#define FORCE_DEFINING_FILE_TO_BE_LINKED(name) \
+  namespace llvm { \
+    extern const char name ## LinkVar; \
+    static const IncludeFile name ## LinkObj ( &name ## LinkVar ); \
+  } 
+#endif
 
 /// This macro is the counterpart to FORCE_DEFINING_FILE_TO_BE_LINKED. It should
 /// be used in a .cpp file to define the name referenced in a header file that
 /// will cause linkage of the .cpp file. It should only be used at extern level.
-#define DEFINING_FILE_FOR(name) char name
+#define DEFINING_FILE_FOR(name) \
+  namespace llvm { const char name ## LinkVar = 0; }
 
 namespace llvm {
 
@@ -55,7 +70,7 @@ namespace llvm {
 /// <tt>static IncludeFile LinkMyModule(&LinkMyCodeStub);</tt><br/>
 /// @brief Class to ensure linking of corresponding object file.
 struct IncludeFile {
-  IncludeFile(void *);
+  explicit IncludeFile(const void *);
 };
 
 }