2001-09-10 07:58:01 +00:00
|
|
|
//===-- llvm/Global.h - Class to represent a global variable -----*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// This file contains the declaration of the GlobalVariable class, which
|
2001-09-18 04:01:05 +00:00
|
|
|
// represents a single global variable (or constant) in the VM.
|
2001-09-10 07:58:01 +00:00
|
|
|
//
|
|
|
|
// Global variables are constant pointers that refer to hunks of space that are
|
2001-09-18 04:01:05 +00:00
|
|
|
// allocated by either the VM, or by the linker in a static compiler. A global
|
|
|
|
// variable may have an intial value, which is copied into the executables .data
|
|
|
|
// area. Global Constants are required to have initializers.
|
2001-09-10 07:58:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_GLOBAL_VARIABLE_H
|
|
|
|
#define LLVM_GLOBAL_VARIABLE_H
|
|
|
|
|
2001-10-03 14:53:21 +00:00
|
|
|
#include "llvm/GlobalValue.h"
|
2001-09-10 07:58:01 +00:00
|
|
|
class Module;
|
2001-12-03 22:26:30 +00:00
|
|
|
class Constant;
|
2001-09-18 04:01:05 +00:00
|
|
|
class PointerType;
|
2001-09-10 07:58:01 +00:00
|
|
|
|
2001-10-03 14:53:21 +00:00
|
|
|
class GlobalVariable : public GlobalValue {
|
2001-09-10 07:58:01 +00:00
|
|
|
friend class ValueHolder<GlobalVariable, Module, Module>;
|
|
|
|
void setParent(Module *parent) { Parent = parent; }
|
|
|
|
|
2001-12-03 22:26:30 +00:00
|
|
|
bool isConstantGlobal; // Is this a global constant?
|
2001-09-10 07:58:01 +00:00
|
|
|
public:
|
2001-11-26 18:46:40 +00:00
|
|
|
GlobalVariable(const Type *Ty, bool isConstant, bool isInternal,
|
2002-01-20 22:54:45 +00:00
|
|
|
Constant *Initializer = 0, const std::string &Name = "");
|
2001-09-10 07:58:01 +00:00
|
|
|
~GlobalVariable() {}
|
|
|
|
|
|
|
|
// Specialize setName to handle symbol table majik...
|
2002-01-20 22:54:45 +00:00
|
|
|
virtual void setName(const std::string &name, SymbolTable *ST = 0);
|
2001-09-10 07:58:01 +00:00
|
|
|
|
2001-09-18 04:01:05 +00:00
|
|
|
// The initializer for the global variable/constant is held by Operands[0] if
|
|
|
|
// an initializer is specified.
|
|
|
|
//
|
|
|
|
inline bool hasInitializer() const { return !Operands.empty(); }
|
2001-12-03 22:26:30 +00:00
|
|
|
inline Constant *getInitializer() const {
|
2001-10-13 06:12:38 +00:00
|
|
|
assert(hasInitializer() && "GV doesn't have initializer!");
|
2001-12-03 22:26:30 +00:00
|
|
|
return (Constant*)Operands[0].get();
|
2001-09-18 04:01:05 +00:00
|
|
|
}
|
2001-12-03 22:26:30 +00:00
|
|
|
inline Constant *getInitializer() {
|
2001-10-13 06:12:38 +00:00
|
|
|
assert(hasInitializer() && "GV doesn't have initializer!");
|
2001-12-03 22:26:30 +00:00
|
|
|
return (Constant*)Operands[0].get();
|
2001-09-18 04:01:05 +00:00
|
|
|
}
|
2001-12-03 22:26:30 +00:00
|
|
|
inline void setInitializer(Constant *CPV) {
|
2001-10-03 15:38:36 +00:00
|
|
|
if (CPV == 0) {
|
|
|
|
if (hasInitializer()) Operands.pop_back();
|
|
|
|
} else {
|
|
|
|
if (!hasInitializer()) Operands.push_back(Use(0, this));
|
|
|
|
Operands[0] = (Value*)CPV;
|
|
|
|
}
|
|
|
|
}
|
2001-09-18 04:01:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
// If the value is a global constant, its value is immutable throughout the
|
|
|
|
// runtime execution of the program. Assigning a value into the constant
|
|
|
|
// leads to undefined behavior.
|
|
|
|
//
|
2001-12-03 22:26:30 +00:00
|
|
|
inline bool isConstant() const { return isConstantGlobal; }
|
2001-10-01 18:26:53 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const GlobalVariable *) { return true; }
|
|
|
|
static inline bool classof(const Value *V) {
|
2001-10-03 14:53:21 +00:00
|
|
|
return V->getValueType() == Value::GlobalVariableVal;
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-09-10 07:58:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|