aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode/Reader/InstructionReader.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-08 21:10:27 +0000
committerChris Lattner <sabre@nondot.org>2001-07-08 21:10:27 +0000
commit027dcc5b2249bc260f8bbf3fe5f6ce774054e671 (patch)
tree14f209003a2776cd602dbbb9eeeee56ab29b642c /lib/Bytecode/Reader/InstructionReader.cpp
parent71496b3b50cfcba84eb4acd988ce88a4463e4515 (diff)
Implemented shl, shl, & load instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bytecode/Reader/InstructionReader.cpp')
-rw-r--r--lib/Bytecode/Reader/InstructionReader.cpp87
1 files changed, 71 insertions, 16 deletions
diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp
index d08d19b6bd..9dc5c6fc3d 100644
--- a/lib/Bytecode/Reader/InstructionReader.cpp
+++ b/lib/Bytecode/Reader/InstructionReader.cpp
@@ -105,10 +105,15 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
getValue(Raw.Ty, Raw.Arg1),
getValue(Raw.Ty, Raw.Arg2));
return false;
- } else if (Raw.Opcode == Instruction::Cast) {
+ }
+
+ Value *V;
+ switch (Raw.Opcode) {
+ case Instruction::Cast:
Res = new CastInst(getValue(Raw.Ty, Raw.Arg1), getType(Raw.Arg2));
return false;
- } else if (Raw.Opcode == Instruction::PHINode) {
+
+ case Instruction::PHINode: {
PHINode *PN = new PHINode(Raw.Ty);
switch (Raw.NumOperands) {
case 0:
@@ -137,13 +142,23 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
}
Res = PN;
return false;
- } else if (Raw.Opcode == Instruction::Ret) {
+ }
+
+ case Instruction::Shl:
+ case Instruction::Shr:
+ Res = new ShiftInst((Instruction::OtherOps)Raw.Opcode,
+ getValue(Raw.Ty, Raw.Arg1),
+ getValue(Type::UByteTy, Raw.Arg2));
+ return false;
+ case Instruction::Ret:
if (Raw.NumOperands == 0) {
Res = new ReturnInst(); return false;
} else if (Raw.NumOperands == 1) {
Res = new ReturnInst(getValue(Raw.Ty, Raw.Arg1)); return false;
}
- } else if (Raw.Opcode == Instruction::Br) {
+ break;
+
+ case Instruction::Br:
if (Raw.NumOperands == 1) {
Res = new BranchInst((BasicBlock*)getValue(Type::LabelTy, Raw.Arg1));
return false;
@@ -153,7 +168,9 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
getValue(Type::BoolTy , Raw.Arg3));
return false;
}
- } else if (Raw.Opcode == Instruction::Switch) {
+ break;
+
+ case Instruction::Switch: {
SwitchInst *I =
new SwitchInst(getValue(Raw.Ty, Raw.Arg1),
(BasicBlock*)getValue(Type::LabelTy, Raw.Arg2));
@@ -173,7 +190,9 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
delete Raw.VarArgs;
return false;
- } else if (Raw.Opcode == Instruction::Call) {
+ }
+
+ case Instruction::Call: {
Method *M = (Method*)getValue(Raw.Ty, Raw.Arg1);
if (M == 0) return true;
@@ -204,22 +223,58 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
Res = new CallInst(M, Params);
return false;
- } else if (Raw.Opcode == Instruction::Malloc) {
+ }
+ case Instruction::Malloc:
if (Raw.NumOperands > 2) return true;
- Value *Sz = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
- Res = new MallocInst(Raw.Ty, Sz);
+ V = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
+ Res = new MallocInst(Raw.Ty, V);
return false;
- } else if (Raw.Opcode == Instruction::Alloca) {
+
+ case Instruction::Alloca:
if (Raw.NumOperands > 2) return true;
- Value *Sz = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
- Res = new AllocaInst(Raw.Ty, Sz);
+ V = Raw.NumOperands ? getValue(Type::UIntTy, Raw.Arg1) : 0;
+ Res = new AllocaInst(Raw.Ty, V);
+ return false;
+
+ case Instruction::Free:
+ V = getValue(Raw.Ty, Raw.Arg1);
+ if (!V->getType()->isPointerType()) return true;
+ Res = new FreeInst(V);
return false;
- } else if (Raw.Opcode == Instruction::Free) {
- Value *Val = getValue(Raw.Ty, Raw.Arg1);
- if (!Val->getType()->isPointerType()) return true;
- Res = new FreeInst(Val);
+
+ case Instruction::Load: {
+ vector<ConstPoolVal*> Idx;
+ switch (Raw.NumOperands) {
+ case 0: cerr << "Invalid load encountered!\n"; return true;
+ case 1: break;
+ case 2: V = getValue(Type::UByteTy, Raw.Arg2);
+ if (!V->isConstant()) return true;
+ Idx.push_back(V->castConstant());
+ break;
+ case 3: V = getValue(Type::UByteTy, Raw.Arg2);
+ if (!V->isConstant()) return true;
+ Idx.push_back(V->castConstant());
+ V = getValue(Type::UByteTy, Raw.Arg3);
+ if (!V->isConstant()) return true;
+ Idx.push_back(V->castConstant());
+ break;
+ default:
+ V = getValue(Type::UByteTy, Raw.Arg2);
+ if (!V->isConstant()) return true;
+ Idx.push_back(V->castConstant());
+ 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;
+ }
+ Res = new LoadInst(getValue(Raw.Ty, Raw.Arg1), Idx);
return false;
}
+ } // end switch(Raw.Opcode)
cerr << "Unrecognized instruction! " << Raw.Opcode
<< " ADDR = 0x" << (void*)Buf << endl;