mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-21 13:14:59 -07:00
Minimal Dependency Map: Only build what is needed
This commit is contained in:
+81
-68
@@ -497,7 +497,7 @@ Type *ssa_type(ssaInstr *instr) {
|
||||
case ssaInstr_Select:
|
||||
return ssa_type(instr->Select.true_value);
|
||||
case ssaInstr_Call: {
|
||||
Type *pt = get_base_type(instr->Call.type);
|
||||
Type *pt = base_type(instr->Call.type);
|
||||
if (pt != NULL) {
|
||||
if (pt->kind == Type_Tuple && pt->Tuple.variable_count == 1)
|
||||
return pt->Tuple.variables[0]->type;
|
||||
@@ -507,7 +507,7 @@ Type *ssa_type(ssaInstr *instr) {
|
||||
} break;
|
||||
case ssaInstr_ExtractElement: {
|
||||
Type *vt = ssa_type(instr->ExtractElement.vector);
|
||||
Type *bt = base_vector_type(get_base_type(vt));
|
||||
Type *bt = base_vector_type(vt);
|
||||
GB_ASSERT(!is_type_vector(bt));
|
||||
return bt;
|
||||
} break;
|
||||
@@ -768,7 +768,7 @@ ssaValue *ssa_make_instr_shuffle_vector(ssaProcedure *p, ssaValue *vector, i32 *
|
||||
v->Instr.ShuffleVector.indices = indices;
|
||||
v->Instr.ShuffleVector.index_count = index_count;
|
||||
|
||||
Type *vt = get_base_type(ssa_type(vector));
|
||||
Type *vt = base_type(ssa_type(vector));
|
||||
v->Instr.ShuffleVector.type = make_type_vector(p->module->allocator, vt->Vector.elem, index_count);
|
||||
|
||||
return v;
|
||||
@@ -950,7 +950,7 @@ ssaValue *ssa_add_param(ssaProcedure *proc, Entity *e) {
|
||||
|
||||
|
||||
ssaValue *ssa_emit_call(ssaProcedure *p, ssaValue *value, ssaValue **args, isize arg_count) {
|
||||
Type *pt = get_base_type(ssa_type(value));
|
||||
Type *pt = base_type(ssa_type(value));
|
||||
GB_ASSERT(pt->kind == Type_Proc);
|
||||
Type *results = pt->Proc.results;
|
||||
return ssa_emit(p, ssa_make_instr_call(p, value, args, arg_count, results));
|
||||
@@ -1077,7 +1077,7 @@ ssaValue *ssa_lvalue_store(ssaProcedure *proc, ssaAddr lval, ssaValue *value) {
|
||||
if (lval.addr != NULL) {
|
||||
if (lval.is_vector) {
|
||||
ssaValue *v = ssa_emit_load(proc, lval.addr);
|
||||
Type *elem_type = get_base_type(ssa_type(v))->Vector.elem;
|
||||
Type *elem_type = base_type(ssa_type(v))->Vector.elem;
|
||||
ssaValue *elem = ssa_emit_conv(proc, value, elem_type);
|
||||
ssaValue *out = ssa_emit(proc, ssa_make_instr_insert_element(proc, v, elem, lval.index));
|
||||
return ssa_emit_store(proc, lval.addr, out);
|
||||
@@ -1095,7 +1095,7 @@ ssaValue *ssa_lvalue_load(ssaProcedure *proc, ssaAddr lval) {
|
||||
return ssa_emit(proc, ssa_make_instr_extract_element(proc, v, lval.index));
|
||||
}
|
||||
// NOTE(bill): Imported procedures don't require a load as they are pointers
|
||||
Type *t = get_base_type(ssa_type(lval.addr));
|
||||
Type *t = base_type(ssa_type(lval.addr));
|
||||
if (t->kind == Type_Proc) {
|
||||
return lval.addr;
|
||||
}
|
||||
@@ -1214,8 +1214,8 @@ ssaValue *ssa_emit_arith(ssaProcedure *proc, Token op, ssaValue *left, ssaValue
|
||||
}
|
||||
|
||||
ssaValue *ssa_emit_comp(ssaProcedure *proc, Token op, ssaValue *left, ssaValue *right) {
|
||||
Type *a = get_base_type(ssa_type(left));
|
||||
Type *b = get_base_type(ssa_type(right));
|
||||
Type *a = base_type(ssa_type(left));
|
||||
Type *b = base_type(ssa_type(right));
|
||||
|
||||
if (are_types_identical(a, b)) {
|
||||
// NOTE(bill): No need for a conversion
|
||||
@@ -1280,7 +1280,7 @@ ssaValue *ssa_emit_deep_field_gep(ssaProcedure *proc, Type *type, ssaValue *e, S
|
||||
e = ssa_emit_load(proc, e);
|
||||
e = ssa_emit_ptr_offset(proc, e, v_zero);
|
||||
}
|
||||
type = get_base_type(type);
|
||||
type = base_type(type);
|
||||
|
||||
|
||||
if (is_type_raw_union(type)) {
|
||||
@@ -1329,7 +1329,7 @@ ssaValue *ssa_emit_deep_field_ev(ssaProcedure *proc, Type *type, ssaValue *e, Se
|
||||
e = ssa_emit_load(proc, e);
|
||||
e = ssa_emit_ptr_offset(proc, e, v_zero);
|
||||
}
|
||||
type = get_base_type(type);
|
||||
type = base_type(type);
|
||||
|
||||
|
||||
if (is_type_raw_union(type)) {
|
||||
@@ -1465,20 +1465,20 @@ ssaValue *ssa_add_local_slice(ssaProcedure *proc, Type *slice_type, ssaValue *ba
|
||||
// TODO(bill): array bounds checking for slice creation
|
||||
// TODO(bill): check that low < high <= max
|
||||
gbAllocator a = proc->module->allocator;
|
||||
Type *base_type = get_base_type(ssa_type(base));
|
||||
Type *bt = base_type(ssa_type(base));
|
||||
|
||||
if (low == NULL) {
|
||||
low = v_zero;
|
||||
}
|
||||
if (high == NULL) {
|
||||
switch (base_type->kind) {
|
||||
switch (bt->kind) {
|
||||
case Type_Array: high = ssa_array_len(proc, base); break;
|
||||
case Type_Slice: high = ssa_slice_len(proc, base); break;
|
||||
case Type_Pointer: high = v_one; break;
|
||||
}
|
||||
}
|
||||
if (max == NULL) {
|
||||
switch (base_type->kind) {
|
||||
switch (bt->kind) {
|
||||
case Type_Array: max = ssa_array_cap(proc, base); break;
|
||||
case Type_Slice: max = ssa_slice_cap(proc, base); break;
|
||||
case Type_Pointer: max = high; break;
|
||||
@@ -1491,7 +1491,7 @@ ssaValue *ssa_add_local_slice(ssaProcedure *proc, Type *slice_type, ssaValue *ba
|
||||
ssaValue *cap = ssa_emit_arith(proc, op_sub, max, low, t_int);
|
||||
|
||||
ssaValue *elem = NULL;
|
||||
switch (base_type->kind) {
|
||||
switch (bt->kind) {
|
||||
case Type_Array: elem = ssa_array_elem(proc, base); break;
|
||||
case Type_Slice: elem = ssa_slice_elem(proc, base); break;
|
||||
case Type_Pointer: elem = ssa_emit_load(proc, base); break;
|
||||
@@ -1565,8 +1565,8 @@ ssaValue *ssa_emit_global_string(ssaProcedure *proc, String str) {
|
||||
String lookup_polymorphic_field(CheckerInfo *info, Type *dst, Type *src) {
|
||||
Type *prev_src = src;
|
||||
// Type *prev_dst = dst;
|
||||
src = get_base_type(type_deref(src));
|
||||
// dst = get_base_type(type_deref(dst));
|
||||
src = base_type(type_deref(src));
|
||||
// dst = base_type(type_deref(dst));
|
||||
b32 src_is_ptr = src != prev_src;
|
||||
// b32 dst_is_ptr = dst != prev_dst;
|
||||
|
||||
@@ -1599,8 +1599,8 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t, b32 is_arg
|
||||
}
|
||||
|
||||
|
||||
Type *src = get_enum_base_type(get_base_type(src_type));
|
||||
Type *dst = get_enum_base_type(get_base_type(t));
|
||||
Type *src = get_enum_base_type(base_type(src_type));
|
||||
Type *dst = get_enum_base_type(base_type(t));
|
||||
|
||||
if (value->kind == ssaValue_Constant) {
|
||||
if (is_type_any(dst)) {
|
||||
@@ -1718,7 +1718,7 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t, b32 is_arg
|
||||
// NOTE(bill): This has to be done beofre `Pointer <-> Pointer` as it's
|
||||
// subtype polymorphism casting
|
||||
if (is_argument) {
|
||||
Type *sb = get_base_type(type_deref(src));
|
||||
Type *sb = base_type(type_deref(src));
|
||||
b32 src_is_ptr = src != sb;
|
||||
if (is_type_struct(sb)) {
|
||||
String field_name = lookup_polymorphic_field(proc->module->info, t, src);
|
||||
@@ -1840,8 +1840,8 @@ ssaValue *ssa_emit_transmute(ssaProcedure *proc, ssaValue *value, Type *t) {
|
||||
return value;
|
||||
}
|
||||
|
||||
Type *src = get_base_type(src_type);
|
||||
Type *dst = get_base_type(t);
|
||||
Type *src = base_type(src_type);
|
||||
Type *dst = base_type(t);
|
||||
if (are_types_identical(t, src_type))
|
||||
return value;
|
||||
|
||||
@@ -2080,17 +2080,17 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
case_ast_node(cl, CompoundLit, expr);
|
||||
ssa_emit_comment(proc, make_string("CompoundLit"));
|
||||
Type *type = type_of_expr(proc->module->info, expr);
|
||||
Type *base_type = get_base_type(type);
|
||||
Type *bt = base_type(type);
|
||||
ssaValue *v = ssa_add_local_generated(proc, type);
|
||||
|
||||
Type *et = NULL;
|
||||
switch (base_type->kind) {
|
||||
case Type_Vector: et = base_type->Vector.elem; break;
|
||||
case Type_Array: et = base_type->Array.elem; break;
|
||||
case Type_Slice: et = base_type->Slice.elem; break;
|
||||
switch (bt->kind) {
|
||||
case Type_Vector: et = bt->Vector.elem; break;
|
||||
case Type_Array: et = bt->Array.elem; break;
|
||||
case Type_Slice: et = bt->Slice.elem; break;
|
||||
}
|
||||
|
||||
switch (base_type->kind) {
|
||||
switch (bt->kind) {
|
||||
default: GB_PANIC("Unknown CompoundLit type: %s", type_to_string(type)); break;
|
||||
|
||||
case Type_Vector: {
|
||||
@@ -2105,8 +2105,8 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
ssaValue *i = ssa_make_const_int(proc->module->allocator, index);
|
||||
result = ssa_emit(proc, ssa_make_instr_insert_element(proc, result, ev, i));
|
||||
}
|
||||
if (index == 1 && base_type->Vector.count > 1) {
|
||||
isize index_count = base_type->Vector.count;
|
||||
if (index == 1 && bt->Vector.count > 1) {
|
||||
isize index_count = bt->Vector.count;
|
||||
i32 *indices = gb_alloc_array(proc->module->allocator, i32, index_count);
|
||||
for (isize i = 0; i < index_count; i++) {
|
||||
indices[i] = 0;
|
||||
@@ -2120,8 +2120,8 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
} break;
|
||||
|
||||
case Type_Record: {
|
||||
GB_ASSERT(is_type_struct(base_type));
|
||||
auto *st = &base_type->Record;
|
||||
GB_ASSERT(is_type_struct(bt));
|
||||
auto *st = &bt->Record;
|
||||
if (cl->elems != NULL && gb_array_count(cl->elems) > 0) {
|
||||
gb_for_array(field_index, cl->elems) {
|
||||
isize index = field_index;
|
||||
@@ -2131,11 +2131,11 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
|
||||
if (elem->kind == AstNode_FieldValue) {
|
||||
ast_node(kv, FieldValue, elem);
|
||||
Selection sel = lookup_field(proc->module->allocator, base_type, kv->field->Ident.string, false);
|
||||
Selection sel = lookup_field(proc->module->allocator, bt, kv->field->Ident.string, false);
|
||||
index = sel.index[0];
|
||||
field_expr = ssa_build_expr(proc, kv->value);
|
||||
} else {
|
||||
Selection sel = lookup_field(proc->module->allocator, base_type, st->fields_in_src_order[field_index]->token.string, false);
|
||||
Selection sel = lookup_field(proc->module->allocator, bt, st->fields_in_src_order[field_index]->token.string, false);
|
||||
index = sel.index[0];
|
||||
field_expr = ssa_build_expr(proc, elem);
|
||||
}
|
||||
@@ -2164,7 +2164,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
} break;
|
||||
case Type_Slice: {
|
||||
i64 count = gb_array_count(cl->elems);
|
||||
Type *elem_type = base_type->Slice.elem;
|
||||
Type *elem_type = bt->Slice.elem;
|
||||
Type *elem_ptr_type = make_type_pointer(proc->module->allocator, elem_type);
|
||||
ssaValue *array = ssa_add_local_generated(proc, make_type_array(proc->module->allocator, elem_type, count));
|
||||
|
||||
@@ -2334,7 +2334,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
AstNode *src_node = ce->args[1];
|
||||
ssaValue *dst_slice = ssa_build_expr(proc, dst_node);
|
||||
ssaValue *src_slice = ssa_build_expr(proc, src_node);
|
||||
Type *slice_type = get_base_type(ssa_type(dst_slice));
|
||||
Type *slice_type = base_type(ssa_type(dst_slice));
|
||||
GB_ASSERT(slice_type->kind == Type_Slice);
|
||||
Type *elem_type = slice_type->Slice.elem;
|
||||
i64 size_of_elem = type_size_of(proc->module->sizes, proc->module->allocator, elem_type);
|
||||
@@ -2455,7 +2455,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
ssa_emit_comment(proc, make_string("ptr_sub"));
|
||||
ssaValue *ptr_a = ssa_build_expr(proc, ce->args[0]);
|
||||
ssaValue *ptr_b = ssa_build_expr(proc, ce->args[1]);
|
||||
Type *ptr_type = get_base_type(ssa_type(ptr_a));
|
||||
Type *ptr_type = base_type(ssa_type(ptr_a));
|
||||
GB_ASSERT(ptr_type->kind == Type_Pointer);
|
||||
isize elem_size = type_size_of(proc->module->sizes, proc->module->allocator, ptr_type->Pointer.elem);
|
||||
Token sub = {Token_Sub};
|
||||
@@ -2495,7 +2495,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
ssa_emit_comment(proc, make_string("min"));
|
||||
ssaValue *x = ssa_build_expr(proc, ce->args[0]);
|
||||
ssaValue *y = ssa_build_expr(proc, ce->args[1]);
|
||||
Type *t = get_base_type(ssa_type(x));
|
||||
Type *t = base_type(ssa_type(x));
|
||||
Token lt = {Token_Lt};
|
||||
ssaValue *cond = ssa_emit_comp(proc, lt, x, y);
|
||||
return ssa_emit_select(proc, cond, x, y);
|
||||
@@ -2505,7 +2505,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
ssa_emit_comment(proc, make_string("max"));
|
||||
ssaValue *x = ssa_build_expr(proc, ce->args[0]);
|
||||
ssaValue *y = ssa_build_expr(proc, ce->args[1]);
|
||||
Type *t = get_base_type(ssa_type(x));
|
||||
Type *t = base_type(ssa_type(x));
|
||||
Token gt = {Token_Gt};
|
||||
ssaValue *cond = ssa_emit_comp(proc, gt, x, y);
|
||||
return ssa_emit_select(proc, cond, x, y);
|
||||
@@ -2544,7 +2544,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
|
||||
// NOTE(bill): Regular call
|
||||
ssaValue *value = ssa_build_expr(proc, ce->proc);
|
||||
Type *proc_type_ = get_base_type(ssa_type(value));
|
||||
Type *proc_type_ = base_type(ssa_type(value));
|
||||
GB_ASSERT(proc_type_->kind == Type_Proc);
|
||||
auto *type = &proc_type_->Proc;
|
||||
|
||||
@@ -2553,7 +2553,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
isize arg_count = 0;
|
||||
gb_for_array(i, ce->args) {
|
||||
AstNode *a = ce->args[i];
|
||||
Type *at = get_base_type(type_of_expr(proc->module->info, a));
|
||||
Type *at = base_type(type_of_expr(proc->module->info, a));
|
||||
if (at->kind == Type_Tuple) {
|
||||
arg_count += at->Tuple.variable_count;
|
||||
} else {
|
||||
@@ -2588,7 +2588,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
if (!vari_expand) {
|
||||
Type *variadic_type = pt->variables[i]->type;
|
||||
GB_ASSERT(is_type_slice(variadic_type));
|
||||
variadic_type = get_base_type(variadic_type)->Slice.elem;
|
||||
variadic_type = base_type(variadic_type)->Slice.elem;
|
||||
for (; i < arg_count; i++) {
|
||||
args[i] = ssa_emit_conv(proc, args[i], variadic_type, true);
|
||||
}
|
||||
@@ -2603,7 +2603,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
||||
ssa_emit_comment(proc, make_string("variadic call argument generation"));
|
||||
gbAllocator allocator = proc->module->allocator;
|
||||
Type *slice_type = pt->variables[type->param_count-1]->type;
|
||||
Type *elem_type = get_base_type(slice_type)->Slice.elem;
|
||||
Type *elem_type = base_type(slice_type)->Slice.elem;
|
||||
Type *elem_ptr_type = make_type_pointer(allocator, elem_type);
|
||||
ssaValue *slice = ssa_add_local_generated(proc, slice_type);
|
||||
isize slice_len = arg_count+1 - type->param_count;
|
||||
@@ -2716,7 +2716,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
|
||||
Entity *e = entity_of_ident(proc->module->info, expr);
|
||||
|
||||
if (e->kind == Entity_Constant) {
|
||||
if (get_base_type(e->type) == t_string) {
|
||||
if (base_type(e->type) == t_string) {
|
||||
// HACK TODO(bill): This is lazy but it works
|
||||
String str = e->Constant.value.value_string;
|
||||
ssaValue *global_array = ssa_add_global_string_array(proc->module, str);
|
||||
@@ -2752,7 +2752,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
|
||||
case_ast_node(se, SelectorExpr, expr);
|
||||
ssa_emit_comment(proc, make_string("SelectorExpr"));
|
||||
String selector = unparen_expr(se->selector)->Ident.string;
|
||||
Type *type = get_base_type(type_of_expr(proc->module->info, se->expr));
|
||||
Type *type = base_type(type_of_expr(proc->module->info, se->expr));
|
||||
|
||||
if (type == t_invalid) {
|
||||
// NOTE(bill): Imports
|
||||
@@ -2807,7 +2807,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
|
||||
|
||||
case_ast_node(ie, IndexExpr, expr);
|
||||
ssa_emit_comment(proc, make_string("IndexExpr"));
|
||||
Type *t = get_base_type(type_of_expr(proc->module->info, ie->expr));
|
||||
Type *t = base_type(type_of_expr(proc->module->info, ie->expr));
|
||||
gbAllocator a = proc->module->allocator;
|
||||
|
||||
switch (t->kind) {
|
||||
@@ -2874,7 +2874,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
|
||||
if (se->high != NULL) high = ssa_build_expr(proc, se->high);
|
||||
if (se->triple_indexed) max = ssa_build_expr(proc, se->max);
|
||||
ssaAddr base = ssa_build_addr(proc, se->expr);
|
||||
Type *type = get_base_type(ssa_addr_type(base));
|
||||
Type *type = base_type(ssa_addr_type(base));
|
||||
|
||||
// TODO(bill): Cleanup like mad!
|
||||
|
||||
@@ -3052,7 +3052,7 @@ void ssa_gen_global_type_name(ssaModule *m, Entity *e, String name) {
|
||||
ssa_module_add_value(m, e, t);
|
||||
map_set(&m->members, hash_string(name), t);
|
||||
|
||||
Type *bt = get_base_type(e->type);
|
||||
Type *bt = base_type(e->type);
|
||||
if (bt->kind == Type_Record) {
|
||||
auto *s = &bt->Record;
|
||||
for (isize j = 0; j < s->other_field_count; j++) {
|
||||
@@ -3232,7 +3232,6 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
name = pd->foreign_name;
|
||||
}
|
||||
|
||||
Entity *f = *map_get(&info->foreign_procs, hash_string(name));
|
||||
ssaValue *value = ssa_make_value_procedure(proc->module->allocator,
|
||||
proc->module, e, e->type, pd->type, pd->body, name);
|
||||
|
||||
@@ -3240,8 +3239,15 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
|
||||
ssa_module_add_value(proc->module, e, value);
|
||||
ssa_build_proc(value, proc);
|
||||
if (e == f) {
|
||||
// NOTE(bill): Don't do mutliple declarations in the IR
|
||||
|
||||
if (value->Proc.tags & ProcTag_foreign) {
|
||||
HashKey key = hash_string(name);
|
||||
auto *prev_value = map_get(&proc->module->members, key);
|
||||
if (prev_value == NULL) {
|
||||
// NOTE(bill): Don't do mutliple declarations in the IR
|
||||
map_set(&proc->module->members, key, value);
|
||||
}
|
||||
} else {
|
||||
gb_array_append(proc->children, &value->Proc);
|
||||
}
|
||||
}
|
||||
@@ -3685,13 +3691,13 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
|
||||
|
||||
|
||||
Type *base_type = type_deref(tag_var_entity->type);
|
||||
Type *bt = type_deref(tag_var_entity->type);
|
||||
ssaValue *index = NULL;
|
||||
Type *ut = get_base_type(union_type);
|
||||
Type *ut = base_type(union_type);
|
||||
GB_ASSERT(ut->Record.kind == TypeRecord_Union);
|
||||
for (isize field_index = 1; field_index < ut->Record.field_count; field_index++) {
|
||||
Entity *f = get_base_type(union_type)->Record.fields[field_index];
|
||||
if (are_types_identical(f->type, base_type)) {
|
||||
Entity *f = base_type(union_type)->Record.fields[field_index];
|
||||
if (are_types_identical(f->type, bt)) {
|
||||
index = ssa_make_const_int(allocator, field_index);
|
||||
break;
|
||||
}
|
||||
@@ -3739,14 +3745,22 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
|
||||
case_ast_node(bs, BranchStmt, node);
|
||||
ssaBlock *block = NULL;
|
||||
#define branch_case(x) case GB_JOIN2(Token_, x): \
|
||||
for (ssaTargetList *t = proc->target_list; t != NULL && block == NULL; t = t->prev) { \
|
||||
block = GB_JOIN3(t->, x, _); \
|
||||
} break
|
||||
switch (bs->token.kind) {
|
||||
branch_case(break);
|
||||
branch_case(continue);
|
||||
branch_case(fallthrough);
|
||||
case Token_break:
|
||||
for (ssaTargetList *t = proc->target_list; t != NULL && block == NULL; t = t->prev) {
|
||||
block = t->break_;
|
||||
}
|
||||
break;
|
||||
case Token_continue:
|
||||
for (ssaTargetList *t = proc->target_list; t != NULL && block == NULL; t = t->prev) {
|
||||
block = t->continue_;
|
||||
}
|
||||
break;
|
||||
case Token_fallthrough:
|
||||
for (ssaTargetList *t = proc->target_list; t != NULL && block == NULL; t = t->prev) {
|
||||
block = t->fallthrough_;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// TODO(bill): Handle fallthrough scope exit correctly
|
||||
// if (block != NULL && bs->token.kind != Token_fallthrough) {
|
||||
@@ -3806,14 +3820,14 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
|
||||
|
||||
|
||||
void ssa_emit_startup_runtime(ssaProcedure *proc) {
|
||||
GB_ASSERT(proc->parent == NULL && proc->name == make_string("main"));
|
||||
GB_ASSERT(proc->parent == NULL && proc->name == "main");
|
||||
|
||||
ssa_emit(proc, ssa_alloc_instr(proc, ssaInstr_StartupRuntime));
|
||||
}
|
||||
|
||||
void ssa_insert_code_before_proc(ssaProcedure* proc, ssaProcedure *parent) {
|
||||
if (parent == NULL) {
|
||||
if (proc->name == make_string("main")) {
|
||||
if (proc->name == "main") {
|
||||
ssa_emit_startup_runtime(proc);
|
||||
}
|
||||
}
|
||||
@@ -3834,7 +3848,6 @@ void ssa_build_proc(ssaValue *value, ssaProcedure *parent) {
|
||||
AstFile *f = *found;
|
||||
ssaDebugInfo *di_file = NULL;
|
||||
|
||||
|
||||
ssaDebugInfo **di_file_found = map_get(&m->debug_info, hash_pointer(f));
|
||||
if (di_file_found) {
|
||||
di_file = *di_file_found;
|
||||
@@ -3856,11 +3869,11 @@ void ssa_build_proc(ssaValue *value, ssaProcedure *parent) {
|
||||
defer (proc->module->stmt_state_flags = out);
|
||||
|
||||
if (in & ProcTag_bounds_check) {
|
||||
out |= ProcTag_bounds_check;
|
||||
out &= ~ProcTag_no_bounds_check;
|
||||
out |= StmtStateFlag_bounds_check;
|
||||
out &= ~StmtStateFlag_no_bounds_check;
|
||||
} else if (in & ProcTag_no_bounds_check) {
|
||||
out |= ProcTag_no_bounds_check;
|
||||
out &= ~ProcTag_bounds_check;
|
||||
out |= StmtStateFlag_no_bounds_check;
|
||||
out &= ~StmtStateFlag_bounds_check;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user