Loading...
Searching...
No Matches
Compiler.hpp
1#pragma once
2#include <JitCpp/ClangDriver.hpp>
3
4#include <QDebug>
5
6#include <llvm/ExecutionEngine/JITLink/JITLink.h>
7#include <llvm/ExecutionEngine/Orc/ExecutionUtils.h>
8#include <llvm/ExecutionEngine/Orc/LLJIT.h>
9#include <llvm/ExecutionEngine/Orc/ThreadSafeModule.h>
10
11namespace Jit
12{
14{
15 using ModulePtr_t = std::unique_ptr<llvm::Module>;
16
17public:
20
21 void compile(
22 const std::string& cppCode, const std::vector<std::string>& flags,
23 CompilerOptions opts, llvm::orc::ThreadSafeContext& context);
24
25 // Whether the executor is driven by an Orc Platform (orc_rt: native TLS, real
26 // static-init/atexit, and -- on COFF -- SEH/exception registration). Set at
27 // construction; on COFF the platform is mandatory.
28 bool m_useNativePlatform{};
29
30 template <class Signature_t>
31 llvm::Expected<std::function<Signature_t>> getFunction(std::string name)
32 {
33 auto& JIT = *m_jit;
34 // Look up the JIT'd code entry point.
35 auto EntrySym = JIT.lookup(name);
36 if(!EntrySym)
37 return EntrySym.takeError();
38
39 // Cast the entry point address to a function pointer.
40#if LLVM_VERSION_MAJOR <= 14
41 auto* Entry = (Signature_t*)EntrySym->getAddress();
42#else
43 auto* Entry = (Signature_t*)(*EntrySym).getValue();
44#endif
45 return std::function<Signature_t>(Entry);
46 }
47
48 const QString& errors() const noexcept
49 {
50 return m_errors;
51 }
52 std::unique_ptr<llvm::jitlink::JITLinkMemoryManager> m_memmgr;
53 ClangCC1Driver m_driver;
54 std::unique_ptr<llvm::orc::LLJIT> m_jit;
55
56 llvm::orc::MangleAndInterner m_mangler;
57
58 QString m_errors;
59
60 int m_atExitId{};
61};
62}
Definition ClangDriver.hpp:14
Definition Compiler.hpp:14
Definition JitOptions.hpp:7