ai: stage1 unify IR values and globals
- add spl_ir_value_t (INST/CONST/GLOBAL) and global table - remove mem.global_alloc and global.ref instructions - dedup byte constants in a program-level pool - zero-init aggregate literals in ast2ir; honor undefined - C backend: fix zero-arg main return, extern prototypes/varargs - fix dangling inline-module method names (0018 flake)
This commit is contained in:
1 parent
663adf6cae
commit
480945a92f
9 files changed
+1657
-1110
No files matched your search
@@ -5,26 +5,34 @@
|
||||
#include "spl_ir.h"
|
||||
#include "spl_sema.h"
|
||||
|
||||
typedef MAP(spl_def_id_t, spl_ir_node_ref_t) spl_def2ir_map_t;
|
||||
typedef MAP(spl_def_id_t, spl_ir_value_t) spl_def2ir_map_t;
|
||||
|
||||
typedef struct {
|
||||
usize cont_blk;
|
||||
usize defer_base;
|
||||
const char *label;
|
||||
spl_ir_node_ref_vec_t breaks;
|
||||
spl_ir_node_ref_t result_slot;
|
||||
spl_ir_value_t result_slot;
|
||||
spl_type_id_t result_tid;
|
||||
} spl_loop_ctx_t;
|
||||
typedef VEC(spl_loop_ctx_t) spl_loop_ctx_vec_t;
|
||||
|
||||
typedef VEC(spl_ast_node_ref_t) spl_defer_stack_t;
|
||||
|
||||
typedef struct {
|
||||
spl_ast_t *ast;
|
||||
spl_ast_node_ref_t decl;
|
||||
} spl_module_init_t;
|
||||
typedef VEC(spl_module_init_t) spl_module_init_vec_t;
|
||||
|
||||
typedef struct {
|
||||
const spl_sema_t *sema;
|
||||
spl_ir_builder_t *ir;
|
||||
spl_ast_t *ast;
|
||||
spl_layout_t *layout; /* 借用 splc0 的 layout */
|
||||
spl_def2ir_map_t def2ir_map;
|
||||
MAP(spl_def_id_t, usize) global_map;
|
||||
spl_module_init_vec_t module_inits;
|
||||
spl_loop_ctx_vec_t loop_stack;
|
||||
spl_defer_stack_t defer_stack;
|
||||
spl_lang_type_id_t cur_ret_lang;
|
||||
|
||||
+217
-107
@@ -39,14 +39,12 @@
|
||||
X(case.int2float, V0, SPL_IR_CASE_INT2FLOAT) \
|
||||
X(case.float2int, V0, SPL_IR_CASE_FLOAT2INT) \
|
||||
X(mem.alloca, V0, SPL_IR_MEM_ALLOCA) \
|
||||
X(mem.global_alloc, V0, SPL_IR_MEM_GLOBAL_ALLOC) \
|
||||
X(mem.load, V0, SPL_IR_MEM_LOAD) \
|
||||
X(mem.store, V0, SPL_IR_MEM_STORE) \
|
||||
X(mem.offset, V0, SPL_IR_MEM_OFFSET) \
|
||||
X(mem.field, V0, SPL_IR_MEM_FIELD_PTR) \
|
||||
X(mem.copy, V0, SPL_IR_MEM_COPY) \
|
||||
X(mem.set, V0, SPL_IR_MEM_SET) \
|
||||
X(type.const, V0, SPL_IR_TYPE_CONST) \
|
||||
X(type.bitsizeof, V0, SPL_IR_TYPE_BITSIZEOF) \
|
||||
X(type.sizeof, V0, SPL_IR_TYPE_SIZEOF) \
|
||||
X(type.alignof, V0, SPL_IR_TYPE_ALIGNOF) \
|
||||
@@ -65,6 +63,7 @@
|
||||
X(control.trap, V0, SPL_IR_CONTROL_TRAP) \
|
||||
X(dbg.breakpoint, V0, SPL_IR_DBG_BREAKPOINT) \
|
||||
X(dbg.panic, V0, SPL_IR_DBG_PANIC) \
|
||||
/* clang-format on */
|
||||
|
||||
typedef enum {
|
||||
#ifdef X
|
||||
@@ -74,13 +73,129 @@ typedef enum {
|
||||
SPL_IR_FN_TABLE
|
||||
#undef X
|
||||
} spl_ir_kind_t;
|
||||
/* clang-format on */
|
||||
|
||||
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 */
|
||||
|
||||
/* 抽象机器的值:指令结果、常量或全局实体句柄。常量按 tid 的 SPL_TYPE_* 解释:
|
||||
* BOOL/INT(<=64) -> int_bits,FLOAT -> float_bits,FN -> fn,
|
||||
* PTR -> 仅表示 null,其余需要去重的量 -> const_id。
|
||||
* GLOBAL 表示模块级全局实体的地址,载荷是 global_id。 */
|
||||
typedef enum {
|
||||
SPL_IR_VALUE_INST,
|
||||
SPL_IR_VALUE_CONST,
|
||||
SPL_IR_VALUE_GLOBAL,
|
||||
} spl_ir_value_kind_t;
|
||||
|
||||
typedef struct {
|
||||
spl_ir_value_kind_t kind;
|
||||
spl_type_id_t tid; /* CONST 时有效;INST 必须为 0 */
|
||||
union {
|
||||
spl_ir_node_ref_t inst;
|
||||
uint64_t int_bits;
|
||||
double float_bits;
|
||||
spl_ir_func_ref_t fn;
|
||||
usize global_id;
|
||||
usize const_id;
|
||||
};
|
||||
} spl_ir_value_t;
|
||||
typedef VEC(spl_ir_value_t) spl_ir_value_vec_t;
|
||||
|
||||
static inline spl_ir_value_t spl_ir_value_none(void) {
|
||||
spl_ir_value_t v = {0};
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline bool spl_ir_value_is_none(spl_ir_value_t v) {
|
||||
return v.kind == SPL_IR_VALUE_INST && v.inst == 0;
|
||||
}
|
||||
|
||||
static inline spl_ir_value_t spl_ir_value_inst(spl_ir_node_ref_t ref) {
|
||||
spl_ir_value_t v = {0};
|
||||
v.kind = SPL_IR_VALUE_INST;
|
||||
v.inst = ref;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline spl_ir_value_t spl_ir_value_const_int(spl_type_id_t tid, uint64_t bits) {
|
||||
spl_ir_value_t v = {0};
|
||||
v.kind = SPL_IR_VALUE_CONST;
|
||||
v.tid = tid;
|
||||
v.int_bits = bits;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline spl_ir_value_t spl_ir_value_const_float(spl_type_id_t tid, double bits) {
|
||||
spl_ir_value_t v = {0};
|
||||
v.kind = SPL_IR_VALUE_CONST;
|
||||
v.tid = tid;
|
||||
v.float_bits = bits;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline spl_ir_value_t spl_ir_value_const_fn(spl_type_id_t tid, spl_ir_func_ref_t fn) {
|
||||
spl_ir_value_t v = {0};
|
||||
v.kind = SPL_IR_VALUE_CONST;
|
||||
v.tid = tid;
|
||||
v.fn = fn;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline spl_ir_value_t spl_ir_value_const_null(spl_type_id_t tid) {
|
||||
spl_ir_value_t v = {0};
|
||||
v.kind = SPL_IR_VALUE_CONST;
|
||||
v.tid = tid;
|
||||
v.global_id = 0;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline spl_ir_value_t spl_ir_value_global(spl_type_id_t ptr_tid, usize gid) {
|
||||
spl_ir_value_t v = {0};
|
||||
v.kind = SPL_IR_VALUE_GLOBAL;
|
||||
v.tid = ptr_tid;
|
||||
v.global_id = gid;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline spl_ir_value_t spl_ir_value_const_pool(spl_type_id_t tid, usize const_id) {
|
||||
spl_ir_value_t v = {0};
|
||||
v.kind = SPL_IR_VALUE_CONST;
|
||||
v.tid = tid;
|
||||
v.const_id = const_id;
|
||||
return v;
|
||||
}
|
||||
|
||||
static inline spl_ir_node_ref_t spl_ir_value_inst_ref(spl_ir_value_t v) {
|
||||
return v.kind == SPL_IR_VALUE_INST ? v.inst : 0;
|
||||
}
|
||||
|
||||
/* 常量池项:只放需要去重的量,标量直接内联在 Value 里。 */
|
||||
typedef struct {
|
||||
spl_type_id_t tid;
|
||||
union {
|
||||
struct {
|
||||
unsigned char *data;
|
||||
usize len;
|
||||
} bytes;
|
||||
struct {
|
||||
uint64_t *limbs;
|
||||
usize count;
|
||||
} big_int;
|
||||
};
|
||||
} spl_ir_const_t;
|
||||
typedef VEC(spl_ir_const_t) spl_ir_const_vec_t;
|
||||
|
||||
/* 全局存储声明。引用是 PTR 常量(global_id),不是指令。 */
|
||||
typedef struct {
|
||||
const char *name;
|
||||
spl_type_id_t tid; /* 对象类型 */
|
||||
spl_ir_value_t init;
|
||||
bool readonly;
|
||||
} spl_ir_global_t;
|
||||
typedef VEC(spl_ir_global_t) spl_ir_global_vec_t;
|
||||
|
||||
#define SPL_ENUM_TAG_FIELD_IDX 0
|
||||
|
||||
typedef struct {
|
||||
@@ -91,70 +206,54 @@ typedef struct {
|
||||
spl_type_id_t tid;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t left;
|
||||
spl_ir_node_ref_t right;
|
||||
spl_ir_value_t left;
|
||||
spl_ir_value_t right;
|
||||
} arith;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t a;
|
||||
spl_ir_node_ref_t b;
|
||||
spl_ir_value_t a;
|
||||
spl_ir_value_t b;
|
||||
} cmp;
|
||||
struct {
|
||||
spl_type_id_t from_tid;
|
||||
spl_type_id_t to_tid;
|
||||
spl_ir_node_ref_t val;
|
||||
spl_ir_value_t val;
|
||||
} cast;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t count;
|
||||
spl_ir_value_t count;
|
||||
} mem_alloc;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t const_node;
|
||||
} mem_global_alloc;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t ptr;
|
||||
spl_ir_value_t ptr;
|
||||
} mem_load;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t ptr;
|
||||
spl_ir_node_ref_t val;
|
||||
spl_ir_value_t ptr;
|
||||
spl_ir_value_t val;
|
||||
} mem_store;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t ptr;
|
||||
spl_ir_node_ref_t offset;
|
||||
spl_ir_value_t ptr;
|
||||
spl_ir_value_t offset;
|
||||
} mem_offset;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t agg;
|
||||
spl_ir_value_t agg;
|
||||
usize field_idx;
|
||||
} mem_field_ptr;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t dst;
|
||||
spl_ir_node_ref_t src;
|
||||
spl_ir_node_ref_t size;
|
||||
spl_ir_value_t dst;
|
||||
spl_ir_value_t src;
|
||||
spl_ir_value_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;
|
||||
spl_ir_value_t dst;
|
||||
spl_ir_value_t val;
|
||||
spl_ir_value_t size;
|
||||
} mem_set;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
union {
|
||||
bool bool_lit;
|
||||
void *ptr_lit;
|
||||
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;
|
||||
@@ -166,7 +265,7 @@ typedef struct {
|
||||
} ir_alignof;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t field_idx;
|
||||
spl_ir_value_t field_idx;
|
||||
} ir_offsetof;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
@@ -174,29 +273,29 @@ typedef struct {
|
||||
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_vec_t fields;
|
||||
spl_ir_value_vec_t fields;
|
||||
} agg_construct;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_type_id_t field_tid;
|
||||
usize field_idx;
|
||||
spl_ir_node_ref_t val;
|
||||
spl_ir_value_t val;
|
||||
} agg_extract;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
usize field_idx;
|
||||
spl_ir_node_ref_t agg;
|
||||
spl_ir_node_ref_t field;
|
||||
spl_ir_value_t agg;
|
||||
spl_ir_value_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;
|
||||
spl_ir_value_t cond;
|
||||
spl_ir_value_t true_val;
|
||||
spl_ir_value_t false_val;
|
||||
} control_select;
|
||||
struct {
|
||||
spl_ir_node_ref_t cond;
|
||||
spl_ir_value_t cond;
|
||||
spl_ir_node_ref_t true_label;
|
||||
spl_ir_node_ref_t false_label;
|
||||
} control_br;
|
||||
@@ -205,16 +304,16 @@ typedef struct {
|
||||
} control_jmp;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t func;
|
||||
spl_ir_node_ref_vec_t params;
|
||||
spl_ir_value_t func;
|
||||
spl_ir_value_vec_t params;
|
||||
} control_call;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t idx;
|
||||
spl_ir_value_t idx;
|
||||
} control_param;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t val;
|
||||
spl_ir_value_t val;
|
||||
} control_ret;
|
||||
|
||||
struct {
|
||||
@@ -243,8 +342,17 @@ typedef struct {
|
||||
} spl_ir_fix_t;
|
||||
typedef VEC(spl_ir_fix_t) spl_ir_fix_vec_t;
|
||||
|
||||
typedef struct {
|
||||
spl_type_id_t tid;
|
||||
const unsigned char *data;
|
||||
usize len;
|
||||
} spl_ir_const_key_t;
|
||||
|
||||
typedef struct {
|
||||
spl_ir_func_vec_t funcs;
|
||||
spl_ir_const_vec_t consts;
|
||||
spl_ir_global_vec_t globals;
|
||||
MAP(spl_ir_const_key_t, usize) const_index;
|
||||
} spl_ir_t;
|
||||
|
||||
void spl_ir_init(spl_ir_t *ir);
|
||||
@@ -255,6 +363,12 @@ 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);
|
||||
spl_ir_const_t *spl_ir_const(spl_ir_t *ir, usize const_id);
|
||||
/* INST 返回对应节点;CONST 返回 NULL。 */
|
||||
spl_ir_node_t *spl_ir_value_node(spl_ir_t *ir, spl_ir_func_ref_t fn_id, spl_ir_value_t v);
|
||||
/* 遍历节点里所有值型操作数(块标签除外)。 */
|
||||
typedef void (*spl_ir_value_cb_t)(void *ud, spl_ir_value_t v);
|
||||
void spl_ir_node_visit_values(spl_ir_node_t *n, spl_ir_value_cb_t cb, void *ud);
|
||||
|
||||
/* f 是否声明为 extern(属性表内名为 "extern" 的属性);命中返回该属性节点,否则 NULL。
|
||||
供各后端复用,避免 "extern" 字符串判断散落多处。 */
|
||||
@@ -323,102 +437,98 @@ 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, \
|
||||
spl_ir_node_ref_t left, spl_ir_node_ref_t right);
|
||||
spl_ir_value_t spl_ir_builder_##name(spl_ir_builder_t *b, spl_type_id_t tid, \
|
||||
spl_ir_value_t left, spl_ir_value_t right);
|
||||
SPL_IR_BIN_ARITH_TABLE
|
||||
#undef X
|
||||
|
||||
#define X(name, kind) \
|
||||
spl_ir_node_ref_t spl_ir_builder_##name(spl_ir_builder_t *b, spl_type_id_t tid, \
|
||||
spl_ir_node_ref_t val);
|
||||
spl_ir_value_t spl_ir_builder_##name(spl_ir_builder_t *b, spl_type_id_t tid, \
|
||||
spl_ir_value_t val);
|
||||
SPL_IR_UN_ARITH_TABLE
|
||||
#undef X
|
||||
|
||||
#define X(name, kind) \
|
||||
spl_ir_node_ref_t spl_ir_builder_##name(spl_ir_builder_t *builder, spl_type_id_t tid, \
|
||||
spl_ir_node_ref_t a, spl_ir_node_ref_t b);
|
||||
spl_ir_value_t spl_ir_builder_##name(spl_ir_builder_t *builder, spl_type_id_t tid, \
|
||||
spl_ir_value_t a, spl_ir_value_t b);
|
||||
SPL_IR_CMP_TABLE
|
||||
#undef X
|
||||
|
||||
#define X(name, kind) \
|
||||
spl_ir_node_ref_t spl_ir_builder_##name(spl_ir_builder_t *b, spl_type_id_t from_tid, \
|
||||
spl_type_id_t to_tid, spl_ir_node_ref_t val);
|
||||
spl_ir_value_t spl_ir_builder_##name(spl_ir_builder_t *b, spl_type_id_t from_tid, \
|
||||
spl_type_id_t to_tid, spl_ir_value_t val);
|
||||
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,
|
||||
spl_ir_node_ref_t const_node);
|
||||
spl_ir_node_ref_t spl_ir_builder_mem_load(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t ptr);
|
||||
spl_ir_value_t spl_ir_builder_mem_alloca(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_value_t count);
|
||||
spl_ir_value_t spl_ir_builder_mem_load(spl_ir_builder_t *b, spl_type_id_t tid, spl_ir_value_t ptr);
|
||||
spl_ir_node_ref_t spl_ir_builder_mem_store(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t ptr, spl_ir_node_ref_t val);
|
||||
spl_ir_node_ref_t spl_ir_builder_mem_offset(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t ptr, spl_ir_node_ref_t offset);
|
||||
spl_ir_node_ref_t spl_ir_builder_mem_field(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t agg, usize field_idx);
|
||||
spl_ir_node_ref_t spl_ir_builder_mem_copy(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t dst, spl_ir_node_ref_t src,
|
||||
spl_ir_node_ref_t size);
|
||||
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);
|
||||
spl_ir_value_t ptr, spl_ir_value_t val);
|
||||
spl_ir_value_t spl_ir_builder_mem_offset(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_value_t ptr, spl_ir_value_t offset);
|
||||
spl_ir_value_t spl_ir_builder_mem_field(spl_ir_builder_t *b, spl_type_id_t tid, spl_ir_value_t agg,
|
||||
usize field_idx);
|
||||
spl_ir_node_ref_t spl_ir_builder_mem_copy(spl_ir_builder_t *b, spl_type_id_t tid, spl_ir_value_t dst,
|
||||
spl_ir_value_t src, spl_ir_value_t size);
|
||||
spl_ir_node_ref_t spl_ir_builder_mem_set(spl_ir_builder_t *b, spl_type_id_t tid, spl_ir_value_t dst,
|
||||
spl_ir_value_t val, spl_ir_value_t size);
|
||||
|
||||
/* type const */
|
||||
/* 常量:标量内联;需要去重的量进常量池并返回 const_id。 */
|
||||
|
||||
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);
|
||||
spl_ir_node_ref_t spl_ir_builder_type_const_bytes(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
const void *data, usize len);
|
||||
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);
|
||||
spl_ir_value_t spl_ir_builder_const_int(spl_type_id_t tid, uint64_t bits);
|
||||
spl_ir_value_t spl_ir_builder_const_bool(spl_type_id_t tid, bool val);
|
||||
spl_ir_value_t spl_ir_builder_const_float(spl_type_id_t tid, double val);
|
||||
spl_ir_value_t spl_ir_builder_const_null(spl_type_id_t tid);
|
||||
spl_ir_value_t spl_ir_builder_const_fn(spl_type_id_t tid, spl_ir_func_ref_t fn);
|
||||
spl_ir_value_t spl_ir_builder_global_addr(spl_type_id_t ptr_tid, usize global_id);
|
||||
spl_ir_value_t spl_ir_builder_const_bytes(spl_ir_builder_t *b, spl_type_id_t tid, const void *data,
|
||||
usize len);
|
||||
|
||||
usize spl_ir_builder_global_declare(spl_ir_builder_t *b, const char *name, spl_type_id_t tid,
|
||||
spl_ir_value_t init, bool readonly);
|
||||
|
||||
/* 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);
|
||||
spl_ir_node_ref_t spl_ir_builder_type_offsetof(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
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);
|
||||
spl_ir_value_t spl_ir_builder_type_bitsizeof(spl_ir_builder_t *b, spl_type_id_t tid);
|
||||
spl_ir_value_t spl_ir_builder_type_sizeof(spl_ir_builder_t *b, spl_type_id_t tid);
|
||||
spl_ir_value_t spl_ir_builder_type_alignof(spl_ir_builder_t *b, spl_type_id_t tid);
|
||||
spl_ir_value_t spl_ir_builder_type_offsetof(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_value_t field_idx);
|
||||
spl_ir_value_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);
|
||||
spl_ir_node_ref_t spl_ir_builder_agg_extract(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_type_id_t field_tid, usize field_idx,
|
||||
spl_ir_node_ref_t val);
|
||||
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);
|
||||
spl_ir_value_t field);
|
||||
spl_ir_value_t spl_ir_builder_agg_extract(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_type_id_t field_tid, usize field_idx,
|
||||
spl_ir_value_t val);
|
||||
spl_ir_value_t spl_ir_builder_agg_insert(spl_ir_builder_t *b, spl_type_id_t tid, usize field_idx,
|
||||
spl_ir_value_t agg, spl_ir_value_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_value_t spl_ir_builder_control_select(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_value_t cond, spl_ir_value_t true_val,
|
||||
spl_ir_value_t false_val);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_br(spl_ir_builder_t *b, spl_ir_value_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);
|
||||
spl_ir_value_t func);
|
||||
void spl_ir_builder_control_call_param(spl_ir_builder_t *b, spl_ir_node_ref_t call_node,
|
||||
spl_ir_node_ref_t arg);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_param(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t idx);
|
||||
spl_ir_value_t arg);
|
||||
spl_ir_value_t spl_ir_builder_control_param(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_value_t idx);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_ret(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
spl_ir_node_ref_t val);
|
||||
spl_ir_value_t val);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_unreachable(spl_ir_builder_t *b);
|
||||
spl_ir_node_ref_t spl_ir_builder_control_trap(spl_ir_builder_t *b);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ typedef struct {
|
||||
const spl_type_t *type;
|
||||
const spl_attr_t *attr;
|
||||
spl_extern_idx_map_t extern_native;
|
||||
VEC(isize) global_data_idx;
|
||||
spl_prog_t prog;
|
||||
spl_layout_t *layout; /* 借用 splc0 的 layout(size/align/offset 唯一来源) */
|
||||
|
||||
|
||||
Reference in new issue
Block a user