summaryrefslogtreecommitdiff
path: root/yjit_codegen.h
blob: 683765319e31d4592a2ee82fd05c74baf6f65527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef YJIT_CODEGEN_H
#define YJIT_CODEGEN_H 1

#include "stddef.h"
#include "yjit_core.h"

// Code blocks we generate code into
extern codeblock_t *cb;
extern codeblock_t *ocb;

// Code generation state
typedef struct JITState
{
    // Block version being compiled
    block_t* block;

    // Instruction sequence this is associated with
    const rb_iseq_t *iseq;

    // Index of the current instruction being compiled
    uint32_t insn_idx;

    // Opcode for the instruction being compiled
    int opcode;

    // PC of the instruction being compiled
    VALUE *pc;

    // Execution context when compilation started
    // This allows us to peek at run-time values
    rb_execution_context_t* ec;

} jitstate_t;

typedef enum codegen_status {
    YJIT_END_BLOCK,
    YJIT_KEEP_COMPILING,
    YJIT_CANT_COMPILE
} codegen_status_t;

// Code generation function signature
typedef codegen_status_t (*codegen_fn)(jitstate_t* jit, ctx_t* ctx);

uint8_t* yjit_entry_prologue();

void yjit_gen_block(block_t* block, rb_execution_context_t* ec);

void yjit_init_codegen(void);

#endif // #ifndef YJIT_CODEGEN_H