aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-04-17 13:50:28 +0100
committergingerBill <bill@gingerbill.org>2020-04-17 13:50:28 +0100
commit4438b3e7afebc88dc5b39c39ec55d648ad7b8904 (patch)
tree3da655ccdaef13909254296fb07e8b8f66b997f7 /src/llvm_backend.cpp
parent602a651613cc144ed4690924aee4bf8cc1602efc (diff)
Fix LLVM API backend for procedure "constant" values
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp47
1 files changed, 23 insertions, 24 deletions
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);
}