#include "serene/jit/jit.h"
#include <llvm-c/Core.h>
#include <llvm-c/Error.h>
#include <llvm-c/LLJIT.h>
#include <llvm-c/Support.h>
#include <llvm-c/Target.h>
#include <stdio.h>
#include "serene/rt/context.h"
#include "serene/rt/engine.h"
#include "serene/rt/mm/interface.h"
#include "serene/utils.h"
#include <string.h>
Go to the source code of this file.
◆ handle_error()
| static int handle_error |
( |
LLVMErrorRef | err | ) |
|
|
inlinestatic |
Definition at line 36 of file jit.c.
36 {
37
38 char *err_msg = LLVMGetErrorMessage(err);
39 UNUSED(fprintf(stderr,
"Error: %s\n", err_msg));
40 LLVMDisposeErrorMessage(err_msg);
41 return 1;
42}
◆ srn_jit_add_module()
Add a module to the jit compiler.
Definition at line 83 of file jit.c.
83 {
86
87 LLVMOrcLLJITRef j = ctx->
engine->jit->llvm_jit;
88
89 LLVMOrcJITDylibRef jd = LLVMOrcLLJITGetMainJITDylib(j);
90 LLVMErrorRef err = LLVMOrcLLJITAddLLVMIRModule(j, jd, module->
tsm);
92
93 if (err != nullptr) {
94
95
96
97
98
99 char *jit_err_msg = LLVMGetErrorMessage(err);
100 char *msg =
srn_copy_bytes(ctx, jit_err_msg, strlen(jit_err_msg),
alignof(
char));
102 LLVMDisposeErrorMessage(jit_err_msg);
103 }
104 return srn_err;
105}
srn_error_t * srn_errors_make(const srn_context_t *ctx, srn_error_tag_t tag, const char *msg)
@ FAILED_TO_ADD_MODULE
Failed to add a module to the jit engine.
srn_engine_t * engine
Long term state of the compiler.
LLVMOrcThreadSafeModuleRef tsm
#define PANIC_IF_NULL(ptr)
char * srn_copy_bytes(srn_context_t *ctx, const char *src, size_t len, size_t alignment)
◆ srn_jit_make()
Definition at line 44 of file jit.c.
44 {
50 return jit;
51}
#define srn_mm_immortal_allocate(mm, T)
LLVMOrcLLJITBuilderRef builder
◆ srn_jit_make_and_initialize()
| int srn_jit_make_and_initialize |
( |
srn_jit_t * | result | ) |
|
Definition at line 53 of file jit.c.
53 {
55
56 int error = 0;
57
58
59
60
61
62 LLVMInitializeNativeTarget();
63 LLVMInitializeNativeAsmPrinter();
64
65 LLVMErrorRef err = nullptr;
67 if (err) {
69 LLVMShutdown();
70 return error;
71 }
72 return 0;
73}
static int handle_error(LLVMErrorRef err)
◆ srn_jit_shutdown()
Definition at line 75 of file jit.c.
75 {
76 LLVMErrorRef err = LLVMOrcDisposeLLJIT(jit->
llvm_jit);
77 if (err) {
79 }
80 return 0;
81}