stage1 修复设计问题 实现ast2ir
This commit is contained in:
140
stage1/spl_ir.h
140
stage1/spl_ir.h
@@ -2,6 +2,7 @@
|
||||
#define __SPL_IR_H__
|
||||
|
||||
#include "../stage0/include/utils.h"
|
||||
#include "spl_type.h"
|
||||
|
||||
/* clang-format off */
|
||||
#define SPL_IR_FN_TABLE \
|
||||
@@ -64,6 +65,7 @@
|
||||
X(control.br, V0, SPL_IR_CONTROL_BR) \
|
||||
X(control.jmp, V0, SPL_IR_CONTROL_JMP) \
|
||||
X(control.call, V0, SPL_IR_CONTROL_CALL) \
|
||||
X(control.param, V0, SPL_IR_CONTROL_PARAM) \
|
||||
X(control.ret, V0, SPL_IR_CONTROL_RET) \
|
||||
X(control.unreachable, V0, SPL_IR_CONTROL_UNREACHABLE) \
|
||||
X(control.trap, V0, SPL_IR_CONTROL_TRAP) \
|
||||
@@ -80,14 +82,136 @@ typedef enum {
|
||||
} spl_ir_kind_t;
|
||||
/* clang-format on */
|
||||
|
||||
typedef struct {
|
||||
spl_ir_kind_t kind;
|
||||
} spl_ir_node_t;
|
||||
typedef VEC(spl_ir_node_t) spl_ir_node_vec_t;
|
||||
|
||||
typedef usize spl_ir_node_ref_t; /* 0 is error */
|
||||
typedef VEC(spl_ir_node_ref_t) spl_ir_node_ref_vec_t;
|
||||
|
||||
typedef usize spl_ir_func_ref_t; /* 0 is error */
|
||||
|
||||
typedef struct {
|
||||
spl_ir_kind_t kind;
|
||||
union {
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t left;
|
||||
spl_ir_node_ref_t right;
|
||||
} arith;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t a;
|
||||
spl_ir_node_ref_t b;
|
||||
} cmp;
|
||||
struct {
|
||||
spl_type_id_t from_tid;
|
||||
spl_type_id_t to_tid;
|
||||
spl_ir_node_ref_t val;
|
||||
} cast;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t count;
|
||||
} mem_alloc;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t ptr;
|
||||
} mem_load;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t ptr;
|
||||
spl_ir_node_ref_t val;
|
||||
} mem_store;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t ptr;
|
||||
spl_ir_node_ref_t offset;
|
||||
} mem_offset;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t dst;
|
||||
spl_ir_node_ref_t src;
|
||||
spl_ir_node_ref_t size;
|
||||
} mem_copy;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t dst;
|
||||
spl_ir_node_ref_t val;
|
||||
spl_ir_node_ref_t size;
|
||||
} mem_set;
|
||||
struct {
|
||||
spl_ir_node_ref_t ordering;
|
||||
} mem_fence;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
union {
|
||||
usize int_lit;
|
||||
double float_lit;
|
||||
const char *cstr_lit;
|
||||
char ch_lit;
|
||||
spl_ir_func_ref_t fn;
|
||||
};
|
||||
} type_const;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
} bitsizeof;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
} ir_sizeof;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
} ir_alignof;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t field_idx;
|
||||
} ir_offsetof;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
} field_count;
|
||||
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_vec_t fields;
|
||||
} agg_construct;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
isize field_idx;
|
||||
spl_ir_node_ref_t val;
|
||||
} agg_extract;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
isize field_idx;
|
||||
spl_ir_node_ref_t agg;
|
||||
spl_ir_node_ref_t field;
|
||||
} agg_insert;
|
||||
|
||||
struct {
|
||||
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;
|
||||
} control_select;
|
||||
struct {
|
||||
spl_ir_node_ref_t cond;
|
||||
spl_ir_node_ref_t true_label;
|
||||
spl_ir_node_ref_t false_label;
|
||||
} control_br;
|
||||
struct {
|
||||
spl_ir_node_ref_t label;
|
||||
} control_jmp;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t func;
|
||||
spl_ir_node_ref_vec_t params;
|
||||
} control_call;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t idx;
|
||||
} control_param;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t val;
|
||||
} control_ret;
|
||||
};
|
||||
} spl_ir_node_t;
|
||||
typedef VEC(spl_ir_node_t) spl_ir_node_vec_t;
|
||||
|
||||
typedef struct {
|
||||
enum {
|
||||
SPL_IR_ATTR_NONE,
|
||||
@@ -103,12 +227,12 @@ typedef VEC(spl_ir_attr_t) spl_ir_attr_vec_t;
|
||||
typedef struct {
|
||||
const char *name;
|
||||
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 usize spl_ir_func_ref_t; /* 0 is error */
|
||||
typedef VEC(spl_ir_func_t) spl_ir_func_vec_t;
|
||||
|
||||
typedef VEC(spl_ir_func_t) spl_ir_func_vec_t;
|
||||
typedef struct {
|
||||
spl_ir_func_vec_t funcs;
|
||||
} spl_ir_t;
|
||||
@@ -122,6 +246,6 @@ spl_ir_func_ref_t spl_ir_alloc_fn(spl_ir_t *ir);
|
||||
spl_ir_node_t *spl_ir_node(spl_ir_t *ir, spl_ir_func_ref_t fn_id, spl_ir_node_ref_t node_id);
|
||||
spl_ir_func_t *spl_ir_func(spl_ir_t *ir, spl_ir_func_ref_t fn_id);
|
||||
|
||||
void spl_ir_dump(spl_ir_t *ir);
|
||||
void spl_ir_dump(spl_ir_t *ir, const spl_type_t *ty);
|
||||
|
||||
#endif /* __SPL_IR_H__ */
|
||||
|
||||
Reference in New Issue
Block a user