diff options
author | Chris Lattner <sabre@nondot.org> | 2001-07-08 23:22:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-07-08 23:22:50 +0000 |
commit | ab5ac6bb384ec1e4f1cbc4e0ad0fb32d39eb7ff3 (patch) | |
tree | 1f05b07519bbc5138edde0c8dc04302c47d1f987 /lib/Bytecode | |
parent | 0bd654a049490a56b6c39f56acf7c8e634085c23 (diff) |
Implementation of Store & GetElementPtr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode')
-rw-r--r-- | lib/Bytecode/Reader/InstructionReader.cpp | 37 | ||||
-rw-r--r-- | lib/Bytecode/Writer/InstructionWriter.cpp | 19 |
2 files changed, 49 insertions, 7 deletions
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp index 9dc5c6fc3d..3af40f2d81 100644 --- a/lib/Bytecode/Reader/InstructionReader.cpp +++ b/lib/Bytecode/Reader/InstructionReader.cpp @@ -242,7 +242,8 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, Res = new FreeInst(V); return false; - case Instruction::Load: { + case Instruction::Load: + case Instruction::GetElementPtr: { vector<ConstPoolVal*> Idx; switch (Raw.NumOperands) { case 0: cerr << "Invalid load encountered!\n"; return true; @@ -271,7 +272,39 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf, delete Raw.VarArgs; break; } - Res = new LoadInst(getValue(Raw.Ty, Raw.Arg1), Idx); + if (Raw.Opcode == Instruction::Load) + Res = new LoadInst(getValue(Raw.Ty, Raw.Arg1), Idx); + else if (Raw.Opcode == Instruction::GetElementPtr) + Res = new GetElementPtrInst(getValue(Raw.Ty, Raw.Arg1), Idx); + else + abort(); + return false; + } + case Instruction::Store: { + vector<ConstPoolVal*> Idx; + switch (Raw.NumOperands) { + case 0: + case 1: cerr << "Invalid store encountered!\n"; return true; + case 2: break; + case 3: V = getValue(Type::UByteTy, Raw.Arg3); + if (!V->isConstant()) return true; + Idx.push_back(V->castConstant()); + break; + default: + vector<unsigned> &args = *Raw.VarArgs; + for (unsigned i = 0, E = args.size(); i != E; ++i) { + V = getValue(Type::UByteTy, args[i]); + if (!V->isConstant()) return true; + Idx.push_back(V->castConstant()); + } + delete Raw.VarArgs; + break; + } + + const Type *ElType = StoreInst::getIndexedType(Raw.Ty, Idx); + if (ElType == 0) return true; + Res = new StoreInst(getValue(ElType, Raw.Arg1), getValue(Raw.Ty, Raw.Arg2), + Idx); return false; } } // end switch(Raw.Opcode) diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp index 34d95682bf..73969e65df 100644 --- a/lib/Bytecode/Writer/InstructionWriter.cpp +++ b/lib/Bytecode/Writer/InstructionWriter.cpp @@ -135,10 +135,19 @@ bool BytecodeWriter::processInstruction(const Instruction *I) { // the first param is actually interesting). But if we have no arguments // we take the type of the instruction itself. // - const Type *Ty = NumOperands ? I->getOperand(0)->getType() : I->getType(); - if (I->getOpcode() == Instruction::Malloc || - I->getOpcode() == Instruction::Alloca) + const Type *Ty; + switch (I->getOpcode()) { + case Instruction::Malloc: + case Instruction::Alloca: Ty = I->getType(); // Malloc & Alloca ALWAYS want to encode the return type + break; + case Instruction::Store: + Ty = I->getOperand(1)->getType(); // Encode the pointer type... + break; + default: // Otherwise use the default behavior... + Ty = NumOperands ? I->getOperand(0)->getType() : I->getType(); + break; + } unsigned Type; int Slot = Table.getValSlot(Ty); @@ -184,8 +193,8 @@ bool BytecodeWriter::processInstruction(const Instruction *I) { break; } - // If we weren't handled before here, we either have a large number of operands - // or a large operand index that we are refering to. + // If we weren't handled before here, we either have a large number of + // operands or a large operand index that we are refering to. outputInstructionFormat0(I, Table, Type, Out); return false; } |