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/Bytecode | |
parent | 24a3cc4c83e5edb25fadf7b8979a26b4451795c6 (diff) |
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/Bytecode')
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 51 | ||||
-rw-r--r-- | lib/Bytecode/Writer/Writer.cpp | 27 |
2 files changed, 75 insertions, 3 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index ee6d9e6208c..f7606c6e5af 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -348,7 +348,7 @@ Constant* BytecodeReader::getConstantValue(unsigned TypeSlot, unsigned Slot) { /// with this method. The ValueTable argument must be one of ModuleValues /// or FunctionValues data members of this class. unsigned BytecodeReader::insertValue(Value *Val, unsigned type, - ValueTable &ValueTab) { + ValueTable &ValueTab) { if (ValueTab.size() <= type) ValueTab.resize(type+1); @@ -1855,7 +1855,7 @@ void BytecodeReader::ParseModuleGlobalInfo() { case 1: Func->setLinkage(Function::DLLImportLinkage); break; case 2: Func->setLinkage(Function::ExternalWeakLinkage); break; default: assert(0 && "Unsupported external linkage"); - } + } } Func->setCallingConv(CC-1); @@ -1919,6 +1919,53 @@ void BytecodeReader::ParseModuleGlobalInfo() { I->first->setSection(SectionNames[I->second-1]); } + if (At != BlockEnd) { + // Read aliases... + unsigned VarType = read_vbr_uint(); + while (VarType != Type::VoidTyID) { // List is terminated by Void + unsigned TypeSlotNo = VarType >> 2; + unsigned EncodedLinkage = VarType & 3; + unsigned AliaseeTypeSlotNo, AliaseeSlotNo; + + AliaseeTypeSlotNo = read_vbr_uint(); + AliaseeSlotNo = read_vbr_uint(); + + const Type *Ty = getType(TypeSlotNo); + if (!Ty) + error("Alias has no type! SlotNo=" + utostr(TypeSlotNo)); + + if (!isa<PointerType>(Ty)) + error("Alias not a pointer type! Ty= " + Ty->getDescription()); + + Value* V = getValue(AliaseeTypeSlotNo, AliaseeSlotNo, false); + if (!V) + error("Invalid aliasee! TypeSlotNo=" + utostr(AliaseeTypeSlotNo) + + " SlotNo=" + utostr(AliaseeSlotNo)); + if (!isa<GlobalValue>(V)) + error("Aliasee is not global value! SlotNo=" + utostr(AliaseeSlotNo)); + + GlobalValue::LinkageTypes Linkage; + switch (EncodedLinkage) { + case 0: + Linkage = GlobalValue::ExternalLinkage; + break; + case 1: + Linkage = GlobalValue::InternalLinkage; + break; + case 2: + Linkage = GlobalValue::WeakLinkage; + break; + default: + assert(0 && "Unsupported encoded alias linkage"); + } + + GlobalAlias *GA = new GlobalAlias(Ty, Linkage, "", + dyn_cast<GlobalValue>(V), TheModule); + insertValue(GA, TypeSlotNo, ModuleValues); + VarType = read_vbr_uint(); + } + } + // This is for future proofing... in the future extra fields may be added that // we don't understand, so we transparently ignore them. // diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp index 12724dd6bec..7295239fdd0 100644 --- a/lib/Bytecode/Writer/Writer.cpp +++ b/lib/Bytecode/Writer/Writer.cpp @@ -1088,9 +1088,34 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) { output_vbr((unsigned)SectionNames.size()); for (unsigned i = 0, e = SectionNames.size(); i != e; ++i) output(SectionNames[i]); - + // Output the inline asm string. output(M->getModuleInlineAsm()); + + // Output aliases + for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); + I != E; ++I) { + unsigned Slot = Table.getTypeSlot(I->getType()); + assert(((Slot << 2) >> 2) == Slot && "Slot # too big!"); + unsigned aliasLinkage = 0; + switch (I->getLinkage()) { + case GlobalValue::ExternalLinkage: + aliasLinkage = 0; + break; + case GlobalValue::InternalLinkage: + aliasLinkage = 1; + break; + case GlobalValue::WeakLinkage: + aliasLinkage = 2; + break; + default: + assert(0 && "Invalid alias linkage"); + } + output_vbr((Slot << 2) | aliasLinkage); + output_vbr(Table.getTypeSlot(I->getAliasee()->getType())); + output_vbr(Table.getSlot(I->getAliasee())); + } + output_typeid(Table.getTypeSlot(Type::VoidTy)); } void BytecodeWriter::outputInstructions(const Function *F) { |