Make set_procedure_abi_types use the permanent_allocator

This commit is contained in:
gingerBill
2020-11-15 18:11:49 +00:00
parent 3c1c10a178
commit 30d922b059
5 changed files with 30 additions and 28 deletions

View File

@@ -89,7 +89,7 @@ Type * check_init_variable (CheckerContext *c, Entity *e, Operand *
Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type, ProcCallingConvention cc);
Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type, ProcCallingConvention cc);
bool abi_compat_return_by_pointer(gbAllocator a, ProcCallingConvention cc, Type *abi_return_type);
void set_procedure_abi_types(gbAllocator a, Type *type);
void set_procedure_abi_types(Type *type);
void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type);
@@ -1012,7 +1012,7 @@ bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source,
}
if (modify_type) {
set_procedure_abi_types(c->allocator, source);
set_procedure_abi_types(source);
}
return true;

View File

@@ -1390,7 +1390,7 @@ Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Oper
if (is_polymorphic_type_assignable(ctx, poly_type, operand.type, false, modify_type)) {
if (show_error) {
set_procedure_abi_types(ctx->allocator, poly_type);
set_procedure_abi_types(poly_type);
}
return poly_type;
}
@@ -2508,7 +2508,7 @@ bool abi_compat_return_by_pointer(gbAllocator a, ProcCallingConvention cc, Type
return false;
}
void set_procedure_abi_types(gbAllocator allocator, Type *type) {
void set_procedure_abi_types(Type *type) {
type = base_type(type);
if (type->kind != Type_Proc) {
return;
@@ -2518,6 +2518,8 @@ void set_procedure_abi_types(gbAllocator allocator, Type *type) {
return;
}
gbAllocator allocator = permanent_allocator();
u32 flags = type->flags;
type->flags |= TypeFlag_InProcessOfCheckingABI;
@@ -2550,13 +2552,13 @@ void set_procedure_abi_types(gbAllocator allocator, Type *type) {
for (i32 i = 0; i < type->Proc.param_count; i++) {
Entity *e = type->Proc.params->Tuple.variables[i];
if (e->kind == Entity_Variable) {
set_procedure_abi_types(allocator, e->type);
set_procedure_abi_types(e->type);
}
}
for (i32 i = 0; i < type->Proc.result_count; i++) {
Entity *e = type->Proc.results->Tuple.variables[i];
if (e->kind == Entity_Variable) {
set_procedure_abi_types(allocator, e->type);
set_procedure_abi_types(e->type);
}
}

View File

@@ -1159,7 +1159,7 @@ irValue *ir_instr_atomic_cxchg(irProcedure *p, Type *type, irValue *address, irV
GB_ASSERT(type->Tuple.variables.count == 2);
Type *elem = type->Tuple.variables[0]->type;
// LEAK TODO(bill): LLVM returns {T, i1} whilst Odin does {T, bool}, fix this mapping hack
gbAllocator a = heap_allocator();
gbAllocator a = permanent_allocator();
Type *llvm_type = alloc_type_tuple();
array_init(&llvm_type->Tuple.variables, a, 0, 2);
array_add (&llvm_type->Tuple.variables, alloc_entity_field(nullptr, blank_token, elem, false, 0));
@@ -1799,7 +1799,7 @@ irValue *ir_add_local(irProcedure *proc, Entity *e, Ast *expr, bool zero_initial
if (zero_initialized) {
ir_emit_zero_init(proc, instr, expr);
}
set_procedure_abi_types(heap_allocator(), e->type);
set_procedure_abi_types(e->type);
// if (proc->module->generate_debug_info && expr != nullptr && proc->entity != nullptr) {
// if (proc->module->generate_debug_info && proc->entity != nullptr) {
@@ -3282,7 +3282,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array<irValue *> const &ar
context_ptr = ir_find_or_generate_context_ptr(p);
}
set_procedure_abi_types(heap_allocator(), pt);
set_procedure_abi_types(pt);
bool is_c_vararg = pt->Proc.c_vararg;
isize param_count = pt->Proc.param_count;
@@ -6636,7 +6636,7 @@ void ir_mangle_add_sub_type_name(irModule *m, Entity *field, String parent) {
return;
}
if (is_type_proc(field->type)) {
set_procedure_abi_types(heap_allocator(), field->type);
set_procedure_abi_types(field->type);
}
String cn = field->token.string;
@@ -6733,7 +6733,7 @@ irValue *ir_gen_anonymous_proc_lit(irModule *m, String prefix_name, Ast *expr, i
String name = make_string(name_text, name_len-1);
Type *type = type_of_expr(expr);
set_procedure_abi_types(heap_allocator(), type);
set_procedure_abi_types(type);
irValue *value = ir_value_procedure(m, nullptr, type, pl->type, pl->body, name);
value->Proc.tags = pl->tags;
@@ -7584,7 +7584,7 @@ irValue *ir_build_call_expr(irProcedure *proc, Ast *expr) {
Type *proc_type_ = base_type(ir_type(value));
GB_ASSERT(proc_type_->kind == Type_Proc);
TypeProc *pt = &proc_type_->Proc;
set_procedure_abi_types(heap_allocator(), proc_type_);
set_procedure_abi_types(proc_type_);
if (is_call_expr_field_value(ce)) {
auto args = array_make<irValue *>(ir_allocator(), pt->param_count);
@@ -9574,7 +9574,7 @@ void ir_build_nested_proc(irProcedure *proc, AstProcLit *pd, Entity *e) {
name_len = gb_snprintf(cast(char *)name_text, name_len, "%.*s.%.*s-%d", LIT(proc->name), LIT(pd_name), guid);
String name = make_string(name_text, name_len-1);
set_procedure_abi_types(heap_allocator(), e->type);
set_procedure_abi_types(e->type);
irValue *value = ir_value_procedure(proc->module, e, e->type, pd->type, pd->body, name);
value->Proc.tags = pd->tags;
@@ -9673,7 +9673,7 @@ void ir_build_constant_value_decl(irProcedure *proc, AstValueDecl *vd) {
return;
}
set_procedure_abi_types(heap_allocator(), e->type);
set_procedure_abi_types(e->type);
irValue *value = ir_value_procedure(proc->module, e, e->type, pl->type, pl->body, name);
value->Proc.tags = pl->tags;
@@ -11471,7 +11471,7 @@ void ir_insert_code_before_proc(irProcedure* proc, irProcedure *parent) {
void ir_build_proc(irValue *value, irProcedure *parent) {
irProcedure *proc = &value->Proc;
set_procedure_abi_types(heap_allocator(), proc->type);
set_procedure_abi_types(proc->type);
proc->parent = parent;
@@ -12612,7 +12612,7 @@ void ir_gen_tree(irGen *s) {
Ast *type_expr = pl->type;
set_procedure_abi_types(heap_allocator(), e->type);
set_procedure_abi_types(e->type);
irValue *p = ir_value_procedure(m, e, e->type, type_expr, body, name);
p->Proc.tags = pl->tags;
p->Proc.inlining = pl->inlining;

View File

@@ -296,7 +296,7 @@ void ir_print_alignment_prefix_hack(irFileBuffer *f, i64 alignment) {
void ir_print_proc_results(irFileBuffer *f, irModule *m, Type *t) {
set_procedure_abi_types(heap_allocator(), t);
set_procedure_abi_types(t);
GB_ASSERT(is_type_proc(t));
t = base_type(t);
@@ -325,7 +325,7 @@ void ir_print_proc_results(irFileBuffer *f, irModule *m, Type *t) {
void ir_print_proc_type_without_pointer(irFileBuffer *f, irModule *m, Type *t) {
set_procedure_abi_types(heap_allocator(), t);
set_procedure_abi_types(t);
i64 word_bits = 8*build_context.word_size;
t = base_type(t);
@@ -2189,7 +2189,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
irInstrCall *call = &instr->Call;
Type *proc_type = base_type(ir_type(call->value));
GB_ASSERT(is_type_proc(proc_type));
set_procedure_abi_types(heap_allocator(), proc_type);
set_procedure_abi_types(proc_type);
bool is_c_vararg = proc_type->Proc.c_vararg;
Type *result_type = call->type;
@@ -2396,7 +2396,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
set_procedure_abi_types(heap_allocator(), proc->type);
set_procedure_abi_types(proc->type);
if (proc->body == nullptr) {
ir_write_str_lit(f, "declare ");

View File

@@ -1421,7 +1421,7 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
return lb_function_type_to_llvm_ptr(ft, type->Proc.c_vararg);
}
} else {
set_procedure_abi_types(heap_allocator(), type);
set_procedure_abi_types(type);
LLVMTypeRef return_type = LLVMVoidTypeInContext(ctx);
if (type->Proc.return_by_pointer) {
// Void
@@ -1950,7 +1950,7 @@ LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
case Type_Proc:
{
return nullptr;
// set_procedure_abi_types(heap_allocator(), type);
// set_procedure_abi_types(type);
// LLVMTypeRef return_type = LLVMVoidTypeInContext(ctx);
// isize offset = 0;
@@ -2141,7 +2141,7 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity) {
Type *pt = base_type(entity->type);
GB_ASSERT(pt->kind == Type_Proc);
set_procedure_abi_types(permanent_allocator(), entity->type);
set_procedure_abi_types(entity->type);
p->type = entity->type;
p->type_expr = decl->type_expr;
@@ -2978,7 +2978,7 @@ void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) {
name_len = gb_snprintf(name_text, name_len, "%.*s.%.*s-%d", LIT(p->name), LIT(pd_name), guid);
String name = make_string(cast(u8 *)name_text, name_len-1);
set_procedure_abi_types(permanent_allocator(), e->type);
set_procedure_abi_types(e->type);
e->Procedure.link_name = name;
@@ -3115,7 +3115,7 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) {
return;
}
set_procedure_abi_types(permanent_allocator(), e->type);
set_procedure_abi_types(e->type);
e->Procedure.link_name = name;
lbProcedure *nested_proc = lb_create_procedure(p->module, e);
@@ -7376,7 +7376,7 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args,
LLVMBuildUnreachable(p->builder);
});
set_procedure_abi_types(permanent_allocator(), pt);
set_procedure_abi_types(pt);
bool is_c_vararg = pt->Proc.c_vararg;
isize param_count = pt->Proc.param_count;
@@ -8595,7 +8595,7 @@ lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) {
Type *proc_type_ = base_type(value.type);
GB_ASSERT(proc_type_->kind == Type_Proc);
TypeProc *pt = &proc_type_->Proc;
set_procedure_abi_types(permanent_allocator(), proc_type_);
set_procedure_abi_types(proc_type_);
if (is_call_expr_field_value(ce)) {
auto args = array_make<lbValue>(permanent_allocator(), pt->param_count);
@@ -9442,7 +9442,7 @@ lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, A
String name = make_string((u8 *)name_text, name_len-1);
Type *type = type_of_expr(expr);
set_procedure_abi_types(permanent_allocator(), type);
set_procedure_abi_types(type);
Token token = {};