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