Capturing the assembler from MCJIT

Is there a way to capture the assembler when using MCJIT? I was searching the lists and this popped up:

http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-March/047873.html

However this is quite elaborate and I was wondering if there's not an easier way to do this..?!

The setup I am using:

     llvm::InitializeNativeTarget();
     InitializeNativeTargetAsmPrinter(); // MCJIT
     InitializeNativeTargetAsmParser(); // MCJIT

     Mod = llvm::ParseIRFile( INPUT_FILE , Err, llvm::getGlobalContext());

     Mod->setTargetTriple(llvm::sys::getProcessTriple());

     llvm::EngineBuilder engineBuilder(Mod);
     engineBuilder.setEngineKind(llvm::EngineKind::JIT);
engineBuilder.setOptLevel(llvm::CodeGenOpt::Aggressive);
     TheExecutionEngine = engineBuilder.setUseMCJIT(true).create(); // MCJIT

     targetMachine = engineBuilder.selectTarget();

     mainFunc = Mod->getFunction("main");

     llvm::FunctionPassManager *functionPassManager;

     llvm::PassRegistry &registry = *llvm::PassRegistry::getPassRegistry();
     initializeScalarOpts(registry);

     functionPassManager = new llvm::FunctionPassManager(Mod);
functionPassManager->add(llvm::createVerifierPass(llvm::PrintMessageAction));
targetMachine->addAnalysisPasses(*functionPassManager);
     functionPassManager->add(new llvm::TargetLibraryInfo(llvm::Triple(Mod->getTargetTriple())));
     functionPassManager->add(new llvm::DataLayout(Mod));
functionPassManager->add(llvm::createBasicAliasAnalysisPass());
     functionPassManager->add(llvm::createLICMPass());
     functionPassManager->add(llvm::createGVNPass());
functionPassManager->add(llvm::createPromoteMemoryToRegisterPass());
functionPassManager->add(llvm::createLoopVectorizePass());
functionPassManager->add(llvm::createEarlyCSEPass());
functionPassManager->add(llvm::createInstructionCombiningPass());
functionPassManager->add(llvm::createCFGSimplificationPass());

     functionPassManager->run(*mainFunc);

     TheExecutionEngine->finalizeObject(); // MCJIT

     void *fptr = TheExecutionEngine->getPointerToFunction( mainFunc );

Thanks,
Frank

Frank,

Perhaps someone more knowledgeable will shoot this approach down, but what I do for this case is copy the module after running the function pass manager and pass it through:

const string extension = fileName.substr(fileName.find_last_of(".") + 1);
string errorInfo;

tool_output_file output(fileName.c_str(), errorInfo, sys::fs::F_None);
PassManager pm;
formatted_raw_ostream fos(output.os());
targetMachine->addPassesToEmitFile(pm, fos, extension == “s” ? TargetMachine::CGFT_AssemblyFile : TargetMachine::CGFT_ObjectFile);
pm.run(*module);

This code was basically taken from llc and I believe MCJIT does essentially (exactly?) the same thing.

-Josh