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-09-18 04:01:05 +00:00
|
|
|
class ConstPoolVal;
|
|
|
|
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
|
|
|
Module *Parent; // The module that contains this method
|
|
|
|
|
|
|
|
friend class ValueHolder<GlobalVariable, Module, Module>;
|
|
|
|
void setParent(Module *parent) { Parent = parent; }
|
|
|
|
|
2001-09-18 04:01:05 +00:00
|
|
|
bool Constant; // Is this a global constant?
|
2001-09-10 07:58:01 +00:00
|
|
|
public:
|
2001-09-18 04:01:05 +00:00
|
|
|
GlobalVariable(const Type *Ty, bool isConstant, ConstPoolVal *Initializer = 0,
|
|
|
|
const string &Name = "");
|
2001-09-10 07:58:01 +00:00
|
|
|
~GlobalVariable() {}
|
|
|
|
|
|
|
|
// Specialize setName to handle symbol table majik...
|
|
|
|
virtual void setName(const string &name, SymbolTable *ST = 0);
|
|
|
|
|
|
|
|
inline Module *getParent() { return Parent; }
|
|
|
|
inline const Module *getParent() const { return Parent; }
|
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(); }
|
|
|
|
inline const ConstPoolVal *getInitializer() const {
|
2001-10-01 18:26:53 +00:00
|
|
|
return (const ConstPoolVal*)Operands[0].get();
|
2001-09-18 04:01:05 +00:00
|
|
|
}
|
|
|
|
inline ConstPoolVal *getInitializer() {
|
2001-10-01 18:26:53 +00:00
|
|
|
return (ConstPoolVal*)Operands[0].get();
|
2001-09-18 04:01:05 +00:00
|
|
|
}
|
|
|
|
inline void setInitializer(ConstPoolVal *CPV) { Operands[0] = (Value*)CPV; }
|
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
inline bool isConstant() const { return Constant; }
|
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
|