From 73a565af24005995cd002a041063d00939896719 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 4 Mar 2019 17:49:49 +0100 Subject: [PATCH] Create empty module and pass it to the JIT --- JitFromScratch.cpp | 7 +++++++ JitFromScratch.h | 10 ++++++++++ main.cpp | 13 +++++++++++++ 3 files changed, 30 insertions(+) diff --git a/JitFromScratch.cpp b/JitFromScratch.cpp index 5382c0d..3266ae1 100644 --- a/JitFromScratch.cpp +++ b/JitFromScratch.cpp @@ -1,7 +1,14 @@ #include "JitFromScratch.h" +#include + using namespace llvm; using namespace llvm::orc; JitFromScratch::JitFromScratch(ExitOnError ExitOnErr) : LLJIT(ExitOnErr(LLJITBuilder().create())) {} + +Error JitFromScratch::submitModule(std::unique_ptr M, + std::unique_ptr C) { + return LLJIT->addIRModule(ThreadSafeModule(std::move(M), std::move(C))); +} diff --git a/JitFromScratch.h b/JitFromScratch.h index 94ec822..be48e63 100644 --- a/JitFromScratch.h +++ b/JitFromScratch.h @@ -1,6 +1,10 @@ #pragma once #include +#include +#include +#include +#include #include @@ -14,6 +18,12 @@ class JitFromScratch { JitFromScratch(JitFromScratch &&) = delete; JitFromScratch &operator=(JitFromScratch &&) = delete; + llvm::DataLayout getDataLayout() const { + return LLJIT->getDataLayout(); + } + + llvm::Error submitModule(std::unique_ptr M, + std::unique_ptr C); private: std::unique_ptr LLJIT; }; diff --git a/main.cpp b/main.cpp index 46e44fc..74d7d82 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include @@ -12,6 +14,10 @@ using namespace llvm; +Expected codegenIR(Module &module, unsigned items) { + return "todo"; +} + // Determine the size of a C array at compile-time. template constexpr unsigned arrayElements(T (&)[sizeOfArray]) { @@ -60,6 +66,13 @@ int main(int argc, char **argv) { JitFromScratch Jit(ExitOnErr); + auto C = std::make_unique(); + auto M = std::make_unique("JitFromScratch", *C); + M->setDataLayout(Jit.getDataLayout()); + + ExitOnErr(codegenIR(*M, arrayElements(x))); + ExitOnErr(Jit.submitModule(std::move(M), std::move(C))); + int *z = integerDistances(x, y); outs() << format("Integer Distances: %d, %d, %d\n\n", z[0], z[1], z[2]);