stage1 实现部分ast2ir内容
This commit is contained in:
1 parent
f1d86b6e34
commit
3d57260f3f
6 files changed
+298
-148
No files matched your search
+41
-15
@@ -141,6 +141,8 @@ typedef struct {
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
union {
|
||||
bool bool_lit;
|
||||
void *ptr_lit;
|
||||
usize int_lit;
|
||||
double float_lit;
|
||||
const char *cstr_lit;
|
||||
@@ -231,14 +233,21 @@ typedef struct {
|
||||
spl_ir_attr_t attr;
|
||||
spl_type_id_t fn_tid;
|
||||
spl_ir_node_vec_t nodes;
|
||||
spl_ir_node_ref_vec_t labels;
|
||||
} spl_ir_func_t;
|
||||
|
||||
typedef VEC(spl_ir_func_t) spl_ir_func_vec_t;
|
||||
|
||||
typedef spl_ir_node_ref_t spl_ir_block_t;
|
||||
typedef VEC(spl_ir_block_t) spl_ir_block_vec_t;
|
||||
|
||||
typedef struct {
|
||||
spl_ir_node_ref_t node;
|
||||
enum { SPL_IR_FIX_BR_TRUE, SPL_IR_FIX_BR_FALSE, SPL_IR_FIX_JMP } slot;
|
||||
spl_ir_node_ref_t block;
|
||||
} spl_ir_fix_t;
|
||||
typedef VEC(spl_ir_fix_t) spl_ir_fix_vec_t;
|
||||
|
||||
typedef struct {
|
||||
spl_ir_func_vec_t funcs;
|
||||
spl_ir_node_vec_t gdata;
|
||||
} spl_ir_t;
|
||||
|
||||
void spl_ir_init(spl_ir_t *ir);
|
||||
@@ -255,10 +264,12 @@ const char *spl_ir_kind_name(spl_ir_kind_t kind);
|
||||
|
||||
typedef struct {
|
||||
spl_ir_t ir;
|
||||
spl_ir_func_ref_t current_fn;
|
||||
spl_ir_node_ref_t current_node;
|
||||
spl_ir_node_ref_vec_t reloc_label;
|
||||
spl_dbg_node_t dbg;
|
||||
spl_ir_func_ref_t current_fn; /* 当前函数 */
|
||||
spl_ir_node_ref_t current_block; /* 当前发射块(0 = 未设) */
|
||||
spl_ir_block_vec_t blocks; /* 当前函数的基本块表 */
|
||||
spl_ir_fix_vec_t fixups; /* 跳转回填表 */
|
||||
bool terminated; /* 当前块已以 br/jmp/ret 终止 */
|
||||
} spl_ir_builder_t;
|
||||
|
||||
/* clang-format off */
|
||||
@@ -300,12 +311,12 @@ typedef struct {
|
||||
void spl_ir_builder_init(spl_ir_builder_t *b);
|
||||
void spl_ir_builder_drop(spl_ir_builder_t *b);
|
||||
|
||||
spl_ir_func_ref_t spl_ir_builder_fn_new(spl_ir_builder_t *b, const char *name,
|
||||
spl_type_id_t fn_tid);
|
||||
spl_ir_func_ref_t spl_ir_builder_cur_fn(const spl_ir_builder_t *b);
|
||||
void spl_ir_builder_set_dbg(spl_ir_builder_t *b, spl_dbg_node_t dbg);
|
||||
spl_ir_func_ref_t spl_ir_builder_fn_begin(spl_ir_builder_t *b, const char *name,
|
||||
spl_type_id_t fn_tid, spl_ir_attr_t attr);
|
||||
void spl_ir_builder_fn_end(spl_ir_builder_t *b);
|
||||
|
||||
spl_ir_node_ref_t spl_ir_builder_block_new(spl_ir_builder_t *b);
|
||||
usize spl_ir_builder_block_begin(spl_ir_builder_t *b);
|
||||
void spl_ir_builder_block_end(spl_ir_builder_t *b);
|
||||
|
||||
#define X(name, kind) \
|
||||
spl_ir_node_ref_t spl_ir_builder_##name(spl_ir_builder_t *b, spl_type_id_t tid, \
|
||||
@@ -331,6 +342,8 @@ SPL_IR_CMP_TABLE
|
||||
SPL_IR_CAST_TABLE
|
||||
#undef X
|
||||
|
||||
/* memory */
|
||||
|
||||
spl_ir_node_ref_t spl_ir_builder_mem_alloca(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t count);
|
||||
spl_ir_node_ref_t spl_ir_builder_mem_global_alloc(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
@@ -350,6 +363,10 @@ spl_ir_node_ref_t spl_ir_builder_mem_set(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t dst, spl_ir_node_ref_t val,
|
||||
spl_ir_node_ref_t size);
|
||||
|
||||
/* type const */
|
||||
|
||||
spl_ir_node_ref_t spl_ir_builder_type_const_ptr(spl_ir_builder_t *b, spl_type_id_t tid, void *val);
|
||||
spl_ir_node_ref_t spl_ir_builder_type_const_bool(spl_ir_builder_t *b, spl_type_id_t tid, bool val);
|
||||
spl_ir_node_ref_t spl_ir_builder_type_const_int(spl_ir_builder_t *b, spl_type_id_t tid, usize val);
|
||||
spl_ir_node_ref_t spl_ir_builder_type_const_float(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
double val);
|
||||
@@ -358,6 +375,9 @@ spl_ir_node_ref_t spl_ir_builder_type_const_cstr(spl_ir_builder_t *b, spl_type_i
|
||||
spl_ir_node_ref_t spl_ir_builder_type_const_char(spl_ir_builder_t *b, spl_type_id_t tid, char val);
|
||||
spl_ir_node_ref_t spl_ir_builder_type_const_fn(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_func_ref_t val);
|
||||
|
||||
/* type */
|
||||
|
||||
spl_ir_node_ref_t spl_ir_builder_type_bitsizeof(spl_ir_builder_t *b, spl_type_id_t tid);
|
||||
spl_ir_node_ref_t spl_ir_builder_type_sizeof(spl_ir_builder_t *b, spl_type_id_t tid);
|
||||
spl_ir_node_ref_t spl_ir_builder_type_alignof(spl_ir_builder_t *b, spl_type_id_t tid);
|
||||
@@ -365,6 +385,8 @@ spl_ir_node_ref_t spl_ir_builder_type_offsetof(spl_ir_builder_t *b, spl_type_id_
|
||||
spl_ir_node_ref_t field_idx);
|
||||
spl_ir_node_ref_t spl_ir_builder_type_field_count(spl_ir_builder_t *b, spl_type_id_t tid);
|
||||
|
||||
/* agg */
|
||||
|
||||
spl_ir_node_ref_t spl_ir_builder_agg_construct(spl_ir_builder_t *b, spl_type_id_t tid);
|
||||
void spl_ir_builder_agg_construct_field(spl_ir_builder_t *b, spl_ir_node_ref_t node,
|
||||
spl_ir_node_ref_t field);
|
||||
@@ -374,13 +396,17 @@ spl_ir_node_ref_t spl_ir_builder_agg_extract(spl_ir_builder_t *b, spl_type_id_t
|
||||
spl_ir_node_ref_t spl_ir_builder_agg_insert(spl_ir_builder_t *b, spl_type_id_t tid, usize field_idx,
|
||||
spl_ir_node_ref_t agg, spl_ir_node_ref_t field);
|
||||
|
||||
/* control */
|
||||
|
||||
spl_ir_node_ref_t spl_ir_builder_control_select(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t cond, spl_ir_node_ref_t true_val,
|
||||
spl_ir_node_ref_t false_val);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_br(spl_ir_builder_t *b, spl_ir_node_ref_t cond,
|
||||
spl_ir_node_ref_t true_label,
|
||||
spl_ir_node_ref_t false_label);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_jmp(spl_ir_builder_t *b, spl_ir_node_ref_t label);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_br(spl_ir_builder_t *b, spl_ir_node_ref_t cond);
|
||||
void spl_ir_builder_control_br_fixup(spl_ir_builder_t *b, spl_ir_node_ref_t ref, usize true_block,
|
||||
usize false_block);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_jmp(spl_ir_builder_t *b);
|
||||
void spl_ir_builder_control_jmp_fixup(spl_ir_builder_t *b, spl_ir_node_ref_t ref,
|
||||
usize target_block);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_call(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t func);
|
||||
void spl_ir_builder_control_call_param(spl_ir_builder_t *b, spl_ir_node_ref_t node,
|
||||
|
||||
Reference in new issue
Block a user