2020-12-08 21:54:41 +00:00
|
|
|
#ifndef UJIT_CODEGEN_H
|
|
|
|
#define UJIT_CODEGEN_H 1
|
|
|
|
|
|
|
|
#include "stddef.h"
|
2020-12-18 20:52:13 +00:00
|
|
|
#include "ujit_core.h"
|
2020-12-08 21:54:41 +00:00
|
|
|
|
2020-12-17 02:45:51 +00:00
|
|
|
// Code blocks we generate code into
|
|
|
|
codeblock_t* cb;
|
|
|
|
codeblock_t* ocb;
|
|
|
|
|
2020-12-18 20:02:43 +00:00
|
|
|
// Code generation state
|
|
|
|
typedef struct JITState
|
|
|
|
{
|
|
|
|
// Instruction sequence this is associated with
|
|
|
|
const rb_iseq_t *iseq;
|
|
|
|
|
|
|
|
// Index in the iseq of the opcode we are replacing
|
2021-01-12 19:56:43 +00:00
|
|
|
const uint32_t start_idx;
|
2020-12-18 20:02:43 +00:00
|
|
|
|
|
|
|
// Index of the current instruction being compiled
|
|
|
|
uint32_t insn_idx;
|
|
|
|
|
|
|
|
// Current PC
|
|
|
|
VALUE *pc;
|
|
|
|
|
|
|
|
} jitstate_t;
|
|
|
|
|
2020-12-16 22:07:18 +00:00
|
|
|
// Code generation function signature
|
2020-12-18 20:02:43 +00:00
|
|
|
typedef bool (*codegen_fn)(jitstate_t* jit, ctx_t* ctx);
|
2020-12-16 22:07:18 +00:00
|
|
|
|
2021-01-07 22:09:25 +00:00
|
|
|
// 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;
|
|
|
|
|
2020-12-18 18:49:53 +00:00
|
|
|
uint8_t* ujit_compile_entry(const rb_iseq_t *iseq, uint32_t insn_idx);
|
|
|
|
|
2021-01-12 19:56:43 +00:00
|
|
|
void ujit_compile_block(const rb_iseq_t *iseq, uint32_t insn_idx, ctx_t* ctx, uint32_t* num_instrs);
|
2020-12-08 21:54:41 +00:00
|
|
|
|
|
|
|
void ujit_init_codegen(void);
|
|
|
|
|
|
|
|
#endif // #ifndef UJIT_CODEGEN_H
|