Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
jit.h File Reference
#include <llvm-c/LLJIT.h>
#include "serene/rt/errors.h"
Include dependency graph for jit.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  srn_jit_module_t
 
struct  srn_jit_t
 

Typedefs

typedef struct srn_engine_t srn_engine_t
 
typedef struct srn_mm_t srn_mm_t
 
typedef struct srn_jit_module_t srn_jit_module_t
 
typedef struct srn_context_t srn_context_t
 
typedef struct srn_jit_t srn_jit_t
 

Functions

srn_jit_tsrn_jit_make (srn_mm_t *mm)
 
int srn_jit_init (srn_jit_t *result)
 Creates a jit engine and sets the given result to it.
 
int srn_jit_shutdown (srn_jit_t *jit)
 
srn_error_tsrn_jit_add_module (srn_context_t *ctx, srn_jit_module_t *module)
 Add a module to the jit compiler.
 

Typedef Documentation

◆ srn_context_t

typedef struct srn_context_t srn_context_t

Definition at line 33 of file jit.h.

◆ srn_engine_t

typedef struct srn_engine_t srn_engine_t

Definition at line 25 of file jit.h.

◆ srn_jit_module_t

typedef struct srn_jit_module_t srn_jit_module_t

◆ srn_jit_t

typedef struct srn_jit_t srn_jit_t

◆ srn_mm_t

typedef struct srn_mm_t srn_mm_t

Definition at line 26 of file jit.h.

Function Documentation

◆ srn_jit_add_module()

srn_error_t * srn_jit_add_module ( srn_context_t * ctx,
srn_jit_module_t * module )

Add a module to the jit compiler.

Definition at line 83 of file jit.c.

83 {
84 PANIC_IF_NULL(ctx);
85 PANIC_IF_NULL(module);
86
87 LLVMOrcLLJITRef j = ctx->engine->jit->llvm_jit;
88
89 LLVMOrcJITDylibRef jd = LLVMOrcLLJITGetMainJITDylib(j);
90 LLVMErrorRef err = LLVMOrcLLJITAddLLVMIRModule(j, jd, module->tsm);
91 srn_error_t *srn_err = nullptr;
92
93 if (err != nullptr) {
94 // If adding the ThreadSafeModule fails then we need to clean it up
95 // ourselves. If adding it succeeds the JIT will manage the memory.
96 // LLVMOrcDisposeThreadSafeModule(module);
97
98 // LLVM owns the string message, but we want to own it
99 char *jit_err_msg = LLVMGetErrorMessage(err);
100 char *msg = srn_copy_bytes(ctx, jit_err_msg, strlen(jit_err_msg), alignof(char));
101 srn_err = srn_errors_make(ctx, FAILED_TO_ADD_MODULE, msg);
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)
Definition errors.c:28
@ FAILED_TO_ADD_MODULE
Failed to add a module to the jit engine.
Definition errors.h:49
srn_engine_t * engine
Long term state of the compiler.
Definition context.h:49
LLVMOrcThreadSafeModuleRef tsm
Definition jit.h:29
#define PANIC_IF_NULL(ptr)
Definition utils.h:64
char * srn_copy_bytes(srn_context_t *ctx, const char *src, size_t len, size_t alignment)
Definition utils.c:42
Here is the call graph for this function:

◆ srn_jit_init()

int srn_jit_init ( srn_jit_t * result)

Creates a jit engine and sets the given result to it.

◆ srn_jit_make()

srn_jit_t * srn_jit_make ( srn_mm_t * mm)

Definition at line 44 of file jit.c.

44 {
45 PANIC_IF_NULL(mm);
47 PANIC_IF_NULL(jit);
48 jit->builder = nullptr;
49 jit->llvm_jit = nullptr;
50 return jit;
51}
#define srn_mm_immortal_allocate(mm, T)
Definition interface.h:169
LLVMOrcLLJITRef llvm_jit
Definition jit.h:36
LLVMOrcLLJITBuilderRef builder
Definition jit.h:37
Here is the caller graph for this function:

◆ srn_jit_shutdown()

int srn_jit_shutdown ( srn_jit_t * jit)

Definition at line 75 of file jit.c.

75 {
76 LLVMErrorRef err = LLVMOrcDisposeLLJIT(jit->llvm_jit);
77 if (err) {
78 return handle_error(err);
79 }
80 return 0;
81}
static int handle_error(LLVMErrorRef err)
Definition jit.c:36
Here is the call graph for this function:
Here is the caller graph for this function: