aboutsummaryrefslogtreecommitdiff
path: root/lib/Bytecode
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/Reader.cpp5
-rw-r--r--lib/Bytecode/Writer/InstructionWriter.cpp34
-rw-r--r--lib/Bytecode/Writer/Writer.cpp42
-rw-r--r--lib/Bytecode/Writer/WriterInternals.h4
4 files changed, 40 insertions, 45 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index c4ab67f91b..f84ad565ca 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -18,7 +18,6 @@
#include "llvm/Constants.h"
#include "llvm/iPHINode.h"
#include "llvm/iOther.h"
-#include "llvm/Argument.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -312,7 +311,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
delete M; return failure(true); // Parse error... :(
}
- M->getBasicBlocks().push_back(BB);
+ M->getBasicBlockList().push_back(BB);
break;
}
@@ -368,7 +367,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
// If the method is empty, we don't need the method argument entries...
if (M->isExternal())
- M->getArgumentList().delete_all();
+ M->getArgumentList().clear();
DeclareNewGlobalValue(M, MethSlot);
diff --git a/lib/Bytecode/Writer/InstructionWriter.cpp b/lib/Bytecode/Writer/InstructionWriter.cpp
index 227980a75e..36414bea94 100644
--- a/lib/Bytecode/Writer/InstructionWriter.cpp
+++ b/lib/Bytecode/Writer/InstructionWriter.cpp
@@ -169,15 +169,15 @@ static void outputInstructionFormat3(const Instruction *I,
output(Bits, Out);
}
-void BytecodeWriter::processInstruction(const Instruction *I) {
- assert(I->getOpcode() < 64 && "Opcode too big???");
+void BytecodeWriter::processInstruction(const Instruction &I) {
+ assert(I.getOpcode() < 64 && "Opcode too big???");
- unsigned NumOperands = I->getNumOperands();
+ unsigned NumOperands = I.getNumOperands();
int MaxOpSlot = 0;
int Slots[3]; Slots[0] = (1 << 12)-1; // Marker to signify 0 operands
for (unsigned i = 0; i < NumOperands; ++i) {
- const Value *Def = I->getOperand(i);
+ const Value *Def = I.getOperand(i);
int slot = Table.getValSlot(Def);
assert(slot != -1 && "Broken bytecode!");
if (slot > MaxOpSlot) MaxOpSlot = slot;
@@ -191,17 +191,17 @@ void BytecodeWriter::processInstruction(const Instruction *I) {
// we take the type of the instruction itself.
//
const Type *Ty;
- switch (I->getOpcode()) {
+ switch (I.getOpcode()) {
case Instruction::Malloc:
case Instruction::Alloca:
- Ty = I->getType(); // Malloc & Alloca ALWAYS want to encode the return type
+ 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...
+ Ty = I.getOperand(1)->getType(); // Encode the pointer type...
assert(isa<PointerType>(Ty) && "Store to nonpointer type!?!?");
break;
default: // Otherwise use the default behavior...
- Ty = NumOperands ? I->getOperand(0)->getType() : I->getType();
+ Ty = NumOperands ? I.getOperand(0)->getType() : I.getType();
break;
}
@@ -219,20 +219,20 @@ void BytecodeWriter::processInstruction(const Instruction *I) {
if (isa<CastInst>(I)) {
// Cast has to encode the destination type as the second argument in the
// packet, or else we won't know what type to cast to!
- Slots[1] = Table.getValSlot(I->getType());
+ Slots[1] = Table.getValSlot(I.getType());
assert(Slots[1] != -1 && "Cast return type unknown?");
if (Slots[1] > MaxOpSlot) MaxOpSlot = Slots[1];
NumOperands++;
- } else if (const CallInst *CI = dyn_cast<CallInst>(I)) {// Handle VarArg calls
+ } else if (const CallInst *CI = dyn_cast<CallInst>(&I)){// Handle VarArg calls
const PointerType *Ty = cast<PointerType>(CI->getCalledValue()->getType());
if (cast<FunctionType>(Ty->getElementType())->isVarArg()) {
- outputInstrVarArgsCall(I, Table, Type, Out);
+ outputInstrVarArgsCall(CI, Table, Type, Out);
return;
}
- } else if (const InvokeInst *II = dyn_cast<InvokeInst>(I)) { // ... & Invokes
+ } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {// ... & Invokes
const PointerType *Ty = cast<PointerType>(II->getCalledValue()->getType());
if (cast<FunctionType>(Ty->getElementType())->isVarArg()) {
- outputInstrVarArgsCall(I, Table, Type, Out);
+ outputInstrVarArgsCall(II, Table, Type, Out);
return;
}
}
@@ -246,21 +246,21 @@ void BytecodeWriter::processInstruction(const Instruction *I) {
case 0:
case 1:
if (MaxOpSlot < (1 << 12)-1) { // -1 because we use 4095 to indicate 0 ops
- outputInstructionFormat1(I, Table, Slots, Type, Out);
+ outputInstructionFormat1(&I, Table, Slots, Type, Out);
return;
}
break;
case 2:
if (MaxOpSlot < (1 << 8)) {
- outputInstructionFormat2(I, Table, Slots, Type, Out);
+ outputInstructionFormat2(&I, Table, Slots, Type, Out);
return;
}
break;
case 3:
if (MaxOpSlot < (1 << 6)) {
- outputInstructionFormat3(I, Table, Slots, Type, Out);
+ outputInstructionFormat3(&I, Table, Slots, Type, Out);
return;
}
break;
@@ -268,5 +268,5 @@ void BytecodeWriter::processInstruction(const Instruction *I) {
// 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);
+ outputInstructionFormat0(&I, Table, Type, Out);
}
diff --git a/lib/Bytecode/Writer/Writer.cpp b/lib/Bytecode/Writer/Writer.cpp
index 145004b716..5545834ff7 100644
--- a/lib/Bytecode/Writer/Writer.cpp
+++ b/lib/Bytecode/Writer/Writer.cpp
@@ -21,9 +21,6 @@
#include "WriterInternals.h"
#include "llvm/Module.h"
-#include "llvm/GlobalVariable.h"
-#include "llvm/Function.h"
-#include "llvm/BasicBlock.h"
#include "llvm/SymbolTable.h"
#include "llvm/DerivedTypes.h"
#include "Support/STLExtras.h"
@@ -49,8 +46,8 @@ BytecodeWriter::BytecodeWriter(std::deque<unsigned char> &o, const Module *M)
outputModuleInfoBlock(M);
// Do the whole module now! Process each function at a time...
- for_each(M->begin(), M->end(),
- bind_obj(this, &BytecodeWriter::processMethod));
+ for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
+ processMethod(I);
// If needed, output the symbol table for the module...
if (M->hasSymbolTable())
@@ -112,19 +109,18 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
// Output the types for the global variables in the module...
for (Module::const_giterator I = M->gbegin(), End = M->gend(); I != End;++I) {
- const GlobalVariable *GV = *I;
- int Slot = Table.getValSlot(GV->getType());
+ int Slot = Table.getValSlot(I->getType());
assert(Slot != -1 && "Module global vars is broken!");
// Fields: bit0 = isConstant, bit1 = hasInitializer, bit2=InternalLinkage,
// bit3+ = slot#
- unsigned oSlot = ((unsigned)Slot << 3) | (GV->hasInternalLinkage() << 2) |
- (GV->hasInitializer() << 1) | GV->isConstant();
+ unsigned oSlot = ((unsigned)Slot << 3) | (I->hasInternalLinkage() << 2) |
+ (I->hasInitializer() << 1) | I->isConstant();
output_vbr(oSlot, Out);
// If we have an initializer, output it now.
- if (GV->hasInitializer()) {
- Slot = Table.getValSlot((Value*)GV->getInitializer());
+ if (I->hasInitializer()) {
+ Slot = Table.getValSlot((Value*)I->getInitializer());
assert(Slot != -1 && "No slot for global var initializer!");
output_vbr((unsigned)Slot, Out);
}
@@ -133,7 +129,7 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
// Output the types of the functions in this module...
for (Module::const_iterator I = M->begin(), End = M->end(); I != End; ++I) {
- int Slot = Table.getValSlot((*I)->getType());
+ int Slot = Table.getValSlot(I->getType());
assert(Slot != -1 && "Module const pool is broken!");
assert(Slot >= Type::FirstDerivedTyID && "Derived type not in range!");
output_vbr((unsigned)Slot, Out);
@@ -144,36 +140,36 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
align32(Out);
}
-void BytecodeWriter::processMethod(const Function *M) {
+void BytecodeWriter::processMethod(const Function *F) {
BytecodeBlock FunctionBlock(BytecodeFormat::Function, Out);
- output_vbr((unsigned)M->hasInternalLinkage(), Out);
+ output_vbr((unsigned)F->hasInternalLinkage(), Out);
// Only output the constant pool and other goodies if needed...
- if (!M->isExternal()) {
+ if (!F->isExternal()) {
// Get slot information about the function...
- Table.incorporateFunction(M);
+ Table.incorporateFunction(F);
// Output information about the constants in the function...
outputConstants(true);
// Output basic block nodes...
- for_each(M->begin(), M->end(),
- bind_obj(this, &BytecodeWriter::processBasicBlock));
+ for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
+ processBasicBlock(*I);
// If needed, output the symbol table for the function...
- if (M->hasSymbolTable())
- outputSymbolTable(*M->getSymbolTable());
+ if (F->hasSymbolTable())
+ outputSymbolTable(*F->getSymbolTable());
Table.purgeFunction();
}
}
-void BytecodeWriter::processBasicBlock(const BasicBlock *BB) {
+void BytecodeWriter::processBasicBlock(const BasicBlock &BB) {
BytecodeBlock FunctionBlock(BytecodeFormat::BasicBlock, Out);
// Process all the instructions in the bb...
- for_each(BB->begin(), BB->end(),
- bind_obj(this, &BytecodeWriter::processInstruction));
+ for(BasicBlock::const_iterator I = BB.begin(), E = BB.end(); I != E; ++I)
+ processInstruction(*I);
}
void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
diff --git a/lib/Bytecode/Writer/WriterInternals.h b/lib/Bytecode/Writer/WriterInternals.h
index bd4a328826..7b54a56497 100644
--- a/lib/Bytecode/Writer/WriterInternals.h
+++ b/lib/Bytecode/Writer/WriterInternals.h
@@ -27,8 +27,8 @@ public:
protected:
void outputConstants(bool isMethod);
void processMethod(const Function *F);
- void processBasicBlock(const BasicBlock *BB);
- void processInstruction(const Instruction *I);
+ void processBasicBlock(const BasicBlock &BB);
+ void processInstruction(const Instruction &I);
private :
inline void outputSignature() {