#include "llvm/Pass.h"
#include "llvm/PassManager.h"
#include "llvm/TypeSymbolTable.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/Streams.h"
#include "llvm/Target/TargetRegistry.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h"
#include <algorithm>
#include <set>
private:
void printLinkageType(GlobalValue::LinkageTypes LT);
void printVisibilityType(GlobalValue::VisibilityTypes VisTypes);
- void printCallingConv(unsigned cc);
+ void printCallingConv(CallingConv::ID cc);
void printEscapedString(const std::string& str);
void printCFP(const ConstantFP* CFP);
APFloat APF = APFloat(CFP->getValueAPF()); // copy
if (CFP->getType() == Type::getFloatTy(CFP->getContext()))
APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &ignored);
- Out << "ConstantFP::get(";
+ Out << "ConstantFP::get(getGlobalContext(), ";
Out << "APFloat(";
#if HAVE_PRINTF_A
char Buffer[100];
Out << ")";
}
- void CppWriter::printCallingConv(unsigned cc){
+ void CppWriter::printCallingConv(CallingConv::ID cc){
// Print the calling convention.
switch (cc) {
case CallingConv::C: Out << "CallingConv::C"; break;
Out << "GlobalValue::DLLExportLinkage"; break;
case GlobalValue::ExternalWeakLinkage:
Out << "GlobalValue::ExternalWeakLinkage"; break;
- case GlobalValue::GhostLinkage:
- Out << "GlobalValue::GhostLinkage"; break;
case GlobalValue::CommonLinkage:
Out << "GlobalValue::CommonLinkage"; break;
}
Out << "ConstantInt* " << constName
<< " = ConstantInt::get(getGlobalContext(), APInt("
<< cast<IntegerType>(CI->getType())->getBitWidth()
- << ", StringRef(\"" << constValue << "\"), 10));";
+ << ", StringRef(\"" << constValue << "\"), 10));";
} else if (isa<ConstantAggregateZero>(CV)) {
Out << "ConstantAggregateZero* " << constName
<< " = ConstantAggregateZero::get(" << typeName << ");";
<< getCppName(CE->getOperand(0)) << ", "
<< "&" << constName << "_indices[0], "
<< constName << "_indices.size()"
- << " );";
+ << ");";
} else if (CE->isCast()) {
printConstant(CE->getOperand(0));
Out << "Constant* " << constName << " = ConstantExpr::getCast(";
nl(Out);
printType(GV->getType());
if (GV->hasInitializer()) {
- Constant* Init = GV->getInitializer();
+ Constant *Init = GV->getInitializer();
printType(Init->getType());
- if (Function* F = dyn_cast<Function>(Init)) {
+ if (Function *F = dyn_cast<Function>(Init)) {
nl(Out)<< "/ Function Declarations"; nl(Out);
printFunctionHead(F);
} else if (GlobalVariable* gv = dyn_cast<GlobalVariable>(Init)) {
nl(Out) << "// Global Variable Declarations"; nl(Out);
printVariableHead(gv);
- } else {
- nl(Out) << "// Constant Definitions"; nl(Out);
- printConstant(gv);
- }
- if (GlobalVariable* gv = dyn_cast<GlobalVariable>(Init)) {
+
nl(Out) << "// Global Variable Definitions"; nl(Out);
printVariableBody(gv);
+ } else {
+ nl(Out) << "// Constant Definitions"; nl(Out);
+ printConstant(Init);
}
}
}
break;
}
case Instruction::Switch: {
- const SwitchInst* sw = cast<SwitchInst>(I);
+ const SwitchInst *SI = cast<SwitchInst>(I);
Out << "SwitchInst* " << iName << " = SwitchInst::Create("
<< opNames[0] << ", "
<< opNames[1] << ", "
- << sw->getNumCases() << ", " << bbname << ");";
+ << SI->getNumCases() << ", " << bbname << ");";
nl(Out);
- for (unsigned i = 2; i < sw->getNumOperands(); i += 2 ) {
+ for (unsigned i = 2; i != SI->getNumOperands(); i += 2) {
Out << iName << "->addCase("
<< opNames[i] << ", "
<< opNames[i+1] << ");";
}
break;
}
+ case Instruction::IndirectBr: {
+ const IndirectBrInst *IBI = cast<IndirectBrInst>(I);
+ Out << "IndirectBrInst *" << iName << " = IndirectBrInst::Create("
+ << opNames[0] << ", " << IBI->getNumDestinations() << ");";
+ nl(Out);
+ for (unsigned i = 1; i != IBI->getNumOperands(); ++i) {
+ Out << iName << "->addDestination(" << opNames[i] << ");";
+ nl(Out);
+ }
+ break;
+ }
case Instruction::Invoke: {
const InvokeInst* inv = cast<InvokeInst>(I);
Out << "std::vector<Value*> " << iName << "_params;";
break;
}
case Instruction::FCmp: {
- Out << "FCmpInst* " << iName << " = new FCmpInst(";
+ Out << "FCmpInst* " << iName << " = new FCmpInst(*" << bbname << ", ";
switch (cast<FCmpInst>(I)->getPredicate()) {
case FCmpInst::FCMP_FALSE: Out << "FCmpInst::FCMP_FALSE"; break;
case FCmpInst::FCMP_OEQ : Out << "FCmpInst::FCMP_OEQ"; break;
}
Out << ", " << opNames[0] << ", " << opNames[1] << ", \"";
printEscapedString(I->getName());
- Out << "\", " << bbname << ");";
+ Out << "\");";
break;
}
case Instruction::ICmp: {
Out << "\");";
break;
}
- case Instruction::Malloc: {
- const MallocInst* mallocI = cast<MallocInst>(I);
- Out << "MallocInst* " << iName << " = new MallocInst("
- << getCppName(mallocI->getAllocatedType()) << ", ";
- if (mallocI->isArrayAllocation())
- Out << opNames[0] << ", " ;
- Out << "\"";
- printEscapedString(mallocI->getName());
- Out << "\", " << bbname << ");";
- if (mallocI->getAlignment())
- nl(Out) << iName << "->setAlignment("
- << mallocI->getAlignment() << ");";
- break;
- }
- case Instruction::Free: {
- Out << "FreeInst* " << iName << " = new FreeInst("
- << getCppName(I->getOperand(0)) << ", " << bbname << ");";
- break;
- }
case Instruction::Alloca: {
const AllocaInst* allocaI = cast<AllocaInst>(I);
Out << "AllocaInst* " << iName << " = new AllocaInst("