/** ** \file llvmtranslate/tasks.cc ** \brief LLVM Translate tasks. */ #include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #include // LLVM_VERSION_* #include #include #include #include #include // llvm::outs() #pragma GCC diagnostic pop #include #include #include #define DEFINE_TASKS 1 #include #undef DEFINE_TASKS namespace llvmtranslate::tasks { std::pair, std::unique_ptr> module = {nullptr, nullptr}; /// Translate the AST to LLVM IR. void llvm_compute() { module = translate(*ast::tasks::the_program); } /// Display the LLVM IR. void llvm_display() { // If the runtime has to be displayed, get the runtime module, // link it with the program module and print it. if (llvm_runtime_display_p) { auto runtime = runtime_get(*module.first); #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 7 auto link = llvm::Linker::LinkModules(module.second.get(), runtime.get()); #else auto link = llvm::Linker::linkModules(*module.second, std::move(runtime)); #endif (void)link; postcondition(!link); // Returns true on error } auto& out = llvm::outs(); llvm::PrintModulePass printer{out}; #if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 8 printer.run(*module.second); #else llvm::ModuleAnalysisManager dummy_mam; printer.run(*module.second, dummy_mam); #endif } } // namespace llvmtranslate::tasks