static inline void RunOnModule(llvm::FunctionPassManager& pm, llvm::Module* m) { pm.doInitialization(); for (llvm::Module::iterator f = m->begin(), e = m->end(); f != e; ++f) pm.run(*f); pm.doFinalization(); }
void Codegen::emitCode(llvm::raw_ostream *os) { llvm::formatted_raw_ostream formattedOS; createPasses(); llvm::TargetMachine::CodeGenFileType cgft = llvm::TargetMachine::CGFT_AssemblyFile; switch (options.type) { case codegen::LLVM: formattedOS.setStream(*os, llvm::formatted_raw_ostream::PRESERVE_STREAM); modulePasses->add(llvm::createPrintModulePass(*os)); break; case codegen::BC: modulePasses->add(llvm::createBitcodeWriterPass(*os)); break; case codegen::ASM: break; case codegen::OBJ: cgft = llvm::TargetMachine::CGFT_ObjectFile; break; default: // screem break; } functionPasses->doInitialization(); for (llvm::Module::iterator I = llvmModule().begin(), E = llvmModule().end(); I != E; ++I) if (!I->isDeclaration()) functionPasses->run(*I); functionPasses->doFinalization(); modulePasses->run(llvmModule()); if (codegenPasses) { formattedOS.setStream(*os, llvm::formatted_raw_ostream::PRESERVE_STREAM); if (targetMachine()->addPassesToEmitFile(*codegenPasses, formattedOS, cgft)) { std::cout << "pass fail"; } codegenPasses->run(llvmModule()); } }