mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-28 01:03:56 +00:00
Remove allocator parameter to types.cpp functions
This commit is contained in:
@@ -231,7 +231,7 @@ void check_type_decl(Checker *c, Entity *e, AstNode *type_expr, Type *def) {
|
||||
AstNode *te = remove_type_alias_clutter(type_expr);
|
||||
e->type = t_invalid;
|
||||
String name = e->token.string;
|
||||
Type *named = make_type_named(c->allocator, name, nullptr, e);
|
||||
Type *named = alloc_type_named(name, nullptr, e);
|
||||
named->Named.type_name = e;
|
||||
if (def != nullptr && def->kind == Type_Named) {
|
||||
def->Named.base = named;
|
||||
@@ -400,8 +400,8 @@ bool are_signatures_similar_enough(Type *a_, Type *b_) {
|
||||
if (is_type_integer(x) && is_type_integer(y)) {
|
||||
GB_ASSERT(x->kind == Type_Basic);
|
||||
GB_ASSERT(y->kind == Type_Basic);
|
||||
i64 sx = type_size_of(heap_allocator(), x);
|
||||
i64 sy = type_size_of(heap_allocator(), y);
|
||||
i64 sx = type_size_of(x);
|
||||
i64 sy = type_size_of(y);
|
||||
if (sx == sy) continue;
|
||||
}
|
||||
|
||||
@@ -417,8 +417,8 @@ bool are_signatures_similar_enough(Type *a_, Type *b_) {
|
||||
if (is_type_integer(x) && is_type_integer(y)) {
|
||||
GB_ASSERT(x->kind == Type_Basic);
|
||||
GB_ASSERT(y->kind == Type_Basic);
|
||||
i64 sx = type_size_of(heap_allocator(), x);
|
||||
i64 sy = type_size_of(heap_allocator(), y);
|
||||
i64 sx = type_size_of(x);
|
||||
i64 sy = type_size_of(y);
|
||||
if (sx == sy) continue;
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
|
||||
if (d->gen_proc_type != nullptr) {
|
||||
proc_type = d->gen_proc_type;
|
||||
} else {
|
||||
proc_type = make_type_proc(c->allocator, e->scope, nullptr, 0, nullptr, 0, false, ProcCC_Odin);
|
||||
proc_type = alloc_type_proc(e->scope, nullptr, 0, nullptr, 0, false, ProcCC_Odin);
|
||||
}
|
||||
e->type = proc_type;
|
||||
ast_node(pl, ProcLit, d->proc_lit);
|
||||
|
||||
@@ -56,7 +56,7 @@ void check_expr_or_type (Checker *c, Operand *operand, AstNode *
|
||||
ExprKind check_expr_base (Checker *c, Operand *operand, AstNode *expression, Type *type_hint);
|
||||
void check_expr_with_type_hint (Checker *c, Operand *o, AstNode *e, Type *t);
|
||||
Type * check_type (Checker *c, AstNode *expression, Type *named_type = nullptr);
|
||||
Type * make_optional_ok_type (gbAllocator a, Type *value);
|
||||
Type * make_optional_ok_type (Type *value);
|
||||
void check_type_decl (Checker *c, Entity *e, AstNode *type_expr, Type *def);
|
||||
Entity * check_selector (Checker *c, Operand *operand, AstNode *node, Type *type_hint);
|
||||
Entity * check_ident (Checker *c, Operand *o, AstNode *n, Type *named_type, Type *type_hint, bool allow_import_name);
|
||||
@@ -259,7 +259,7 @@ bool find_or_generate_polymorphic_procedure(Checker *c, Entity *base_entity, Typ
|
||||
|
||||
// NOTE(bill): This is slightly memory leaking if the type already exists
|
||||
// Maybe it's better to check with the previous types first?
|
||||
Type *final_proc_type = make_type_proc(c->allocator, scope, nullptr, 0, nullptr, 0, false, pt->calling_convention);
|
||||
Type *final_proc_type = alloc_type_proc(scope, nullptr, 0, nullptr, 0, false, pt->calling_convention);
|
||||
bool success = check_procedure_type(c, final_proc_type, pt->node, &operands);
|
||||
|
||||
if (!success) {
|
||||
@@ -499,7 +499,7 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) {
|
||||
Type *bfv = base_type(operand->type);
|
||||
i32 bits = bfv->BitFieldValue.bits;
|
||||
i32 size = next_pow2((bits+7)/8);
|
||||
i32 dst_size = cast(i32)type_size_of(c->allocator, type);
|
||||
i32 dst_size = cast(i32)type_size_of(type);
|
||||
i32 diff = gb_abs(dst_size - size);
|
||||
// TODO(bill): figure out a decent rule here
|
||||
return 1;
|
||||
@@ -1229,7 +1229,7 @@ bool check_representable_as_constant(Checker *c, ExactValue in_value, Type *type
|
||||
|
||||
i64 i = v.value_integer;
|
||||
u64 u = bit_cast<u64>(i);
|
||||
i64 s = 8*type_size_of(c->allocator, type);
|
||||
i64 s = 8*type_size_of(type);
|
||||
u64 umax = ~cast(u64)0ull;
|
||||
if (s < 64) {
|
||||
umax = (1ull << cast(u64)s) - 1ull;
|
||||
@@ -1397,7 +1397,7 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) {
|
||||
return;
|
||||
}
|
||||
o->mode = Addressing_Value;
|
||||
o->type = make_type_pointer(c->allocator, o->type);
|
||||
o->type = alloc_type_pointer(o->type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1422,7 +1422,7 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) {
|
||||
|
||||
i32 precision = 0;
|
||||
if (is_type_unsigned(type)) {
|
||||
precision = cast(i32)(8 * type_size_of(c->allocator, type));
|
||||
precision = cast(i32)(8 * type_size_of(type));
|
||||
}
|
||||
if (op.kind == Token_Xor && is_type_untyped(type)) {
|
||||
gbString err_str = expr_to_string(node);
|
||||
@@ -1668,7 +1668,7 @@ Operand check_ptr_addition(Checker *c, TokenKind op, Operand *ptr, Operand *offs
|
||||
|
||||
Type *base_ptr = base_type(ptr->type); GB_ASSERT(base_ptr->kind == Type_Pointer);
|
||||
Type *elem = base_ptr->Pointer.elem;
|
||||
i64 elem_size = type_size_of(c->allocator, elem);
|
||||
i64 elem_size = type_size_of(elem);
|
||||
|
||||
if (elem_size <= 0) {
|
||||
gbString str = type_to_string(elem);
|
||||
@@ -1902,8 +1902,8 @@ bool check_transmute(Checker *c, AstNode *node, Operand *o, Type *t) {
|
||||
return false;
|
||||
}
|
||||
|
||||
i64 srcz = type_size_of(c->allocator, o->type);
|
||||
i64 dstz = type_size_of(c->allocator, t);
|
||||
i64 srcz = type_size_of(o->type);
|
||||
i64 dstz = type_size_of(t);
|
||||
if (srcz != dstz) {
|
||||
gbString expr_str = expr_to_string(o->expr);
|
||||
gbString type_str = type_to_string(t);
|
||||
@@ -2082,7 +2082,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) {
|
||||
if (is_type_pointer(type)) {
|
||||
GB_ASSERT(op.kind == Token_Sub);
|
||||
i64 bytes = a.value_pointer - b.value_pointer;
|
||||
i64 diff = bytes/type_size_of(c->allocator, type);
|
||||
i64 diff = bytes/type_size_of(type);
|
||||
x->value = exact_value_pointer(diff);
|
||||
return;
|
||||
}
|
||||
@@ -2628,7 +2628,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
|
||||
|
||||
if (entity == nullptr && selector->kind == AstNode_Ident) {
|
||||
String field_name = selector->Ident.token.string;
|
||||
sel = lookup_field(c->allocator, operand->type, field_name, operand->mode == Addressing_Type);
|
||||
sel = lookup_field(operand->type, field_name, operand->mode == Addressing_Type);
|
||||
entity = sel.entity;
|
||||
|
||||
// NOTE(bill): Add type info needed for fields like 'names'
|
||||
@@ -2672,7 +2672,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sel = lookup_field_from_index(heap_allocator(), type, index);
|
||||
sel = lookup_field_from_index(type, index);
|
||||
entity = sel.entity;
|
||||
|
||||
GB_ASSERT(entity != nullptr);
|
||||
@@ -2929,7 +2929,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
return false;
|
||||
}
|
||||
operand->mode = Addressing_Value;
|
||||
operand->type = make_type_pointer(c->allocator, type);
|
||||
operand->type = alloc_type_pointer(type);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -2970,7 +2970,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
}
|
||||
|
||||
operand->mode = Addressing_Value;
|
||||
operand->type = make_type_slice(c->allocator, type);
|
||||
operand->type = alloc_type_slice(type);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -3147,14 +3147,14 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
} else {
|
||||
elem = type->Slice.elem;
|
||||
}
|
||||
Type *slice_elem = make_type_slice(c->allocator, elem);
|
||||
Type *slice_elem = alloc_type_slice(elem);
|
||||
|
||||
Type *proc_type_params = make_type_tuple(c->allocator);
|
||||
Type *proc_type_params = alloc_type_tuple(c->allocator);
|
||||
proc_type_params->Tuple.variables = gb_alloc_array(c->allocator, Entity *, 2);
|
||||
proc_type_params->Tuple.variable_count = 2;
|
||||
proc_type_params->Tuple.variables[0] = make_entity_param(c->allocator, nullptr, blank_token, operand->type, false, false);
|
||||
proc_type_params->Tuple.variables[1] = make_entity_param(c->allocator, nullptr, blank_token, slice_elem, false, false);
|
||||
Type *proc_type = make_type_proc(c->allocator, nullptr, proc_type_params, 2, nullptr, false, true, ProcCC_Odin);
|
||||
Type *proc_type = alloc_type_proc(nullptr, proc_type_params, 2, nullptr, false, true, ProcCC_Odin);
|
||||
|
||||
check_call_arguments(c, &prev_operand, proc_type, call);
|
||||
|
||||
@@ -3218,7 +3218,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
t = default_type(t);
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = exact_value_i64(type_size_of(c->allocator, t));
|
||||
operand->value = exact_value_i64(type_size_of(t));
|
||||
operand->type = t_untyped_integer;
|
||||
|
||||
break;
|
||||
@@ -3239,7 +3239,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
t = default_type(t);
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = exact_value_i64(type_align_of(c->allocator, t));
|
||||
operand->value = exact_value_i64(type_align_of(t));
|
||||
operand->type = t_untyped_integer;
|
||||
|
||||
break;
|
||||
@@ -3269,7 +3269,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
|
||||
|
||||
ast_node(arg, Ident, field_arg);
|
||||
Selection sel = lookup_field(c->allocator, type, arg->token.string, operand->mode == Addressing_Type);
|
||||
Selection sel = lookup_field(type, arg->token.string, operand->mode == Addressing_Type);
|
||||
if (sel.entity == nullptr) {
|
||||
gbString type_str = type_to_string(bt);
|
||||
error(ce->args[0],
|
||||
@@ -3286,7 +3286,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
}
|
||||
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->value = exact_value_i64(type_offset_of_from_selection(c->allocator, type, sel));
|
||||
operand->value = exact_value_i64(type_offset_of_from_selection(type, sel));
|
||||
operand->type = t_uintptr;
|
||||
|
||||
break;
|
||||
@@ -3408,7 +3408,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
}
|
||||
|
||||
if (arg_count < max_count) {
|
||||
operand->type = make_type_array(c->allocator, elem_type, arg_count);
|
||||
operand->type = alloc_type_array(elem_type, arg_count);
|
||||
}
|
||||
operand->mode = Addressing_Value;
|
||||
|
||||
@@ -3586,7 +3586,7 @@ break;
|
||||
// No need quit
|
||||
}
|
||||
}
|
||||
operand->type = make_type_slice(c->allocator, ptr_type->Pointer.elem);
|
||||
operand->type = alloc_type_slice(ptr_type->Pointer.elem);
|
||||
operand->mode = Addressing_Value;
|
||||
|
||||
break;
|
||||
@@ -3619,7 +3619,7 @@ break;
|
||||
}
|
||||
gbAllocator a = c->allocator;
|
||||
|
||||
Type *tuple = make_type_tuple(a);
|
||||
Type *tuple = alloc_type_tuple();
|
||||
isize variable_count = type->Struct.fields.count;
|
||||
array_init(&tuple->Tuple.variables, a, variable_count);
|
||||
// TODO(bill): Should I copy each of the entities or is this good enough?
|
||||
@@ -3933,8 +3933,8 @@ break;
|
||||
return false;
|
||||
}
|
||||
|
||||
i64 srcz = type_size_of(c->allocator, o->type);
|
||||
i64 dstz = type_size_of(c->allocator, t);
|
||||
i64 srcz = type_size_of(o->type);
|
||||
i64 dstz = type_size_of(t);
|
||||
if (srcz != dstz) {
|
||||
gbString expr_str = expr_to_string(o->expr);
|
||||
gbString type_str = type_to_string(t);
|
||||
@@ -4005,7 +4005,7 @@ void check_unpack_arguments(Checker *c, Entity **lhs, isize lhs_count, Array<Ope
|
||||
if (o.type == nullptr || o.type->kind != Type_Tuple) {
|
||||
if (allow_ok && lhs_count == 2 && rhs.count == 1 &&
|
||||
(o.mode == Addressing_MapIndex || o.mode == Addressing_OptionalOk)) {
|
||||
Type *tuple = make_optional_ok_type(c->allocator, o.type);
|
||||
Type *tuple = make_optional_ok_type(o.type);
|
||||
add_type_and_value(&c->info, o.expr, o.mode, tuple, o.value);
|
||||
|
||||
Operand val = o;
|
||||
@@ -4797,9 +4797,9 @@ CallArgumentError check_polymorphic_struct_type(Checker *c, Operand *operand, As
|
||||
|
||||
String generated_name = make_string_c(expr_to_string(call));
|
||||
|
||||
Type *named_type = make_type_named(a, generated_name, nullptr, nullptr);
|
||||
Type *named_type = alloc_type_named(generated_name, nullptr, nullptr);
|
||||
AstNode *node = clone_ast_node(a, st->node);
|
||||
Type *struct_type = make_type_struct(a);
|
||||
Type *struct_type = alloc_type_struct();
|
||||
struct_type->Struct.node = node;
|
||||
struct_type->Struct.polymorphic_parent = original_type;
|
||||
set_base_type(named_type, struct_type);
|
||||
@@ -5198,7 +5198,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
case_ast_node(pl, ProcLit, node);
|
||||
CheckerContext prev_context = c->context;
|
||||
DeclInfo *decl = nullptr;
|
||||
Type *type = alloc_type(c->allocator, Type_Proc);
|
||||
Type *type = alloc_type(Type_Proc);
|
||||
check_open_scope(c, pl->type);
|
||||
{
|
||||
decl = make_declaration_info(c->allocator, c->context.scope, c->context.decl);
|
||||
@@ -5324,7 +5324,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
AstNode *count = cl->type->ArrayType.count;
|
||||
if (count->kind == AstNode_UnaryExpr &&
|
||||
count->UnaryExpr.op.kind == Token_Question) {
|
||||
type = make_type_array(c->allocator, check_type(c, cl->type->ArrayType.elem), -1);
|
||||
type = alloc_type_array(check_type(c, cl->type->ArrayType.elem), -1);
|
||||
is_to_be_determined_array_count = true;
|
||||
}
|
||||
}
|
||||
@@ -5403,7 +5403,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
}
|
||||
String name = fv->field->Ident.token.string;
|
||||
|
||||
Selection sel = lookup_field(c->allocator, type, name, o->mode == Addressing_Type);
|
||||
Selection sel = lookup_field(type, name, o->mode == Addressing_Type);
|
||||
bool is_unknown = sel.entity == nullptr;
|
||||
if (is_unknown) {
|
||||
error(elem, "Unknown field '%.*s' in structure literal", LIT(name));
|
||||
@@ -5583,7 +5583,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
}
|
||||
String name = fv->field->Ident.token.string;
|
||||
|
||||
Selection sel = lookup_field(c->allocator, type, name, o->mode == Addressing_Type);
|
||||
Selection sel = lookup_field(type, name, o->mode == Addressing_Type);
|
||||
if (sel.entity == nullptr) {
|
||||
error(elem, "Unknown field '%.*s' in 'any' literal", LIT(name));
|
||||
continue;
|
||||
@@ -5950,7 +5950,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
o->expr = node;
|
||||
return kind;
|
||||
}
|
||||
o->type = make_type_slice(c->allocator, t->Array.elem);
|
||||
o->type = alloc_type_slice(t->Array.elem);
|
||||
break;
|
||||
|
||||
case Type_Slice:
|
||||
@@ -5960,7 +5960,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
||||
|
||||
case Type_DynamicArray:
|
||||
valid = true;
|
||||
o->type = make_type_slice(c->allocator, t->DynamicArray.elem);
|
||||
o->type = alloc_type_slice(t->DynamicArray.elem);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -987,7 +987,7 @@ void check_type_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
|
||||
!is_type_any(type_deref(x.type)) &&
|
||||
cc->list.count == 1 &&
|
||||
case_type != nullptr) {
|
||||
case_type = make_type_pointer(c->allocator, case_type);
|
||||
case_type = alloc_type_pointer(case_type);
|
||||
}
|
||||
|
||||
if (cc->list.count > 1) {
|
||||
|
||||
@@ -401,7 +401,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Opera
|
||||
// specialization = nullptr;
|
||||
// }
|
||||
}
|
||||
type = make_type_generic(c->allocator, c->context.scope, 0, str_lit(""), specialization);
|
||||
type = alloc_type_generic(c->context.scope, 0, str_lit(""), specialization);
|
||||
} else {
|
||||
type = check_type(c, type_expr);
|
||||
if (is_type_polymorphic(type)) {
|
||||
@@ -476,7 +476,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Opera
|
||||
}
|
||||
|
||||
if (entities.count > 0) {
|
||||
Type *tuple = make_type_tuple(c->allocator);
|
||||
Type *tuple = alloc_type_tuple();
|
||||
tuple->Tuple.variables = entities;
|
||||
polymorphic_params = tuple;
|
||||
}
|
||||
@@ -788,7 +788,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, AstNode *node) {
|
||||
}
|
||||
u32 bits = cast(u32)bits_;
|
||||
|
||||
Type *value_type = make_type_bit_field_value(c->allocator, bits);
|
||||
Type *value_type = alloc_type_bit_field_value(bits);
|
||||
Entity *e = make_entity_variable(c->allocator, bit_field_type->BitField.scope, ident->Ident.token, value_type, false);
|
||||
e->identifier = ident;
|
||||
e->flags |= EntityFlag_BitFieldValue;
|
||||
@@ -1039,7 +1039,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
|
||||
detemine_type_from_operand = true;
|
||||
type = t_invalid;
|
||||
} else {
|
||||
type = make_type_generic(c->allocator, c->context.scope, 0, str_lit(""), specialization);
|
||||
type = alloc_type_generic(c->context.scope, 0, str_lit(""), specialization);
|
||||
}
|
||||
} else {
|
||||
bool prev = c->context.allow_polymorphic_types;
|
||||
@@ -1232,7 +1232,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
|
||||
// NOTE(bill): Change last variadic parameter to be a slice
|
||||
// Custom Calling convention for variadic parameters
|
||||
Entity *end = variables[variadic_index];
|
||||
end->type = make_type_slice(c->allocator, end->type);
|
||||
end->type = alloc_type_slice(end->type);
|
||||
end->flags |= EntityFlag_Ellipsis;
|
||||
if (is_c_vararg) {
|
||||
end->flags |= EntityFlag_CVarArg;
|
||||
@@ -1253,7 +1253,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari
|
||||
}
|
||||
}
|
||||
|
||||
Type *tuple = make_type_tuple(c->allocator);
|
||||
Type *tuple = alloc_type_tuple();
|
||||
tuple->Tuple.variables = variables;
|
||||
|
||||
if (success_) *success_ = success;
|
||||
@@ -1274,7 +1274,7 @@ Type *check_get_results(Checker *c, Scope *scope, AstNode *_results) {
|
||||
if (results.count == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
Type *tuple = make_type_tuple(c->allocator);
|
||||
Type *tuple = alloc_type_tuple();
|
||||
|
||||
isize variable_count = 0;
|
||||
for_array(i, results) {
|
||||
@@ -1413,7 +1413,7 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) {
|
||||
i64 sz = bt->Basic.size;
|
||||
// if (sz > 8 && build_context.word_size < 8) {
|
||||
if (sz > 8) {
|
||||
new_type = make_type_pointer(a, original_type);
|
||||
new_type = alloc_type_pointer(original_type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1429,15 +1429,15 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) {
|
||||
// Could be in C too
|
||||
case Type_Struct:
|
||||
{
|
||||
i64 align = type_align_of(a, original_type);
|
||||
i64 size = type_size_of(a, original_type);
|
||||
i64 align = type_align_of(original_type);
|
||||
i64 size = type_size_of(original_type);
|
||||
switch (8*size) {
|
||||
case 8: new_type = t_u8; break;
|
||||
case 16: new_type = t_u16; break;
|
||||
case 32: new_type = t_u32; break;
|
||||
case 64: new_type = t_u64; break;
|
||||
default:
|
||||
new_type = make_type_pointer(a, original_type);
|
||||
new_type = alloc_type_pointer(original_type);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1454,7 +1454,7 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) {
|
||||
i64 sz = bt->Basic.size;
|
||||
// if (sz > 8 && build_context.word_size < 8) {
|
||||
if (sz > 8) {
|
||||
new_type = make_type_pointer(a, original_type);
|
||||
new_type = alloc_type_pointer(original_type);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1470,10 +1470,10 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) {
|
||||
case Type_Union:
|
||||
// Could be in C too
|
||||
case Type_Struct: {
|
||||
i64 align = type_align_of(a, original_type);
|
||||
i64 size = type_size_of(a, original_type);
|
||||
i64 align = type_align_of(original_type);
|
||||
i64 size = type_size_of(original_type);
|
||||
if (8*size > 16) {
|
||||
new_type = make_type_pointer(a, original_type);
|
||||
new_type = alloc_type_pointer(original_type);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -1518,8 +1518,8 @@ Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type) {
|
||||
|
||||
|
||||
default: {
|
||||
i64 align = type_align_of(a, original_type);
|
||||
i64 size = type_size_of(a, original_type);
|
||||
i64 align = type_align_of(original_type);
|
||||
i64 size = type_size_of(original_type);
|
||||
switch (8*size) {
|
||||
#if 1
|
||||
case 8: new_type = t_u8; break;
|
||||
@@ -1540,7 +1540,7 @@ Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type) {
|
||||
}
|
||||
|
||||
if (new_type != original_type) {
|
||||
Type *tuple = make_type_tuple(a);
|
||||
Type *tuple = alloc_type_tuple();
|
||||
auto variables = array_make<Entity *>(a, 0, 1);
|
||||
array_add(&variables, make_entity_param(a, original_type->Tuple.variables[0]->scope, empty_token, new_type, false, false));
|
||||
tuple->Tuple.variables = variables;
|
||||
@@ -1564,7 +1564,7 @@ bool abi_compat_return_by_value(gbAllocator a, ProcCallingConvention cc, Type *a
|
||||
|
||||
|
||||
if (build_context.ODIN_OS == "windows") {
|
||||
i64 size = 8*type_size_of(a, abi_return_type);
|
||||
i64 size = 8*type_size_of(abi_return_type);
|
||||
switch (size) {
|
||||
case 0:
|
||||
case 8:
|
||||
@@ -1727,23 +1727,24 @@ i64 check_array_count(Checker *c, Operand *o, AstNode *e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Type *make_optional_ok_type(gbAllocator a, Type *value) {
|
||||
Type *make_optional_ok_type(Type *value) {
|
||||
gbAllocator a = heap_allocator();
|
||||
bool typed = true;
|
||||
Type *t = make_type_tuple(a);
|
||||
Type *t = alloc_type_tuple();
|
||||
array_init(&t->Tuple.variables, a, 0, 2);
|
||||
array_add (&t->Tuple.variables, make_entity_field(a, nullptr, blank_token, value, false, 0));
|
||||
array_add (&t->Tuple.variables, make_entity_field(a, nullptr, blank_token, typed ? t_bool : t_untyped_bool, false, 1));
|
||||
return t;
|
||||
}
|
||||
|
||||
void generate_map_entry_type(gbAllocator a, Type *type) {
|
||||
void init_map_entry_type(Type *type) {
|
||||
GB_ASSERT(type->kind == Type_Map);
|
||||
if (type->Map.entry_type != nullptr) return;
|
||||
|
||||
// NOTE(bill): The preload types may have not been set yet
|
||||
GB_ASSERT(t_map_key != nullptr);
|
||||
|
||||
Type *entry_type = make_type_struct(a);
|
||||
gbAllocator a = heap_allocator();
|
||||
Type *entry_type = alloc_type_struct();
|
||||
|
||||
/*
|
||||
struct {
|
||||
@@ -1769,9 +1770,9 @@ void generate_map_entry_type(gbAllocator a, Type *type) {
|
||||
type->Map.entry_type = entry_type;
|
||||
}
|
||||
|
||||
void generate_map_internal_types(gbAllocator a, Type *type) {
|
||||
void init_map_internal_types(Type *type) {
|
||||
GB_ASSERT(type->kind == Type_Map);
|
||||
generate_map_entry_type(a, type);
|
||||
init_map_entry_type(type);
|
||||
if (type->Map.internal_type != nullptr) return;
|
||||
if (type->Map.generated_struct_type != nullptr) return;
|
||||
|
||||
@@ -1780,7 +1781,7 @@ void generate_map_internal_types(gbAllocator a, Type *type) {
|
||||
GB_ASSERT(key != nullptr);
|
||||
GB_ASSERT(value != nullptr);
|
||||
|
||||
Type *generated_struct_type = make_type_struct(a);
|
||||
Type *generated_struct_type = alloc_type_struct();
|
||||
|
||||
/*
|
||||
struct {
|
||||
@@ -1788,12 +1789,13 @@ void generate_map_internal_types(gbAllocator a, Type *type) {
|
||||
entries: [dynamic]EntryType;
|
||||
}
|
||||
*/
|
||||
gbAllocator a = heap_allocator();
|
||||
AstNode *dummy_node = gb_alloc_item(a, AstNode);
|
||||
dummy_node->kind = AstNode_Invalid;
|
||||
Scope *s = create_scope(universal_scope, a);
|
||||
|
||||
Type *hashes_type = make_type_dynamic_array(a, t_int);
|
||||
Type *entries_type = make_type_dynamic_array(a, type->Map.entry_type);
|
||||
Type *hashes_type = alloc_type_dynamic_array(t_int);
|
||||
Type *entries_type = alloc_type_dynamic_array(type->Map.entry_type);
|
||||
|
||||
|
||||
auto fields = array_make<Entity *>(a, 0, 2);
|
||||
@@ -1802,10 +1804,10 @@ void generate_map_internal_types(gbAllocator a, Type *type) {
|
||||
|
||||
generated_struct_type->Struct.fields = fields;
|
||||
|
||||
type_set_offsets(a, generated_struct_type);
|
||||
type_set_offsets(generated_struct_type);
|
||||
type->Map.generated_struct_type = generated_struct_type;
|
||||
type->Map.internal_type = generated_struct_type;
|
||||
type->Map.lookup_result_type = make_optional_ok_type(a, value);
|
||||
type->Map.lookup_result_type = make_optional_ok_type(value);
|
||||
}
|
||||
|
||||
void check_map_type(Checker *c, Type *type, AstNode *node) {
|
||||
@@ -1830,7 +1832,7 @@ void check_map_type(Checker *c, Type *type, AstNode *node) {
|
||||
|
||||
|
||||
init_preload(c);
|
||||
generate_map_internal_types(c->allocator, type);
|
||||
init_map_internal_types(type);
|
||||
|
||||
// error(node, "'map' types are not yet implemented");
|
||||
}
|
||||
@@ -1916,7 +1918,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
// specific = nullptr;
|
||||
// }
|
||||
}
|
||||
Type *t = make_type_generic(c->allocator, c->context.scope, 0, token.string, specific);
|
||||
Type *t = alloc_type_generic(c->context.scope, 0, token.string, specific);
|
||||
if (c->context.allow_polymorphic_types) {
|
||||
Scope *ps = c->context.polymorphic_scope;
|
||||
Scope *s = c->context.scope;
|
||||
@@ -1974,14 +1976,14 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
case_ast_node(ue, UnaryExpr, e);
|
||||
switch (ue->op.kind) {
|
||||
case Token_Pointer:
|
||||
*type = make_type_pointer(c->allocator, check_type(c, ue->expr));
|
||||
*type = alloc_type_pointer(check_type(c, ue->expr));
|
||||
set_base_type(named_type, *type);
|
||||
return true;
|
||||
}
|
||||
case_end;
|
||||
|
||||
case_ast_node(pt, PointerType, e);
|
||||
*type = make_type_pointer(c->allocator, check_type(c, pt->type));
|
||||
*type = alloc_type_pointer(check_type(c, pt->type));
|
||||
set_base_type(named_type, *type);
|
||||
return true;
|
||||
case_end;
|
||||
@@ -1999,10 +2001,10 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
count = 0;
|
||||
}
|
||||
Type *elem = check_type(c, at->elem, nullptr);
|
||||
*type = make_type_array(c->allocator, elem, count, generic_type);
|
||||
*type = alloc_type_array(elem, count, generic_type);
|
||||
} else {
|
||||
Type *elem = check_type(c, at->elem);
|
||||
*type = make_type_slice(c->allocator, elem);
|
||||
*type = alloc_type_slice(elem);
|
||||
}
|
||||
set_base_type(named_type, *type);
|
||||
return true;
|
||||
@@ -2010,7 +2012,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
|
||||
case_ast_node(dat, DynamicArrayType, e);
|
||||
Type *elem = check_type(c, dat->elem);
|
||||
*type = make_type_dynamic_array(c->allocator, elem);
|
||||
*type = alloc_type_dynamic_array(elem);
|
||||
set_base_type(named_type, *type);
|
||||
return true;
|
||||
case_end;
|
||||
@@ -2020,7 +2022,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
c->context.in_polymorphic_specialization = false;
|
||||
c->context.type_level += 1;
|
||||
|
||||
*type = make_type_struct(c->allocator);
|
||||
*type = alloc_type_struct();
|
||||
set_base_type(named_type, *type);
|
||||
check_open_scope(c, e);
|
||||
check_struct_type(c, *type, e, nullptr, named_type);
|
||||
@@ -2034,7 +2036,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
c->context.in_polymorphic_specialization = false;
|
||||
c->context.type_level += 1;
|
||||
|
||||
*type = make_type_union(c->allocator);
|
||||
*type = alloc_type_union();
|
||||
set_base_type(named_type, *type);
|
||||
check_open_scope(c, e);
|
||||
check_union_type(c, *type, e);
|
||||
@@ -2048,7 +2050,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
defer (c->context.in_polymorphic_specialization = ips);
|
||||
c->context.in_polymorphic_specialization = false;
|
||||
|
||||
*type = make_type_enum(c->allocator);
|
||||
*type = alloc_type_enum();
|
||||
set_base_type(named_type, *type);
|
||||
check_open_scope(c, e);
|
||||
check_enum_type(c, *type, named_type, e);
|
||||
@@ -2058,7 +2060,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
case_end;
|
||||
|
||||
case_ast_node(et, BitFieldType, e);
|
||||
*type = make_type_bit_field(c->allocator);
|
||||
*type = alloc_type_bit_field();
|
||||
set_base_type(named_type, *type);
|
||||
check_open_scope(c, e);
|
||||
check_bit_field_type(c, *type, e);
|
||||
@@ -2071,7 +2073,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
defer (c->context.in_polymorphic_specialization = ips);
|
||||
c->context.in_polymorphic_specialization = false;
|
||||
|
||||
*type = alloc_type(c->allocator, Type_Proc);
|
||||
*type = alloc_type(Type_Proc);
|
||||
set_base_type(named_type, *type);
|
||||
check_open_scope(c, e);
|
||||
check_procedure_type(c, *type, e);
|
||||
@@ -2084,7 +2086,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
defer (c->context.in_polymorphic_specialization = ips);
|
||||
c->context.in_polymorphic_specialization = false;
|
||||
|
||||
*type = alloc_type(c->allocator, Type_Map);
|
||||
*type = alloc_type(Type_Map);
|
||||
set_base_type(named_type, *type);
|
||||
check_map_type(c, *type, e);
|
||||
return true;
|
||||
|
||||
@@ -568,12 +568,12 @@ void init_universal_scope(void) {
|
||||
}
|
||||
|
||||
|
||||
t_u8_ptr = make_type_pointer(a, t_u8);
|
||||
t_int_ptr = make_type_pointer(a, t_int);
|
||||
t_i64_ptr = make_type_pointer(a, t_i64);
|
||||
t_f64_ptr = make_type_pointer(a, t_f64);
|
||||
t_u8_slice = make_type_slice(a, t_u8);
|
||||
t_string_slice = make_type_slice(a, t_string);
|
||||
t_u8_ptr = alloc_type_pointer(t_u8);
|
||||
t_int_ptr = alloc_type_pointer(t_int);
|
||||
t_i64_ptr = alloc_type_pointer(t_i64);
|
||||
t_f64_ptr = alloc_type_pointer(t_f64);
|
||||
t_u8_slice = alloc_type_slice(t_u8);
|
||||
t_string_slice = alloc_type_slice(t_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -1015,18 +1015,18 @@ void add_type_info_type(Checker *c, Type *t) {
|
||||
|
||||
case Type_Array:
|
||||
add_type_info_type(c, bt->Array.elem);
|
||||
add_type_info_type(c, make_type_pointer(c->allocator, bt->Array.elem));
|
||||
add_type_info_type(c, alloc_type_pointer(bt->Array.elem));
|
||||
add_type_info_type(c, t_int);
|
||||
break;
|
||||
case Type_DynamicArray:
|
||||
add_type_info_type(c, bt->DynamicArray.elem);
|
||||
add_type_info_type(c, make_type_pointer(c->allocator, bt->DynamicArray.elem));
|
||||
add_type_info_type(c, alloc_type_pointer(bt->DynamicArray.elem));
|
||||
add_type_info_type(c, t_int);
|
||||
add_type_info_type(c, t_allocator);
|
||||
break;
|
||||
case Type_Slice:
|
||||
add_type_info_type(c, bt->Slice.elem);
|
||||
add_type_info_type(c, make_type_pointer(c->allocator, bt->Slice.elem));
|
||||
add_type_info_type(c, alloc_type_pointer(bt->Slice.elem));
|
||||
add_type_info_type(c, t_int);
|
||||
break;
|
||||
|
||||
@@ -1056,7 +1056,7 @@ void add_type_info_type(Checker *c, Type *t) {
|
||||
break;
|
||||
|
||||
case Type_Map:
|
||||
generate_map_internal_types(c->allocator, bt);
|
||||
init_map_internal_types(bt);
|
||||
add_type_info_type(c, bt->Map.key);
|
||||
add_type_info_type(c, bt->Map.value);
|
||||
add_type_info_type(c, bt->Map.generated_struct_type);
|
||||
@@ -1332,14 +1332,14 @@ void init_preload(Checker *c) {
|
||||
Entity *type_info_entity = find_core_entity(c, str_lit("Type_Info"));
|
||||
|
||||
t_type_info = type_info_entity->type;
|
||||
t_type_info_ptr = make_type_pointer(c->allocator, t_type_info);
|
||||
t_type_info_ptr = alloc_type_pointer(t_type_info);
|
||||
GB_ASSERT(is_type_struct(type_info_entity->type));
|
||||
TypeStruct *tis = &base_type(type_info_entity->type)->Struct;
|
||||
|
||||
Entity *type_info_enum_value = find_core_entity(c, str_lit("Type_Info_Enum_Value"));
|
||||
|
||||
t_type_info_enum_value = type_info_enum_value->type;
|
||||
t_type_info_enum_value_ptr = make_type_pointer(c->allocator, t_type_info_enum_value);
|
||||
t_type_info_enum_value_ptr = alloc_type_pointer(t_type_info_enum_value);
|
||||
|
||||
GB_ASSERT(tis->fields.count == 3);
|
||||
|
||||
@@ -1367,44 +1367,44 @@ void init_preload(Checker *c) {
|
||||
t_type_info_map = find_core_type(c, str_lit("Type_Info_Map"));
|
||||
t_type_info_bit_field = find_core_type(c, str_lit("Type_Info_Bit_Field"));
|
||||
|
||||
t_type_info_named_ptr = make_type_pointer(c->allocator, t_type_info_named);
|
||||
t_type_info_integer_ptr = make_type_pointer(c->allocator, t_type_info_integer);
|
||||
t_type_info_rune_ptr = make_type_pointer(c->allocator, t_type_info_rune);
|
||||
t_type_info_float_ptr = make_type_pointer(c->allocator, t_type_info_float);
|
||||
t_type_info_complex_ptr = make_type_pointer(c->allocator, t_type_info_complex);
|
||||
t_type_info_string_ptr = make_type_pointer(c->allocator, t_type_info_string);
|
||||
t_type_info_boolean_ptr = make_type_pointer(c->allocator, t_type_info_boolean);
|
||||
t_type_info_any_ptr = make_type_pointer(c->allocator, t_type_info_any);
|
||||
t_type_info_pointer_ptr = make_type_pointer(c->allocator, t_type_info_pointer);
|
||||
t_type_info_procedure_ptr = make_type_pointer(c->allocator, t_type_info_procedure);
|
||||
t_type_info_array_ptr = make_type_pointer(c->allocator, t_type_info_array);
|
||||
t_type_info_dynamic_array_ptr = make_type_pointer(c->allocator, t_type_info_dynamic_array);
|
||||
t_type_info_slice_ptr = make_type_pointer(c->allocator, t_type_info_slice);
|
||||
t_type_info_tuple_ptr = make_type_pointer(c->allocator, t_type_info_tuple);
|
||||
t_type_info_struct_ptr = make_type_pointer(c->allocator, t_type_info_struct);
|
||||
t_type_info_union_ptr = make_type_pointer(c->allocator, t_type_info_union);
|
||||
t_type_info_enum_ptr = make_type_pointer(c->allocator, t_type_info_enum);
|
||||
t_type_info_map_ptr = make_type_pointer(c->allocator, t_type_info_map);
|
||||
t_type_info_bit_field_ptr = make_type_pointer(c->allocator, t_type_info_bit_field);
|
||||
t_type_info_named_ptr = alloc_type_pointer(t_type_info_named);
|
||||
t_type_info_integer_ptr = alloc_type_pointer(t_type_info_integer);
|
||||
t_type_info_rune_ptr = alloc_type_pointer(t_type_info_rune);
|
||||
t_type_info_float_ptr = alloc_type_pointer(t_type_info_float);
|
||||
t_type_info_complex_ptr = alloc_type_pointer(t_type_info_complex);
|
||||
t_type_info_string_ptr = alloc_type_pointer(t_type_info_string);
|
||||
t_type_info_boolean_ptr = alloc_type_pointer(t_type_info_boolean);
|
||||
t_type_info_any_ptr = alloc_type_pointer(t_type_info_any);
|
||||
t_type_info_pointer_ptr = alloc_type_pointer(t_type_info_pointer);
|
||||
t_type_info_procedure_ptr = alloc_type_pointer(t_type_info_procedure);
|
||||
t_type_info_array_ptr = alloc_type_pointer(t_type_info_array);
|
||||
t_type_info_dynamic_array_ptr = alloc_type_pointer(t_type_info_dynamic_array);
|
||||
t_type_info_slice_ptr = alloc_type_pointer(t_type_info_slice);
|
||||
t_type_info_tuple_ptr = alloc_type_pointer(t_type_info_tuple);
|
||||
t_type_info_struct_ptr = alloc_type_pointer(t_type_info_struct);
|
||||
t_type_info_union_ptr = alloc_type_pointer(t_type_info_union);
|
||||
t_type_info_enum_ptr = alloc_type_pointer(t_type_info_enum);
|
||||
t_type_info_map_ptr = alloc_type_pointer(t_type_info_map);
|
||||
t_type_info_bit_field_ptr = alloc_type_pointer(t_type_info_bit_field);
|
||||
}
|
||||
|
||||
if (t_allocator == nullptr) {
|
||||
Entity *e = find_core_entity(c, str_lit("Allocator"));
|
||||
t_allocator = e->type;
|
||||
t_allocator_ptr = make_type_pointer(c->allocator, t_allocator);
|
||||
t_allocator_ptr = alloc_type_pointer(t_allocator);
|
||||
}
|
||||
|
||||
if (t_context == nullptr) {
|
||||
Entity *e = find_core_entity(c, str_lit("Context"));
|
||||
e_context = e;
|
||||
t_context = e->type;
|
||||
t_context_ptr = make_type_pointer(c->allocator, t_context);
|
||||
t_context_ptr = alloc_type_pointer(t_context);
|
||||
}
|
||||
|
||||
if (t_source_code_location == nullptr) {
|
||||
Entity *e = find_core_entity(c, str_lit("Source_Code_Location"));
|
||||
t_source_code_location = e->type;
|
||||
t_source_code_location_ptr = make_type_pointer(c->allocator, t_allocator);
|
||||
t_source_code_location_ptr = alloc_type_pointer(t_allocator);
|
||||
}
|
||||
|
||||
if (t_map_key == nullptr) {
|
||||
@@ -3125,7 +3125,7 @@ void check_parsed_files(Checker *c) {
|
||||
Entity *e = c->info.definitions[i];
|
||||
if (e->kind == Entity_TypeName && e->type != nullptr) {
|
||||
// i64 size = type_size_of(c->allocator, e->type);
|
||||
i64 align = type_align_of(c->allocator, e->type);
|
||||
i64 align = type_align_of(e->type);
|
||||
if (align > 0 && ptr_set_exists(&c->info.minimum_dependency_set, e)) {
|
||||
add_type_info_type(c, e->type);
|
||||
}
|
||||
|
||||
267
src/ir.cpp
267
src/ir.cpp
@@ -826,7 +826,7 @@ irValue *ir_value_type_name(gbAllocator a, String name, Type *type) {
|
||||
irValue *ir_value_global(gbAllocator a, Entity *e, irValue *value) {
|
||||
irValue *v = ir_alloc_value(a, irValue_Global);
|
||||
v->Global.entity = e;
|
||||
v->Global.type = make_type_pointer(a, e->type);
|
||||
v->Global.type = alloc_type_pointer(e->type);
|
||||
v->Global.value = value;
|
||||
array_init(&v->Global.referrers, heap_allocator()); // TODO(bill): Replace heap allocator here
|
||||
return v;
|
||||
@@ -902,11 +902,11 @@ irValue *ir_instr_local(irProcedure *p, Entity *e, bool zero_initialized) {
|
||||
irValue *v = ir_alloc_instr(p, irInstr_Local);
|
||||
irInstr *i = &v->Instr;
|
||||
i->Local.entity = e;
|
||||
i->Local.type = make_type_pointer(p->module->allocator, e->type);
|
||||
i->Local.type = alloc_type_pointer(e->type);
|
||||
i->Local.zero_initialized = zero_initialized;
|
||||
// i->Local.alignment = type_align_of(p->module->allocator, e->type);
|
||||
// TODO(bill): determine the correct alignment
|
||||
i->Local.alignment = gb_max(16, type_align_of(p->module->allocator, e->type));
|
||||
i->Local.alignment = gb_max(16, type_align_of(e->type));
|
||||
array_init(&i->Local.referrers, heap_allocator()); // TODO(bill): Replace heap allocator here
|
||||
ir_module_add_value(p->module, e, v);
|
||||
return v;
|
||||
@@ -944,7 +944,7 @@ irValue *ir_instr_array_element_ptr(irProcedure *p, irValue *address, irValue *e
|
||||
t = base_type(type_deref(t));
|
||||
GB_ASSERT(is_type_array(t));
|
||||
|
||||
Type *result_type = make_type_pointer(p->module->allocator, t->Array.elem);
|
||||
Type *result_type = alloc_type_pointer(t->Array.elem);
|
||||
|
||||
i->ArrayElementPtr.address = address;
|
||||
i->ArrayElementPtr.elem_index = elem_index;
|
||||
@@ -994,9 +994,9 @@ irValue *ir_instr_union_tag_ptr(irProcedure *p, irValue *address) {
|
||||
irValue *v = ir_alloc_instr(p, irInstr_UnionTagPtr);
|
||||
irInstr *i = &v->Instr;
|
||||
i->UnionTagPtr.address = address;
|
||||
// i->UnionTagPtr.type = make_type_pointer(p->module->allocator, t_type_info_ptr);
|
||||
// i->UnionTagPtr.type = alloc_type_pointer(t_type_info_ptr);
|
||||
Type *u = type_deref(ir_type(address));
|
||||
i->UnionTagPtr.type = make_type_pointer(p->module->allocator, union_tag_type(p->module->allocator, u));
|
||||
i->UnionTagPtr.type = alloc_type_pointer(union_tag_type(u));
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -1007,7 +1007,7 @@ irValue *ir_instr_union_tag_value(irProcedure *p, irValue *address) {
|
||||
// i->UnionTagValue.type = t_type_info_ptr;
|
||||
// i->UnionTagValue.type = t_int;
|
||||
Type *u = type_deref(ir_type(address));
|
||||
i->UnionTagPtr.type = union_tag_type(p->module->allocator, u);
|
||||
i->UnionTagPtr.type = union_tag_type(u);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -1208,7 +1208,7 @@ irValue *ir_generate_array(irModule *m, Type *elem_type, i64 count, String prefi
|
||||
|
||||
Entity *e = make_entity_variable(a, nullptr,
|
||||
make_token_ident(s),
|
||||
make_type_array(a, elem_type, count),
|
||||
alloc_type_array(elem_type, count),
|
||||
false);
|
||||
irValue *value = ir_value_global(a, e, nullptr);
|
||||
value->Global.is_private = true;
|
||||
@@ -1297,7 +1297,7 @@ irValue *ir_add_module_constant(irModule *m, Type *type, ExactValue value) {
|
||||
return ir_value_nil(a, type);
|
||||
}
|
||||
Type *elem = base_type(type)->Slice.elem;
|
||||
Type *t = make_type_array(a, elem, count);
|
||||
Type *t = alloc_type_array(elem, count);
|
||||
irValue *backing_array = ir_add_module_constant(m, t, value);
|
||||
|
||||
|
||||
@@ -1333,7 +1333,7 @@ irValue *ir_add_global_string_array(irModule *m, String string) {
|
||||
String name = make_string(str, len-1);
|
||||
Token token = {Token_String};
|
||||
token.string = name;
|
||||
Type *type = make_type_array(a, t_u8, string.len+1);
|
||||
Type *type = alloc_type_array(t_u8, string.len+1);
|
||||
ExactValue ev = exact_value_string(string);
|
||||
Entity *entity = make_entity_constant(a, nullptr, token, type, ev);
|
||||
irValue *g = ir_value_global(a, entity, ir_add_module_constant(m, type, ev));
|
||||
@@ -1482,7 +1482,7 @@ irValue *ir_add_param(irProcedure *proc, Entity *e, AstNode *expr, Type *abi_typ
|
||||
|
||||
case irParamPass_Integer: {
|
||||
irValue *l = ir_add_local(proc, e, expr, false);
|
||||
irValue *iptr = ir_emit_conv(proc, l, make_type_pointer(proc->module->allocator, p->type));
|
||||
irValue *iptr = ir_emit_conv(proc, l, alloc_type_pointer(p->type));
|
||||
ir_emit_store(proc, iptr, v);
|
||||
return ir_emit_load(proc, l);
|
||||
}
|
||||
@@ -1600,7 +1600,7 @@ void ir_emit_zero_init(irProcedure *p, irValue *address, AstNode *expr) {
|
||||
Type *t = type_deref(ir_type(address));
|
||||
auto args = array_make<irValue *>(a, 2);
|
||||
args[0] = ir_emit_conv(p, address, t_rawptr);
|
||||
args[1] = ir_const_int(a, type_size_of(a, t));
|
||||
args[1] = ir_const_int(a, type_size_of(t));
|
||||
if (p->entity->token.string != "__mem_zero") {
|
||||
ir_emit_global_call(p, "__mem_zero", args, expr);
|
||||
}
|
||||
@@ -1625,7 +1625,7 @@ void ir_emit_init_context(irProcedure *proc, irValue *c = nullptr) {
|
||||
|
||||
|
||||
irValue *ir_copy_value_to_ptr(irProcedure *proc, irValue *val, Type *new_type, i64 alignment) {
|
||||
i64 type_alignment = type_align_of(proc->module->allocator, new_type);
|
||||
i64 type_alignment = type_align_of(new_type);
|
||||
if (alignment < type_alignment) {
|
||||
alignment = type_alignment;
|
||||
}
|
||||
@@ -1840,10 +1840,10 @@ irValue *ir_gen_map_header(irProcedure *proc, irValue *map_val_ptr, Type *map_ty
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, h, 1), v_true);
|
||||
}
|
||||
|
||||
i64 entry_size = type_size_of(a, map_type->Map.entry_type);
|
||||
i64 entry_align = type_align_of(a, map_type->Map.entry_type);
|
||||
i64 value_offset = type_offset_of(a, map_type->Map.entry_type, 2);
|
||||
i64 value_size = type_size_of(a, map_type->Map.value);
|
||||
i64 entry_size = type_size_of (map_type->Map.entry_type);
|
||||
i64 entry_align = type_align_of (map_type->Map.entry_type);
|
||||
i64 value_offset = type_offset_of(map_type->Map.entry_type, 2);
|
||||
i64 value_size = type_size_of (map_type->Map.value);
|
||||
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, h, 2), ir_const_int(a, entry_size));
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, h, 3), ir_const_int(a, entry_align));
|
||||
@@ -1866,7 +1866,7 @@ irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) {
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), ir_emit_conv(proc, p, hash_type));
|
||||
} else if (is_type_float(t)) {
|
||||
irValue *bits = nullptr;
|
||||
i64 size = type_size_of(proc->module->allocator, t);
|
||||
i64 size = type_size_of(t);
|
||||
switch (8*size) {
|
||||
case 32: bits = ir_emit_transmute(proc, key, t_u32); break;
|
||||
case 64: bits = ir_emit_transmute(proc, key, t_u64); break;
|
||||
@@ -2000,7 +2000,7 @@ irValue *ir_addr_store(irProcedure *proc, irAddr addr, irValue *value) {
|
||||
v = ir_emit_arith(proc, Token_Shl, v, shift_amount, int_type);
|
||||
v = ir_emit_arith(proc, Token_Shr, v, shift_amount, int_type);
|
||||
}
|
||||
irValue *ptr = ir_emit_conv(proc, bytes, make_type_pointer(a, int_type));
|
||||
irValue *ptr = ir_emit_conv(proc, bytes, alloc_type_pointer(int_type));
|
||||
v = ir_emit_arith(proc, Token_Or, ir_emit_load(proc, ptr), v, int_type);
|
||||
return ir_emit_store(proc, ptr, v);
|
||||
}
|
||||
@@ -2020,7 +2020,7 @@ irValue *ir_addr_store(irProcedure *proc, irAddr addr, irValue *value) {
|
||||
// Remaining bytes
|
||||
{
|
||||
irValue *shift_amount = ir_const_int(a, bit_inset);
|
||||
irValue *ptr = ir_emit_conv(proc, ir_emit_ptr_offset(proc, bytes, v_one), make_type_pointer(a, int_type));
|
||||
irValue *ptr = ir_emit_conv(proc, ir_emit_ptr_offset(proc, bytes, v_one), alloc_type_pointer(int_type));
|
||||
irValue *v = ir_emit_arith(proc, Token_Shr, value, shift_amount, int_type);
|
||||
v = ir_emit_arith(proc, Token_Or, ir_emit_load(proc, ptr), v, int_type);
|
||||
return ir_emit_store(proc, ptr, v);
|
||||
@@ -2104,7 +2104,7 @@ irValue *ir_addr_load(irProcedure *proc, irAddr addr) {
|
||||
irValue *bytes = ir_emit_conv(proc, addr.addr, t_u8_ptr);
|
||||
bytes = ir_emit_ptr_offset(proc, bytes, ir_const_int(a, byte_index));
|
||||
|
||||
Type *int_ptr = make_type_pointer(a, int_type);
|
||||
Type *int_ptr = alloc_type_pointer(int_type);
|
||||
|
||||
if (bit_inset == 0) {
|
||||
irValue *v = ir_emit_load(proc, ir_emit_conv(proc, bytes, int_ptr));
|
||||
@@ -2168,7 +2168,7 @@ irValue *ir_map_entries(irProcedure *proc, irValue *value) {
|
||||
gbAllocator a = proc->module->allocator;
|
||||
Type *t = base_type(ir_type(value));
|
||||
GB_ASSERT_MSG(t->kind == Type_Map, "%s", type_to_string(t));
|
||||
generate_map_internal_types(a, t);
|
||||
init_map_internal_types(t);
|
||||
Type *gst = t->Map.generated_struct_type;
|
||||
isize index = 1;
|
||||
irValue *entries = ir_emit(proc, ir_instr_struct_extract_value(proc, value, index, gst->Struct.fields[index]->type));
|
||||
@@ -2179,10 +2179,10 @@ irValue *ir_map_entries_ptr(irProcedure *proc, irValue *value) {
|
||||
gbAllocator a = proc->module->allocator;
|
||||
Type *t = base_type(type_deref(ir_type(value)));
|
||||
GB_ASSERT_MSG(t->kind == Type_Map, "%s", type_to_string(t));
|
||||
generate_map_internal_types(a, t);
|
||||
init_map_internal_types(t);
|
||||
Type *gst = t->Map.generated_struct_type;
|
||||
isize index = 1;
|
||||
Type *ptr_t = make_type_pointer(a, gst->Struct.fields[index]->type);
|
||||
Type *ptr_t = alloc_type_pointer(gst->Struct.fields[index]->type);
|
||||
irValue *entries = ir_emit(proc, ir_instr_struct_element_ptr(proc, value, index, ptr_t));
|
||||
return entries;
|
||||
}
|
||||
@@ -2348,7 +2348,7 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *
|
||||
irModule *m = proc->module;
|
||||
Type *ptr_type = base_type(t_left);
|
||||
GB_ASSERT(!is_type_rawptr(ptr_type));
|
||||
irValue *elem_size = ir_const_int(m->allocator, type_size_of(m->allocator, ptr_type->Pointer.elem));
|
||||
irValue *elem_size = ir_const_int(m->allocator, type_size_of(ptr_type->Pointer.elem));
|
||||
irValue *x = ir_emit_conv(proc, ir_emit_conv(proc, left, t_uintptr), type);
|
||||
irValue *y = ir_emit_conv(proc, ir_emit_conv(proc, right, t_uintptr), type);
|
||||
irValue *diff = ir_emit_arith(proc, op, x, y, type);
|
||||
@@ -2494,8 +2494,8 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal
|
||||
right = ir_emit_conv(proc, right, ir_type(left));
|
||||
} else {
|
||||
gbAllocator a = proc->module->allocator;
|
||||
i64 ls = type_size_of(a, ir_type(left));
|
||||
i64 rs = type_size_of(a, ir_type(right));
|
||||
i64 ls = type_size_of(ir_type(left));
|
||||
i64 rs = type_size_of(ir_type(right));
|
||||
if (ls < rs) {
|
||||
left = ir_emit_conv(proc, left, ir_type(right));
|
||||
} else if (ls > rs) {
|
||||
@@ -2552,7 +2552,7 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal
|
||||
|
||||
if (is_type_complex(a)) {
|
||||
char *runtime_proc = "";
|
||||
i64 sz = 8*type_size_of(proc->module->allocator, a);
|
||||
i64 sz = 8*type_size_of(a);
|
||||
switch (sz) {
|
||||
case 64:
|
||||
switch (op_kind) {
|
||||
@@ -2603,52 +2603,52 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) {
|
||||
Type *result_type = nullptr;
|
||||
|
||||
if (is_type_struct(t)) {
|
||||
result_type = make_type_pointer(a, t->Struct.fields[index]->type);
|
||||
result_type = alloc_type_pointer(t->Struct.fields[index]->type);
|
||||
} else if (is_type_union(t)) {
|
||||
GB_ASSERT(index == -1);
|
||||
return ir_emit_union_tag_ptr(proc, s);
|
||||
} else if (is_type_tuple(t)) {
|
||||
GB_ASSERT(t->Tuple.variables.count > 0);
|
||||
result_type = make_type_pointer(a, t->Tuple.variables[index]->type);
|
||||
result_type = alloc_type_pointer(t->Tuple.variables[index]->type);
|
||||
} else if (is_type_complex(t)) {
|
||||
Type *ft = base_complex_elem_type(t);
|
||||
switch (index) {
|
||||
case 0: result_type = make_type_pointer(a, ft); break;
|
||||
case 1: result_type = make_type_pointer(a, ft); break;
|
||||
case 0: result_type = alloc_type_pointer(ft); break;
|
||||
case 1: result_type = alloc_type_pointer(ft); break;
|
||||
}
|
||||
} else if (is_type_slice(t)) {
|
||||
switch (index) {
|
||||
case 0: result_type = make_type_pointer(a, make_type_pointer(a, t->Slice.elem)); break;
|
||||
case 1: result_type = make_type_pointer(a, t_int); break;
|
||||
case 2: result_type = make_type_pointer(a, t_int); break;
|
||||
case 0: result_type = alloc_type_pointer(alloc_type_pointer(t->Slice.elem)); break;
|
||||
case 1: result_type = alloc_type_pointer(t_int); break;
|
||||
case 2: result_type = alloc_type_pointer(t_int); break;
|
||||
}
|
||||
} else if (is_type_string(t)) {
|
||||
switch (index) {
|
||||
case 0: result_type = make_type_pointer(a, t_u8_ptr); break;
|
||||
case 1: result_type = make_type_pointer(a, t_int); break;
|
||||
case 0: result_type = alloc_type_pointer(t_u8_ptr); break;
|
||||
case 1: result_type = alloc_type_pointer(t_int); break;
|
||||
}
|
||||
} else if (is_type_any(t)) {
|
||||
switch (index) {
|
||||
case 0: result_type = make_type_pointer(a, t_rawptr); break;
|
||||
case 1: result_type = make_type_pointer(a, t_type_info_ptr); break;
|
||||
case 0: result_type = alloc_type_pointer(t_rawptr); break;
|
||||
case 1: result_type = alloc_type_pointer(t_type_info_ptr); break;
|
||||
}
|
||||
} else if (is_type_dynamic_array(t)) {
|
||||
switch (index) {
|
||||
case 0: result_type = make_type_pointer(a, make_type_pointer(a, t->DynamicArray.elem)); break;
|
||||
case 0: result_type = alloc_type_pointer(alloc_type_pointer(t->DynamicArray.elem)); break;
|
||||
case 1: result_type = t_int_ptr; break;
|
||||
case 2: result_type = t_int_ptr; break;
|
||||
case 3: result_type = t_allocator_ptr; break;
|
||||
}
|
||||
} /* else if (is_type_map(t)) {
|
||||
generate_map_internal_types(a, t);
|
||||
Type *itp = make_type_pointer(a, t->Map.internal_type);
|
||||
init_map_internal_types(t);
|
||||
Type *itp = alloc_type_pointer(t->Map.internal_type);
|
||||
s = ir_emit_load(proc, ir_emit_transmute(proc, s, itp));
|
||||
|
||||
Type *gst = t->Map.generated_struct_type;
|
||||
GB_ASSERT(gst->kind == Type_Struct);
|
||||
switch (index) {
|
||||
case 0: result_type = make_type_pointer(a, gst->Struct.fields[0]->type); break;
|
||||
case 1: result_type = make_type_pointer(a, gst->Struct.fields[1]->type); break;
|
||||
case 0: result_type = alloc_type_pointer(gst->Struct.fields[0]->type); break;
|
||||
case 1: result_type = alloc_type_pointer(gst->Struct.fields[1]->type); break;
|
||||
}
|
||||
} */else {
|
||||
GB_PANIC("TODO(bill): struct_gep type: %s, %d", type_to_string(ir_type(s)), index);
|
||||
@@ -2705,13 +2705,13 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) {
|
||||
break;
|
||||
case Type_Slice:
|
||||
switch (index) {
|
||||
case 0: result_type = make_type_pointer(a, t->Slice.elem); break;
|
||||
case 0: result_type = alloc_type_pointer(t->Slice.elem); break;
|
||||
case 1: result_type = t_int; break;
|
||||
}
|
||||
break;
|
||||
case Type_DynamicArray:
|
||||
switch (index) {
|
||||
case 0: result_type = make_type_pointer(a, t->DynamicArray.elem); break;
|
||||
case 0: result_type = alloc_type_pointer(t->DynamicArray.elem); break;
|
||||
case 1: result_type = t_int; break;
|
||||
case 2: result_type = t_int; break;
|
||||
case 3: result_type = t_allocator; break;
|
||||
@@ -2719,7 +2719,7 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) {
|
||||
break;
|
||||
|
||||
// case Type_Map: {
|
||||
// generate_map_internal_types(a, t);
|
||||
// init_map_internal_types(t);
|
||||
// Type *gst = t->Map.generated_struct_type;
|
||||
// switch (index) {
|
||||
// case 0: result_type = gst->Struct.fields[0]->type; break;
|
||||
@@ -2755,7 +2755,7 @@ irValue *ir_emit_deep_field_gep(irProcedure *proc, irValue *e, Selection sel) {
|
||||
|
||||
if (is_type_raw_union(type)) {
|
||||
type = type->Struct.fields[index]->type;
|
||||
e = ir_emit_conv(proc, e, make_type_pointer(a, type));
|
||||
e = ir_emit_conv(proc, e, alloc_type_pointer(type));
|
||||
} else if (is_type_struct(type)) {
|
||||
type = type->Struct.fields[index]->type;
|
||||
e = ir_emit_struct_ep(proc, e, index);
|
||||
@@ -2974,7 +2974,7 @@ irValue *ir_find_or_add_entity_string(irModule *m, String str) {
|
||||
|
||||
|
||||
irValue *ir_const_union_tag(gbAllocator a, Type *u, Type *v) {
|
||||
return ir_value_constant(a, union_tag_type(a, u), exact_value_i64(union_variant_index(u, v)));
|
||||
return ir_value_constant(a, union_tag_type(u), exact_value_i64(union_variant_index(u, v)));
|
||||
}
|
||||
|
||||
|
||||
@@ -3030,7 +3030,7 @@ irValue *ir_emit_uintptr_to_ptr(irProcedure *proc, irValue *value, Type *t) {
|
||||
|
||||
void ir_emit_store_union_variant(irProcedure *proc, irValue *parent, irValue *variant, Type *variant_type) {
|
||||
gbAllocator a = proc->module->allocator;
|
||||
irValue *underlying = ir_emit_conv(proc, parent, make_type_pointer(a, variant_type));
|
||||
irValue *underlying = ir_emit_conv(proc, parent, alloc_type_pointer(variant_type));
|
||||
|
||||
irValue *v = variant;
|
||||
ir_emit_store(proc, underlying, variant);
|
||||
@@ -3104,8 +3104,8 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
|
||||
if (is_type_integer(src) && is_type_integer(dst)) {
|
||||
GB_ASSERT(src->kind == Type_Basic &&
|
||||
dst->kind == Type_Basic);
|
||||
i64 sz = type_size_of(proc->module->allocator, default_type(src));
|
||||
i64 dz = type_size_of(proc->module->allocator, default_type(dst));
|
||||
i64 sz = type_size_of(default_type(src));
|
||||
i64 dz = type_size_of(default_type(dst));
|
||||
irConvKind kind = irConv_trunc;
|
||||
|
||||
if (dz < sz) {
|
||||
@@ -3157,8 +3157,8 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
|
||||
// float -> float
|
||||
if (is_type_float(src) && is_type_float(dst)) {
|
||||
gbAllocator a = proc->module->allocator;
|
||||
i64 sz = type_size_of(proc->module->allocator, src);
|
||||
i64 dz = type_size_of(proc->module->allocator, dst);
|
||||
i64 sz = type_size_of(src);
|
||||
i64 dz = type_size_of(dst);
|
||||
if (sz == 2) {
|
||||
switch (dz) {
|
||||
case 2: return value;
|
||||
@@ -3265,7 +3265,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
|
||||
// gb_printf("field_name: %.*s\n", LIT(field_name));
|
||||
if (field_name.len > 0) {
|
||||
// NOTE(bill): It can be casted
|
||||
Selection sel = lookup_field(proc->module->allocator, st, field_name, false);
|
||||
Selection sel = lookup_field(st, field_name, false);
|
||||
if (sel.entity != nullptr) {
|
||||
ir_emit_comment(proc, str_lit("cast - polymorphism"));
|
||||
if (st_is_ptr) {
|
||||
@@ -3429,8 +3429,8 @@ irValue *ir_emit_transmute(irProcedure *proc, irValue *value, Type *t) {
|
||||
|
||||
irModule *m = proc->module;
|
||||
|
||||
i64 sz = type_size_of(m->allocator, src);
|
||||
i64 dz = type_size_of(m->allocator, dst);
|
||||
i64 sz = type_size_of(src);
|
||||
i64 dz = type_size_of(dst);
|
||||
|
||||
GB_ASSERT_MSG(sz == dz, "Invalid transmute conversion: '%s' to '%s'", type_to_string(src_type), type_to_string(t));
|
||||
|
||||
@@ -3444,7 +3444,7 @@ irValue *ir_emit_transmute(irProcedure *proc, irValue *value, Type *t) {
|
||||
|
||||
if (ir_is_type_aggregate(src) || ir_is_type_aggregate(dst)) {
|
||||
irValue *s = ir_address_from_load_or_generate_local(proc, value);
|
||||
irValue *d = ir_emit_bitcast(proc, s, make_type_pointer(m->allocator, t));
|
||||
irValue *d = ir_emit_bitcast(proc, s, alloc_type_pointer(t));
|
||||
return ir_emit_load(proc, d);
|
||||
}
|
||||
|
||||
@@ -3464,7 +3464,7 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token
|
||||
Type *tuple = type;
|
||||
if (type->kind != Type_Tuple) {
|
||||
is_tuple = false;
|
||||
tuple = make_optional_ok_type(a, type);
|
||||
tuple = make_optional_ok_type(type);
|
||||
}
|
||||
|
||||
irValue *v = ir_add_local_generated(proc, tuple);
|
||||
@@ -3533,7 +3533,7 @@ irAddr ir_emit_any_cast_addr(irProcedure *proc, irValue *value, Type *type, Toke
|
||||
Type *tuple = type;
|
||||
if (type->kind != Type_Tuple) {
|
||||
is_tuple = false;
|
||||
tuple = make_optional_ok_type(a, type);
|
||||
tuple = make_optional_ok_type(type);
|
||||
}
|
||||
Type *dst_type = tuple->Tuple.variables[0]->type;
|
||||
|
||||
@@ -3553,7 +3553,7 @@ irAddr ir_emit_any_cast_addr(irProcedure *proc, irValue *value, Type *type, Toke
|
||||
irValue *gep1 = ir_emit_struct_ep(proc, v, 1);
|
||||
|
||||
irValue *any_data = ir_emit_struct_ev(proc, value, 0);
|
||||
irValue *ptr = ir_emit_conv(proc, any_data, make_type_pointer(a, dst_type));
|
||||
irValue *ptr = ir_emit_conv(proc, any_data, alloc_type_pointer(dst_type));
|
||||
ir_emit_store(proc, gep0, ir_emit_load(proc, ptr));
|
||||
ir_emit_store(proc, gep1, v_true);
|
||||
|
||||
@@ -4029,7 +4029,7 @@ irValue *ir_emit_min(irProcedure *proc, Type *t, irValue *x, irValue *y) {
|
||||
|
||||
if (is_type_float(t)) {
|
||||
gbAllocator a = proc->module->allocator;
|
||||
i64 sz = 8*type_size_of(a, t);
|
||||
i64 sz = 8*type_size_of(t);
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 2);
|
||||
args[0] = x;
|
||||
args[1] = y;
|
||||
@@ -4047,7 +4047,7 @@ irValue *ir_emit_max(irProcedure *proc, Type *t, irValue *x, irValue *y) {
|
||||
|
||||
if (is_type_float(t)) {
|
||||
gbAllocator a = proc->module->allocator;
|
||||
i64 sz = 8*type_size_of(a, t);
|
||||
i64 sz = 8*type_size_of(t);
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 2);
|
||||
args[0] = x;
|
||||
args[1] = y;
|
||||
@@ -4254,10 +4254,10 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
GB_ASSERT(allocation_type != nullptr);
|
||||
}
|
||||
}
|
||||
Type *ptr_type = make_type_pointer(a, type);
|
||||
Type *ptr_type = alloc_type_pointer(type);
|
||||
|
||||
i64 size = type_size_of(a, allocation_type);
|
||||
i64 align = type_align_of(a, allocation_type);
|
||||
i64 size = type_size_of(allocation_type);
|
||||
i64 align = type_align_of(allocation_type);
|
||||
|
||||
irValue **args = gb_alloc_array(a, irValue *, 2);
|
||||
args[0] = ir_const_int(a, size);
|
||||
@@ -4266,7 +4266,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
irValue *v = ir_emit_conv(proc, call, ptr_type);
|
||||
if (type != allocation_type) {
|
||||
Type *u = base_type(allocation_type);
|
||||
Type *uptr_type = make_type_pointer(a, u);
|
||||
Type *uptr_type = alloc_type_pointer(u);
|
||||
irValue *parent = ir_emit_conv(proc, call, uptr_type);
|
||||
irValue *tag_ptr = ir_emit_union_tag_ptr(proc, parent);
|
||||
ir_emit_store(proc, tag_ptr, ir_const_int(a, variant_index));
|
||||
@@ -4288,10 +4288,10 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
|
||||
if (is_type_slice(type)) {
|
||||
Type *elem_type = core_type(type)->Slice.elem;
|
||||
Type *elem_ptr_type = make_type_pointer(a, elem_type);
|
||||
Type *elem_ptr_type = alloc_type_pointer(elem_type);
|
||||
|
||||
i64 esz = type_size_of(a, elem_type);
|
||||
i64 eal = type_align_of(a, elem_type);
|
||||
i64 esz = type_size_of(elem_type);
|
||||
i64 eal = type_align_of(elem_type);
|
||||
|
||||
irValue *elem_size = ir_const_int(a, esz);
|
||||
irValue *elem_align = ir_const_int(a, eal);
|
||||
@@ -4359,8 +4359,8 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 6);
|
||||
args[0] = ir_emit_conv(proc, array, t_rawptr);
|
||||
args[1] = ir_const_int(a, type_size_of(a, elem_type));
|
||||
args[2] = ir_const_int(a, type_align_of(a, elem_type));
|
||||
args[1] = ir_const_int(a, type_size_of(elem_type));
|
||||
args[2] = ir_const_int(a, type_align_of(elem_type));
|
||||
args[3] = len;
|
||||
args[4] = cap;
|
||||
args[5] = ir_emit_source_code_location(proc, ce->args[0]);
|
||||
@@ -4466,8 +4466,8 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
if (is_type_dynamic_array(type)) {
|
||||
Type *elem = type->DynamicArray.elem;
|
||||
|
||||
irValue *elem_size = ir_const_int(a, type_size_of(a, elem));
|
||||
irValue *elem_align = ir_const_int(a, type_align_of(a, elem));
|
||||
irValue *elem_size = ir_const_int(a, type_size_of(elem));
|
||||
irValue *elem_align = ir_const_int(a, type_align_of(elem));
|
||||
|
||||
ptr = ir_emit_conv(proc, ptr, t_rawptr);
|
||||
|
||||
@@ -4546,8 +4546,8 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
GB_PANIC("Invalid type to append");
|
||||
}
|
||||
|
||||
irValue *elem_size = ir_const_int(a, type_size_of(a, elem_type));
|
||||
irValue *elem_align = ir_const_int(a, type_align_of(a, elem_type));
|
||||
irValue *elem_size = ir_const_int(a, type_size_of(elem_type));
|
||||
irValue *elem_align = ir_const_int(a, type_align_of(elem_type));
|
||||
|
||||
array_ptr = ir_emit_conv(proc, array_ptr, t_rawptr);
|
||||
|
||||
@@ -4588,12 +4588,12 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
|
||||
if (!vari_expand) {
|
||||
ir_emit_comment(proc, str_lit("variadic call argument generation"));
|
||||
Type *slice_type = make_type_slice(a, elem_type);
|
||||
Type *slice_type = alloc_type_slice(elem_type);
|
||||
irValue *slice = ir_add_local_generated(proc, slice_type);
|
||||
isize slice_len = arg_count-1;
|
||||
|
||||
if (slice_len > 0) {
|
||||
irValue *base_array = ir_add_local_generated(proc, make_type_array(a, elem_type, slice_len));
|
||||
irValue *base_array = ir_add_local_generated(proc, alloc_type_array(elem_type, slice_len));
|
||||
|
||||
for (isize i = 1; i < arg_count; i++) {
|
||||
irValue *addr = ir_emit_array_epi(proc, base_array, i-1);
|
||||
@@ -4759,7 +4759,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
irValue *x = ir_build_expr(proc, ce->args[0]);
|
||||
Type *t = ir_type(x);
|
||||
if (is_type_complex(t)) {
|
||||
i64 sz = 8*type_size_of(a, t);
|
||||
i64 sz = 8*type_size_of(t);
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = x;
|
||||
switch (sz) {
|
||||
@@ -4768,7 +4768,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv
|
||||
}
|
||||
GB_PANIC("Unknown complex type");
|
||||
} else if (is_type_float(t)) {
|
||||
i64 sz = 8*type_size_of(a, t);
|
||||
i64 sz = 8*type_size_of(t);
|
||||
auto args = array_make<irValue *>(proc->module->allocator, 1);
|
||||
args[0] = x;
|
||||
switch (sz) {
|
||||
@@ -5319,7 +5319,7 @@ irValue *ir_build_expr_internal(irProcedure *proc, AstNode *expr) {
|
||||
isize slice_len = arg_count+1 - (variadic_index+1);
|
||||
|
||||
if (slice_len > 0) {
|
||||
irValue *base_array = ir_add_local_generated(proc, make_type_array(allocator, elem_type, slice_len));
|
||||
irValue *base_array = ir_add_local_generated(proc, alloc_type_array(elem_type, slice_len));
|
||||
|
||||
for (isize i = variadic_index, j = 0; i < arg_count; i++, j++) {
|
||||
irValue *addr = ir_emit_array_epi(proc, base_array, cast(i32)j);
|
||||
@@ -5375,7 +5375,7 @@ irValue *ir_get_using_variable(irProcedure *proc, Entity *e) {
|
||||
GB_ASSERT(e->kind == Entity_Variable && e->flags & EntityFlag_Using);
|
||||
String name = e->token.string;
|
||||
Entity *parent = e->using_parent;
|
||||
Selection sel = lookup_field(proc->module->allocator, parent->type, name, false);
|
||||
Selection sel = lookup_field(parent->type, name, false);
|
||||
GB_ASSERT(sel.entity != nullptr);
|
||||
irValue **pv = map_get(&proc->module->values, hash_entity(parent));
|
||||
irValue *v = nullptr;
|
||||
@@ -5473,7 +5473,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
|
||||
Type *type = base_type(tav.type);
|
||||
if (tav.mode == Addressing_Type) { // Addressing_Type
|
||||
Selection sel = lookup_field(proc->module->allocator, type, selector, true);
|
||||
Selection sel = lookup_field(type, selector, true);
|
||||
Entity *e = sel.entity;
|
||||
GB_ASSERT(e->kind == Entity_Variable);
|
||||
GB_ASSERT(e->flags & EntityFlag_TypeField);
|
||||
@@ -5498,7 +5498,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
GB_PANIC("Unreachable");
|
||||
}
|
||||
|
||||
Selection sel = lookup_field(proc->module->allocator, type, selector, false);
|
||||
Selection sel = lookup_field(type, selector, false);
|
||||
GB_ASSERT(sel.entity != nullptr);
|
||||
|
||||
|
||||
@@ -5530,7 +5530,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
ExactValue val = type_and_value_of_expr(proc->module->info, sel).value;
|
||||
i64 index = val.value_integer;
|
||||
|
||||
Selection sel = lookup_field_from_index(proc->module->allocator, type, index);
|
||||
Selection sel = lookup_field_from_index(type, index);
|
||||
GB_ASSERT(sel.entity != nullptr);
|
||||
|
||||
irValue *a = ir_build_addr_ptr(proc, se->expr);
|
||||
@@ -5730,7 +5730,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
|
||||
case Type_DynamicArray: {
|
||||
Type *elem_type = type->DynamicArray.elem;
|
||||
Type *slice_type = make_type_slice(a, elem_type);
|
||||
Type *slice_type = alloc_type_slice(elem_type);
|
||||
|
||||
irValue *len = ir_dynamic_array_len(proc, base);
|
||||
if (high == nullptr) high = len;
|
||||
@@ -5747,7 +5747,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
|
||||
|
||||
case Type_Array: {
|
||||
Type *slice_type = make_type_slice(a, type->Array.elem);
|
||||
Type *slice_type = alloc_type_slice(type->Array.elem);
|
||||
irValue *len = ir_array_len(proc, base);
|
||||
|
||||
if (high == nullptr) high = len;
|
||||
@@ -5842,13 +5842,12 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
if (elem->kind == AstNode_FieldValue) {
|
||||
ast_node(fv, FieldValue, elem);
|
||||
String name = fv->field->Ident.token.string;
|
||||
Selection sel = lookup_field(proc->module->allocator, bt, name, false);
|
||||
Selection sel = lookup_field(bt, name, false);
|
||||
index = sel.index[0];
|
||||
elem = fv->value;
|
||||
} else {
|
||||
TypeAndValue tav = type_and_value_of_expr(proc->module->info, elem);
|
||||
Selection sel = lookup_field_from_index(proc->module->allocator, bt,
|
||||
st->fields[field_index]->Variable.field_src_index);
|
||||
Selection sel = lookup_field_from_index(bt, st->fields[field_index]->Variable.field_src_index);
|
||||
index = sel.index[0];
|
||||
}
|
||||
|
||||
@@ -5899,8 +5898,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
}
|
||||
Type *elem = bt->DynamicArray.elem;
|
||||
gbAllocator a = proc->module->allocator;
|
||||
irValue *size = ir_const_int(a, type_size_of(a, elem));
|
||||
irValue *align = ir_const_int(a, type_align_of(a, elem));
|
||||
irValue *size = ir_const_int(a, type_size_of(elem));
|
||||
irValue *align = ir_const_int(a, type_align_of(elem));
|
||||
{
|
||||
auto args = array_make<irValue *>(a, 5);
|
||||
args[0] = ir_emit_conv(proc, v, t_rawptr);
|
||||
@@ -5955,8 +5954,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
case Type_Slice: {
|
||||
if (cl->elems.count > 0) {
|
||||
Type *elem_type = bt->Slice.elem;
|
||||
Type *elem_ptr_type = make_type_pointer(proc->module->allocator, elem_type);
|
||||
Type *elem_ptr_ptr_type = make_type_pointer(proc->module->allocator, elem_ptr_type);
|
||||
Type *elem_ptr_type = alloc_type_pointer(elem_type);
|
||||
Type *elem_ptr_ptr_type = alloc_type_pointer(elem_ptr_type);
|
||||
irValue *slice = ir_add_module_constant(proc->module, type, exact_value_compound(expr));
|
||||
GB_ASSERT(slice->kind == irValue_ConstantSlice);
|
||||
|
||||
@@ -6003,12 +6002,12 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
||||
|
||||
if (elem->kind == AstNode_FieldValue) {
|
||||
ast_node(fv, FieldValue, elem);
|
||||
Selection sel = lookup_field(proc->module->allocator, bt, fv->field->Ident.token.string, false);
|
||||
Selection sel = lookup_field(bt, fv->field->Ident.token.string, false);
|
||||
index = sel.index[0];
|
||||
elem = fv->value;
|
||||
} else {
|
||||
TypeAndValue tav = type_and_value_of_expr(proc->module->info, elem);
|
||||
Selection sel = lookup_field(proc->module->allocator, bt, field_names[field_index], false);
|
||||
Selection sel = lookup_field(bt, field_names[field_index], false);
|
||||
index = sel.index[0];
|
||||
}
|
||||
|
||||
@@ -6914,7 +6913,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
gbAllocator a = proc->module->allocator;
|
||||
Type *t = tav.type;
|
||||
GB_ASSERT(is_type_enum(t));
|
||||
Type *enum_ptr = make_type_pointer(a, t);
|
||||
Type *enum_ptr = alloc_type_pointer(t);
|
||||
t = base_type(t);
|
||||
Type *core_elem = core_type(t);
|
||||
i64 enum_count = t->Enum.fields.count;
|
||||
@@ -7240,7 +7239,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
|
||||
Type *ct = case_entity->type;
|
||||
if (any_or_not_ptr) {
|
||||
ct = make_type_pointer(proc->module->allocator, ct);
|
||||
ct = alloc_type_pointer(ct);
|
||||
}
|
||||
GB_ASSERT_MSG(is_type_pointer(ct), "%s", type_to_string(ct));
|
||||
irValue *data = nullptr;
|
||||
@@ -7314,7 +7313,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
||||
irValue *next = ir_add_local_generated(proc, t_context);
|
||||
ir_emit_store(proc, next, new_context);
|
||||
|
||||
Selection sel = lookup_field(proc->module->allocator, t_context, str_lit("parent"), false);
|
||||
Selection sel = lookup_field(t_context, str_lit("parent"), false);
|
||||
GB_ASSERT(sel.entity != nullptr);
|
||||
irValue *parent_ptr = ir_emit_deep_field_gep(proc, next, sel);
|
||||
ir_emit_store(proc, parent_ptr, prev);
|
||||
@@ -7389,7 +7388,7 @@ void ir_begin_procedure_body(irProcedure *proc) {
|
||||
|
||||
if (proc->type->Proc.return_by_pointer) {
|
||||
// NOTE(bill): this must be the first parameter stored
|
||||
Type *ptr_type = make_type_pointer(a, reduce_tuple_to_single_type(proc->type->Proc.results));
|
||||
Type *ptr_type = alloc_type_pointer(reduce_tuple_to_single_type(proc->type->Proc.results));
|
||||
Entity *e = make_entity_param(a, nullptr, make_token_ident(str_lit("agg.result")), ptr_type, false, false);
|
||||
e->flags |= EntityFlag_Sret | EntityFlag_NoAlias;
|
||||
|
||||
@@ -7634,7 +7633,7 @@ void ir_init_module(irModule *m, Checker *c) {
|
||||
isize max_type_info_count = m->info->type_info_types.count;
|
||||
|
||||
String name = str_lit(IR_TYPE_INFO_DATA_NAME);
|
||||
Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name), make_type_array(m->allocator, t_type_info, max_type_info_count), false);
|
||||
Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name), alloc_type_array(t_type_info, max_type_info_count), false);
|
||||
irValue *g = ir_value_global(m->allocator, e, nullptr);
|
||||
g->Global.is_private = true;
|
||||
ir_module_add_value(m, e, g);
|
||||
@@ -7666,7 +7665,7 @@ void ir_init_module(irModule *m, Checker *c) {
|
||||
{
|
||||
String name = str_lit(IR_TYPE_INFO_TYPES_NAME);
|
||||
Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name),
|
||||
make_type_array(m->allocator, t_type_info_ptr, count), false);
|
||||
alloc_type_array(t_type_info_ptr, count), false);
|
||||
irValue *g = ir_value_global(m->allocator, e, nullptr);
|
||||
ir_module_add_value(m, e, g);
|
||||
map_set(&m->members, hash_string(name), g);
|
||||
@@ -7675,7 +7674,7 @@ void ir_init_module(irModule *m, Checker *c) {
|
||||
{
|
||||
String name = str_lit(IR_TYPE_INFO_NAMES_NAME);
|
||||
Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name),
|
||||
make_type_array(m->allocator, t_string, count), false);
|
||||
alloc_type_array(t_string, count), false);
|
||||
irValue *g = ir_value_global(m->allocator, e, nullptr);
|
||||
ir_module_add_value(m, e, g);
|
||||
map_set(&m->members, hash_string(name), g);
|
||||
@@ -7684,7 +7683,7 @@ void ir_init_module(irModule *m, Checker *c) {
|
||||
{
|
||||
String name = str_lit(IR_TYPE_INFO_OFFSETS_NAME);
|
||||
Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name),
|
||||
make_type_array(m->allocator, t_uintptr, count), false);
|
||||
alloc_type_array(t_uintptr, count), false);
|
||||
irValue *g = ir_value_global(m->allocator, e, nullptr);
|
||||
ir_module_add_value(m, e, g);
|
||||
map_set(&m->members, hash_string(name), g);
|
||||
@@ -7694,7 +7693,7 @@ void ir_init_module(irModule *m, Checker *c) {
|
||||
{
|
||||
String name = str_lit(IR_TYPE_INFO_USINGS_NAME);
|
||||
Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name),
|
||||
make_type_array(m->allocator, t_bool, count), false);
|
||||
alloc_type_array(t_bool, count), false);
|
||||
irValue *g = ir_value_global(m->allocator, e, nullptr);
|
||||
ir_module_add_value(m, e, g);
|
||||
map_set(&m->members, hash_string(name), g);
|
||||
@@ -7839,8 +7838,8 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
|
||||
|
||||
// Useful types
|
||||
Type *t_i64_slice_ptr = make_type_pointer(a, make_type_slice(a, t_i64));
|
||||
Type *t_string_slice_ptr = make_type_pointer(a, make_type_slice(a, t_string));
|
||||
Type *t_i64_slice_ptr = alloc_type_pointer(alloc_type_slice(t_i64));
|
||||
Type *t_string_slice_ptr = alloc_type_pointer(alloc_type_slice(t_string));
|
||||
|
||||
i32 type_info_member_types_index = 0;
|
||||
i32 type_info_member_names_index = 0;
|
||||
@@ -7859,8 +7858,8 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
irValue *ti_ptr = ir_emit_array_epi(proc, ir_global_type_info_data, cast(i32)entry_index);
|
||||
irValue *variant_ptr = ir_emit_struct_ep(proc, ti_ptr, 2);
|
||||
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, ti_ptr, 0), ir_const_int(a, type_size_of(a, t)));
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, ti_ptr, 1), ir_const_int(a, type_align_of(a, t)));
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, ti_ptr, 0), ir_const_int(a, type_size_of(t)));
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, ti_ptr, 1), ir_const_int(a, type_align_of(t)));
|
||||
|
||||
|
||||
switch (t->kind) {
|
||||
@@ -7953,7 +7952,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
irValue *gep = ir_get_type_info_ptr(proc, t->Array.elem);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
||||
|
||||
isize ez = type_size_of(a, t->Array.elem);
|
||||
isize ez = type_size_of(t->Array.elem);
|
||||
irValue *elem_size = ir_emit_struct_ep(proc, tag, 1);
|
||||
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
|
||||
|
||||
@@ -7968,7 +7967,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
irValue *gep = ir_get_type_info_ptr(proc, t->DynamicArray.elem);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
||||
|
||||
isize ez = type_size_of(a, t->DynamicArray.elem);
|
||||
isize ez = type_size_of(t->DynamicArray.elem);
|
||||
irValue *elem_size = ir_emit_struct_ep(proc, tag, 1);
|
||||
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
|
||||
break;
|
||||
@@ -7979,7 +7978,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
irValue *gep = ir_get_type_info_ptr(proc, t->Slice.elem);
|
||||
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), gep);
|
||||
|
||||
isize ez = type_size_of(a, t->Slice.elem);
|
||||
isize ez = type_size_of(t->Slice.elem);
|
||||
irValue *elem_size = ir_emit_struct_ep(proc, tag, 1);
|
||||
ir_emit_store(proc, elem_size, ir_const_int(a, ez));
|
||||
break;
|
||||
@@ -8103,12 +8102,12 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
irValue *count = ir_const_int(a, variant_count);
|
||||
ir_fill_slice(proc, variant_types, memory_types, count);
|
||||
|
||||
i64 tag_size = union_tag_size(a, t);
|
||||
i64 tag_size = union_tag_size(t);
|
||||
i64 tag_offset = align_formula(t->Union.variant_block_size, tag_size);
|
||||
|
||||
if (tag_size > 0) {
|
||||
ir_emit_store(proc, tag_offset_ptr, ir_const_uintptr(a, tag_offset));
|
||||
ir_emit_store(proc, tag_type_ptr, ir_type_info(proc, union_tag_type(a, t)));
|
||||
ir_emit_store(proc, tag_type_ptr, ir_type_info(proc, union_tag_type(t)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8135,7 +8134,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
irValue *memory_offsets = ir_type_info_member_offsets_offset(proc, count);
|
||||
irValue *memory_usings = ir_type_info_member_usings_offset (proc, count);
|
||||
|
||||
type_set_offsets(a, t); // NOTE(bill): Just incase the offsets have not been set yet
|
||||
type_set_offsets(t); // NOTE(bill): Just incase the offsets have not been set yet
|
||||
for (isize source_index = 0; source_index < count; source_index++) {
|
||||
// TODO(bill): Order fields in source order not layout order
|
||||
Entity *f = t->Struct.fields[source_index];
|
||||
@@ -8170,7 +8169,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
|
||||
case Type_Map: {
|
||||
ir_emit_comment(proc, str_lit("Type_Info_Map"));
|
||||
tag = ir_emit_conv(proc, variant_ptr, t_type_info_map_ptr);
|
||||
generate_map_internal_types(a, t);
|
||||
init_map_internal_types(t);
|
||||
|
||||
irValue *key = ir_emit_struct_ep(proc, tag, 0);
|
||||
irValue *value = ir_emit_struct_ep(proc, tag, 1);
|
||||
@@ -8480,8 +8479,8 @@ void ir_gen_tree(irGen *s) {
|
||||
if (build_context.is_dll && !has_dll_main) {
|
||||
// DllMain :: proc(inst: rawptr, reason: u32, reserved: rawptr) -> i32
|
||||
String name = str_lit("DllMain");
|
||||
Type *proc_params = make_type_tuple(a);
|
||||
Type *proc_results = make_type_tuple(a);
|
||||
Type *proc_params = alloc_type_tuple();
|
||||
Type *proc_results = alloc_type_tuple();
|
||||
|
||||
Scope *proc_scope = gb_alloc_item(a, Scope);
|
||||
|
||||
@@ -8496,9 +8495,9 @@ void ir_gen_tree(irGen *s) {
|
||||
proc_results->Tuple.variables[0] = make_entity_param(a, proc_scope, empty_token, t_i32, false, false);
|
||||
|
||||
|
||||
Type *proc_type = make_type_proc(a, proc_scope,
|
||||
proc_params, 3,
|
||||
proc_results, 1, false, ProcCC_StdCall);
|
||||
Type *proc_type = alloc_type_proc(proc_scope,
|
||||
proc_params, 3,
|
||||
proc_results, 1, false, ProcCC_StdCall);
|
||||
|
||||
// TODO(bill): make this more robust
|
||||
proc_type->Proc.abi_compat_params = array_make<Type *>(a, proc_params->Tuple.variables.count);
|
||||
@@ -8558,15 +8557,15 @@ void ir_gen_tree(irGen *s) {
|
||||
name = str_lit("ProgramEntry");
|
||||
}
|
||||
|
||||
Type *proc_params = make_type_tuple(a);
|
||||
Type *proc_results = make_type_tuple(a);
|
||||
Type *proc_params = alloc_type_tuple();
|
||||
Type *proc_results = alloc_type_tuple();
|
||||
|
||||
Scope *proc_scope = gb_alloc_item(a, Scope);
|
||||
|
||||
array_init(&proc_params->Tuple.variables, a, 2);
|
||||
array_init(&proc_results->Tuple.variables, a, 1);
|
||||
|
||||
Type *cstring_ptr = make_type_pointer(a, t_cstring);
|
||||
Type *cstring_ptr = alloc_type_pointer(t_cstring);
|
||||
proc_params->Tuple.variables[0] = make_entity_param(a, proc_scope, make_token_ident(str_lit("argc")), t_i32, false, false);
|
||||
proc_params->Tuple.variables[1] = make_entity_param(a, proc_scope, make_token_ident(str_lit("argv")), cstring_ptr, false, false);
|
||||
|
||||
@@ -8574,9 +8573,9 @@ void ir_gen_tree(irGen *s) {
|
||||
proc_results->Tuple.variables[0] = make_entity_param(a, proc_scope, empty_token, t_i32, false, false);
|
||||
|
||||
|
||||
Type *proc_type = make_type_proc(a, proc_scope,
|
||||
proc_params, 2,
|
||||
proc_results, 1, false, ProcCC_CDecl);
|
||||
Type *proc_type = alloc_type_proc(proc_scope,
|
||||
proc_params, 2,
|
||||
proc_results, 1, false, ProcCC_CDecl);
|
||||
|
||||
// TODO(bill): make this more robust
|
||||
proc_type->Proc.abi_compat_params = array_make<Type *>(a, proc_params->Tuple.variables.count);
|
||||
@@ -8626,8 +8625,8 @@ void ir_gen_tree(irGen *s) {
|
||||
if (!m->build_context->is_dll && !has_win_main) {
|
||||
// proc WinMain(inst, prev: rawptr, cmd_line: ^byte, cmd_show: i32) -> i32
|
||||
String name = str_lit("WinMain");
|
||||
Type *proc_params = make_type_tuple(a);
|
||||
Type *proc_results = make_type_tuple(a);
|
||||
Type *proc_params = alloc_type_tuple();
|
||||
Type *proc_results = alloc_type_tuple();
|
||||
|
||||
Scope *proc_scope = gb_alloc_item(a, Scope);
|
||||
|
||||
@@ -8645,7 +8644,7 @@ void ir_gen_tree(irGen *s) {
|
||||
proc_results->Tuple.variables[0] = make_entity_param(a, proc_scope, empty_token, t_i32, false);
|
||||
|
||||
|
||||
Type *proc_type = make_type_proc(a, proc_scope,
|
||||
Type *proc_type = alloc_type_proc(a, proc_scope,
|
||||
proc_params, 4,
|
||||
proc_results, 1, false, ProcCC_Std);
|
||||
|
||||
@@ -8671,10 +8670,10 @@ void ir_gen_tree(irGen *s) {
|
||||
{ // Startup Runtime
|
||||
// Cleanup(bill): probably better way of doing code insertion
|
||||
String name = str_lit(IR_STARTUP_RUNTIME_PROC_NAME);
|
||||
Type *proc_type = make_type_proc(a, gb_alloc_item(a, Scope),
|
||||
nullptr, 0,
|
||||
nullptr, 0, false,
|
||||
ProcCC_Contextless);
|
||||
Type *proc_type = alloc_type_proc(gb_alloc_item(a, Scope),
|
||||
nullptr, 0,
|
||||
nullptr, 0, false,
|
||||
ProcCC_Contextless);
|
||||
AstNode *body = gb_alloc_item(a, AstNode);
|
||||
Entity *e = make_entity_procedure(a, nullptr, make_token_ident(name), proc_type, 0);
|
||||
irValue *p = ir_value_procedure(a, m, e, proc_type, nullptr, body, name);
|
||||
|
||||
@@ -385,13 +385,13 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t, bool in_struct) {
|
||||
} else {
|
||||
// NOTE(bill): The zero size array is used to fix the alignment used in a structure as
|
||||
// LLVM takes the first element's alignment as the entire alignment (like C)
|
||||
i64 align = type_align_of(heap_allocator(), t);
|
||||
i64 align = type_align_of(t);
|
||||
i64 block_size = t->Union.variant_block_size;
|
||||
|
||||
ir_fprintf(f, "{[0 x <%lld x i8>], ", align);
|
||||
ir_fprintf(f, "[%lld x i8], ", block_size);
|
||||
// ir_print_type(f, m, t_type_info_ptr);
|
||||
ir_print_type(f, m, union_tag_type(m->allocator, t));
|
||||
ir_print_type(f, m, union_tag_type(t));
|
||||
ir_write_byte(f, '}');
|
||||
}
|
||||
return;
|
||||
@@ -400,8 +400,8 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t, bool in_struct) {
|
||||
if (t->Struct.is_raw_union) {
|
||||
// NOTE(bill): The zero size array is used to fix the alignment used in a structure as
|
||||
// LLVM takes the first element's alignment as the entire alignment (like C)
|
||||
i64 size_of_union = type_size_of(heap_allocator(), t);
|
||||
i64 align_of_union = type_align_of(heap_allocator(), t);
|
||||
i64 size_of_union = type_size_of(t);
|
||||
i64 align_of_union = type_align_of(t);
|
||||
ir_fprintf(f, "{[0 x <%lld x i8>], [%lld x i8]}", align_of_union, size_of_union);
|
||||
return;
|
||||
} else {
|
||||
@@ -481,14 +481,14 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t, bool in_struct) {
|
||||
return;
|
||||
|
||||
case Type_Map:
|
||||
generate_map_internal_types(m->allocator, t);
|
||||
init_map_internal_types(t);
|
||||
GB_ASSERT(t->Map.internal_type != nullptr);
|
||||
ir_print_type(f, m, t->Map.internal_type);
|
||||
break;
|
||||
|
||||
case Type_BitField: {
|
||||
i64 align = type_align_of(heap_allocator(), t);
|
||||
i64 size = type_size_of(heap_allocator(), t);
|
||||
i64 align = type_align_of(t);
|
||||
i64 size = type_size_of(t);
|
||||
ir_fprintf(f, "{[0 x <%lld x i8>], [%lld x i8]}", align, size);
|
||||
break;
|
||||
}
|
||||
@@ -723,7 +723,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type *
|
||||
TypeAndValue tav = type_and_value_of_expr(m->info, fv->value);
|
||||
GB_ASSERT(tav.mode != Addressing_Invalid);
|
||||
|
||||
Selection sel = lookup_field(m->allocator, type, name, false);
|
||||
Selection sel = lookup_field(type, name, false);
|
||||
Entity *f = type->Struct.fields[sel.index[0]];
|
||||
|
||||
values[f->Variable.field_index] = tav.value;
|
||||
@@ -998,7 +998,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
|
||||
Type *type = instr->Local.entity->type;
|
||||
i64 align = instr->Local.alignment;
|
||||
if (align <= 0) {
|
||||
align = type_align_of(m->allocator, type);
|
||||
align = type_align_of(type);
|
||||
}
|
||||
ir_fprintf(f, "%%%d = alloca ", value->index);
|
||||
ir_print_type(f, m, type);
|
||||
@@ -1040,7 +1040,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
|
||||
ir_print_type(f, m, type);
|
||||
ir_write_str_lit(f, "* ");
|
||||
ir_print_value(f, m, instr->Load.address, type);
|
||||
ir_fprintf(f, ", align %lld", type_align_of(m->allocator, type));
|
||||
ir_fprintf(f, ", align %lld", type_align_of(type));
|
||||
ir_print_debug_location(f, m, value);
|
||||
break;
|
||||
}
|
||||
|
||||
192
src/types.cpp
192
src/types.cpp
@@ -410,11 +410,11 @@ gb_global Type *t_map_header = nullptr;
|
||||
|
||||
|
||||
|
||||
i64 type_size_of (gbAllocator allocator, Type *t);
|
||||
i64 type_align_of (gbAllocator allocator, Type *t);
|
||||
i64 type_offset_of (gbAllocator allocator, Type *t, i32 index);
|
||||
i64 type_size_of (Type *t);
|
||||
i64 type_align_of (Type *t);
|
||||
i64 type_offset_of (Type *t, i32 index);
|
||||
gbString type_to_string (Type *type);
|
||||
void generate_map_internal_types(gbAllocator a, Type *type);
|
||||
void init_map_internal_types(Type *type);
|
||||
|
||||
|
||||
|
||||
@@ -472,7 +472,8 @@ void set_base_type(Type *t, Type *base) {
|
||||
}
|
||||
|
||||
|
||||
Type *alloc_type(gbAllocator a, TypeKind kind) {
|
||||
Type *alloc_type(TypeKind kind) {
|
||||
gbAllocator a = heap_allocator();
|
||||
Type *t = gb_alloc_item(a, Type);
|
||||
gb_zero_item(t);
|
||||
t->kind = kind;
|
||||
@@ -482,8 +483,8 @@ Type *alloc_type(gbAllocator a, TypeKind kind) {
|
||||
}
|
||||
|
||||
|
||||
Type *make_type_generic(gbAllocator a, Scope *scope, i64 id, String name, Type *specialized) {
|
||||
Type *t = alloc_type(a, Type_Generic);
|
||||
Type *alloc_type_generic(Scope *scope, i64 id, String name, Type *specialized) {
|
||||
Type *t = alloc_type(Type_Generic);
|
||||
t->Generic.id = id;
|
||||
t->Generic.name = name;
|
||||
t->Generic.specialized = specialized;
|
||||
@@ -491,45 +492,45 @@ Type *make_type_generic(gbAllocator a, Scope *scope, i64 id, String name, Type *
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_pointer(gbAllocator a, Type *elem) {
|
||||
Type *t = alloc_type(a, Type_Pointer);
|
||||
Type *alloc_type_pointer(Type *elem) {
|
||||
Type *t = alloc_type(Type_Pointer);
|
||||
t->Pointer.elem = elem;
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_array(gbAllocator a, Type *elem, i64 count, Type *generic_type = nullptr) {
|
||||
Type *t = alloc_type(a, Type_Array);
|
||||
Type *alloc_type_array(Type *elem, i64 count, Type *generic_type = nullptr) {
|
||||
Type *t = alloc_type(Type_Array);
|
||||
t->Array.elem = elem;
|
||||
t->Array.count = count;
|
||||
t->Array.generic_type = generic_type;
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_dynamic_array(gbAllocator a, Type *elem) {
|
||||
Type *t = alloc_type(a, Type_DynamicArray);
|
||||
Type *alloc_type_dynamic_array(Type *elem) {
|
||||
Type *t = alloc_type(Type_DynamicArray);
|
||||
t->DynamicArray.elem = elem;
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_slice(gbAllocator a, Type *elem) {
|
||||
Type *t = alloc_type(a, Type_Slice);
|
||||
Type *alloc_type_slice(Type *elem) {
|
||||
Type *t = alloc_type(Type_Slice);
|
||||
t->Array.elem = elem;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
Type *make_type_struct(gbAllocator a) {
|
||||
Type *t = alloc_type(a, Type_Struct);
|
||||
Type *alloc_type_struct() {
|
||||
Type *t = alloc_type(Type_Struct);
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_union(gbAllocator a) {
|
||||
Type *t = alloc_type(a, Type_Union);
|
||||
Type *alloc_type_union() {
|
||||
Type *t = alloc_type(Type_Union);
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_enum(gbAllocator a) {
|
||||
Type *t = alloc_type(a, Type_Enum);
|
||||
Type *alloc_type_enum() {
|
||||
Type *t = alloc_type(Type_Enum);
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -537,21 +538,21 @@ Type *make_type_enum(gbAllocator a) {
|
||||
|
||||
|
||||
|
||||
Type *make_type_named(gbAllocator a, String name, Type *base, Entity *type_name) {
|
||||
Type *t = alloc_type(a, Type_Named);
|
||||
Type *alloc_type_named(String name, Type *base, Entity *type_name) {
|
||||
Type *t = alloc_type(Type_Named);
|
||||
t->Named.name = name;
|
||||
t->Named.base = base;
|
||||
t->Named.type_name = type_name;
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_tuple(gbAllocator a) {
|
||||
Type *t = alloc_type(a, Type_Tuple);
|
||||
Type *alloc_type_tuple() {
|
||||
Type *t = alloc_type(Type_Tuple);
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_proc(gbAllocator a, Scope *scope, Type *params, isize param_count, Type *results, isize result_count, bool variadic, ProcCallingConvention calling_convention) {
|
||||
Type *t = alloc_type(a, Type_Proc);
|
||||
Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, Type *results, isize result_count, bool variadic, ProcCallingConvention calling_convention) {
|
||||
Type *t = alloc_type(Type_Proc);
|
||||
|
||||
if (variadic) {
|
||||
if (param_count == 0) {
|
||||
@@ -577,8 +578,8 @@ Type *make_type_proc(gbAllocator a, Scope *scope, Type *params, isize param_coun
|
||||
|
||||
bool is_type_valid_for_keys(Type *t);
|
||||
|
||||
Type *make_type_map(gbAllocator a, i64 count, Type *key, Type *value) {
|
||||
Type *t = alloc_type(a, Type_Map);
|
||||
Type *alloc_type_map(i64 count, Type *key, Type *value) {
|
||||
Type *t = alloc_type(Type_Map);
|
||||
if (key != nullptr) {
|
||||
GB_ASSERT(is_type_valid_for_keys(key));
|
||||
}
|
||||
@@ -587,14 +588,14 @@ Type *make_type_map(gbAllocator a, i64 count, Type *key, Type *value) {
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_bit_field_value(gbAllocator a, u32 bits) {
|
||||
Type *t = alloc_type(a, Type_BitFieldValue);
|
||||
Type *alloc_type_bit_field_value(u32 bits) {
|
||||
Type *t = alloc_type(Type_BitFieldValue);
|
||||
t->BitFieldValue.bits = bits;
|
||||
return t;
|
||||
}
|
||||
|
||||
Type *make_type_bit_field(gbAllocator a) {
|
||||
Type *t = alloc_type(a, Type_BitField);
|
||||
Type *alloc_type_bit_field() {
|
||||
Type *t = alloc_type(Type_BitField);
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -1396,7 +1397,7 @@ i64 union_variant_index(Type *u, Type *v) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
i64 union_tag_size(gbAllocator a, Type *u) {
|
||||
i64 union_tag_size(Type *u) {
|
||||
u = base_type(u);
|
||||
GB_ASSERT(u->kind == Type_Union);
|
||||
if (u->Union.tag_size > 0) {
|
||||
@@ -1415,8 +1416,8 @@ i64 union_tag_size(gbAllocator a, Type *u) {
|
||||
return tag_size;
|
||||
}
|
||||
|
||||
Type *union_tag_type(gbAllocator a, Type *u) {
|
||||
i64 s = union_tag_size(a, u);
|
||||
Type *union_tag_type(Type *u) {
|
||||
i64 s = union_tag_size(u);
|
||||
switch (s) {
|
||||
case 1: return t_u8;
|
||||
case 2: return t_u16;
|
||||
@@ -1511,16 +1512,17 @@ ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) {
|
||||
|
||||
|
||||
|
||||
Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel);
|
||||
Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel);
|
||||
|
||||
Selection lookup_field(gbAllocator a, Type *type_, String field_name, bool is_type) {
|
||||
return lookup_field_with_selection(a, type_, field_name, is_type, empty_selection);
|
||||
Selection lookup_field(Type *type_, String field_name, bool is_type) {
|
||||
return lookup_field_with_selection(type_, field_name, is_type, empty_selection);
|
||||
}
|
||||
|
||||
Selection lookup_field_from_index(gbAllocator a, Type *type, i64 index) {
|
||||
Selection lookup_field_from_index(Type *type, i64 index) {
|
||||
GB_ASSERT(is_type_struct(type) || is_type_union(type) || is_type_tuple(type));
|
||||
type = base_type(type);
|
||||
|
||||
gbAllocator a = heap_allocator();
|
||||
isize max_count = 0;
|
||||
switch (type->kind) {
|
||||
case Type_Struct: max_count = type->Struct.fields.count; break;
|
||||
@@ -1574,13 +1576,14 @@ gb_global Entity *entity__any_type_info = nullptr;
|
||||
|
||||
Entity *current_scope_lookup_entity(Scope *s, String name);
|
||||
|
||||
Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel) {
|
||||
Selection lookup_field_with_selection(Type *type_, String field_name, bool is_type, Selection sel) {
|
||||
GB_ASSERT(type_ != nullptr);
|
||||
|
||||
if (is_blank_ident(field_name)) {
|
||||
return empty_selection;
|
||||
}
|
||||
|
||||
gbAllocator a = heap_allocator();
|
||||
Type *type = type_deref(type_);
|
||||
bool is_ptr = type != type_;
|
||||
sel.indirect = sel.indirect || is_ptr;
|
||||
@@ -1701,7 +1704,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n
|
||||
}
|
||||
if (type->kind == Type_Generic && type->Generic.specialized != nullptr) {
|
||||
Type *specialized = type->Generic.specialized;
|
||||
return lookup_field_with_selection(a, specialized, field_name, is_type, sel);
|
||||
return lookup_field_with_selection(specialized, field_name, is_type, sel);
|
||||
}
|
||||
|
||||
} else if (type->kind == Type_Union) {
|
||||
@@ -1723,7 +1726,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n
|
||||
isize prev_count = sel.index.count;
|
||||
selection_add_index(&sel, i); // HACK(bill): Leaky memory
|
||||
|
||||
sel = lookup_field_with_selection(a, f->type, field_name, is_type, sel);
|
||||
sel = lookup_field_with_selection(f->type, field_name, is_type, sel);
|
||||
|
||||
if (sel.entity != nullptr) {
|
||||
if (is_type_pointer(f->type)) {
|
||||
@@ -1817,12 +1820,12 @@ void type_path_pop(TypePath *tp) {
|
||||
#define FAILURE_ALIGNMENT 0
|
||||
|
||||
|
||||
i64 type_size_of_internal (gbAllocator allocator, Type *t, TypePath *path);
|
||||
i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path);
|
||||
i64 type_size_of_internal (Type *t, TypePath *path);
|
||||
i64 type_align_of_internal(Type *t, TypePath *path);
|
||||
|
||||
|
||||
|
||||
i64 type_size_of(gbAllocator allocator, Type *t) {
|
||||
i64 type_size_of(Type *t) {
|
||||
if (t == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
@@ -1832,12 +1835,12 @@ i64 type_size_of(gbAllocator allocator, Type *t) {
|
||||
}
|
||||
TypePath path = {0};
|
||||
type_path_init(&path);
|
||||
t->cached_size = type_size_of_internal(allocator, t, &path);
|
||||
t->cached_size = type_size_of_internal(t, &path);
|
||||
type_path_free(&path);
|
||||
return t->cached_size;
|
||||
}
|
||||
|
||||
i64 type_align_of(gbAllocator allocator, Type *t) {
|
||||
i64 type_align_of(Type *t) {
|
||||
if (t == nullptr) {
|
||||
return 1;
|
||||
}
|
||||
@@ -1848,13 +1851,13 @@ i64 type_align_of(gbAllocator allocator, Type *t) {
|
||||
|
||||
TypePath path = {0};
|
||||
type_path_init(&path);
|
||||
t->cached_align = type_align_of_internal(allocator, t, &path);
|
||||
t->cached_align = type_align_of_internal(t, &path);
|
||||
type_path_free(&path);
|
||||
return t->cached_align;
|
||||
}
|
||||
|
||||
|
||||
i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
i64 type_align_of_internal(Type *t, TypePath *path) {
|
||||
GB_ASSERT(path != nullptr);
|
||||
if (t->failure) {
|
||||
return FAILURE_ALIGNMENT;
|
||||
@@ -1874,7 +1877,7 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
return build_context.word_size;
|
||||
|
||||
case Basic_complex64: case Basic_complex128:
|
||||
return type_size_of_internal(allocator, t, path) / 2;
|
||||
return type_size_of_internal(t, path) / 2;
|
||||
}
|
||||
} break;
|
||||
|
||||
@@ -1884,7 +1887,7 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
if (path->failure) {
|
||||
return FAILURE_ALIGNMENT;
|
||||
}
|
||||
i64 align = type_align_of_internal(allocator, t->Array.elem, path);
|
||||
i64 align = type_align_of_internal(t->Array.elem, path);
|
||||
if (pop) type_path_pop(path);
|
||||
return align;
|
||||
}
|
||||
@@ -1900,7 +1903,7 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
case Type_Tuple: {
|
||||
i64 max = 1;
|
||||
for_array(i, t->Tuple.variables) {
|
||||
i64 align = type_align_of_internal(allocator, t->Tuple.variables[i]->type, path);
|
||||
i64 align = type_align_of_internal(t->Tuple.variables[i]->type, path);
|
||||
if (max < align) {
|
||||
max = align;
|
||||
}
|
||||
@@ -1909,10 +1912,10 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
} break;
|
||||
|
||||
case Type_Map:
|
||||
generate_map_internal_types(allocator, t);
|
||||
return type_align_of_internal(allocator, t->Map.internal_type, path);
|
||||
init_map_internal_types(t);
|
||||
return type_align_of_internal(t->Map.internal_type, path);
|
||||
case Type_Enum:
|
||||
return type_align_of_internal(allocator, t->Enum.base_type, path);
|
||||
return type_align_of_internal(t->Enum.base_type, path);
|
||||
|
||||
case Type_Union: {
|
||||
if (t->Union.variants.count == 0) {
|
||||
@@ -1929,7 +1932,7 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
if (path->failure) {
|
||||
return FAILURE_ALIGNMENT;
|
||||
}
|
||||
i64 align = type_align_of_internal(allocator, variant, path);
|
||||
i64 align = type_align_of_internal(variant, path);
|
||||
if (pop) type_path_pop(path);
|
||||
if (max < align) {
|
||||
max = align;
|
||||
@@ -1950,7 +1953,7 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
if (path->failure) {
|
||||
return FAILURE_ALIGNMENT;
|
||||
}
|
||||
i64 align = type_align_of_internal(allocator, field_type, path);
|
||||
i64 align = type_align_of_internal(field_type, path);
|
||||
if (pop) type_path_pop(path);
|
||||
if (max < align) {
|
||||
max = align;
|
||||
@@ -1964,7 +1967,7 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
Type *field_type = t->Struct.fields[i]->type;
|
||||
bool pop = type_path_push(path, field_type);
|
||||
if (path->failure) return FAILURE_ALIGNMENT;
|
||||
i64 align = type_align_of_internal(allocator, field_type, path);
|
||||
i64 align = type_align_of_internal(field_type, path);
|
||||
if (pop) type_path_pop(path);
|
||||
if (max < align) {
|
||||
max = align;
|
||||
@@ -1986,14 +1989,15 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
} break;
|
||||
}
|
||||
|
||||
// return gb_clamp(next_pow2(type_size_of(allocator, t)), 1, build_context.max_align);
|
||||
// return gb_clamp(next_pow2(type_size_of(t)), 1, build_context.max_align);
|
||||
// NOTE(bill): Things that are bigger than build_context.word_size, are actually comprised of smaller types
|
||||
// TODO(bill): Is this correct for 128-bit types (integers)?
|
||||
return gb_clamp(next_pow2(type_size_of_internal(allocator, t, path)), 1, build_context.word_size);
|
||||
return gb_clamp(next_pow2(type_size_of_internal(t, path)), 1, build_context.word_size);
|
||||
}
|
||||
|
||||
Array<i64> type_set_offsets_of(gbAllocator allocator, Array<Entity *> fields, bool is_packed, bool is_raw_union) {
|
||||
auto offsets = array_make<i64>(allocator, fields.count);
|
||||
Array<i64> type_set_offsets_of(Array<Entity *> fields, bool is_packed, bool is_raw_union) {
|
||||
gbAllocator a = heap_allocator();
|
||||
auto offsets = array_make<i64>(a, fields.count);
|
||||
i64 curr_offset = 0;
|
||||
if (is_raw_union) {
|
||||
for_array(i, fields) {
|
||||
@@ -2001,15 +2005,15 @@ Array<i64> type_set_offsets_of(gbAllocator allocator, Array<Entity *> fields, bo
|
||||
}
|
||||
} else if (is_packed) {
|
||||
for_array(i, fields) {
|
||||
i64 size = type_size_of(allocator, fields[i]->type);
|
||||
i64 size = type_size_of(fields[i]->type);
|
||||
offsets[i] = curr_offset;
|
||||
curr_offset += size;
|
||||
}
|
||||
} else {
|
||||
for_array(i, fields) {
|
||||
Type *t = fields[i]->type;
|
||||
i64 align = gb_max(type_align_of(allocator, t), 1);
|
||||
i64 size = gb_max(type_size_of(allocator, t), 0);
|
||||
i64 align = gb_max(type_align_of(t), 1);
|
||||
i64 size = gb_max(type_size_of( t), 0);
|
||||
curr_offset = align_formula(curr_offset, align);
|
||||
offsets[i] = curr_offset;
|
||||
curr_offset += size;
|
||||
@@ -2018,12 +2022,12 @@ Array<i64> type_set_offsets_of(gbAllocator allocator, Array<Entity *> fields, bo
|
||||
return offsets;
|
||||
}
|
||||
|
||||
bool type_set_offsets(gbAllocator allocator, Type *t) {
|
||||
bool type_set_offsets(Type *t) {
|
||||
t = base_type(t);
|
||||
if (t->kind == Type_Struct) {
|
||||
if (!t->Struct.are_offsets_set) {
|
||||
t->Struct.are_offsets_being_processed = true;
|
||||
t->Struct.offsets = type_set_offsets_of(allocator, t->Struct.fields, t->Struct.is_packed, t->Struct.is_raw_union);
|
||||
t->Struct.offsets = type_set_offsets_of(t->Struct.fields, t->Struct.is_packed, t->Struct.is_raw_union);
|
||||
t->Struct.are_offsets_being_processed = false;
|
||||
t->Struct.are_offsets_set = true;
|
||||
return true;
|
||||
@@ -2031,7 +2035,7 @@ bool type_set_offsets(gbAllocator allocator, Type *t) {
|
||||
} else if (is_type_tuple(t)) {
|
||||
if (!t->Tuple.are_offsets_set) {
|
||||
t->Struct.are_offsets_being_processed = true;
|
||||
t->Tuple.offsets = type_set_offsets_of(allocator, t->Tuple.variables, false, false);
|
||||
t->Tuple.offsets = type_set_offsets_of(t->Tuple.variables, false, false);
|
||||
t->Struct.are_offsets_being_processed = false;
|
||||
t->Tuple.are_offsets_set = true;
|
||||
return true;
|
||||
@@ -2042,7 +2046,7 @@ bool type_set_offsets(gbAllocator allocator, Type *t) {
|
||||
return false;
|
||||
}
|
||||
|
||||
i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
i64 type_size_of_internal(Type *t, TypePath *path) {
|
||||
if (t->failure) {
|
||||
return FAILURE_SIZE;
|
||||
}
|
||||
@@ -2053,7 +2057,7 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
if (path->failure) {
|
||||
return FAILURE_ALIGNMENT;
|
||||
}
|
||||
i64 size = type_size_of_internal(allocator, t->Named.base, path);
|
||||
i64 size = type_size_of_internal(t->Named.base, path);
|
||||
if (pop) type_path_pop(path);
|
||||
return size;
|
||||
} break;
|
||||
@@ -2084,11 +2088,11 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
if (count == 0) {
|
||||
return 0;
|
||||
}
|
||||
align = type_align_of_internal(allocator, t->Array.elem, path);
|
||||
align = type_align_of_internal(t->Array.elem, path);
|
||||
if (path->failure) {
|
||||
return FAILURE_SIZE;
|
||||
}
|
||||
size = type_size_of_internal( allocator, t->Array.elem, path);
|
||||
size = type_size_of_internal( t->Array.elem, path);
|
||||
alignment = align_formula(size, align);
|
||||
return alignment*(count-1) + size;
|
||||
} break;
|
||||
@@ -2101,8 +2105,8 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
return 3*build_context.word_size + 2*build_context.word_size;
|
||||
|
||||
case Type_Map:
|
||||
generate_map_internal_types(allocator, t);
|
||||
return type_size_of_internal(allocator, t->Map.internal_type, path);
|
||||
init_map_internal_types(t);
|
||||
return type_size_of_internal(t->Map.internal_type, path);
|
||||
|
||||
case Type_Tuple: {
|
||||
i64 count, align, size;
|
||||
@@ -2110,20 +2114,20 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
if (count == 0) {
|
||||
return 0;
|
||||
}
|
||||
align = type_align_of_internal(allocator, t, path);
|
||||
type_set_offsets(allocator, t);
|
||||
size = t->Tuple.offsets[count-1] + type_size_of_internal(allocator, t->Tuple.variables[count-1]->type, path);
|
||||
align = type_align_of_internal(t, path);
|
||||
type_set_offsets(t);
|
||||
size = t->Tuple.offsets[count-1] + type_size_of_internal(t->Tuple.variables[count-1]->type, path);
|
||||
return align_formula(size, align);
|
||||
} break;
|
||||
|
||||
case Type_Enum:
|
||||
return type_size_of_internal(allocator, t->Enum.base_type, path);
|
||||
return type_size_of_internal(t->Enum.base_type, path);
|
||||
|
||||
case Type_Union: {
|
||||
if (t->Union.variants.count == 0) {
|
||||
return 0;
|
||||
}
|
||||
i64 align = type_align_of_internal(allocator, t, path);
|
||||
i64 align = type_align_of_internal(t, path);
|
||||
if (path->failure) {
|
||||
return FAILURE_SIZE;
|
||||
}
|
||||
@@ -2133,14 +2137,14 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
|
||||
for_array(i, t->Union.variants) {
|
||||
Type *variant_type = t->Union.variants[i];
|
||||
i64 size = type_size_of_internal(allocator, variant_type, path);
|
||||
i64 size = type_size_of_internal(variant_type, path);
|
||||
if (max < size) {
|
||||
max = size;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE(bill): Align to tag
|
||||
i64 tag_size = union_tag_size(allocator, t);
|
||||
i64 tag_size = union_tag_size(t);
|
||||
i64 size = align_formula(max, tag_size);
|
||||
// NOTE(bill): Calculate the padding between the common fields and the tag
|
||||
t->Union.tag_size = tag_size;
|
||||
@@ -2153,13 +2157,13 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
case Type_Struct: {
|
||||
if (t->Struct.is_raw_union) {
|
||||
i64 count = t->Struct.fields.count;
|
||||
i64 align = type_align_of_internal(allocator, t, path);
|
||||
i64 align = type_align_of_internal(t, path);
|
||||
if (path->failure) {
|
||||
return FAILURE_SIZE;
|
||||
}
|
||||
i64 max = 0;
|
||||
for (isize i = 0; i < count; i++) {
|
||||
i64 size = type_size_of_internal(allocator, t->Struct.fields[i]->type, path);
|
||||
i64 size = type_size_of_internal(t->Struct.fields[i]->type, path);
|
||||
if (max < size) {
|
||||
max = size;
|
||||
}
|
||||
@@ -2173,7 +2177,7 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
if (count == 0) {
|
||||
return 0;
|
||||
}
|
||||
align = type_align_of_internal(allocator, t, path);
|
||||
align = type_align_of_internal(t, path);
|
||||
if (path->failure) {
|
||||
return FAILURE_SIZE;
|
||||
}
|
||||
@@ -2181,14 +2185,14 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
type_path_print_illegal_cycle(path, path->path.count-1);
|
||||
return FAILURE_SIZE;
|
||||
}
|
||||
type_set_offsets(allocator, t);
|
||||
size = t->Struct.offsets[count-1] + type_size_of_internal(allocator, t->Struct.fields[count-1]->type, path);
|
||||
type_set_offsets(t);
|
||||
size = t->Struct.offsets[count-1] + type_size_of_internal(t->Struct.fields[count-1]->type, path);
|
||||
return align_formula(size, align);
|
||||
}
|
||||
} break;
|
||||
|
||||
case Type_BitField: {
|
||||
i64 align = 8*type_align_of_internal(allocator, t, path);
|
||||
i64 align = 8*type_align_of_internal(t, path);
|
||||
i64 end = 0;
|
||||
if (t->BitField.fields.count > 0) {
|
||||
i64 last = t->BitField.fields.count-1;
|
||||
@@ -2204,15 +2208,15 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
return build_context.word_size;
|
||||
}
|
||||
|
||||
i64 type_offset_of(gbAllocator allocator, Type *t, i32 index) {
|
||||
i64 type_offset_of(Type *t, i32 index) {
|
||||
t = base_type(t);
|
||||
if (t->kind == Type_Struct) {
|
||||
type_set_offsets(allocator, t);
|
||||
type_set_offsets(t);
|
||||
if (gb_is_between(index, 0, t->Struct.fields.count-1)) {
|
||||
return t->Struct.offsets[index];
|
||||
}
|
||||
} else if (t->kind == Type_Tuple) {
|
||||
type_set_offsets(allocator, t);
|
||||
type_set_offsets(t);
|
||||
if (gb_is_between(index, 0, t->Tuple.variables.count-1)) {
|
||||
return t->Tuple.offsets[index];
|
||||
}
|
||||
@@ -2242,7 +2246,7 @@ i64 type_offset_of(gbAllocator allocator, Type *t, i32 index) {
|
||||
case 3: return 3*build_context.word_size; // allocator
|
||||
}
|
||||
} else if (t->kind == Type_Union) {
|
||||
/* i64 s = */ type_size_of(allocator, t);
|
||||
/* i64 s = */ type_size_of(t);
|
||||
switch (index) {
|
||||
case -1: return align_formula(t->Union.variant_block_size, build_context.word_size); // __type_info
|
||||
}
|
||||
@@ -2251,7 +2255,7 @@ i64 type_offset_of(gbAllocator allocator, Type *t, i32 index) {
|
||||
}
|
||||
|
||||
|
||||
i64 type_offset_of_from_selection(gbAllocator allocator, Type *type, Selection sel) {
|
||||
i64 type_offset_of_from_selection(Type *type, Selection sel) {
|
||||
GB_ASSERT(sel.indirect == false);
|
||||
|
||||
Type *t = type;
|
||||
@@ -2259,7 +2263,7 @@ i64 type_offset_of_from_selection(gbAllocator allocator, Type *type, Selection s
|
||||
for_array(i, sel.index) {
|
||||
i32 index = sel.index[i];
|
||||
t = base_type(t);
|
||||
offset += type_offset_of(allocator, t, index);
|
||||
offset += type_offset_of(t, index);
|
||||
if (t->kind == Type_Struct && !t->Struct.is_raw_union) {
|
||||
t = t->Struct.fields[index]->type;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user