mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-03 11:24:18 +00:00
Remove gross "Operand" instance variable
Remove lots of unneccesary arguments to methods git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2574 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -469,10 +469,11 @@ namespace {
|
|||||||
return printTypeVarInt(Out, Ty, TypeNames, VariableName);
|
return printTypeVarInt(Out, Ty, TypeNames, VariableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ostream& printType(const Type *Ty) {
|
||||||
|
return printTypeInt(Out, Ty, TypeNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeOperand(const Value *Operand, bool PrintName = true);
|
||||||
ostream& printType(const Type *Ty, ostream &Out);
|
|
||||||
void writeOperand(const Value *Operand, ostream &Out,bool PrintName = true);
|
|
||||||
|
|
||||||
string getValueName(const Value *V);
|
string getValueName(const Value *V);
|
||||||
private :
|
private :
|
||||||
@ -540,7 +541,6 @@ namespace {
|
|||||||
CWriter& CW;
|
CWriter& CW;
|
||||||
SlotCalculator& Table;
|
SlotCalculator& Table;
|
||||||
ostream &Out;
|
ostream &Out;
|
||||||
const Value *Operand;
|
|
||||||
|
|
||||||
void outputLValue(Instruction *);
|
void outputLValue(Instruction *);
|
||||||
void printPhiFromNextBlock(TerminatorInst *tI, int indx);
|
void printPhiFromNextBlock(TerminatorInst *tI, int indx);
|
||||||
@ -585,7 +585,7 @@ void CInstPrintVisitor::printPhiFromNextBlock(TerminatorInst *tI, int indx) {
|
|||||||
if (incindex != -1) {
|
if (incindex != -1) {
|
||||||
//now we have to do the printing
|
//now we have to do the printing
|
||||||
outputLValue(pI);
|
outputLValue(pI);
|
||||||
CW.writeOperand(pI->getIncomingValue(incindex), Out);
|
CW.writeOperand(pI->getIncomingValue(incindex));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -598,9 +598,9 @@ void CInstPrintVisitor::printPhiFromNextBlock(TerminatorInst *tI, int indx) {
|
|||||||
void CInstPrintVisitor::visitCastInst(CastInst *I) {
|
void CInstPrintVisitor::visitCastInst(CastInst *I) {
|
||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
Out << "(";
|
Out << "(";
|
||||||
CW.printType(I->getType(), Out);
|
CW.printType(I->getType());
|
||||||
Out << ")";
|
Out << ")";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,11 +617,11 @@ void CInstPrintVisitor::visitCallInst(CallInst *I) {
|
|||||||
Out << CW.getValueName(I->getOperand(0)) << "(";
|
Out << CW.getValueName(I->getOperand(0)) << "(";
|
||||||
|
|
||||||
if (I->getNumOperands() != 0) {
|
if (I->getNumOperands() != 0) {
|
||||||
CW.writeOperand(I->getOperand(1), Out);
|
CW.writeOperand(I->getOperand(1));
|
||||||
|
|
||||||
for (unsigned op = 2, Eop = I->getNumOperands(); op != Eop; ++op) {
|
for (unsigned op = 2, Eop = I->getNumOperands(); op != Eop; ++op) {
|
||||||
Out << ", ";
|
Out << ", ";
|
||||||
CW.writeOperand(I->getOperand(op), Out);
|
CW.writeOperand(I->getOperand(op));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Out << ");\n";
|
Out << ");\n";
|
||||||
@ -633,7 +633,7 @@ void CInstPrintVisitor::visitCallInst(CallInst *I) {
|
|||||||
void CInstPrintVisitor::visitReturnInst(ReturnInst *I) {
|
void CInstPrintVisitor::visitReturnInst(ReturnInst *I) {
|
||||||
Out << " return ";
|
Out << " return ";
|
||||||
if (I->getNumOperands())
|
if (I->getNumOperands())
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,21 +641,21 @@ void CInstPrintVisitor::visitBranchInst(BranchInst *I) {
|
|||||||
TerminatorInst *tI = cast<TerminatorInst>(I);
|
TerminatorInst *tI = cast<TerminatorInst>(I);
|
||||||
if (I->isConditional()) {
|
if (I->isConditional()) {
|
||||||
Out << " if (";
|
Out << " if (";
|
||||||
CW.writeOperand(I->getCondition(), Out);
|
CW.writeOperand(I->getCondition());
|
||||||
Out << ") {\n";
|
Out << ") {\n";
|
||||||
printPhiFromNextBlock(tI,0);
|
printPhiFromNextBlock(tI,0);
|
||||||
Out << " goto ";
|
Out << " goto ";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
Out << " } else {\n";
|
Out << " } else {\n";
|
||||||
printPhiFromNextBlock(tI,1);
|
printPhiFromNextBlock(tI,1);
|
||||||
Out << " goto ";
|
Out << " goto ";
|
||||||
CW.writeOperand(I->getOperand(1), Out);
|
CW.writeOperand(I->getOperand(1));
|
||||||
Out << ";\n }\n";
|
Out << ";\n }\n";
|
||||||
} else {
|
} else {
|
||||||
printPhiFromNextBlock(tI,0);
|
printPhiFromNextBlock(tI,0);
|
||||||
Out << " goto ";
|
Out << " goto ";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
Out << "\n";
|
Out << "\n";
|
||||||
@ -672,21 +672,20 @@ void CInstPrintVisitor::visitInvokeInst(InvokeInst *I) {
|
|||||||
void CInstPrintVisitor::visitMallocInst(MallocInst *I) {
|
void CInstPrintVisitor::visitMallocInst(MallocInst *I) {
|
||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
Out << "(";
|
Out << "(";
|
||||||
CW.printType(I->getType()->getElementType(), Out);
|
CW.printType(I->getType()->getElementType());
|
||||||
Out << "*)malloc(sizeof(";
|
Out << "*)malloc(sizeof(";
|
||||||
CW.printTypeVar(I->getType()->getElementType(), "");
|
CW.printTypeVar(I->getType()->getElementType(), "");
|
||||||
Out << ")";
|
Out << ")";
|
||||||
|
|
||||||
if (I->isArrayAllocation()) {
|
if (I->isArrayAllocation()) {
|
||||||
Out << " * " ;
|
Out << " * " ;
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
}
|
}
|
||||||
Out << ");";
|
Out << ");";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInstPrintVisitor::visitAllocaInst(AllocaInst *I) {
|
void CInstPrintVisitor::visitAllocaInst(AllocaInst *I) {
|
||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
Operand = I->getNumOperands() ? I->getOperand(0) : 0;
|
|
||||||
string tempstr = "";
|
string tempstr = "";
|
||||||
Out << "(";
|
Out << "(";
|
||||||
CW.printTypeVar(I->getType(), tempstr);
|
CW.printTypeVar(I->getType(), tempstr);
|
||||||
@ -694,28 +693,27 @@ void CInstPrintVisitor::visitAllocaInst(AllocaInst *I) {
|
|||||||
CW.printTypeVar(cast<PointerType>(I->getType())->getElementType(),
|
CW.printTypeVar(cast<PointerType>(I->getType())->getElementType(),
|
||||||
tempstr);
|
tempstr);
|
||||||
Out << ")";
|
Out << ")";
|
||||||
if (I->getNumOperands()) {
|
if (I->isArrayAllocation()) {
|
||||||
Out << " * " ;
|
Out << " * " ;
|
||||||
CW.writeOperand(Operand, Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
}
|
}
|
||||||
Out << ");\n";
|
Out << ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInstPrintVisitor::visitFreeInst(FreeInst *I) {
|
void CInstPrintVisitor::visitFreeInst(FreeInst *I) {
|
||||||
Operand = I->getNumOperands() ? I->getOperand(0) : 0;
|
|
||||||
Out << "free(";
|
Out << "free(";
|
||||||
CW.writeOperand(Operand, Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ");\n";
|
Out << ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInstPrintVisitor::printIndexingExpr(MemAccessInst *MAI) {
|
void CInstPrintVisitor::printIndexingExpr(MemAccessInst *MAI) {
|
||||||
CW.writeOperand(MAI->getPointerOperand(), Out);
|
CW.writeOperand(MAI->getPointerOperand());
|
||||||
|
|
||||||
for (MemAccessInst::op_iterator I = MAI->idx_begin(), E = MAI->idx_end();
|
for (MemAccessInst::op_iterator I = MAI->idx_begin(), E = MAI->idx_end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
if ((*I)->getType() == Type::UIntTy) {
|
if ((*I)->getType() == Type::UIntTy) {
|
||||||
Out << "[";
|
Out << "[";
|
||||||
CW.writeOperand(*I, Out);
|
CW.writeOperand(*I);
|
||||||
Out << "]";
|
Out << "]";
|
||||||
} else {
|
} else {
|
||||||
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
||||||
@ -732,7 +730,7 @@ void CInstPrintVisitor::visitStoreInst(StoreInst *I) {
|
|||||||
Out << " ";
|
Out << " ";
|
||||||
printIndexingExpr(I);
|
printIndexingExpr(I);
|
||||||
Out << " = ";
|
Out << " = ";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,7 +744,7 @@ void CInstPrintVisitor::visitGetElementPtrInst(GetElementPtrInst *I) {
|
|||||||
void CInstPrintVisitor::visitNot(GenericUnaryInst *I) {
|
void CInstPrintVisitor::visitNot(GenericUnaryInst *I) {
|
||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
Out << "~";
|
Out << "~";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,12 +753,12 @@ void CInstPrintVisitor::visitBinaryOperator(Instruction *I) {
|
|||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
if (isa<PointerType>(I->getType())) {
|
if (isa<PointerType>(I->getType())) {
|
||||||
Out << "(";
|
Out << "(";
|
||||||
CW.printType(I->getType(), Out);
|
CW.printType(I->getType());
|
||||||
Out << ")";
|
Out << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isa<PointerType>(I->getType())) Out << "(long long)";
|
if (isa<PointerType>(I->getType())) Out << "(long long)";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
|
|
||||||
switch (I->getOpcode()) {
|
switch (I->getOpcode()) {
|
||||||
case Instruction::Add: Out << "+"; break;
|
case Instruction::Add: Out << "+"; break;
|
||||||
@ -783,7 +781,7 @@ void CInstPrintVisitor::visitBinaryOperator(Instruction *I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isa<PointerType>(I->getType())) Out << "(long long)";
|
if (isa<PointerType>(I->getType())) Out << "(long long)";
|
||||||
CW.writeOperand(I->getOperand(1), Out);
|
CW.writeOperand(I->getOperand(1));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -862,7 +860,7 @@ void CWriter::printGlobal(const GlobalVariable *GV) {
|
|||||||
|
|
||||||
if (GV->hasInitializer()) {
|
if (GV->hasInitializer()) {
|
||||||
Out << " = " ;
|
Out << " = " ;
|
||||||
writeOperand(GV->getInitializer(), Out, false);
|
writeOperand(GV->getInitializer(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
@ -922,7 +920,7 @@ void CWriter::printConstant(const Constant *CPV) {
|
|||||||
|
|
||||||
Out << " = ";
|
Out << " = ";
|
||||||
// Write the value out now...
|
// Write the value out now...
|
||||||
writeOperand(CPV, Out, false);
|
writeOperand(CPV, false);
|
||||||
|
|
||||||
Out << "\n";
|
Out << "\n";
|
||||||
}
|
}
|
||||||
@ -941,7 +939,7 @@ void CWriter::printFunctionSignature(const Function *F) {
|
|||||||
const FunctionType *FT = cast<FunctionType>(F->getFunctionType());
|
const FunctionType *FT = cast<FunctionType>(F->getFunctionType());
|
||||||
|
|
||||||
// Print out the return type and name...
|
// Print out the return type and name...
|
||||||
printType(F->getReturnType(), Out);
|
printType(F->getReturnType());
|
||||||
Out << " " << getValueName(F) << "(";
|
Out << " " << getValueName(F) << "(";
|
||||||
|
|
||||||
if (!F->isExternal()) {
|
if (!F->isExternal()) {
|
||||||
@ -953,7 +951,7 @@ void CWriter::printFunctionSignature(const Function *F) {
|
|||||||
FT->getParamTypes().begin(),
|
FT->getParamTypes().begin(),
|
||||||
E = FT->getParamTypes().end(); I != E; ++I) {
|
E = FT->getParamTypes().end(); I != E; ++I) {
|
||||||
if (I != FT->getParamTypes().begin()) Out << ", ";
|
if (I != FT->getParamTypes().begin()) Out << ", ";
|
||||||
printType(*I, Out);
|
printType(*I);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1027,15 +1025,7 @@ void CWriter::outputBasicBlock(const BasicBlock* BB) {
|
|||||||
CIPV.visit((BasicBlock *) BB);
|
CIPV.visit((BasicBlock *) BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// printType - Go to extreme measures to attempt to print out a short, symbolic
|
void CWriter::writeOperand(const Value *Operand, bool PrintName = true) {
|
||||||
// version of a type name.
|
|
||||||
ostream& CWriter::printType(const Type *Ty, ostream &Out) {
|
|
||||||
return printTypeInt(Out, Ty, TypeNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CWriter::writeOperand(const Value *Operand,
|
|
||||||
ostream &Out, bool PrintName = true) {
|
|
||||||
if (isa<GlobalValue>(Operand))
|
if (isa<GlobalValue>(Operand))
|
||||||
Out << "(&"; // Global values are references as their addresses by llvm
|
Out << "(&"; // Global values are references as their addresses by llvm
|
||||||
|
|
||||||
|
@ -469,10 +469,11 @@ namespace {
|
|||||||
return printTypeVarInt(Out, Ty, TypeNames, VariableName);
|
return printTypeVarInt(Out, Ty, TypeNames, VariableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ostream& printType(const Type *Ty) {
|
||||||
|
return printTypeInt(Out, Ty, TypeNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeOperand(const Value *Operand, bool PrintName = true);
|
||||||
ostream& printType(const Type *Ty, ostream &Out);
|
|
||||||
void writeOperand(const Value *Operand, ostream &Out,bool PrintName = true);
|
|
||||||
|
|
||||||
string getValueName(const Value *V);
|
string getValueName(const Value *V);
|
||||||
private :
|
private :
|
||||||
@ -540,7 +541,6 @@ namespace {
|
|||||||
CWriter& CW;
|
CWriter& CW;
|
||||||
SlotCalculator& Table;
|
SlotCalculator& Table;
|
||||||
ostream &Out;
|
ostream &Out;
|
||||||
const Value *Operand;
|
|
||||||
|
|
||||||
void outputLValue(Instruction *);
|
void outputLValue(Instruction *);
|
||||||
void printPhiFromNextBlock(TerminatorInst *tI, int indx);
|
void printPhiFromNextBlock(TerminatorInst *tI, int indx);
|
||||||
@ -585,7 +585,7 @@ void CInstPrintVisitor::printPhiFromNextBlock(TerminatorInst *tI, int indx) {
|
|||||||
if (incindex != -1) {
|
if (incindex != -1) {
|
||||||
//now we have to do the printing
|
//now we have to do the printing
|
||||||
outputLValue(pI);
|
outputLValue(pI);
|
||||||
CW.writeOperand(pI->getIncomingValue(incindex), Out);
|
CW.writeOperand(pI->getIncomingValue(incindex));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -598,9 +598,9 @@ void CInstPrintVisitor::printPhiFromNextBlock(TerminatorInst *tI, int indx) {
|
|||||||
void CInstPrintVisitor::visitCastInst(CastInst *I) {
|
void CInstPrintVisitor::visitCastInst(CastInst *I) {
|
||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
Out << "(";
|
Out << "(";
|
||||||
CW.printType(I->getType(), Out);
|
CW.printType(I->getType());
|
||||||
Out << ")";
|
Out << ")";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,11 +617,11 @@ void CInstPrintVisitor::visitCallInst(CallInst *I) {
|
|||||||
Out << CW.getValueName(I->getOperand(0)) << "(";
|
Out << CW.getValueName(I->getOperand(0)) << "(";
|
||||||
|
|
||||||
if (I->getNumOperands() != 0) {
|
if (I->getNumOperands() != 0) {
|
||||||
CW.writeOperand(I->getOperand(1), Out);
|
CW.writeOperand(I->getOperand(1));
|
||||||
|
|
||||||
for (unsigned op = 2, Eop = I->getNumOperands(); op != Eop; ++op) {
|
for (unsigned op = 2, Eop = I->getNumOperands(); op != Eop; ++op) {
|
||||||
Out << ", ";
|
Out << ", ";
|
||||||
CW.writeOperand(I->getOperand(op), Out);
|
CW.writeOperand(I->getOperand(op));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Out << ");\n";
|
Out << ");\n";
|
||||||
@ -633,7 +633,7 @@ void CInstPrintVisitor::visitCallInst(CallInst *I) {
|
|||||||
void CInstPrintVisitor::visitReturnInst(ReturnInst *I) {
|
void CInstPrintVisitor::visitReturnInst(ReturnInst *I) {
|
||||||
Out << " return ";
|
Out << " return ";
|
||||||
if (I->getNumOperands())
|
if (I->getNumOperands())
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,21 +641,21 @@ void CInstPrintVisitor::visitBranchInst(BranchInst *I) {
|
|||||||
TerminatorInst *tI = cast<TerminatorInst>(I);
|
TerminatorInst *tI = cast<TerminatorInst>(I);
|
||||||
if (I->isConditional()) {
|
if (I->isConditional()) {
|
||||||
Out << " if (";
|
Out << " if (";
|
||||||
CW.writeOperand(I->getCondition(), Out);
|
CW.writeOperand(I->getCondition());
|
||||||
Out << ") {\n";
|
Out << ") {\n";
|
||||||
printPhiFromNextBlock(tI,0);
|
printPhiFromNextBlock(tI,0);
|
||||||
Out << " goto ";
|
Out << " goto ";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
Out << " } else {\n";
|
Out << " } else {\n";
|
||||||
printPhiFromNextBlock(tI,1);
|
printPhiFromNextBlock(tI,1);
|
||||||
Out << " goto ";
|
Out << " goto ";
|
||||||
CW.writeOperand(I->getOperand(1), Out);
|
CW.writeOperand(I->getOperand(1));
|
||||||
Out << ";\n }\n";
|
Out << ";\n }\n";
|
||||||
} else {
|
} else {
|
||||||
printPhiFromNextBlock(tI,0);
|
printPhiFromNextBlock(tI,0);
|
||||||
Out << " goto ";
|
Out << " goto ";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
Out << "\n";
|
Out << "\n";
|
||||||
@ -672,21 +672,20 @@ void CInstPrintVisitor::visitInvokeInst(InvokeInst *I) {
|
|||||||
void CInstPrintVisitor::visitMallocInst(MallocInst *I) {
|
void CInstPrintVisitor::visitMallocInst(MallocInst *I) {
|
||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
Out << "(";
|
Out << "(";
|
||||||
CW.printType(I->getType()->getElementType(), Out);
|
CW.printType(I->getType()->getElementType());
|
||||||
Out << "*)malloc(sizeof(";
|
Out << "*)malloc(sizeof(";
|
||||||
CW.printTypeVar(I->getType()->getElementType(), "");
|
CW.printTypeVar(I->getType()->getElementType(), "");
|
||||||
Out << ")";
|
Out << ")";
|
||||||
|
|
||||||
if (I->isArrayAllocation()) {
|
if (I->isArrayAllocation()) {
|
||||||
Out << " * " ;
|
Out << " * " ;
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
}
|
}
|
||||||
Out << ");";
|
Out << ");";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInstPrintVisitor::visitAllocaInst(AllocaInst *I) {
|
void CInstPrintVisitor::visitAllocaInst(AllocaInst *I) {
|
||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
Operand = I->getNumOperands() ? I->getOperand(0) : 0;
|
|
||||||
string tempstr = "";
|
string tempstr = "";
|
||||||
Out << "(";
|
Out << "(";
|
||||||
CW.printTypeVar(I->getType(), tempstr);
|
CW.printTypeVar(I->getType(), tempstr);
|
||||||
@ -694,28 +693,27 @@ void CInstPrintVisitor::visitAllocaInst(AllocaInst *I) {
|
|||||||
CW.printTypeVar(cast<PointerType>(I->getType())->getElementType(),
|
CW.printTypeVar(cast<PointerType>(I->getType())->getElementType(),
|
||||||
tempstr);
|
tempstr);
|
||||||
Out << ")";
|
Out << ")";
|
||||||
if (I->getNumOperands()) {
|
if (I->isArrayAllocation()) {
|
||||||
Out << " * " ;
|
Out << " * " ;
|
||||||
CW.writeOperand(Operand, Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
}
|
}
|
||||||
Out << ");\n";
|
Out << ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInstPrintVisitor::visitFreeInst(FreeInst *I) {
|
void CInstPrintVisitor::visitFreeInst(FreeInst *I) {
|
||||||
Operand = I->getNumOperands() ? I->getOperand(0) : 0;
|
|
||||||
Out << "free(";
|
Out << "free(";
|
||||||
CW.writeOperand(Operand, Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ");\n";
|
Out << ");\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInstPrintVisitor::printIndexingExpr(MemAccessInst *MAI) {
|
void CInstPrintVisitor::printIndexingExpr(MemAccessInst *MAI) {
|
||||||
CW.writeOperand(MAI->getPointerOperand(), Out);
|
CW.writeOperand(MAI->getPointerOperand());
|
||||||
|
|
||||||
for (MemAccessInst::op_iterator I = MAI->idx_begin(), E = MAI->idx_end();
|
for (MemAccessInst::op_iterator I = MAI->idx_begin(), E = MAI->idx_end();
|
||||||
I != E; ++I)
|
I != E; ++I)
|
||||||
if ((*I)->getType() == Type::UIntTy) {
|
if ((*I)->getType() == Type::UIntTy) {
|
||||||
Out << "[";
|
Out << "[";
|
||||||
CW.writeOperand(*I, Out);
|
CW.writeOperand(*I);
|
||||||
Out << "]";
|
Out << "]";
|
||||||
} else {
|
} else {
|
||||||
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
||||||
@ -732,7 +730,7 @@ void CInstPrintVisitor::visitStoreInst(StoreInst *I) {
|
|||||||
Out << " ";
|
Out << " ";
|
||||||
printIndexingExpr(I);
|
printIndexingExpr(I);
|
||||||
Out << " = ";
|
Out << " = ";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,7 +744,7 @@ void CInstPrintVisitor::visitGetElementPtrInst(GetElementPtrInst *I) {
|
|||||||
void CInstPrintVisitor::visitNot(GenericUnaryInst *I) {
|
void CInstPrintVisitor::visitNot(GenericUnaryInst *I) {
|
||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
Out << "~";
|
Out << "~";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,12 +753,12 @@ void CInstPrintVisitor::visitBinaryOperator(Instruction *I) {
|
|||||||
outputLValue(I);
|
outputLValue(I);
|
||||||
if (isa<PointerType>(I->getType())) {
|
if (isa<PointerType>(I->getType())) {
|
||||||
Out << "(";
|
Out << "(";
|
||||||
CW.printType(I->getType(), Out);
|
CW.printType(I->getType());
|
||||||
Out << ")";
|
Out << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isa<PointerType>(I->getType())) Out << "(long long)";
|
if (isa<PointerType>(I->getType())) Out << "(long long)";
|
||||||
CW.writeOperand(I->getOperand(0), Out);
|
CW.writeOperand(I->getOperand(0));
|
||||||
|
|
||||||
switch (I->getOpcode()) {
|
switch (I->getOpcode()) {
|
||||||
case Instruction::Add: Out << "+"; break;
|
case Instruction::Add: Out << "+"; break;
|
||||||
@ -783,7 +781,7 @@ void CInstPrintVisitor::visitBinaryOperator(Instruction *I) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isa<PointerType>(I->getType())) Out << "(long long)";
|
if (isa<PointerType>(I->getType())) Out << "(long long)";
|
||||||
CW.writeOperand(I->getOperand(1), Out);
|
CW.writeOperand(I->getOperand(1));
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -862,7 +860,7 @@ void CWriter::printGlobal(const GlobalVariable *GV) {
|
|||||||
|
|
||||||
if (GV->hasInitializer()) {
|
if (GV->hasInitializer()) {
|
||||||
Out << " = " ;
|
Out << " = " ;
|
||||||
writeOperand(GV->getInitializer(), Out, false);
|
writeOperand(GV->getInitializer(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
@ -922,7 +920,7 @@ void CWriter::printConstant(const Constant *CPV) {
|
|||||||
|
|
||||||
Out << " = ";
|
Out << " = ";
|
||||||
// Write the value out now...
|
// Write the value out now...
|
||||||
writeOperand(CPV, Out, false);
|
writeOperand(CPV, false);
|
||||||
|
|
||||||
Out << "\n";
|
Out << "\n";
|
||||||
}
|
}
|
||||||
@ -941,7 +939,7 @@ void CWriter::printFunctionSignature(const Function *F) {
|
|||||||
const FunctionType *FT = cast<FunctionType>(F->getFunctionType());
|
const FunctionType *FT = cast<FunctionType>(F->getFunctionType());
|
||||||
|
|
||||||
// Print out the return type and name...
|
// Print out the return type and name...
|
||||||
printType(F->getReturnType(), Out);
|
printType(F->getReturnType());
|
||||||
Out << " " << getValueName(F) << "(";
|
Out << " " << getValueName(F) << "(";
|
||||||
|
|
||||||
if (!F->isExternal()) {
|
if (!F->isExternal()) {
|
||||||
@ -953,7 +951,7 @@ void CWriter::printFunctionSignature(const Function *F) {
|
|||||||
FT->getParamTypes().begin(),
|
FT->getParamTypes().begin(),
|
||||||
E = FT->getParamTypes().end(); I != E; ++I) {
|
E = FT->getParamTypes().end(); I != E; ++I) {
|
||||||
if (I != FT->getParamTypes().begin()) Out << ", ";
|
if (I != FT->getParamTypes().begin()) Out << ", ";
|
||||||
printType(*I, Out);
|
printType(*I);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1027,15 +1025,7 @@ void CWriter::outputBasicBlock(const BasicBlock* BB) {
|
|||||||
CIPV.visit((BasicBlock *) BB);
|
CIPV.visit((BasicBlock *) BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// printType - Go to extreme measures to attempt to print out a short, symbolic
|
void CWriter::writeOperand(const Value *Operand, bool PrintName = true) {
|
||||||
// version of a type name.
|
|
||||||
ostream& CWriter::printType(const Type *Ty, ostream &Out) {
|
|
||||||
return printTypeInt(Out, Ty, TypeNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CWriter::writeOperand(const Value *Operand,
|
|
||||||
ostream &Out, bool PrintName = true) {
|
|
||||||
if (isa<GlobalValue>(Operand))
|
if (isa<GlobalValue>(Operand))
|
||||||
Out << "(&"; // Global values are references as their addresses by llvm
|
Out << "(&"; // Global values are references as their addresses by llvm
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user