From 4438b3e7afebc88dc5b39c39ec55d648ad7b8904 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 17 Apr 2020 13:50:28 +0100 Subject: [PATCH] Fix LLVM API backend for procedure "constant" values --- core/runtime/default_allocators.odin | 2 +- src/check_expr.cpp | 2 +- src/llvm_backend.cpp | 47 ++++++++++++++-------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/core/runtime/default_allocators.odin b/core/runtime/default_allocators.odin index a20283b5a..e49e7c6a3 100644 --- a/core/runtime/default_allocators.odin +++ b/core/runtime/default_allocators.odin @@ -50,7 +50,7 @@ default_temp_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode context.allocator.data != allocator_data) { a = default_allocator(); } - default_temp_allocator_init(allocator, make([]byte, 1<<22, a), a); + default_temp_allocator_init(allocator, make([]byte, DEFAULT_SCRATCH_BACKING_SIZE, a), a); } switch mode { diff --git a/src/check_expr.cpp b/src/check_expr.cpp index f401c993f..9879d3b8b 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -8038,7 +8038,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type fields_visited[sel.index[0]] = true; check_expr_or_type(c, o, fv->value, field->type); - if (is_type_any(field->type) || is_type_union(field->type) || is_type_raw_union(field->type)) { + if (is_type_any(field->type) || is_type_union(field->type) || is_type_raw_union(field->type) || is_type_typeid(field->type)) { is_constant = false; } if (is_constant) { diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 34d3aaf7f..977b2abaf 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -4330,6 +4330,22 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value) { return lb_const_nil(m, type); } + if (value.kind == ExactValue_Procedure) { + Ast *expr = value.value_procedure; + if (expr->kind == Ast_ProcLit) { + return lb_generate_anonymous_proc_lit(m, str_lit("_proclit"), expr); + } + Entity *e = entity_from_expr(expr); + e = strip_entity_wrapping(e); + GB_ASSERT(e != nullptr); + auto *found = map_get(&m->values, hash_entity(e)); + if (found) { + return *found; + } + + GB_PANIC("Error in: %.*s(%td:%td), missing procedure %.*s\n", LIT(e->token.pos.file), e->token.pos.line, e->token.pos.column, LIT(e->token.string)); + } + // GB_ASSERT_MSG(is_type_typed(type), "%s", type_to_string(type)); if (is_type_slice(type)) { @@ -7951,6 +7967,13 @@ lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) { res.value = LLVMBuildIsNotNull(p->builder, ptr.value, ""); } return res; + } else if (is_type_proc(t)) { + if (op_kind == Token_CmpEq) { + res.value = LLVMBuildIsNull(p->builder, x.value, ""); + } else if (op_kind == Token_NotEq) { + res.value = LLVMBuildIsNotNull(p->builder, x.value, ""); + } + return res; } else if (is_type_any(t)) { // TODO(bill): is this correct behaviour for nil comparison for any? lbValue data = lb_emit_struct_ev(p, x, 0); @@ -8567,30 +8590,6 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) { GB_ASSERT(tv.mode != Addressing_Type); if (tv.value.kind != ExactValue_Invalid) { - if (tv.value.kind == ExactValue_Procedure) { - Ast *expr = tv.value.value_procedure; - if (expr->kind == Ast_ProcLit) { - return lb_generate_anonymous_proc_lit(m, str_lit("_proclit"), expr); - } - Entity *e = entity_from_expr(expr); - e = strip_entity_wrapping(e); - GB_ASSERT(e != nullptr); - auto *found = map_get(&p->module->values, hash_entity(e)); - if (found) { - auto v = *found; - // NOTE(bill): This is because pointers are already pointers in LLVM - if (is_type_proc(v.type)) { - return v; - } - return lb_emit_load(p, v); - } else if (e != nullptr && e->kind == Entity_Variable) { - return lb_addr_load(p, lb_build_addr(p, expr)); - } - - GB_PANIC("Error in: %.*s(%td:%td) %s\n", LIT(p->name), e->token.pos.line, e->token.pos.column); - // GB_PANIC("nullptr value for expression from identifier: %.*s.%.*s (%p) : %s @ %p", LIT(e->pkg->name), LIT(e->token.string), e, type_to_string(e->type), expr); - } - // NOTE(bill): Short on constant values return lb_const_value(p->module, tv.type, tv.value); }