diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/src/llvmtranslate/libllvmtranslate.cc | |
Diffstat (limited to 'tiger-compiler/src/llvmtranslate/libllvmtranslate.cc')
| -rw-r--r-- | tiger-compiler/src/llvmtranslate/libllvmtranslate.cc | 47 |
1 files changed, 47 insertions, 0 deletions
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 <ast/default-visitor.hh> +#include <ast/non-object-visitor.hh> +#include <common.hh> // program_name + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" + +#include <llvm/AsmParser/Parser.h> +#include <llvm/IR/LLVMContext.h> +#include <llvm/IR/Module.h> +#include <llvm/IR/Verifier.h> +#include <llvm/Support/SourceMgr.h> // llvm::SMDiagnostic +#include <llvmtranslate/escapes-collector.hh> +#include <llvmtranslate/fwd.hh> +#include <llvmtranslate/libllvmtranslate.hh> +#include <llvmtranslate/translator.hh> + +#pragma GCC diagnostic pop + +namespace llvmtranslate +{ + std::pair<std::unique_ptr<llvm::LLVMContext>, std::unique_ptr<llvm::Module>> + translate(const ast::Ast& the_program) + { + auto ctx = std::make_unique<llvm::LLVMContext>(); + auto module = std::make_unique<llvm::Module>(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<llvm::Module> runtime_get(llvm::LLVMContext& ctx) + { + llvm::SMDiagnostic diag; + return llvm::parseAssemblyString(runtime_string(), diag, ctx); + } + +} // namespace llvmtranslate |
