Add weak linking type
[oota-llvm.git] / include / llvm / GlobalValue.h
1 //===-- llvm/GlobalValue.h - Class to represent a global value --*- C++ -*-===//
2 //
3 // This file is a common base class of all globally definable objects.  As such,
4 // it is subclassed by GlobalVariable and by Function.  This is used because you
5 // can do certain things with these global objects that you can't do to anything
6 // else.  For example, use the address of one as a constant.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_GLOBALVALUE_H
11 #define LLVM_GLOBALVALUE_H
12
13 #include "llvm/User.h"
14 class PointerType;
15 class Module;
16
17 class GlobalValue : public User {
18   GlobalValue(const GlobalValue &);             // do not implement
19 public:
20   enum LinkageTypes {
21     ExternalLinkage,   // Externally visible function
22     LinkOnceLinkage,   // Keep one copy of named function when linking (inline)
23     WeakLinkage,       // Keep one copy of named function when linking (weak)
24     AppendingLinkage,  // Special purpose, only applies to global arrays
25     InternalLinkage    // Rename collisions when linking (static functions)
26   };
27 protected:
28   GlobalValue(const Type *Ty, ValueTy vty, LinkageTypes linkage,
29               const std::string &name = "")
30     : User(Ty, vty, name), Linkage(linkage), Parent(0) {}
31
32   LinkageTypes Linkage;   // The linkage of this global
33   Module *Parent;
34 public:
35   ~GlobalValue() {}
36
37   /// getType - Global values are always pointers.
38   inline const PointerType *getType() const {
39     return (const PointerType*)User::getType();
40   }
41
42   bool hasExternalLinkage()  const { return Linkage == ExternalLinkage; }
43   bool hasLinkOnceLinkage()  const { return Linkage == LinkOnceLinkage; }
44   bool hasWeakLinkage()      const { return Linkage == WeakLinkage; }
45   bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
46   bool hasInternalLinkage()  const { return Linkage == InternalLinkage; }
47   void setLinkage(LinkageTypes LT) { Linkage = LT; }
48   LinkageTypes getLinkage() const { return Linkage; }
49
50   /// isExternal - Return true if the primary definition of this global value is
51   /// outside of the current translation unit...
52   virtual bool isExternal() const = 0;
53
54   /// getParent - Get the module that this global value is contained inside
55   /// of...
56   inline Module *getParent() { return Parent; }
57   inline const Module *getParent() const { return Parent; }
58
59   // Methods for support type inquiry through isa, cast, and dyn_cast:
60   static inline bool classof(const GlobalValue *T) { return true; }
61   static inline bool classof(const Value *V) {
62     return V->getValueType() == Value::FunctionVal || 
63            V->getValueType() == Value::GlobalVariableVal;
64   }
65 };
66
67 #endif