aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-01-16 09:07:52 +0000
committergingerBill <bill@gingerbill.org>2020-01-16 09:07:52 +0000
commit527b39ce2b6cd9ef20af7a04c81017af809c2cdb (patch)
tree7727cf5713570740b75ca1454c454a03cb3a4b40 /src
parent5af3c7b0e8ede5c30850d9994c475d298848a8d1 (diff)
parent5db4bd99440c47506a6e22be193efdc235229772 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src')
-rw-r--r--src/check_expr.cpp27
-rw-r--r--src/ir.cpp37
2 files changed, 59 insertions, 5 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 0ec147f68..c29325ea0 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -8391,6 +8391,33 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
bits |= bit;
}
o->value = exact_value_u64(bits);
+ } else if (is_type_constant_type(type) && cl->elems.count == 0) {
+ ExactValue value = exact_value_compound(node);
+ Type *bt = core_type(type);
+ if (bt->kind == Type_Basic) {
+ if (bt->Basic.flags & BasicFlag_Boolean) {
+ value = exact_value_bool(false);
+ } else if (bt->Basic.flags & BasicFlag_Integer) {
+ value = exact_value_i64(0);
+ } else if (bt->Basic.flags & BasicFlag_Unsigned) {
+ value = exact_value_i64(0);
+ } else if (bt->Basic.flags & BasicFlag_Float) {
+ value = exact_value_float(0);
+ } else if (bt->Basic.flags & BasicFlag_Complex) {
+ value = exact_value_complex(0, 0);
+ } else if (bt->Basic.flags & BasicFlag_Quaternion) {
+ value = exact_value_quaternion(0, 0, 0, 0);
+ } else if (bt->Basic.flags & BasicFlag_Pointer) {
+ value = exact_value_pointer(0);
+ } else if (bt->Basic.flags & BasicFlag_String) {
+ String empty_string = {};
+ value = exact_value_string(empty_string);
+ } else if (bt->Basic.flags & BasicFlag_Rune) {
+ value = exact_value_i64(0);
+ }
+ }
+
+ o->value = value;
} else {
o->value = exact_value_compound(node);
}
diff --git a/src/ir.cpp b/src/ir.cpp
index e00dc42ee..04c57c37b 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -2664,6 +2664,20 @@ irDebugInfo *ir_add_debug_info_type(irModule *module, Type *type, Entity *e, irD
return di;
}
+ if (is_type_enumerated_array(type)) {
+ irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_CompositeType);
+ di->CompositeType.size = ir_debug_size_bits(type);
+ di->CompositeType.align = ir_debug_align_bits(type);
+ di->CompositeType.tag = irDebugBasicEncoding_array_type;
+ di->CompositeType.array_count = (i32)type->EnumeratedArray.count;
+
+ map_set(&module->debug_info, hash_type(type), di);
+ di->CompositeType.base_type = ir_add_debug_info_type(module, type->EnumeratedArray.elem, e, scope, file);
+ GB_ASSERT(base->kind != Type_Named);
+
+ return di;
+ }
+
if (is_type_slice(type)) {
// NOTE(lachsinc): Every slice type has its own composite type / field debug infos created. This is sorta wasteful.
irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_CompositeType);
@@ -3917,7 +3931,7 @@ irValue *ir_addr_get_ptr(irProcedure *proc, irAddr const &addr) {
}
irValue *ir_build_addr_ptr(irProcedure *proc, Ast *expr) {
- irAddr const &addr = ir_build_addr(proc, expr);
+ irAddr addr = ir_build_addr(proc, expr);
return ir_addr_get_ptr(proc, addr);
}
@@ -4714,6 +4728,10 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) {
Type *t = base_type(type_deref(ir_type(s)));
Type *result_type = nullptr;
+ if (t->kind == Type_Opaque) {
+ t = t->Opaque.elem;
+ }
+
if (is_type_struct(t)) {
result_type = alloc_type_pointer(t->Struct.fields[index]->type);
} else if (is_type_union(t)) {
@@ -4897,6 +4915,9 @@ irValue *ir_emit_deep_field_gep(irProcedure *proc, irValue *e, Selection sel) {
// e = ir_emit_ptr_offset(proc, e, v_zero); // TODO(bill): Do I need these copies?
}
type = core_type(type);
+ if (type->kind == Type_Opaque) {
+ type = type->Opaque.elem;
+ }
if (is_type_quaternion(type)) {
e = ir_emit_struct_ep(proc, e, index);
@@ -6588,7 +6609,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, Bu
case BuiltinProc_swizzle: {
ir_emit_comment(proc, str_lit("swizzle.begin"));
- irAddr const &addr = ir_build_addr(proc, ce->args[0]);
+ irAddr addr = ir_build_addr(proc, ce->args[0]);
isize index_count = ce->args.count-1;
if (index_count == 0) {
return ir_addr_load(proc, addr);
@@ -7709,7 +7730,13 @@ bool ir_is_elem_const(irModule *m, Ast *elem, Type *elem_type) {
irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, Ast *expr) {
GB_ASSERT(e != nullptr);
- GB_ASSERT(e->kind != Entity_Constant);
+ if (e->kind == Entity_Constant) {
+ Type *t = default_type(type_of_expr(expr));
+ irValue *v = ir_add_module_constant(proc->module, t, e->Constant.value);
+ irValue *g = ir_add_global_generated(proc->module, ir_type(v), v);
+ return ir_addr(g);
+ }
+
irValue *v = nullptr;
irValue **found = map_get(&proc->module->values, hash_entity(e));
@@ -7816,7 +7843,7 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) {
if (sel.entity->type->kind == Type_BitFieldValue) {
- irAddr const &addr = ir_build_addr(proc, se->expr);
+ irAddr addr = ir_build_addr(proc, se->expr);
Type *bft = type_deref(ir_addr_type(addr));
if (sel.index.count == 1) {
GB_ASSERT(is_type_bit_field(bft));
@@ -9900,7 +9927,7 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
case Type_Map: {
is_map = true;
gbAllocator a = ir_allocator();
- irAddr const &addr = ir_build_addr(proc, expr);
+ irAddr addr = ir_build_addr(proc, expr);
irValue *map = ir_addr_get_ptr(proc, addr);
if (is_type_pointer(type_deref(ir_addr_type(addr)))) {
map = ir_addr_load(proc, addr);