mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-20 14:29:27 +00:00
Finalize bytecode dumping. The "handleFinish" method was getting called
too soon so the function data was not getting dumped (it was generated after the call handleFinish). Also cleaned up the output format for proper indentation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14627 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c156095b17
commit
5c15fe5cf8
@ -185,9 +185,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleGlobalInitializer(GlobalVariable* GV, Constant* CV) {
|
virtual void handleGlobalInitializer(GlobalVariable* GV, Constant* CV) {
|
||||||
dump << " Initializer: GV=";
|
dump << " Initializer: GV=";
|
||||||
GV->print(dump);
|
GV->print(dump);
|
||||||
dump << " CV=";
|
dump << " CV=";
|
||||||
CV->print(dump);
|
CV->print(dump);
|
||||||
dump << "\n";
|
dump << "\n";
|
||||||
}
|
}
|
||||||
@ -204,17 +204,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleCompactionTableBegin() {
|
virtual void handleCompactionTableBegin() {
|
||||||
dump << " BLOCK: CompactionTable {\n";
|
dump << " BLOCK: CompactionTable {\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) {
|
virtual void handleCompactionTablePlane( unsigned Ty, unsigned NumEntries) {
|
||||||
bca.numCmpctnTables++;
|
bca.numCmpctnTables++;
|
||||||
dump << " Plane: Ty=" << Ty << " Size=" << NumEntries << "\n";
|
dump << " Plane: Ty=" << Ty << " Size=" << NumEntries << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleCompactionTableType( unsigned i, unsigned TypSlot,
|
virtual void handleCompactionTableType( unsigned i, unsigned TypSlot,
|
||||||
const Type* Ty ) {
|
const Type* Ty ) {
|
||||||
dump << " Type: " << i << " Slot:" << TypSlot
|
dump << " Type: " << i << " Slot:" << TypSlot
|
||||||
<< " is " << Ty->getDescription() << "\n";
|
<< " is " << Ty->getDescription() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,13 +223,13 @@ public:
|
|||||||
unsigned TypSlot,
|
unsigned TypSlot,
|
||||||
unsigned ValSlot,
|
unsigned ValSlot,
|
||||||
const Type* Ty ) {
|
const Type* Ty ) {
|
||||||
dump << " Value: " << i << " TypSlot: " << TypSlot
|
dump << " Value: " << i << " TypSlot: " << TypSlot
|
||||||
<< " ValSlot:" << ValSlot << " is " << Ty->getDescription()
|
<< " ValSlot:" << ValSlot << " is " << Ty->getDescription()
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleCompactionTableEnd() {
|
virtual void handleCompactionTableEnd() {
|
||||||
dump << " } END BLOCK: CompactionTable\n";
|
dump << " } END BLOCK: CompactionTable\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleSymbolTableBegin(Function* CF, SymbolTable* ST) {
|
virtual void handleSymbolTableBegin(Function* CF, SymbolTable* ST) {
|
||||||
@ -260,9 +260,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleFunctionBegin(Function* Func, unsigned Size) {
|
virtual void handleFunctionBegin(Function* Func, unsigned Size) {
|
||||||
dump << "BLOCK: Function {\n";
|
dump << " BLOCK: Function {\n";
|
||||||
dump << " Linkage: " << Func->getLinkage() << "\n";
|
dump << " Linkage: " << Func->getLinkage() << "\n";
|
||||||
dump << " Type: " << Func->getType()->getDescription() << "\n";
|
dump << " Type: " << Func->getType()->getDescription() << "\n";
|
||||||
const FunctionType* FType =
|
const FunctionType* FType =
|
||||||
cast<FunctionType>(Func->getType()->getElementType());
|
cast<FunctionType>(Func->getType()->getElementType());
|
||||||
currFunc = &bca.FunctionInfo[Func];
|
currFunc = &bca.FunctionInfo[Func];
|
||||||
@ -284,7 +284,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleFunctionEnd( Function* Func) {
|
virtual void handleFunctionEnd( Function* Func) {
|
||||||
dump << "} END BLOCK: Function\n";
|
dump << " } END BLOCK: Function\n";
|
||||||
currFunc->density = double(currFunc->byteSize) /
|
currFunc->density = double(currFunc->byteSize) /
|
||||||
double(currFunc->numInstructions+currFunc->numBasicBlocks);
|
double(currFunc->numInstructions+currFunc->numBasicBlocks);
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleBasicBlockBegin( unsigned blocknum) {
|
virtual void handleBasicBlockBegin( unsigned blocknum) {
|
||||||
dump << " BLOCK: BasicBlock #" << blocknum << "{\n";
|
dump << " BLOCK: BasicBlock #" << blocknum << "{\n";
|
||||||
bca.numBasicBlocks++;
|
bca.numBasicBlocks++;
|
||||||
bca.numValues++;
|
bca.numValues++;
|
||||||
if ( currFunc ) currFunc->numBasicBlocks++;
|
if ( currFunc ) currFunc->numBasicBlocks++;
|
||||||
@ -306,11 +306,12 @@ public:
|
|||||||
|
|
||||||
virtual bool handleInstruction( unsigned Opcode, const Type* iType,
|
virtual bool handleInstruction( unsigned Opcode, const Type* iType,
|
||||||
std::vector<unsigned>& Operands, unsigned Size){
|
std::vector<unsigned>& Operands, unsigned Size){
|
||||||
dump << " INST: OpCode="
|
dump << " INST: OpCode="
|
||||||
<< Instruction::getOpcodeName(Opcode) << " Type="
|
<< Instruction::getOpcodeName(Opcode) << " Type=\""
|
||||||
<< iType->getDescription() << "\n";
|
<< iType->getDescription() << "\"";
|
||||||
for ( unsigned i = 0; i < Operands.size(); ++i )
|
for ( unsigned i = 0; i < Operands.size(); ++i )
|
||||||
dump << " Op#" << i << " Slot=" << Operands[i] << "\n";
|
dump << " Op(" << i << ")=Slot(" << Operands[i] << ")";
|
||||||
|
dump << "\n";
|
||||||
|
|
||||||
bca.numInstructions++;
|
bca.numInstructions++;
|
||||||
bca.numValues++;
|
bca.numValues++;
|
||||||
@ -327,7 +328,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleBasicBlockEnd(unsigned blocknum) {
|
virtual void handleBasicBlockEnd(unsigned blocknum) {
|
||||||
dump << " } END BLOCK: BasicBlock #" << blocknum << "{\n";
|
dump << " } END BLOCK: BasicBlock #" << blocknum << "{\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleGlobalConstantsBegin() {
|
virtual void handleGlobalConstantsBegin() {
|
||||||
|
@ -894,7 +894,6 @@ unsigned BytecodeReader::ParseInstructionList(Function* F) {
|
|||||||
BB = ParsedBasicBlocks[BlockNo] = new BasicBlock();
|
BB = ParsedBasicBlocks[BlockNo] = new BasicBlock();
|
||||||
else
|
else
|
||||||
BB = ParsedBasicBlocks[BlockNo];
|
BB = ParsedBasicBlocks[BlockNo];
|
||||||
if (Handler) Handler->handleBasicBlockEnd( BlockNo );
|
|
||||||
++BlockNo;
|
++BlockNo;
|
||||||
F->getBasicBlockList().push_back(BB);
|
F->getBasicBlockList().push_back(BB);
|
||||||
|
|
||||||
@ -904,6 +903,8 @@ unsigned BytecodeReader::ParseInstructionList(Function* F) {
|
|||||||
|
|
||||||
if (!BB->getTerminator())
|
if (!BB->getTerminator())
|
||||||
throw std::string("Non-terminated basic block found!");
|
throw std::string("Non-terminated basic block found!");
|
||||||
|
|
||||||
|
if (Handler) Handler->handleBasicBlockEnd( BlockNo-1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return BlockNo;
|
return BlockNo;
|
||||||
@ -1898,7 +1899,8 @@ void BytecodeReader::ParseModule() {
|
|||||||
/// and \p Length parameters.
|
/// and \p Length parameters.
|
||||||
void BytecodeReader::ParseBytecode(
|
void BytecodeReader::ParseBytecode(
|
||||||
BufPtr Buf, unsigned Length,
|
BufPtr Buf, unsigned Length,
|
||||||
const std::string &ModuleID) {
|
const std::string &ModuleID,
|
||||||
|
bool processFunctions) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
At = MemStart = BlockStart = Buf;
|
At = MemStart = BlockStart = Buf;
|
||||||
@ -1934,14 +1936,19 @@ void BytecodeReader::ParseBytecode(
|
|||||||
// Parse the module contents
|
// Parse the module contents
|
||||||
this->ParseModule();
|
this->ParseModule();
|
||||||
|
|
||||||
// Tell the handler we're done
|
|
||||||
if (Handler) Handler->handleModuleEnd(ModuleID);
|
|
||||||
|
|
||||||
// Check for missing functions
|
// Check for missing functions
|
||||||
if ( hasFunctions() )
|
if ( hasFunctions() )
|
||||||
throw std::string("Function expected, but bytecode stream ended!");
|
throw std::string("Function expected, but bytecode stream ended!");
|
||||||
|
|
||||||
// Tell the handler we're
|
// Process all the function bodies now, if requested
|
||||||
|
if ( processFunctions )
|
||||||
|
ParseAllFunctionBodies();
|
||||||
|
|
||||||
|
// Tell the handler we're done with the module
|
||||||
|
if (Handler)
|
||||||
|
Handler->handleModuleEnd(ModuleID);
|
||||||
|
|
||||||
|
// Tell the handler we're finished the parse
|
||||||
if (Handler) Handler->handleFinish();
|
if (Handler) Handler->handleFinish();
|
||||||
|
|
||||||
} catch (std::string& errstr ) {
|
} catch (std::string& errstr ) {
|
||||||
|
@ -127,9 +127,10 @@ public:
|
|||||||
public:
|
public:
|
||||||
/// @brief Main interface to parsing a bytecode buffer.
|
/// @brief Main interface to parsing a bytecode buffer.
|
||||||
void ParseBytecode(
|
void ParseBytecode(
|
||||||
const unsigned char *Buf, ///< Beginning of the bytecode buffer
|
const unsigned char *Buf, ///< Beginning of the bytecode buffer
|
||||||
unsigned Length, ///< Length of the bytecode buffer
|
unsigned Length, ///< Length of the bytecode buffer
|
||||||
const std::string &ModuleID ///< An identifier for the module constructed.
|
const std::string &ModuleID, ///< An identifier for the module constructed.
|
||||||
|
bool processFunctions=false ///< Process all function bodies fully.
|
||||||
);
|
);
|
||||||
|
|
||||||
/// @brief Parse all function bodies
|
/// @brief Parse all function bodies
|
||||||
|
@ -58,7 +58,7 @@ BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Parse the bytecode we mmapped in
|
// Parse the bytecode we mmapped in
|
||||||
ParseBytecode(Buffer, Length, Filename);
|
ParseBytecode(Buffer, Length, Filename, H != 0);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
UnmapFileFromAddressSpace(Buffer, Length);
|
UnmapFileFromAddressSpace(Buffer, Length);
|
||||||
throw;
|
throw;
|
||||||
@ -114,7 +114,7 @@ BytecodeBufferReader::BytecodeBufferReader(const unsigned char *Buf,
|
|||||||
MustDelete = false;
|
MustDelete = false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ParseBytecode(ParseBegin, Length, ModuleID);
|
ParseBytecode(ParseBegin, Length, ModuleID, H != 0);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
if (MustDelete) delete [] Buffer;
|
if (MustDelete) delete [] Buffer;
|
||||||
throw;
|
throw;
|
||||||
@ -163,7 +163,7 @@ BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H )
|
|||||||
throw std::string("Standard Input empty!");
|
throw std::string("Standard Input empty!");
|
||||||
|
|
||||||
FileBuf = &FileData[0];
|
FileBuf = &FileData[0];
|
||||||
ParseBytecode(FileBuf, FileData.size(), "<stdin>");
|
ParseBytecode(FileBuf, FileData.size(), "<stdin>", H != 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user