Rename ConstPoolVal -> Constant
[oota-llvm.git] / include / llvm / GlobalVariable.h
1 //===-- llvm/Global.h - Class to represent a global variable -----*- C++ -*--=//
2 //
3 // This file contains the declaration of the GlobalVariable class, which
4 // represents a single global variable (or constant) in the VM.
5 //
6 // Global variables are constant pointers that refer to hunks of space that are
7 // allocated by either the VM, or by the linker in a static compiler.  A global
8 // variable may have an intial value, which is copied into the executables .data
9 // area.  Global Constants are required to have initializers.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_GLOBAL_VARIABLE_H
14 #define LLVM_GLOBAL_VARIABLE_H
15
16 #include "llvm/GlobalValue.h"
17 class Module;
18 class Constant;
19 class PointerType;
20
21 class GlobalVariable : public GlobalValue {
22   friend class ValueHolder<GlobalVariable, Module, Module>;
23   void setParent(Module *parent) { Parent = parent; }
24
25   bool isConstantGlobal;               // Is this a global constant?
26 public:
27   GlobalVariable(const Type *Ty, bool isConstant, bool isInternal,
28                  Constant *Initializer = 0, const string &Name = "");
29   ~GlobalVariable() {}
30
31   // Specialize setName to handle symbol table majik...
32   virtual void setName(const string &name, SymbolTable *ST = 0);
33
34   // The initializer for the global variable/constant is held by Operands[0] if
35   // an initializer is specified.
36   //
37   inline bool hasInitializer() const { return !Operands.empty(); }
38   inline Constant *getInitializer() const {
39     assert(hasInitializer() && "GV doesn't have initializer!");
40     return (Constant*)Operands[0].get();
41   }
42   inline Constant *getInitializer() {
43     assert(hasInitializer() && "GV doesn't have initializer!");
44     return (Constant*)Operands[0].get();
45   }
46   inline void setInitializer(Constant *CPV) {
47     if (CPV == 0) {
48       if (hasInitializer()) Operands.pop_back();
49     } else {
50       if (!hasInitializer()) Operands.push_back(Use(0, this));
51       Operands[0] = (Value*)CPV;
52     }
53   }
54
55
56   // If the value is a global constant, its value is immutable throughout the
57   // runtime execution of the program.  Assigning a value into the constant
58   // leads to undefined behavior.
59   //
60   inline bool isConstant() const { return isConstantGlobal; }
61
62   // Methods for support type inquiry through isa, cast, and dyn_cast:
63   static inline bool classof(const GlobalVariable *) { return true; }
64   static inline bool classof(const Value *V) {
65     return V->getValueType() == Value::GlobalVariableVal;
66   }
67 };
68
69 #endif