}
}
-
+/// ParseBasicBlock - In LLVM 1.0 bytecode files, we used to output one
+/// basicblock at a time. This method reads in one of the basicblock packets.
BasicBlock *BytecodeParser::ParseBasicBlock(const unsigned char *&Buf,
const unsigned char *EndBuf,
unsigned BlockNo) {
return BB;
}
+
+/// ParseInstructionList - Parse all of the BasicBlock's & Instruction's in the
+/// body of a function. In post 1.0 bytecode files, we no longer emit basic
+/// block individually, in order to avoid per-basic-block overhead.
+unsigned BytecodeParser::ParseInstructionList(Function *F,
+ const unsigned char *&Buf,
+ const unsigned char *EndBuf) {
+ unsigned BlockNo = 0;
+ std::vector<unsigned> Args;
+
+ while (Buf < EndBuf) {
+ BasicBlock *BB;
+ if (ParsedBasicBlocks.size() == BlockNo)
+ ParsedBasicBlocks.push_back(BB = new BasicBlock());
+ else if (ParsedBasicBlocks[BlockNo] == 0)
+ BB = ParsedBasicBlocks[BlockNo] = new BasicBlock();
+ else
+ BB = ParsedBasicBlocks[BlockNo];
+ ++BlockNo;
+ F->getBasicBlockList().push_back(BB);
+
+ // Read instructions into this basic block until we get to a terminator
+ while (Buf < EndBuf && !BB->getTerminator())
+ ParseInstruction(Buf, EndBuf, Args, BB);
+
+ if (!BB->getTerminator())
+ throw std::string("Non-terminated basic block found!");
+ }
+
+ return BlockNo;
+}
+
void BytecodeParser::ParseSymbolTable(const unsigned char *&Buf,
const unsigned char *EndBuf,
SymbolTable *ST,
break;
}
+ case BytecodeFormat::InstructionList: {
+ BCR_TRACE(2, "BLOCK BytecodeFormat::InstructionList: {\n");
+ if (BlockNum) throw std::string("Already parsed basic blocks!");
+ BlockNum = ParseInstructionList(F, Buf, Buf+Size);
+ break;
+ }
+
case BytecodeFormat::SymbolTable:
BCR_TRACE(2, "BLOCK BytecodeFormat::SymbolTable: {\n");
ParseSymbolTable(Buf, Buf+Size, &F->getSymbolTable(), F);
BasicBlock *ParseBasicBlock(const unsigned char *&Buf,
const unsigned char *End,
unsigned BlockNo);
-
+ unsigned ParseInstructionList(Function *F, const unsigned char *&Buf,
+ const unsigned char *EndBuf);
+
void ParseInstruction(const unsigned char *&Buf, const unsigned char *End,
std::vector<unsigned> &Args, BasicBlock *BB);
// Output information about the constants in the function...
outputConstants(true);
- // Output basic block nodes...
- for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
- processBasicBlock(*I);
+ { // Output all of the instructions in the body of the function
+ BytecodeBlock ILBlock(BytecodeFormat::InstructionList, Out);
+
+ for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E;++BB)
+ for(BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I)
+ processInstruction(*I);
+ }
// If needed, output the symbol table for the function...
outputSymbolTable(F->getSymbolTable());
}
}
-
-void BytecodeWriter::processBasicBlock(const BasicBlock &BB) {
- BytecodeBlock FunctionBlock(BytecodeFormat::BasicBlock, Out);
- // Process all the instructions in the bb...
- for(BasicBlock::const_iterator I = BB.begin(), E = BB.end(); I != E; ++I)
- processInstruction(*I);
-}
-
void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
BytecodeBlock FunctionBlock(BytecodeFormat::SymbolTable, Out);