aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/2022-07-07-llvm-orc-jit/main.cc
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2023-12-19 18:53:31 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2023-12-19 18:54:35 +0100
commita599959a61e2a9ae313b851b2b63c0a2b97d3cb5 (patch)
treece0b3346b48df0926560c305394ff04b86fcccb3 /content/2022-07-07-llvm-orc-jit/main.cc
parent34fe7e1b93f73dc8ffb42cc172f4a9966453faa9 (diff)
downloadblog-a599959a61e2a9ae313b851b2b63c0a2b97d3cb5.tar.gz
blog-a599959a61e2a9ae313b851b2b63c0a2b97d3cb5.zip
llvm-orc-jit: migrate to llvm17
Diffstat (limited to 'content/2022-07-07-llvm-orc-jit/main.cc')
-rw-r--r--content/2022-07-07-llvm-orc-jit/main.cc27
1 files changed, 16 insertions, 11 deletions
diff --git a/content/2022-07-07-llvm-orc-jit/main.cc b/content/2022-07-07-llvm-orc-jit/main.cc
index 1631990..a6ee67b 100644
--- a/content/2022-07-07-llvm-orc-jit/main.cc
+++ b/content/2022-07-07-llvm-orc-jit/main.cc
@@ -2,13 +2,14 @@
#include "jit.h"
int main() {
- const char code[] = "extern void libc_puts(const char*);"
- "struct S { int a; int b; };"
- "static void init_a(struct S* s) { s->a = 1111; }"
- "static void init_b(struct S* s) { s->b = 2222; }"
- "void init(struct S* s) {"
- "init_a(s); init_b(s);"
- "libc_puts(\"libc_puts()\"); }";
+ const char code[] =
+ "extern void libc_puts(const char*);"
+ "struct S { int a; int b; };"
+ "static void init_a(struct S* s) { s->a = 1111; }"
+ "static void init_b(struct S* s) { s->b = 2222; }"
+ "void init(struct S* s) {"
+ "init_a(s); init_b(s);"
+ "libc_puts(\"libc_puts()\"); }";
auto R = cc::CCompiler().compile(code);
// Abort if compilation failed.
@@ -30,12 +31,12 @@ int main() {
}
if (auto ADDR = JIT->lookup("init")) {
- std::printf("JIT ADDR 0x%lx\n", (*ADDR).getAddress());
+ std::printf("JIT ADDR 0x%lx\n", (*ADDR).getAddress().getValue());
struct S {
int a, b;
} state = {0, 0};
- auto JIT_FN = (void (*)(struct S *))(*ADDR).getAddress();
+ auto JIT_FN = (*ADDR).getAddress().toPtr<void(struct S*)>();
std::printf("S { a=%d b=%d }\n", state.a, state.b);
JIT_FN(&state);
@@ -43,10 +44,14 @@ int main() {
}
// Remove jitted code tracked by this RT.
- (void)(*RT)->remove();
+ cantFail((*RT)->remove());
if (auto E = JIT->lookup("init").takeError()) {
- llvm::errs() << "Expected error, we dropped removed code tracked by RT and "
+ // In ERROR state, as expected, consume the error.
+ llvm::consumeError(std::move(E));
+ } else {
+ // In SUCCESS state, not expected as code was dropped.
+ llvm::errs() << "Expected error, we removed code tracked by RT and "
"hence 'init' should be "
"removed from the JIT!\n";
}