forked from OSchip/llvm-project
Fix several bugs relating to changes in the LLVM IR API or just outright
typos in the output. This is sufficient to get most of the llvm2cpp tests working again. llvm-svn: 35898
This commit is contained in:
parent
d73f84ed7b
commit
ff6e0eda94
|
@ -467,7 +467,7 @@ CppWriter::printTypeInternal(const Type* Ty) {
|
||||||
for (unsigned i = 0; i < PAL->size(); ++i) {
|
for (unsigned i = 0; i < PAL->size(); ++i) {
|
||||||
uint16_t index = PAL->getParamIndex(i);
|
uint16_t index = PAL->getParamIndex(i);
|
||||||
uint16_t attrs = PAL->getParamAttrs(index);
|
uint16_t attrs = PAL->getParamAttrs(index);
|
||||||
Out << typeName << "_PAL->addAttribute(" << index << ", 0";
|
Out << typeName << "_PAL->addAttributes(" << index << ", 0";
|
||||||
if (attrs & ParamAttr::SExt)
|
if (attrs & ParamAttr::SExt)
|
||||||
Out << " | ParamAttr::SExt";
|
Out << " | ParamAttr::SExt";
|
||||||
if (attrs & ParamAttr::ZExt)
|
if (attrs & ParamAttr::ZExt)
|
||||||
|
@ -492,7 +492,7 @@ CppWriter::printTypeInternal(const Type* Ty) {
|
||||||
Out << "_fwd";
|
Out << "_fwd";
|
||||||
Out << ",";
|
Out << ",";
|
||||||
nl(Out) << "/*Params=*/" << typeName << "_args,";
|
nl(Out) << "/*Params=*/" << typeName << "_args,";
|
||||||
nl(Out) << "/*isVarArg=*/" << (FT->isVarArg() ? "true" : "false") ;
|
nl(Out) << "/*isVarArg=*/" << (FT->isVarArg() ? "true," : "false,") ;
|
||||||
nl(Out) << "/*ParamAttrs=*/" << typeName << "_PAL" << ");";
|
nl(Out) << "/*ParamAttrs=*/" << typeName << "_PAL" << ");";
|
||||||
out();
|
out();
|
||||||
nl(Out);
|
nl(Out);
|
||||||
|
@ -563,10 +563,11 @@ CppWriter::printTypeInternal(const Type* Ty) {
|
||||||
// If the type had a name, make sure we recreate it.
|
// If the type had a name, make sure we recreate it.
|
||||||
const std::string* progTypeName =
|
const std::string* progTypeName =
|
||||||
findTypeName(TheModule->getTypeSymbolTable(),Ty);
|
findTypeName(TheModule->getTypeSymbolTable(),Ty);
|
||||||
if (progTypeName)
|
if (progTypeName) {
|
||||||
Out << "mod->addTypeName(\"" << *progTypeName << "\", "
|
Out << "mod->addTypeName(\"" << *progTypeName << "\", "
|
||||||
<< typeName << ");";
|
<< typeName << ");";
|
||||||
nl(Out);
|
nl(Out);
|
||||||
|
}
|
||||||
|
|
||||||
// Pop us off the type stack
|
// Pop us off the type stack
|
||||||
TypeStack.pop_back();
|
TypeStack.pop_back();
|
||||||
|
@ -693,7 +694,7 @@ void CppWriter::printConstant(const Constant *CV) {
|
||||||
}
|
}
|
||||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
|
||||||
Out << "ConstantInt* " << constName << " = ConstantInt::get("
|
Out << "ConstantInt* " << constName << " = ConstantInt::get("
|
||||||
<< "APInt(cast<IntegerTyp>(" << typeName << ")->getBitWidth(),"
|
<< "APInt(cast<IntegerType>(" << typeName << ")->getBitWidth(),"
|
||||||
<< " \"" << CI->getValue().toStringSigned(10) << "\", 10));";
|
<< " \"" << CI->getValue().toStringSigned(10) << "\", 10));";
|
||||||
} else if (isa<ConstantAggregateZero>(CV)) {
|
} else if (isa<ConstantAggregateZero>(CV)) {
|
||||||
Out << "ConstantAggregateZero* " << constName
|
Out << "ConstantAggregateZero* " << constName
|
||||||
|
@ -769,7 +770,8 @@ void CppWriter::printConstant(const Constant *CV) {
|
||||||
Out << "Constant* " << constName
|
Out << "Constant* " << constName
|
||||||
<< " = ConstantExpr::getGetElementPtr("
|
<< " = ConstantExpr::getGetElementPtr("
|
||||||
<< getCppName(CE->getOperand(0)) << ", "
|
<< getCppName(CE->getOperand(0)) << ", "
|
||||||
<< constName << "_indices);";
|
<< "&" << constName << "_indices[0], " << CE->getNumOperands() - 1
|
||||||
|
<< " );";
|
||||||
} else if (CE->isCast()) {
|
} else if (CE->isCast()) {
|
||||||
printConstant(CE->getOperand(0));
|
printConstant(CE->getOperand(0));
|
||||||
Out << "Constant* " << constName << " = ConstantExpr::getCast(";
|
Out << "Constant* " << constName << " = ConstantExpr::getCast(";
|
||||||
|
@ -1016,13 +1018,13 @@ CppWriter::printInstruction(const Instruction *I, const std::string& bbname) {
|
||||||
switch (I->getOpcode()) {
|
switch (I->getOpcode()) {
|
||||||
case Instruction::Ret: {
|
case Instruction::Ret: {
|
||||||
const ReturnInst* ret = cast<ReturnInst>(I);
|
const ReturnInst* ret = cast<ReturnInst>(I);
|
||||||
Out << "ReturnInst* " << iName << " = new ReturnInst("
|
Out << "new ReturnInst("
|
||||||
<< (ret->getReturnValue() ? opNames[0] + ", " : "") << bbname << ");";
|
<< (ret->getReturnValue() ? opNames[0] + ", " : "") << bbname << ");";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Instruction::Br: {
|
case Instruction::Br: {
|
||||||
const BranchInst* br = cast<BranchInst>(I);
|
const BranchInst* br = cast<BranchInst>(I);
|
||||||
Out << "BranchInst* " << iName << " = new BranchInst(" ;
|
Out << "new BranchInst(" ;
|
||||||
if (br->getNumOperands() == 3 ) {
|
if (br->getNumOperands() == 3 ) {
|
||||||
Out << opNames[0] << ", "
|
Out << opNames[0] << ", "
|
||||||
<< opNames[1] << ", "
|
<< opNames[1] << ", "
|
||||||
|
@ -1060,11 +1062,12 @@ CppWriter::printInstruction(const Instruction *I, const std::string& bbname) {
|
||||||
<< opNames[i] << ");";
|
<< opNames[i] << ");";
|
||||||
nl(Out);
|
nl(Out);
|
||||||
}
|
}
|
||||||
Out << "InvokeInst* " << iName << " = new InvokeInst("
|
Out << "InvokeInst *" << iName << " = new InvokeInst("
|
||||||
<< opNames[0] << ", "
|
<< opNames[0] << ", "
|
||||||
<< opNames[1] << ", "
|
<< opNames[1] << ", "
|
||||||
<< opNames[2] << ", "
|
<< opNames[2] << ", "
|
||||||
<< iName << "_params, \"";
|
<< "&" << iName << "_params[0], " << inv->getNumOperands() - 3
|
||||||
|
<< ", \"";
|
||||||
printEscapedString(inv->getName());
|
printEscapedString(inv->getName());
|
||||||
Out << "\", " << bbname << ");";
|
Out << "\", " << bbname << ");";
|
||||||
nl(Out) << iName << "->setCallingConv(";
|
nl(Out) << iName << "->setCallingConv(";
|
||||||
|
@ -1073,12 +1076,12 @@ CppWriter::printInstruction(const Instruction *I, const std::string& bbname) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Instruction::Unwind: {
|
case Instruction::Unwind: {
|
||||||
Out << "UnwindInst* " << iName << " = new UnwindInst("
|
Out << "new UnwindInst("
|
||||||
<< bbname << ");";
|
<< bbname << ");";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Instruction::Unreachable:{
|
case Instruction::Unreachable:{
|
||||||
Out << "UnreachableInst* " << iName << " = new UnreachableInst("
|
Out << "new UnreachableInst("
|
||||||
<< bbname << ");";
|
<< bbname << ");";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1234,7 +1237,8 @@ CppWriter::printInstruction(const Instruction *I, const std::string& bbname) {
|
||||||
nl(Out);
|
nl(Out);
|
||||||
}
|
}
|
||||||
Out << "Instruction* " << iName << " = new GetElementPtrInst("
|
Out << "Instruction* " << iName << " = new GetElementPtrInst("
|
||||||
<< opNames[0] << ", " << iName << "_indices";
|
<< opNames[0] << ", &" << iName << "_indices[0], "
|
||||||
|
<< gep->getNumOperands() - 1;
|
||||||
}
|
}
|
||||||
Out << ", \"";
|
Out << ", \"";
|
||||||
printEscapedString(gep->getName());
|
printEscapedString(gep->getName());
|
||||||
|
@ -1283,7 +1287,7 @@ CppWriter::printInstruction(const Instruction *I, const std::string& bbname) {
|
||||||
case Instruction::FPToSI: Out << "FPToSIInst"; break;
|
case Instruction::FPToSI: Out << "FPToSIInst"; break;
|
||||||
case Instruction::UIToFP: Out << "UIToFPInst"; break;
|
case Instruction::UIToFP: Out << "UIToFPInst"; break;
|
||||||
case Instruction::SIToFP: Out << "SIToFPInst"; break;
|
case Instruction::SIToFP: Out << "SIToFPInst"; break;
|
||||||
case Instruction::PtrToInt: Out << "PtrToInst"; break;
|
case Instruction::PtrToInt: Out << "PtrToIntInst"; break;
|
||||||
case Instruction::IntToPtr: Out << "IntToPtrInst"; break;
|
case Instruction::IntToPtr: Out << "IntToPtrInst"; break;
|
||||||
case Instruction::BitCast: Out << "BitCastInst"; break;
|
case Instruction::BitCast: Out << "BitCastInst"; break;
|
||||||
default: assert(!"Unreachable"); break;
|
default: assert(!"Unreachable"); break;
|
||||||
|
@ -1312,7 +1316,8 @@ CppWriter::printInstruction(const Instruction *I, const std::string& bbname) {
|
||||||
nl(Out);
|
nl(Out);
|
||||||
}
|
}
|
||||||
Out << "CallInst* " << iName << " = new CallInst("
|
Out << "CallInst* " << iName << " = new CallInst("
|
||||||
<< opNames[0] << ", " << iName << "_params, \"";
|
<< opNames[0] << ", &" << iName << "_params[0], "
|
||||||
|
<< call->getNumOperands() - 1 << ", \"";
|
||||||
} else if (call->getNumOperands() == 3) {
|
} else if (call->getNumOperands() == 3) {
|
||||||
Out << "CallInst* " << iName << " = new CallInst("
|
Out << "CallInst* " << iName << " = new CallInst("
|
||||||
<< opNames[0] << ", " << opNames[1] << ", " << opNames[2] << ", \"";
|
<< opNames[0] << ", " << opNames[1] << ", " << opNames[2] << ", \"";
|
||||||
|
@ -1664,6 +1669,7 @@ void CppWriter::printProgram(
|
||||||
Out << "#include <llvm/BasicBlock.h>\n";
|
Out << "#include <llvm/BasicBlock.h>\n";
|
||||||
Out << "#include <llvm/Instructions.h>\n";
|
Out << "#include <llvm/Instructions.h>\n";
|
||||||
Out << "#include <llvm/InlineAsm.h>\n";
|
Out << "#include <llvm/InlineAsm.h>\n";
|
||||||
|
Out << "#include <llvm/ParameterAttributes.h>\n";
|
||||||
Out << "#include <llvm/Support/MathExtras.h>\n";
|
Out << "#include <llvm/Support/MathExtras.h>\n";
|
||||||
Out << "#include <llvm/Pass.h>\n";
|
Out << "#include <llvm/Pass.h>\n";
|
||||||
Out << "#include <llvm/PassManager.h>\n";
|
Out << "#include <llvm/PassManager.h>\n";
|
||||||
|
@ -1679,7 +1685,7 @@ void CppWriter::printProgram(
|
||||||
Out << " std::cerr.flush();\n";
|
Out << " std::cerr.flush();\n";
|
||||||
Out << " std::cout.flush();\n";
|
Out << " std::cout.flush();\n";
|
||||||
Out << " PassManager PM;\n";
|
Out << " PassManager PM;\n";
|
||||||
Out << " PM.add(new PrintModulePass(&std::cout));\n";
|
Out << " PM.add(new PrintModulePass(&llvm::cout));\n";
|
||||||
Out << " PM.run(*Mod);\n";
|
Out << " PM.run(*Mod);\n";
|
||||||
Out << " return 0;\n";
|
Out << " return 0;\n";
|
||||||
Out << "}\n\n";
|
Out << "}\n\n";
|
||||||
|
@ -1693,31 +1699,20 @@ void CppWriter::printModule(
|
||||||
nl(Out) << "Module* " << fname << "() {";
|
nl(Out) << "Module* " << fname << "() {";
|
||||||
nl(Out,1) << "// Module Construction";
|
nl(Out,1) << "// Module Construction";
|
||||||
nl(Out) << "Module* mod = new Module(\"" << mName << "\");";
|
nl(Out) << "Module* mod = new Module(\"" << mName << "\");";
|
||||||
nl(Out) << "mod->setEndianness(";
|
|
||||||
switch (TheModule->getEndianness()) {
|
|
||||||
case Module::LittleEndian: Out << "Module::LittleEndian);"; break;
|
|
||||||
case Module::BigEndian: Out << "Module::BigEndian);"; break;
|
|
||||||
case Module::AnyEndianness:Out << "Module::AnyEndianness);"; break;
|
|
||||||
}
|
|
||||||
nl(Out) << "mod->setPointerSize(";
|
|
||||||
switch (TheModule->getPointerSize()) {
|
|
||||||
case Module::Pointer32: Out << "Module::Pointer32);"; break;
|
|
||||||
case Module::Pointer64: Out << "Module::Pointer64);"; break;
|
|
||||||
case Module::AnyPointerSize: Out << "Module::AnyPointerSize);"; break;
|
|
||||||
}
|
|
||||||
nl(Out);
|
|
||||||
if (!TheModule->getTargetTriple().empty()) {
|
if (!TheModule->getTargetTriple().empty()) {
|
||||||
Out << "mod->setTargetTriple(\"" << TheModule->getTargetTriple()
|
nl(Out) << "mod->setDataLayout(\"" << TheModule->getDataLayout() << "\");";
|
||||||
<< "\");";
|
}
|
||||||
nl(Out);
|
if (!TheModule->getTargetTriple().empty()) {
|
||||||
|
nl(Out) << "mod->setTargetTriple(\"" << TheModule->getTargetTriple()
|
||||||
|
<< "\");";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TheModule->getModuleInlineAsm().empty()) {
|
if (!TheModule->getModuleInlineAsm().empty()) {
|
||||||
Out << "mod->setModuleInlineAsm(\"";
|
nl(Out) << "mod->setModuleInlineAsm(\"";
|
||||||
printEscapedString(TheModule->getModuleInlineAsm());
|
printEscapedString(TheModule->getModuleInlineAsm());
|
||||||
Out << "\");";
|
Out << "\");";
|
||||||
nl(Out);
|
|
||||||
}
|
}
|
||||||
|
nl(Out);
|
||||||
|
|
||||||
// Loop over the dependent libraries and emit them.
|
// Loop over the dependent libraries and emit them.
|
||||||
Module::lib_iterator LI = TheModule->lib_begin();
|
Module::lib_iterator LI = TheModule->lib_begin();
|
||||||
|
|
Loading…
Reference in New Issue