Added the name of the public CVS repository.
[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 class PointerType;
22 class Module;
23
24 class GlobalValue : public User {
25   GlobalValue(const GlobalValue &);             // do not implement
26 public:
27   enum LinkageTypes {
28     ExternalLinkage,   // Externally visible function
29     LinkOnceLinkage,   // Keep one copy of named function when linking (inline)
30     WeakLinkage,       // Keep one copy of named function when linking (weak)
31     AppendingLinkage,  // Special purpose, only applies to global arrays
32     InternalLinkage    // Rename collisions when linking (static functions)
33   };
34 protected:
35   GlobalValue(const Type *Ty, ValueTy vty, LinkageTypes linkage,
36               const std::string &name = "")
37     : User(Ty, vty, name), Linkage(linkage), Parent(0) {}
38
39   LinkageTypes Linkage;   // The linkage of this global
40   Module *Parent;
41 public:
42   ~GlobalValue() {}
43
44   /// getType - Global values are always pointers.
45   inline const PointerType *getType() const {
46     return (const PointerType*)User::getType();
47   }
48
49   bool hasExternalLinkage()  const { return Linkage == ExternalLinkage; }
50   bool hasLinkOnceLinkage()  const { return Linkage == LinkOnceLinkage; }
51   bool hasWeakLinkage()      const { return Linkage == WeakLinkage; }
52   bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
53   bool hasInternalLinkage()  const { return Linkage == InternalLinkage; }
54   void setLinkage(LinkageTypes LT) { Linkage = LT; }
55   LinkageTypes getLinkage() const { return Linkage; }
56
57   /// isExternal - Return true if the primary definition of this global value is
58   /// outside of the current translation unit...
59   virtual bool isExternal() const = 0;
60
61   /// getParent - Get the module that this global value is contained inside
62   /// of...
63   inline Module *getParent() { return Parent; }
64   inline const Module *getParent() const { return Parent; }
65
66   // Methods for support type inquiry through isa, cast, and dyn_cast:
67   static inline bool classof(const GlobalValue *T) { return true; }
68   static inline bool classof(const Value *V) {
69     return V->getValueType() == Value::FunctionVal || 
70            V->getValueType() == Value::GlobalVariableVal;
71   }
72 };
73
74 #endif