stage1 使用切片表达字符串而非C字符串 提供属性系统
This commit is contained in:
1 parent
a64a96f9a4
commit
72ae6d6994
14 files changed
+685
-1256
No files matched your search
+42
-10
@@ -28,6 +28,9 @@ static void node_drop_vecs(spl_ir_node_t *n) {
|
||||
case SPL_IR_CONTROL_CALL:
|
||||
vec_free(n->control_call.params);
|
||||
break;
|
||||
case SPL_IR_DBG_PANIC:
|
||||
free((char *)n->dbg_panic.msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -36,7 +39,11 @@ static void node_drop_vecs(spl_ir_node_t *n) {
|
||||
void spl_ir_drop(spl_ir_t *ir) {
|
||||
vec_for(ir->funcs, i) {
|
||||
spl_ir_func_t *f = &vec_at(ir->funcs, i);
|
||||
vec_for(f->nodes, j) { node_drop_vecs(&vec_at(f->nodes, j)); }
|
||||
vec_for(f->nodes, j) {
|
||||
vec_free(vec_at(f->nodes, j).attrs);
|
||||
node_drop_vecs(&vec_at(f->nodes, j));
|
||||
}
|
||||
vec_free(f->attrs);
|
||||
vec_free(f->nodes);
|
||||
}
|
||||
vec_free(ir->funcs);
|
||||
@@ -267,10 +274,25 @@ static void ir_dump_node(const spl_type_t *ty, spl_ir_node_t *n) {
|
||||
case SPL_IR_CONTROL_TRAP:
|
||||
case SPL_IR_DBG_BREAKPOINT:
|
||||
break;
|
||||
case SPL_IR_DBG_PANIC:
|
||||
printf(" \"%.*s\"", (int)n->dbg_panic.len, n->dbg_panic.msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void spl_ir_dump(spl_ir_t *ir, const spl_type_t *ty) {
|
||||
static void ir_dump_attr_list(const spl_attr_t *attr, spl_attr_id_vec_t *ids) {
|
||||
if (!attr || !ids || vec_size(*ids) == 0)
|
||||
return;
|
||||
printf(" attrs=[");
|
||||
for (usize i = 0; i < vec_size(*ids); ++i) {
|
||||
if (i > 0)
|
||||
printf(", ");
|
||||
spl_attr_dump_id(attr, vec_at(*ids, i));
|
||||
}
|
||||
printf("]");
|
||||
}
|
||||
|
||||
void spl_ir_dump(spl_ir_t *ir, const spl_type_t *ty, const spl_attr_t *attr) {
|
||||
vec_for(ir->funcs, i) {
|
||||
if (i == 0)
|
||||
continue;
|
||||
@@ -278,7 +300,9 @@ void spl_ir_dump(spl_ir_t *ir, const spl_type_t *ty) {
|
||||
printf("func %s %%%zu", func->name ? func->name : "?", i);
|
||||
printf(" tid = ");
|
||||
spl_type_pure_dump((spl_type_t *)ty, func->fn_tid);
|
||||
ir_dump_attr_list(attr, &func->attrs);
|
||||
printf("\n");
|
||||
|
||||
vec_for(func->nodes, j) {
|
||||
if (j == 0)
|
||||
continue;
|
||||
@@ -286,10 +310,9 @@ void spl_ir_dump(spl_ir_t *ir, const spl_type_t *ty) {
|
||||
printf(" #%zu ", j);
|
||||
printf("%s", spl_ir_kind_name(node->kind));
|
||||
ir_dump_node(ty, node);
|
||||
ir_dump_attr_list(attr, &node->attrs);
|
||||
printf("\n");
|
||||
}
|
||||
if (vec_size(func->nodes) == 0)
|
||||
printf(" (extern)\n");
|
||||
}
|
||||
// if (vec_size(ir->gdata) > 1) {
|
||||
// printf("gdata:\n");
|
||||
@@ -315,6 +338,7 @@ static spl_ir_node_ref_t builder_alloc_node(spl_ir_builder_t *b, spl_ir_kind_t k
|
||||
spl_ir_node_t *n = spl_ir_node(&b->ir, b->current_fn, ref);
|
||||
n->kind = kind;
|
||||
n->dbg = b->dbg;
|
||||
vec_init(n->attrs);
|
||||
|
||||
if (b->current_block >= vec_size(b->blocks)) {
|
||||
Panic("unknown bblock");
|
||||
@@ -345,14 +369,14 @@ void spl_ir_builder_drop(spl_ir_builder_t *b) {
|
||||
}
|
||||
|
||||
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) {
|
||||
spl_type_id_t fn_tid) {
|
||||
if (b->current_fn) {
|
||||
spl_ir_builder_fn_end(b);
|
||||
}
|
||||
spl_ir_func_ref_t fid = spl_ir_alloc_fn(&b->ir);
|
||||
spl_ir_func_t *f = spl_ir_func(&b->ir, fid);
|
||||
f->name = name;
|
||||
f->attr = attr;
|
||||
vec_init(f->attrs);
|
||||
f->fn_tid = fn_tid;
|
||||
|
||||
b->current_fn = fid;
|
||||
@@ -587,13 +611,13 @@ spl_ir_node_ref_t spl_ir_builder_type_const_float(spl_ir_builder_t *b, spl_type_
|
||||
return ref;
|
||||
}
|
||||
|
||||
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_bytes(spl_ir_builder_t *b, spl_type_id_t tid,
|
||||
const void *data, usize len) {
|
||||
(void)len;
|
||||
spl_ir_node_ref_t ref = builder_alloc_node(b, SPL_IR_TYPE_CONST);
|
||||
spl_ir_node_t *n = spl_ir_node(&b->ir, b->current_fn, ref);
|
||||
n->type_const.tid = tid;
|
||||
TODO();
|
||||
// n->type_const.cstr_lit = val;
|
||||
n->type_const.ptr_lit = (void *)data;
|
||||
return ref;
|
||||
}
|
||||
|
||||
@@ -792,3 +816,11 @@ 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) {
|
||||
return builder_alloc_node(b, SPL_IR_DBG_BREAKPOINT);
|
||||
}
|
||||
|
||||
spl_ir_node_ref_t spl_ir_builder_dbg_panic(spl_ir_builder_t *b, const char *msg, usize len) {
|
||||
spl_ir_node_ref_t ref = builder_alloc_node(b, SPL_IR_DBG_PANIC);
|
||||
spl_ir_node_t *n = spl_ir_node(&b->ir, b->current_fn, ref);
|
||||
n->dbg_panic.msg = msg;
|
||||
n->dbg_panic.len = len;
|
||||
return ref;
|
||||
}
|
||||
Reference in new issue
Block a user