2001-10-03 14:53:21 +00:00
|
|
|
//===-- llvm/GlobalValue.h - Class to represent a global value ---*- C++ -*--=//
|
|
|
|
//
|
|
|
|
// This file is a common base class of all globally definable objects. As such,
|
2002-09-06 21:31:57 +00:00
|
|
|
// it is subclassed by GlobalVariable and by Function. This is used because you
|
2001-10-03 14:53:21 +00:00
|
|
|
// can do certain things with these global objects that you can't do to anything
|
|
|
|
// else. For example, use the address of one as a constant.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_GLOBALVALUE_H
|
|
|
|
#define LLVM_GLOBALVALUE_H
|
|
|
|
|
|
|
|
#include "llvm/User.h"
|
|
|
|
class PointerType;
|
2002-04-28 04:45:05 +00:00
|
|
|
class Module;
|
2001-10-03 14:53:21 +00:00
|
|
|
|
|
|
|
class GlobalValue : public User {
|
|
|
|
GlobalValue(const GlobalValue &); // do not implement
|
2003-04-16 20:28:45 +00:00
|
|
|
public:
|
|
|
|
enum LinkageTypes {
|
|
|
|
ExternalLinkage, // Externally visible function
|
|
|
|
LinkOnceLinkage, // Keep one copy of named function when linking (inline)
|
|
|
|
AppendingLinkage, // Special purpose, only applies to global arrays
|
|
|
|
InternalLinkage // Rename collisions when linking (static functions)
|
|
|
|
};
|
2001-10-03 14:53:21 +00:00
|
|
|
protected:
|
2003-04-16 20:28:45 +00:00
|
|
|
GlobalValue(const Type *Ty, ValueTy vty, LinkageTypes linkage,
|
2002-01-20 22:54:45 +00:00
|
|
|
const std::string &name = "")
|
2003-04-16 20:28:45 +00:00
|
|
|
: User(Ty, vty, name), Linkage(linkage), Parent(0) {}
|
2001-10-03 19:28:15 +00:00
|
|
|
|
2003-04-16 20:28:45 +00:00
|
|
|
LinkageTypes Linkage; // The linkage of this global
|
2001-10-03 19:28:15 +00:00
|
|
|
Module *Parent;
|
2001-10-03 14:53:21 +00:00
|
|
|
public:
|
2001-10-03 19:28:15 +00:00
|
|
|
~GlobalValue() {}
|
2001-10-03 14:53:21 +00:00
|
|
|
|
2002-10-09 23:11:33 +00:00
|
|
|
/// getType - Global values are always pointers.
|
2001-10-03 14:53:21 +00:00
|
|
|
inline const PointerType *getType() const {
|
|
|
|
return (const PointerType*)User::getType();
|
|
|
|
}
|
|
|
|
|
2003-04-16 20:28:45 +00:00
|
|
|
bool hasExternalLinkage() const { return Linkage == ExternalLinkage; }
|
|
|
|
bool hasLinkOnceLinkage() const { return Linkage == LinkOnceLinkage; }
|
|
|
|
bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
|
|
|
|
bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
|
|
|
|
void setLinkage(LinkageTypes LT) { Linkage = LT; }
|
|
|
|
LinkageTypes getLinkage() const { return Linkage; }
|
2001-11-26 18:46:40 +00:00
|
|
|
|
2002-10-09 23:11:33 +00:00
|
|
|
/// isExternal - Return true if the primary definition of this global value is
|
|
|
|
/// outside of the current translation unit...
|
|
|
|
virtual bool isExternal() const = 0;
|
|
|
|
|
|
|
|
/// getParent - Get the module that this global value is contained inside
|
|
|
|
/// of...
|
2001-10-03 19:28:15 +00:00
|
|
|
inline Module *getParent() { return Parent; }
|
|
|
|
inline const Module *getParent() const { return Parent; }
|
|
|
|
|
2001-10-03 14:53:21 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const GlobalValue *T) { return true; }
|
|
|
|
static inline bool classof(const Value *V) {
|
2002-03-26 17:48:08 +00:00
|
|
|
return V->getValueType() == Value::FunctionVal ||
|
2001-10-03 14:53:21 +00:00
|
|
|
V->getValueType() == Value::GlobalVariableVal;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|