stage1 重构语义分析 ast2ir ir部分
This commit is contained in:
@@ -5,14 +5,13 @@ vm = [
|
||||
]
|
||||
|
||||
splc0_part = [
|
||||
# "stage1/spl_ir.c",
|
||||
"stage1/spl_ast.c",
|
||||
"stage1/spl_lexer.c",
|
||||
"stage1/spl_dumptree.c",
|
||||
# "stage1/spl_type.c",
|
||||
# "stage1/spl_sema.c",
|
||||
# "stage1/spl_builtin.c",
|
||||
# "stage1/spl_ast2ir.c",
|
||||
"stage1/spl_type.c",
|
||||
"stage1/spl_sema.c",
|
||||
"stage1/spl_ir.c",
|
||||
"stage1/spl_ast2ir.c",
|
||||
# "stage1/spl_ir2vm.c",
|
||||
]
|
||||
|
||||
|
||||
3384
stage1/spl_ast2ir.c
3384
stage1/spl_ast2ir.c
File diff suppressed because it is too large
Load Diff
@@ -4,21 +4,13 @@
|
||||
#include "spl_ir.h"
|
||||
#include "spl_sema.h"
|
||||
|
||||
/* 全局 var/const 的 def → gdata 向量中的 value 节点索引 */
|
||||
typedef struct {
|
||||
spl_def_id_t def_id;
|
||||
usize gdata_idx;
|
||||
} spl_ast2ir_gref_t;
|
||||
|
||||
typedef struct {
|
||||
const spl_sema_t *sema;
|
||||
spl_ir_t ir;
|
||||
VEC(char *) owned_names; /* 本模块 malloc 的函数名,drop 时释放 */
|
||||
VEC(spl_ast2ir_gref_t) gdata_ref; /* def_id → gdata value 节点索引 */
|
||||
spl_ir_builder_t *ir;
|
||||
int err_count;
|
||||
} spl_ast2ir_t;
|
||||
|
||||
void spl_ast2ir_init(spl_ast2ir_t *ast2ir, const spl_sema_t *sema);
|
||||
void spl_ast2ir_init(spl_ast2ir_t *ast2ir, spl_ir_builder_t *ir, const spl_sema_t *sema);
|
||||
void spl_ast2ir_drop(spl_ast2ir_t *ast2ir);
|
||||
|
||||
void spl_ast2ir_run(spl_ast2ir_t *ast2ir);
|
||||
|
||||
948
stage1/spl_ir.c
948
stage1/spl_ir.c
File diff suppressed because it is too large
Load Diff
159
stage1/spl_ir.h
159
stage1/spl_ir.h
@@ -5,7 +5,6 @@
|
||||
#include "spl_dbg.h"
|
||||
#include "spl_type.h"
|
||||
|
||||
|
||||
/* clang-format off */
|
||||
#define SPL_IR_FN_TABLE \
|
||||
X(arith.add, V0, SPL_IR_ARITH_ADD) \
|
||||
@@ -46,7 +45,6 @@
|
||||
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(mem.fence, V0, SPL_IR_MEM_FENCE) \
|
||||
X(type.const, V0, SPL_IR_TYPE_CONST) \
|
||||
X(type.bitsizeof, V0, SPL_IR_TYPE_BITSIZEOF) \
|
||||
X(type.sizeof, V0, SPL_IR_TYPE_SIZEOF) \
|
||||
@@ -56,15 +54,6 @@
|
||||
X(agg.construct, V0, SPL_IR_AGG_CONSTRUCT) \
|
||||
X(agg.extract, V0, SPL_IR_AGG_EXTRACT) \
|
||||
X(agg.insert, V0, SPL_IR_AGG_INSERT) \
|
||||
X(atomic.load, V0, SPL_IR_ATOMIC_LOAD) \
|
||||
X(atomic.store, V0, SPL_IR_ATOMIC_STORE) \
|
||||
X(atomic.rmw_add, V0, SPL_IR_ATOMIC_RMW_ADD) \
|
||||
X(atomic.rmw_sub, V0, SPL_IR_ATOMIC_RMW_SUB) \
|
||||
X(atomic.rmw_and, V0, SPL_IR_ATOMIC_RMW_AND) \
|
||||
X(atomic.rmw_or, V0, SPL_IR_ATOMIC_RMW_OR) \
|
||||
X(atomic.rmw_xor, V0, SPL_IR_ATOMIC_RMW_XOR) \
|
||||
X(atomic.rmw_xchg, V0, SPL_IR_ATOMIC_RMW_XCHG) \
|
||||
X(atomic.cmpxchg, V0, SPL_IR_ATOMIC_CMPXCHG) \
|
||||
X(control.select, V0, SPL_IR_CONTROL_SELECT) \
|
||||
X(control.br, V0, SPL_IR_CONTROL_BR) \
|
||||
X(control.jmp, V0, SPL_IR_CONTROL_JMP) \
|
||||
@@ -74,8 +63,7 @@
|
||||
X(control.unreachable, V0, SPL_IR_CONTROL_UNREACHABLE) \
|
||||
X(control.trap, V0, SPL_IR_CONTROL_TRAP) \
|
||||
X(dbg.breakpoint, V0, SPL_IR_DBG_BREAKPOINT) \
|
||||
X(dbg.declare, V0, SPL_IR_DBG_DECLARE)
|
||||
|
||||
|
||||
typedef enum {
|
||||
#ifdef X
|
||||
#undef X
|
||||
@@ -95,6 +83,7 @@ typedef struct {
|
||||
spl_ir_kind_t kind;
|
||||
spl_dbg_node_t dbg;
|
||||
union {
|
||||
spl_type_id_t tid;
|
||||
struct {
|
||||
spl_type_id_t tid;
|
||||
spl_ir_node_ref_t left;
|
||||
@@ -149,9 +138,6 @@ typedef struct {
|
||||
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 {
|
||||
@@ -267,4 +253,145 @@ 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, const spl_type_t *ty);
|
||||
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_builder_t;
|
||||
|
||||
/* clang-format off */
|
||||
#define SPL_IR_BIN_ARITH_TABLE \
|
||||
X(arith_add, SPL_IR_ARITH_ADD) \
|
||||
X(arith_sub, SPL_IR_ARITH_SUB) \
|
||||
X(arith_mul, SPL_IR_ARITH_MUL) \
|
||||
X(arith_div, SPL_IR_ARITH_DIV) \
|
||||
X(arith_rem, SPL_IR_ARITH_REM) \
|
||||
X(arith_and, SPL_IR_ARITH_AND) \
|
||||
X(arith_or, SPL_IR_ARITH_OR) \
|
||||
X(arith_xor, SPL_IR_ARITH_XOR) \
|
||||
X(arith_shl, SPL_IR_ARITH_SHL) \
|
||||
X(arith_shr, SPL_IR_ARITH_SHR)
|
||||
#define SPL_IR_UN_ARITH_TABLE \
|
||||
X(arith_neg, SPL_IR_ARITH_NEG) \
|
||||
X(arith_abs, SPL_IR_ARITH_ABS) \
|
||||
X(arith_not, SPL_IR_ARITH_NOT)
|
||||
#define SPL_IR_CMP_TABLE \
|
||||
X(cmp_eq, SPL_IR_CMP_EQ) \
|
||||
X(cmp_ne, SPL_IR_CMP_NE) \
|
||||
X(cmp_lt, SPL_IR_CMP_LT) \
|
||||
X(cmp_le, SPL_IR_CMP_LE) \
|
||||
X(cmp_gt, SPL_IR_CMP_GT) \
|
||||
X(cmp_ge, SPL_IR_CMP_GE)
|
||||
#define SPL_IR_CAST_TABLE \
|
||||
X(cast_trunc, SPL_IR_CAST_TRUNC) \
|
||||
X(cast_zext, SPL_IR_CAST_ZEXT) \
|
||||
X(cast_sext, SPL_IR_CAST_SEXT) \
|
||||
X(cast_fext, SPL_IR_CAST_FEXT) \
|
||||
X(cast_ftrunc, SPL_IR_CAST_FTRUNC) \
|
||||
X(cast_bitcast, SPL_IR_CAST_BITCAST) \
|
||||
X(cast_ptr2int, SPL_IR_CAST_PTR2INT) \
|
||||
X(cast_int2ptr, SPL_IR_CAST_INT2PTR) \
|
||||
X(cast_bool2int, SPL_IR_CAST_BOOL2INT) \
|
||||
X(case_int2float, SPL_IR_CASE_INT2FLOAT) \
|
||||
X(case_float2int, SPL_IR_CASE_FLOAT2INT)
|
||||
/* clang-format on */
|
||||
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_node_ref_t spl_ir_builder_block_new(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_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_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_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_CAST_TABLE
|
||||
#undef X
|
||||
|
||||
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_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_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_cstr(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
const char *val);
|
||||
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_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_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_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_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,
|
||||
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_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_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);
|
||||
|
||||
spl_ir_node_ref_t spl_ir_builder_dbg_breakpoint(spl_ir_builder_t *b);
|
||||
|
||||
#endif /* __SPL_IR_H__ */
|
||||
|
||||
@@ -43,15 +43,14 @@ bool spl_scope_find(spl_scope_t *scope, const char *name, spl_symbol_t *out) {
|
||||
if (scope == NULL || name == NULL || out == NULL) {
|
||||
return false;
|
||||
}
|
||||
spl_symbol_t symbol = {0};
|
||||
for (spl_scope_node_t *s = &vec_at(scope->scopes, scope->current_scope); s->parent != 0;
|
||||
for (spl_scope_node_t *s = &vec_at(scope->scopes, scope->current_scope); s != 0;
|
||||
s = &vec_at(scope->scopes, s->parent)) {
|
||||
if (map_get(s->symbols, name, &symbol) == true) {
|
||||
Assert(symbol.kind != SPL_SYMBOL_KIND_ERROR);
|
||||
if (map_get(s->symbols, name, out) == true) {
|
||||
Assert(out->kind != SPL_SYMBOL_KIND_ERROR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (symbol.kind == SPL_SYMBOL_KIND_ERROR) {
|
||||
if (out->kind == SPL_SYMBOL_KIND_ERROR) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -153,23 +152,71 @@ static void sema_collect(spl_sema_t *sema, spl_ast_node_ref_t ref) {
|
||||
|
||||
// Parse twice
|
||||
static void sema_parse(spl_sema_t *sema, spl_ast_node_ref_t ref) {
|
||||
Assert(sema != NULL && ref != 0);
|
||||
if (ref == 0)
|
||||
return;
|
||||
Assert(sema != NULL);
|
||||
spl_ast_node_t *n = spl_ast_node(sema->ast, ref);
|
||||
spl_symbol_t symbol = {0};
|
||||
spl_def_id_t def = 0;
|
||||
Assert(n != NULL);
|
||||
switch (n->kind) {
|
||||
case SPL_AST_NONE:
|
||||
case SPL_AST_CONTAINER_MEMBERS:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
case SPL_AST_CONTAINER_MEMBERS: {
|
||||
vec_for(n->container_members, i) { sema_parse(sema, vec_at(n->container_members, i)); }
|
||||
} break;
|
||||
case SPL_AST_FN_DECL:
|
||||
case SPL_AST_FN_DEFINE:
|
||||
case SPL_AST_FN_DEFINE: {
|
||||
if (n->resolved_def_id == 0) {
|
||||
Panic("fn `%s` don't collect", n->fn_decl.name);
|
||||
}
|
||||
|
||||
spl_def_node_t *def = spl_type_def(sema->type, n->resolved_def_id);
|
||||
def->kind = SPL_DEF_FN_PARAMS;
|
||||
vec_init(def->fn_params_def);
|
||||
|
||||
spl_scope_id_t scope_id = spl_scope_alloc(sema->scope);
|
||||
spl_scope_id_t old_id = sema->scope->current_scope;
|
||||
sema->scope->current_scope = scope_id;
|
||||
vec_for(n->fn_decl.param_list, i) {
|
||||
spl_ast_node_ref_t ref = vec_at(n->fn_decl.param_list, i);
|
||||
// sema_parse(sema, ref);
|
||||
spl_ast_node_t *node = spl_ast_node(sema->ast, ref);
|
||||
Assert(node->kind = SPL_AST_PARAM_DECL);
|
||||
|
||||
spl_var_def_t var_def = {0};
|
||||
var_def.name = node->param_decl.name;
|
||||
var_def.scope_id = sema->scope->current_scope;
|
||||
vec_push(def->fn_params_def, var_def);
|
||||
}
|
||||
vec_for(n->fn_decl.block, i) { sema_parse(sema, vec_at(n->fn_decl.block, i)); }
|
||||
sema->scope->current_scope = old_id;
|
||||
} break;
|
||||
case SPL_AST_TYPE_DECL:
|
||||
case SPL_AST_VAR_DECL:
|
||||
TODO();
|
||||
break;
|
||||
case SPL_AST_VAR_DECL: {
|
||||
if (n->resolved_def_id == 0) {
|
||||
symbol.name = n->var_const_decl.name;
|
||||
symbol.kind = SPL_SYMBOL_KIND_VAR;
|
||||
symbol.node = spl_type_def_alloc(sema->type);
|
||||
n->resolved_def_id = symbol.node;
|
||||
|
||||
spl_def_node_t *def = spl_type_def(sema->type, symbol.node);
|
||||
def->kind = SPL_DEF_VAR;
|
||||
spl_scope_insert(sema->scope, sema->scope->current_scope, symbol);
|
||||
}
|
||||
spl_def_node_t *def_node = spl_type_def(sema->type, n->resolved_def_id);
|
||||
} break;
|
||||
case SPL_AST_CONST_DECL:
|
||||
case SPL_AST_MEMBER_DECL:
|
||||
TODO();
|
||||
break;
|
||||
case SPL_AST__COMPTIME_STMT:
|
||||
case SPL_AST__DIRECTIVE_BLOCK:
|
||||
case SPL_AST_PARAM_DECL:
|
||||
break;
|
||||
case SPL_AST_ATTR_ITEM:
|
||||
case SPL_AST_ARGG_INIT_ITEM:
|
||||
case SPL_AST_IF_STATEMENT:
|
||||
@@ -178,7 +225,11 @@ static void sema_parse(spl_sema_t *sema, spl_ast_node_ref_t ref) {
|
||||
case SPL_AST_LOOP_STATEMENT:
|
||||
case SPL_AST_FOR_STATEMENT:
|
||||
case SPL_AST_MATCH_STATEMENT:
|
||||
case SPL_AST_RET_STATEMENT:
|
||||
TODO();
|
||||
break;
|
||||
case SPL_AST_RET_STATEMENT: {
|
||||
sema_parse(sema, n->ret_statement.expr);
|
||||
} break;
|
||||
case SPL_AST_BREAK_STATEMENT:
|
||||
case SPL_AST_CONTINUE_STATEMENT:
|
||||
case SPL_AST_DEFER_STATEMENT:
|
||||
@@ -227,6 +278,8 @@ static void sema_parse(spl_sema_t *sema, spl_ast_node_ref_t ref) {
|
||||
case SPL_AST_INDEX_EXPR:
|
||||
case SPL_AST_SLICE_EXPR:
|
||||
case SPL_AST_AS_EXPR:
|
||||
TODO();
|
||||
break;
|
||||
case SPL_AST_EXPR_INTEGER_LIT:
|
||||
case SPL_AST_EXPR_FLOAT_LIT:
|
||||
case SPL_AST_EXPR_CHAR_LIT:
|
||||
@@ -235,7 +288,15 @@ static void sema_parse(spl_sema_t *sema, spl_ast_node_ref_t ref) {
|
||||
case SPL_AST_EXPR_FALSE:
|
||||
case SPL_AST_EXPR_NULL:
|
||||
case SPL_AST_EXPR_UNDEFINED:
|
||||
case SPL_AST_EXPR_IDENT:
|
||||
break;
|
||||
case SPL_AST_EXPR_IDENT: {
|
||||
if (!spl_scope_find(sema->scope, n->primary_expr.ident, &symbol)) {
|
||||
LOG_FATAL("can't find ident `%s`", n->primary_expr.ident);
|
||||
return;
|
||||
}
|
||||
Assert(symbol.node != 0);
|
||||
n->resolved_def_id = symbol.node;
|
||||
} break;
|
||||
case SPL_AST_ARGGREGATE_INIT:
|
||||
case SPL_AST_EXPR_EXPR:
|
||||
case SPL_AST_ARRAY_LIT:
|
||||
@@ -243,6 +304,8 @@ static void sema_parse(spl_sema_t *sema, spl_ast_node_ref_t ref) {
|
||||
case SPL_AST_BLOCK_EXPR:
|
||||
case SPL_AST_BASE_TYPE_FN:
|
||||
case SPL_AST_BASE_TYPE_PATH:
|
||||
TODO();
|
||||
break;
|
||||
case SPL_AST_TYPE_POINTER:
|
||||
case SPL_AST_TYPE_ARRAY:
|
||||
case SPL_AST_TYPE_SLICE:
|
||||
@@ -267,6 +330,7 @@ static void sema_parse(spl_sema_t *sema, spl_ast_node_ref_t ref) {
|
||||
case SPL_AST_TYPE__F64:
|
||||
case SPL_AST_TYPE_ANY:
|
||||
case SPL_AST_TYPE_IDENT:
|
||||
TODO();
|
||||
break;
|
||||
case SPL_AST_COUNT:
|
||||
UNREACHABLE();
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "spl_ast.h"
|
||||
// #include "spl_ast2ir.h"
|
||||
#include "spl_ast2ir.h"
|
||||
// #include "spl_ir2vm.h"
|
||||
#include "spl_lexer.h"
|
||||
#include "spl_sema.h"
|
||||
@@ -107,16 +107,25 @@ static int compile_spl(const char *src, const char *fname, const char *outpath,
|
||||
// memory leak
|
||||
return 0;
|
||||
}
|
||||
// spl_ast2ir_t a2ir;
|
||||
// spl_ast2ir_init(&a2ir, &sema);
|
||||
// spl_ast2ir_run(&a2ir);
|
||||
// if (a2ir.err_count) {
|
||||
// printf("ast2ir errors=%d, no output\n", a2ir.err_count);
|
||||
// spl_ast2ir_drop(&a2ir);
|
||||
// spl_sema_drop(&sema);
|
||||
// spl_ast_drop(&ast);
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
spl_ast2ir_t a2ir;
|
||||
spl_ir_builder_t ir_builder;
|
||||
spl_ir_builder_init(&ir_builder);
|
||||
spl_ast2ir_init(&a2ir, &ir_builder, &sema);
|
||||
spl_ast2ir_run(&a2ir);
|
||||
if (a2ir.err_count) {
|
||||
printf("ast2ir errors=%d, no output\n", a2ir.err_count);
|
||||
spl_ast2ir_drop(&a2ir);
|
||||
spl_sema_drop(&sema);
|
||||
spl_ast_drop(&ast);
|
||||
return 1;
|
||||
}
|
||||
if (dump == DUMP_IR) {
|
||||
spl_ir_dump(&ir_builder.ir, &type);
|
||||
// memory leak
|
||||
return 0;
|
||||
}
|
||||
|
||||
// spl_ir2vm_t ir2vm;
|
||||
// spl_ir2vm_init(&ir2vm, &a2ir.ir, &sema.type);
|
||||
// int rc = spl_ir2vm_run(&ir2vm, outpath);
|
||||
|
||||
Reference in New Issue
Block a user