diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2007-04-25 14:27:10 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2007-04-25 14:27:10 +0000 |
commit | 8b0a8c84da2030ee8f4440d5b60a8033de691222 (patch) | |
tree | 7b780ed0cf12403faeac0e65fb16bca29fda5dbf /lib/VMCore/Globals.cpp | |
parent | 24a3cc4c83e5edb25fadf7b8979a26b4451795c6 (diff) | |
download | llvm-8b0a8c84da2030ee8f4440d5b60a8033de691222.tar.gz llvm-8b0a8c84da2030ee8f4440d5b60a8033de691222.tar.bz2 llvm-8b0a8c84da2030ee8f4440d5b60a8033de691222.tar.xz |
Implement aliases. This fixes PR1017 and it's dependent bugs. CFE part
will follow.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36435 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Globals.cpp')
-rw-r--r-- | lib/VMCore/Globals.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp index 61d9de3a23..c64b719095 100644 --- a/lib/VMCore/Globals.cpp +++ b/lib/VMCore/Globals.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "llvm/GlobalVariable.h" +#include "llvm/GlobalAlias.h" #include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/Support/LeakDetector.h" @@ -76,6 +77,7 @@ void GlobalValue::destroyConstant() { assert(0 && "You can't GV->destroyConstant()!"); abort(); } + //===----------------------------------------------------------------------===// // GlobalVariable Implementation //===----------------------------------------------------------------------===// @@ -120,7 +122,6 @@ GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link, Before->getParent()->getGlobalList().insert(Before, this); } - void GlobalVariable::setParent(Module *parent) { if (getParent()) LeakDetector::addGarbageObject(this); @@ -156,3 +157,45 @@ void GlobalVariable::replaceUsesOfWithOnConstant(Value *From, Value *To, // Okay, preconditions out of the way, replace the constant initializer. this->setOperand(0, cast<Constant>(To)); } + +//===----------------------------------------------------------------------===// +// GlobalAlias Implementation +//===----------------------------------------------------------------------===// + +GlobalAlias::GlobalAlias(const Type *Ty, LinkageTypes Link, + const std::string &Name, const GlobalValue* aliasee, + Module *ParentModule) + : GlobalValue(Ty, Value::GlobalAliasVal, 0, 0, + Link, Name), Aliasee(aliasee) { + LeakDetector::addGarbageObject(this); + + if (ParentModule) + ParentModule->getAliasList().push_back(this); +} + +void GlobalAlias::setParent(Module *parent) { + if (getParent()) + LeakDetector::addGarbageObject(this); + Parent = parent; + if (getParent()) + LeakDetector::removeGarbageObject(this); +} + +void GlobalAlias::removeFromParent() { + getParent()->getAliasList().remove(this); +} + +void GlobalAlias::eraseFromParent() { + getParent()->getAliasList().erase(this); +} + +bool GlobalAlias::isDeclaration() const { + return (Aliasee && Aliasee->isDeclaration()); +} + +void GlobalAlias::setAliasee(const GlobalValue *GV) +{ + // FIXME: Some checks? + Aliasee = GV; +} + |