aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-11-23 15:53:49 +0000
committergingerBill <bill@gingerbill.org>2020-11-23 15:53:49 +0000
commit4e370e6ed8d6cfe3dee306dfbc298ba68722f12e (patch)
tree075c3639d3378c47279800a97229d6ee159126ff /src
parent0b30c3dc5ad3f3908719af19e9f7e61daae37706 (diff)
Add `equal` procedure field to `runtime.Type_Info_Struct`
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp11
-rw-r--r--src/llvm_backend.cpp14
-rw-r--r--src/types.cpp97
3 files changed, 66 insertions, 56 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index ce5dea86d..28edd5981 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -12353,8 +12353,13 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 6), is_raw_union);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 7), is_custom_align);
+ if (is_type_comparable(t) && !is_type_simple_compare(t)) {
+ ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 8), ir_get_compare_proc_for_type(proc->module, t));
+ }
+
+
if (t->Struct.soa_kind != StructSoa_None) {
- irValue *kind = ir_emit_struct_ep(proc, tag, 8);
+ irValue *kind = ir_emit_struct_ep(proc, tag, 9);
Type *kind_type = type_deref(ir_type(kind));
irValue *soa_kind = ir_value_constant(kind_type, exact_value_i64(t->Struct.soa_kind));
@@ -12363,8 +12368,8 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
ir_emit_store(proc, kind, soa_kind);
- ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 9), soa_type);
- ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 10), soa_len);
+ ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 10), soa_type);
+ ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 11), soa_len);
}
}
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index a2727b012..0272d1dfa 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -12178,7 +12178,7 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
case Type_Struct: {
tag = lb_const_ptr_cast(m, variant_ptr, t_type_info_struct_ptr);
- LLVMValueRef vals[11] = {};
+ LLVMValueRef vals[12] = {};
{
@@ -12188,18 +12188,22 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
vals[5] = is_packed.value;
vals[6] = is_raw_union.value;
vals[7] = is_custom_align.value;
+ if (is_type_comparable(t) && !is_type_simple_compare(t)) {
+ vals[8] = lb_get_compare_proc_for_type(m, t).value;
+ }
+
if (t->Struct.soa_kind != StructSoa_None) {
- lbValue kind = lb_emit_struct_ep(p, tag, 8);
+ lbValue kind = lb_emit_struct_ep(p, tag, 9);
Type *kind_type = type_deref(kind.type);
lbValue soa_kind = lb_const_value(m, kind_type, exact_value_i64(t->Struct.soa_kind));
lbValue soa_type = lb_type_info(m, t->Struct.soa_elem);
lbValue soa_len = lb_const_int(m, t_int, t->Struct.soa_count);
- vals[8] = soa_kind.value;
- vals[9] = soa_type.value;
- vals[10] = soa_len.value;
+ vals[9] = soa_kind.value;
+ vals[1] = soa_type.value;
+ vals[11] = soa_len.value;
}
}
diff --git a/src/types.cpp b/src/types.cpp
index 09888f878..b8b4b32f5 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -1321,54 +1321,6 @@ Type *core_array_type(Type *t) {
return t;
}
-// NOTE(bill): type can be easily compared using memcmp
-bool is_type_simple_compare(Type *t) {
- t = core_type(t);
- switch (t->kind) {
- case Type_Array:
- return is_type_simple_compare(t->Array.elem);
-
- case Type_EnumeratedArray:
- return is_type_simple_compare(t->EnumeratedArray.elem);
-
- case Type_Basic:
- if (t->Basic.flags & BasicFlag_SimpleCompare) {
- return true;
- }
- return false;
-
- case Type_Pointer:
- case Type_Proc:
- case Type_BitSet:
- case Type_BitField:
- return true;
-
- case Type_Struct:
- for_array(i, t->Struct.fields) {
- Entity *f = t->Struct.fields[i];
- if (!is_type_simple_compare(f->type)) {
- return false;
- }
- }
- return true;
-
- case Type_Union:
- for_array(i, t->Union.variants) {
- Type *v = t->Union.variants[i];
- if (!is_type_simple_compare(v)) {
- return false;
- }
- }
- return true;
-
- case Type_SimdVector:
- return is_type_simple_compare(t->SimdVector.elem);
-
- }
-
- return false;
-}
-
Type *base_complex_elem_type(Type *t) {
@@ -1978,6 +1930,55 @@ bool is_type_comparable(Type *t) {
return false;
}
+// NOTE(bill): type can be easily compared using memcmp
+bool is_type_simple_compare(Type *t) {
+ t = core_type(t);
+ switch (t->kind) {
+ case Type_Array:
+ return is_type_simple_compare(t->Array.elem);
+
+ case Type_EnumeratedArray:
+ return is_type_simple_compare(t->EnumeratedArray.elem);
+
+ case Type_Basic:
+ if (t->Basic.flags & BasicFlag_SimpleCompare) {
+ return true;
+ }
+ return false;
+
+ case Type_Pointer:
+ case Type_Proc:
+ case Type_BitSet:
+ case Type_BitField:
+ return true;
+
+ case Type_Struct:
+ for_array(i, t->Struct.fields) {
+ Entity *f = t->Struct.fields[i];
+ if (!is_type_simple_compare(f->type)) {
+ return false;
+ }
+ }
+ return true;
+
+ case Type_Union:
+ for_array(i, t->Union.variants) {
+ Type *v = t->Union.variants[i];
+ if (!is_type_simple_compare(v)) {
+ return false;
+ }
+ }
+ return true;
+
+ case Type_SimdVector:
+ return is_type_simple_compare(t->SimdVector.elem);
+
+ }
+
+ return false;
+}
+
+
Type *strip_type_aliasing(Type *x) {
if (x == nullptr) {
return x;