summaryrefslogtreecommitdiff
path: root/ujit_codegen.h
blob: a3fd53a154d48ddd1965d82547c0b1741742fd73 (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
#ifndef UJIT_CODEGEN_H
#define UJIT_CODEGEN_H 1

#include "stddef.h"
#include "ujit_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;

    // Current PC
    VALUE *pc;

} jitstate_t;

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

// Meta-information associated with a given opcode
typedef struct OpDesc
{
    // Code generation function
    codegen_fn gen_fn;

    // Indicates that this is a branch instruction
    // which terminates a block
    bool is_branch;

} opdesc_t;

uint8_t* ujit_entry_prologue();

void ujit_gen_block(ctx_t* ctx, block_t* block);

void ujit_init_codegen(void);

#endif // #ifndef UJIT_CODEGEN_H