diff options
author | Chris Lattner <sabre@nondot.org> | 2001-10-03 14:53:21 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-10-03 14:53:21 +0000 |
commit | ef9c23f2812322ae5c5f3140bfbcf92629d7ff47 (patch) | |
tree | c87db095661379f13a39bf1dee52af9ded6a23a3 /include | |
parent | da257162968820a7fd77a9df44e3f72090a7f13a (diff) | |
download | external_llvm-ef9c23f2812322ae5c5f3140bfbcf92629d7ff47.zip external_llvm-ef9c23f2812322ae5c5f3140bfbcf92629d7ff47.tar.gz external_llvm-ef9c23f2812322ae5c5f3140bfbcf92629d7ff47.tar.bz2 |
* Both Method & GlobalVariable now subclass GlobalValue
* ConstPoolPointerReference now represents a pointer to a GlobalValue
* Methods name references are now explicit pointers to methods
* Rename Value::GlobalVal to Value::GlobalVariableVal to avoid confusion
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@703 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Assembly/Writer.h | 3 | ||||
-rw-r--r-- | include/llvm/ConstPoolVals.h | 14 | ||||
-rw-r--r-- | include/llvm/Function.h | 9 | ||||
-rw-r--r-- | include/llvm/GlobalValue.h | 36 | ||||
-rw-r--r-- | include/llvm/GlobalVariable.h | 11 | ||||
-rw-r--r-- | include/llvm/Value.h | 13 | ||||
-rw-r--r-- | include/llvm/iOther.h | 2 |
7 files changed, 63 insertions, 25 deletions
diff --git a/include/llvm/Assembly/Writer.h b/include/llvm/Assembly/Writer.h index 020989e..bcda38b 100644 --- a/include/llvm/Assembly/Writer.h +++ b/include/llvm/Assembly/Writer.h @@ -97,7 +97,8 @@ inline ostream &operator<<(ostream &o, const Value *I) { case Value::InstructionVal:WriteToAssembly(cast<Instruction>(I) , o); break; case Value::BasicBlockVal: WriteToAssembly(cast<BasicBlock>(I) , o); break; case Value::MethodVal: WriteToAssembly(cast<Method>(I) , o); break; - case Value::GlobalVal: WriteToAssembly(cast<GlobalVariable>(I), o); break; + case Value::GlobalVariableVal: + WriteToAssembly(cast<GlobalVariable>(I), o); break; case Value::ModuleVal: WriteToAssembly(cast<Module>(I) , o); break; default: return o << "<unknown value type: " << I->getValueType() << ">"; } diff --git a/include/llvm/ConstPoolVals.h b/include/llvm/ConstPoolVals.h index a2cd143..68dd0a3 100644 --- a/include/llvm/ConstPoolVals.h +++ b/include/llvm/ConstPoolVals.h @@ -227,26 +227,26 @@ public: // ConstPoolPointerReference - a constant pointer value that is initialized to -// point to a global value, which is a constant. +// point to a global value, which lies at a constant, fixed address. // class ConstPoolPointerReference : public ConstPoolPointer { ConstPoolPointerReference(const ConstPoolPointerReference &); // DNI! protected: - ConstPoolPointerReference(GlobalVariable *GV); + ConstPoolPointerReference(GlobalValue *GV); ~ConstPoolPointerReference() {} public: - static ConstPoolPointerReference *get(GlobalVariable *GV) { + static ConstPoolPointerReference *get(GlobalValue *GV) { // FIXME: These should all be shared! return new ConstPoolPointerReference(GV); } virtual string getStrValue() const; - const GlobalVariable *getValue() const { - return cast<GlobalVariable>(Operands[0].get()); + const GlobalValue *getValue() const { + return cast<GlobalValue>(Operands[0].get()); } - GlobalVariable *getValue() { - return cast<GlobalVariable>(Operands[0].get()); + GlobalValue *getValue() { + return cast<GlobalValue>(Operands[0].get()); } }; diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 227ab53..d7c35b3 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -13,6 +13,7 @@ #include "llvm/SymTabValue.h" #include "llvm/BasicBlock.h" +#include "llvm/GlobalValue.h" class Instruction; class BasicBlock; @@ -20,7 +21,7 @@ class MethodArgument; class MethodType; class Module; -class Method : public Value, public SymTabValue { +class Method : public GlobalValue, public SymTabValue { public: typedef ValueHolder<MethodArgument, Method, Method> ArgumentListType; typedef ValueHolder<BasicBlock , Method, Method> BasicBlocksType; @@ -49,10 +50,8 @@ public: // Specialize setName to handle symbol table majik... virtual void setName(const string &name, SymbolTable *ST = 0); - const Type *getReturnType() const; - const MethodType *getType() const { - return (const MethodType*)Value::getType(); - } + const Type *getReturnType() const; // Return the return type of method + const MethodType *getMethodType() const; // Return the MethodType for me // Is the body of this method unknown? (the basic block list is empty if so) // this is true for external methods, defined as forward "declare"ations diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h new file mode 100644 index 0000000..394e2a2 --- /dev/null +++ b/include/llvm/GlobalValue.h @@ -0,0 +1,36 @@ +//===-- llvm/GlobalValue.h - Class to represent a global value ---*- C++ -*--=// +// +// This file is a common base class of all globally definable objects. As such, +// it is subclassed by GlobalVariable and by Method. This is used because you +// 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; + +class GlobalValue : public User { + GlobalValue(const GlobalValue &); // do not implement +protected: + GlobalValue(const Type *Ty, ValueTy vty, const string &name = "") + : User(Ty, vty, name) {} +public: + + // getType - Global values are always pointers (FIXME, methods should be ptrs too!) + inline const PointerType *getType() const { + return (const PointerType*)User::getType(); + } + + // 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) { + return V->getValueType() == Value::MethodVal || + V->getValueType() == Value::GlobalVariableVal; + } +}; + +#endif diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h index 3ee7f6d..4256ffe 100644 --- a/include/llvm/GlobalVariable.h +++ b/include/llvm/GlobalVariable.h @@ -13,12 +13,12 @@ #ifndef LLVM_GLOBAL_VARIABLE_H #define LLVM_GLOBAL_VARIABLE_H -#include "llvm/User.h" +#include "llvm/GlobalValue.h" class Module; class ConstPoolVal; class PointerType; -class GlobalVariable : public User { +class GlobalVariable : public GlobalValue { Module *Parent; // The module that contains this method friend class ValueHolder<GlobalVariable, Module, Module>; @@ -30,11 +30,6 @@ public: const string &Name = ""); ~GlobalVariable() {} - // getType - Global variables are always pointers - inline const PointerType *getType() const { - return (const PointerType*)User::getType(); - } - // Specialize setName to handle symbol table majik... virtual void setName(const string &name, SymbolTable *ST = 0); @@ -63,7 +58,7 @@ public: // Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const GlobalVariable *) { return true; } static inline bool classof(const Value *V) { - return V->getValueType() == Value::GlobalVal; + return V->getValueType() == Value::GlobalVariableVal; } }; diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 5716d29..255105f 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -22,6 +22,7 @@ class ConstPoolVal; class MethodArgument; class Instruction; class BasicBlock; +class GlobalValue; class Method; class GlobalVariable; class Module; @@ -43,7 +44,7 @@ public: InstructionVal, // This is an instance of Instruction BasicBlockVal, // This is an instance of BasicBlock MethodVal, // This is an instance of Method - GlobalVal, // This is an instance of GlobalVariable + GlobalVariableVal, // This is an instance of GlobalVariable ModuleVal, // This is an instance of Module }; @@ -256,10 +257,16 @@ template <> inline bool isa<Method, Value*>(Value *Val) { return Val->getValueType() == Value::MethodVal; } template <> inline bool isa<GlobalVariable, const Value*>(const Value *Val) { - return Val->getValueType() == Value::GlobalVal; + return Val->getValueType() == Value::GlobalVariableVal; } template <> inline bool isa<GlobalVariable, Value*>(Value *Val) { - return Val->getValueType() == Value::GlobalVal; + return Val->getValueType() == Value::GlobalVariableVal; +} +template <> inline bool isa<GlobalValue, const Value*>(const Value *Val) { + return isa<GlobalVariable>(Val) || isa<Method>(Val); +} +template <> inline bool isa<GlobalValue, Value*>(Value *Val) { + return isa<GlobalVariable>(Val) || isa<Method>(Val); } template <> inline bool isa<Module, const Value*>(const Value *Val) { return Val->getValueType() == Value::ModuleVal; diff --git a/include/llvm/iOther.h b/include/llvm/iOther.h index d0e0e2e..1351e71 100644 --- a/include/llvm/iOther.h +++ b/include/llvm/iOther.h @@ -150,7 +150,7 @@ public: return cast<Method>(Operands[0]); } Method *getCalledMethod() { - return cast<Method>(Operands[0]); + return cast<Method>(Operands[0]); } // Methods for support type inquiry through isa, cast, and dyn_cast: |