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 --- .../src/llvmtranslate/libllvmtranslate.cc | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tiger-compiler/src/llvmtranslate/libllvmtranslate.cc (limited to 'tiger-compiler/src/llvmtranslate/libllvmtranslate.cc') diff --git a/tiger-compiler/src/llvmtranslate/libllvmtranslate.cc b/tiger-compiler/src/llvmtranslate/libllvmtranslate.cc new file mode 100644 index 0000000..b86b03a --- /dev/null +++ b/tiger-compiler/src/llvmtranslate/libllvmtranslate.cc @@ -0,0 +1,47 @@ +/** + ** \file llvmtranslate/libllvmtranslate.hh + ** \brief Public llvmtranslate module interface implementation. + **/ + +#include +#include +#include // program_name + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" + +#include +#include +#include +#include +#include // llvm::SMDiagnostic +#include +#include +#include +#include + +#pragma GCC diagnostic pop + +namespace llvmtranslate +{ + std::pair, std::unique_ptr> + translate(const ast::Ast& the_program) + { + auto ctx = std::make_unique(); + auto module = std::make_unique(program_name, *ctx); + + Translator translate{*module, collect_escapes(the_program)}; + translate(the_program); + + llvm::verifyModule(*module); + + return {std::move(ctx), std::move(module)}; + } + + std::unique_ptr runtime_get(llvm::LLVMContext& ctx) + { + llvm::SMDiagnostic diag; + return llvm::parseAssemblyString(runtime_string(), diag, ctx); + } + +} // namespace llvmtranslate -- cgit v1.2.3