2021-03-06 23:46:56 +00:00
|
|
|
#ifndef YJIT_CODEGEN_H
|
|
|
|
#define YJIT_CODEGEN_H 1
|
2020-12-08 21:54:41 +00:00
|
|
|
|
|
|
|
#include "stddef.h"
|
2021-03-06 23:46:56 +00:00
|
|
|
#include "yjit_core.h"
|
2020-12-08 21:54:41 +00:00
|
|
|
|
2020-12-17 02:45:51 +00:00
|
|
|
// Code blocks we generate code into
|
2021-01-22 20:06:51 +00:00
|
|
|
extern codeblock_t *cb;
|
|
|
|
extern codeblock_t *ocb;
|
2020-12-17 02:45:51 +00:00
|
|
|
|
2020-12-18 20:02:43 +00:00
|
|
|
// Code generation state
|
|
|
|
typedef struct JITState
|
|
|
|
{
|
2021-01-12 22:03:54 +00:00
|
|
|
// Block version being compiled
|
2021-01-14 18:33:19 +00:00
|
|
|
block_t* block;
|
2021-01-12 22:03:54 +00:00
|
|
|
|
2020-12-18 20:02:43 +00:00
|
|
|
// Instruction sequence this is associated with
|
|
|
|
const rb_iseq_t *iseq;
|
|
|
|
|
|
|
|
// Index of the current instruction being compiled
|
|
|
|
uint32_t insn_idx;
|
|
|
|
|
2021-05-04 16:35:51 +00:00
|
|
|
// Opcode for the instruction being compiled
|
|
|
|
int opcode;
|
|
|
|
|
2021-03-02 01:43:58 +00:00
|
|
|
// PC of the instruction being compiled
|
2020-12-18 20:02:43 +00:00
|
|
|
VALUE *pc;
|
|
|
|
|
2021-03-02 01:43:58 +00:00
|
|
|
// Execution context when compilation started
|
|
|
|
// This allows us to peek at run-time values
|
|
|
|
rb_execution_context_t* ec;
|
2020-12-16 22:07:18 +00:00
|
|
|
|
2021-03-02 01:43:58 +00:00
|
|
|
} jitstate_t;
|
2021-01-07 22:09:25 +00:00
|
|
|
|
2021-03-02 01:43:58 +00:00
|
|
|
typedef enum codegen_status {
|
2021-03-06 23:46:56 +00:00
|
|
|
YJIT_END_BLOCK,
|
|
|
|
YJIT_KEEP_COMPILING,
|
|
|
|
YJIT_CANT_COMPILE
|
2021-03-02 01:43:58 +00:00
|
|
|
} codegen_status_t;
|
2021-01-07 22:09:25 +00:00
|
|
|
|
2021-03-02 01:43:58 +00:00
|
|
|
// Code generation function signature
|
|
|
|
typedef codegen_status_t (*codegen_fn)(jitstate_t* jit, ctx_t* ctx);
|
2021-01-07 22:09:25 +00:00
|
|
|
|
2021-07-15 18:09:08 +00:00
|
|
|
uint8_t* yjit_entry_prologue(const rb_iseq_t* iseq);
|
2020-12-18 18:49:53 +00:00
|
|
|
|
2021-04-24 04:16:48 +00:00
|
|
|
void yjit_gen_block(block_t* block, rb_execution_context_t* ec);
|
2020-12-08 21:54:41 +00:00
|
|
|
|
2021-03-06 23:46:56 +00:00
|
|
|
void yjit_init_codegen(void);
|
2020-12-08 21:54:41 +00:00
|
|
|
|
2021-03-06 23:46:56 +00:00
|
|
|
#endif // #ifndef YJIT_CODEGEN_H
|