From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/src/llvmtranslate/tasks.cc | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tiger-compiler/src/llvmtranslate/tasks.cc (limited to 'tiger-compiler/src/llvmtranslate/tasks.cc') diff --git a/tiger-compiler/src/llvmtranslate/tasks.cc b/tiger-compiler/src/llvmtranslate/tasks.cc new file mode 100644 index 0000000..09f865c --- /dev/null +++ b/tiger-compiler/src/llvmtranslate/tasks.cc @@ -0,0 +1,64 @@ +/** + ** \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 -- cgit v1.2.3