diff options
| author | gingerBill <bill@gingerbill.org> | 2018-08-30 19:14:10 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-08-30 19:14:10 +0100 |
| commit | aa542980cea146e05cf9bb5f1d792e1f092328ae (patch) | |
| tree | eea45538d6934f0c669a5bf218396d2ce6294098 /src/ir.cpp | |
| parent | e0240c186f2939f39f2051c5123b8b75e5fdb184 (diff) | |
Change memory layout of `map` to be 3 words smaller
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 0ef239380..002fdcca3 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -2768,6 +2768,7 @@ irValue *ir_emit_array_epi(irProcedure *proc, irValue *s, i32 index) { irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) { gbAllocator a = ir_allocator(); + GB_ASSERT(is_type_pointer(ir_type(s))); Type *t = base_type(type_deref(ir_type(s))); Type *result_type = nullptr; @@ -2808,18 +2809,18 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) { case 2: result_type = t_int_ptr; break; case 3: result_type = t_allocator_ptr; break; } - } /* else if (is_type_map(t)) { + } else if (is_type_map(t)) { init_map_internal_types(t); Type *itp = alloc_type_pointer(t->Map.internal_type); - s = ir_emit_load(proc, ir_emit_transmute(proc, s, itp)); + s = ir_emit_transmute(proc, s, itp); - Type *gst = t->Map.generated_struct_type; + Type *gst = t->Map.internal_type; GB_ASSERT(gst->kind == Type_Struct); switch (index) { case 0: result_type = alloc_type_pointer(gst->Struct.fields[0]->type); break; case 1: result_type = alloc_type_pointer(gst->Struct.fields[1]->type); break; } - } */else { + } else { GB_PANIC("TODO(bill): struct_gep type: %s, %d", type_to_string(ir_type(s)), index); } @@ -2887,15 +2888,15 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) { } break; - // case Type_Map: { - // init_map_internal_types(t); - // Type *gst = t->Map.generated_struct_type; - // switch (index) { - // case 0: result_type = gst->Struct.fields[0]->type; break; - // case 1: result_type = gst->Struct.fields[1]->type; break; - // } - // break; - // } + case Type_Map: { + init_map_internal_types(t); + Type *gst = t->Map.generated_struct_type; + switch (index) { + case 0: result_type = gst->Struct.fields[0]->type; break; + case 1: result_type = gst->Struct.fields[1]->type; break; + } + break; + } default: GB_PANIC("TODO(bill): struct_ev type: %s, %d", type_to_string(ir_type(s)), index); @@ -2962,12 +2963,7 @@ irValue *ir_emit_deep_field_gep(irProcedure *proc, irValue *e, Selection sel) { } else if (type->kind == Type_Array) { e = ir_emit_array_epi(proc, e, index); } else if (type->kind == Type_Map) { - e = ir_emit_struct_ep(proc, e, 1); - switch (index) { - case 0: e = ir_emit_struct_ep(proc, e, 1); break; // count - case 1: e = ir_emit_struct_ep(proc, e, 2); break; // capacity - case 2: e = ir_emit_struct_ep(proc, e, 3); break; // allocator - } + e = ir_emit_struct_ep(proc, e, index); } else { GB_PANIC("un-gep-able type %s", type_to_string(type)); } |