mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 22:28:18 +00:00
* Support writing GlobalVariables with info comments by them
* Print out prototypes correctly in cases that we weren't before * Use new style casts more * Support printing new invoke instruction git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@759 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#include "llvm/ConstPoolVals.h"
|
#include "llvm/ConstPoolVals.h"
|
||||||
#include "llvm/iOther.h"
|
#include "llvm/iOther.h"
|
||||||
#include "llvm/iMemory.h"
|
#include "llvm/iMemory.h"
|
||||||
|
#include "llvm/iTerminators.h"
|
||||||
#include "llvm/Support/STLExtras.h"
|
#include "llvm/Support/STLExtras.h"
|
||||||
#include "llvm/SymbolTable.h"
|
#include "llvm/SymbolTable.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -50,6 +51,8 @@ ostream &WriteAsOperand(ostream &Out, const Value *V, bool PrintType,
|
|||||||
Table = new SlotCalculator(I->getParent()->getParent(), true);
|
Table = new SlotCalculator(I->getParent()->getParent(), true);
|
||||||
} else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(V)) {
|
} else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(V)) {
|
||||||
Table = new SlotCalculator(BB->getParent(), true);
|
Table = new SlotCalculator(BB->getParent(), true);
|
||||||
|
} else if (const GlobalVariable *GV =dyn_cast<const GlobalVariable>(V)){
|
||||||
|
Table = new SlotCalculator(GV->getParent(), true);
|
||||||
} else if (const Method *Meth = dyn_cast<const Method>(V)) {
|
} else if (const Method *Meth = dyn_cast<const Method>(V)) {
|
||||||
Table = new SlotCalculator(Meth, true);
|
Table = new SlotCalculator(Meth, true);
|
||||||
} else if (const Module *Mod = dyn_cast<const Module>(V)) {
|
} else if (const Module *Mod = dyn_cast<const Module>(V)) {
|
||||||
@@ -95,6 +98,11 @@ private :
|
|||||||
void processInstruction(const Instruction *I);
|
void processInstruction(const Instruction *I);
|
||||||
|
|
||||||
void writeOperand(const Value *Op, bool PrintType, bool PrintName = true);
|
void writeOperand(const Value *Op, bool PrintType, bool PrintName = true);
|
||||||
|
|
||||||
|
// printInfoComment - Print a little comment after the instruction indicating
|
||||||
|
// which slot it occupies.
|
||||||
|
void printInfoComment(const Value *V);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -129,6 +137,7 @@ void AssemblyWriter::processGlobal(const GlobalVariable *GV) {
|
|||||||
if (GV->hasInitializer())
|
if (GV->hasInitializer())
|
||||||
writeOperand(GV->getInitializer(), false, false);
|
writeOperand(GV->getInitializer(), false, false);
|
||||||
|
|
||||||
|
printInfoComment(GV);
|
||||||
Out << endl;
|
Out << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,12 +196,22 @@ void AssemblyWriter::processMethod(const Method *M) {
|
|||||||
Table.incorporateMethod(M);
|
Table.incorporateMethod(M);
|
||||||
|
|
||||||
// Loop over the arguments, processing them...
|
// Loop over the arguments, processing them...
|
||||||
|
const MethodType *MT = cast<const MethodType>(M->getMethodType());
|
||||||
|
|
||||||
|
if (!M->isExternal()) {
|
||||||
for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
|
for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
|
||||||
bind_obj(this, &AssemblyWriter::processMethodArgument));
|
bind_obj(this, &AssemblyWriter::processMethodArgument));
|
||||||
|
} else {
|
||||||
|
// Loop over the arguments, processing them...
|
||||||
|
const MethodType *MT = cast<const MethodType>(M->getMethodType());
|
||||||
|
for (MethodType::ParamTypes::const_iterator I = MT->getParamTypes().begin(),
|
||||||
|
E = MT->getParamTypes().end(); I != E; ++I) {
|
||||||
|
if (I != MT->getParamTypes().begin()) Out << ", ";
|
||||||
|
Out << *I;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Finish printing arguments...
|
// Finish printing arguments...
|
||||||
const MethodType *MT = cast<const MethodType>(M->getMethodType());
|
|
||||||
if (MT->isVarArg()) {
|
if (MT->isVarArg()) {
|
||||||
if (MT->getParamTypes().size()) Out << ", ";
|
if (MT->getParamTypes().size()) Out << ", ";
|
||||||
Out << "..."; // Output varargs portion of signature!
|
Out << "..."; // Output varargs portion of signature!
|
||||||
@@ -253,6 +272,23 @@ void AssemblyWriter::processBasicBlock(const BasicBlock *BB) {
|
|||||||
bind_obj(this, &AssemblyWriter::processInstruction));
|
bind_obj(this, &AssemblyWriter::processInstruction));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// printInfoComment - Print a little comment after the instruction indicating
|
||||||
|
// which slot it occupies.
|
||||||
|
//
|
||||||
|
void AssemblyWriter::printInfoComment(const Value *V) {
|
||||||
|
if (V->getType() != Type::VoidTy) {
|
||||||
|
Out << "\t\t; <" << V->getType() << ">";
|
||||||
|
|
||||||
|
if (!V->hasName()) {
|
||||||
|
int Slot = Table.getValSlot(V); // Print out the def slot taken...
|
||||||
|
if (Slot >= 0) Out << ":" << Slot;
|
||||||
|
else Out << ":<badref>";
|
||||||
|
}
|
||||||
|
Out << "\t[#uses=" << V->use_size() << "]"; // Output # uses
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// processInstruction - This member is called for each Instruction in a methd.
|
// processInstruction - This member is called for each Instruction in a methd.
|
||||||
//
|
//
|
||||||
void AssemblyWriter::processInstruction(const Instruction *I) {
|
void AssemblyWriter::processInstruction(const Instruction *I) {
|
||||||
@@ -297,9 +333,9 @@ void AssemblyWriter::processInstruction(const Instruction *I) {
|
|||||||
writeOperand(I->getOperand(op ), false); Out << ",";
|
writeOperand(I->getOperand(op ), false); Out << ",";
|
||||||
writeOperand(I->getOperand(op+1), false); Out << " ]";
|
writeOperand(I->getOperand(op+1), false); Out << " ]";
|
||||||
}
|
}
|
||||||
} else if (I->getOpcode() == Instruction::Ret && !Operand) {
|
} else if (isa<ReturnInst>(I) && !Operand) {
|
||||||
Out << " void";
|
Out << " void";
|
||||||
} else if (I->getOpcode() == Instruction::Call) {
|
} else if (isa<CallInst>(I)) {
|
||||||
// TODO: Should try to print out short form of the Call instruction
|
// TODO: Should try to print out short form of the Call instruction
|
||||||
writeOperand(Operand, true);
|
writeOperand(Operand, true);
|
||||||
Out << "(";
|
Out << "(";
|
||||||
@@ -310,6 +346,21 @@ void AssemblyWriter::processInstruction(const Instruction *I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Out << " )";
|
Out << " )";
|
||||||
|
} else if (const InvokeInst *II = dyn_cast<InvokeInst>(I)) {
|
||||||
|
// TODO: Should try to print out short form of the Invoke instruction
|
||||||
|
writeOperand(Operand, true);
|
||||||
|
Out << "(";
|
||||||
|
if (I->getNumOperands() > 3) writeOperand(I->getOperand(3), true);
|
||||||
|
for (unsigned op = 4, Eop = I->getNumOperands(); op < Eop; ++op) {
|
||||||
|
Out << ",";
|
||||||
|
writeOperand(I->getOperand(op), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Out << " )\n\t\t\tto";
|
||||||
|
writeOperand(II->getNormalDest(), true);
|
||||||
|
Out << " except";
|
||||||
|
writeOperand(II->getExceptionalDest(), true);
|
||||||
|
|
||||||
} else if (I->getOpcode() == Instruction::Malloc ||
|
} else if (I->getOpcode() == Instruction::Malloc ||
|
||||||
I->getOpcode() == Instruction::Alloca) {
|
I->getOpcode() == Instruction::Alloca) {
|
||||||
Out << " " << cast<const PointerType>(I->getType())->getValueType();
|
Out << " " << cast<const PointerType>(I->getType())->getValueType();
|
||||||
@@ -317,7 +368,7 @@ void AssemblyWriter::processInstruction(const Instruction *I) {
|
|||||||
Out << ",";
|
Out << ",";
|
||||||
writeOperand(I->getOperand(0), true);
|
writeOperand(I->getOperand(0), true);
|
||||||
}
|
}
|
||||||
} else if (I->getOpcode() == Instruction::Cast) {
|
} else if (isa<CastInst>(I)) {
|
||||||
writeOperand(Operand, true);
|
writeOperand(Operand, true);
|
||||||
Out << " to " << I->getType();
|
Out << " to " << I->getType();
|
||||||
} else if (Operand) { // Print the normal way...
|
} else if (Operand) { // Print the normal way...
|
||||||
@@ -345,19 +396,7 @@ void AssemblyWriter::processInstruction(const Instruction *I) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print a little comment after the instruction indicating which slot it
|
printInfoComment(I);
|
||||||
// occupies.
|
|
||||||
//
|
|
||||||
if (I->getType() != Type::VoidTy) {
|
|
||||||
Out << "\t\t; <" << I->getType() << ">";
|
|
||||||
|
|
||||||
if (!I->hasName()) {
|
|
||||||
int Slot = Table.getValSlot(I); // Print out the def slot taken...
|
|
||||||
if (Slot >= 0) Out << ":" << Slot;
|
|
||||||
else Out << ":<badref>";
|
|
||||||
}
|
|
||||||
Out << "\t[#uses=" << I->use_size() << "]"; // Output # uses
|
|
||||||
}
|
|
||||||
Out << endl;
|
Out << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user