diff options
| author | gingerBill <bill@gingerbill.org> | 2020-02-01 11:10:28 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-02-01 11:10:28 +0000 |
| commit | 0f399a72941c7cebcb5ad0580a9d94d1a7a37ac0 (patch) | |
| tree | 249d37e76b25472674b4a8e7cb8aabec1ba6ab02 /src/ir_print.cpp | |
| parent | 4bcb667e97fc84d3eb5d7d4df34d566baddfaa1c (diff) | |
Add `union #maybe`
Diffstat (limited to 'src/ir_print.cpp')
| -rw-r--r-- | src/ir_print.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/ir_print.cpp b/src/ir_print.cpp index 2baf1c2a0..a3f28c59f 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -508,13 +508,25 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t, bool in_struct) { // NOTE(bill): The zero size array is used to fix the alignment used in a structure as // LLVM takes the first element's alignment as the entire alignment (like C) i64 align = type_align_of(t); + + if (is_type_union_maybe_pointer_original_alignment(t)) { + ir_write_byte(f, '{'); + ir_print_type(f, m, t->Union.variants[0]); + ir_write_byte(f, '}'); + return; + } + i64 block_size = t->Union.variant_block_size; ir_write_byte(f, '{'); ir_print_alignment_prefix_hack(f, align); - ir_fprintf(f, ", [%lld x i8], ", block_size); - // ir_print_type(f, m, t_type_info_ptr); - ir_print_type(f, m, union_tag_type(t)); + if (is_type_union_maybe_pointer(t)) { + ir_fprintf(f, ", "); + ir_print_type(f, m, t->Union.variants[0]); + } else { + ir_fprintf(f, ", [%lld x i8], ", block_size); + ir_print_type(f, m, union_tag_type(t)); + } ir_write_byte(f, '}'); } return; @@ -1850,6 +1862,12 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { case irInstr_UnionTagPtr: { Type *et = ir_type(instr->UnionTagPtr.address); + + Type *ut = type_deref(et); + if (is_type_union_maybe_pointer(ut)) { + GB_PANIC("union #maybe UnionTagPtr"); + } + ir_fprintf(f, "%%%d = getelementptr inbounds ", value->index); Type *t = base_type(type_deref(et)); GB_ASSERT(is_type_union(t)); @@ -1869,10 +1887,16 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { case irInstr_UnionTagValue: { Type *et = ir_type(instr->UnionTagValue.address); - ir_fprintf(f, "%%%d = extractvalue ", value->index); Type *t = base_type(et); + + if (is_type_union_maybe_pointer(t)) { + GB_PANIC("union #maybe UnionTagValue"); + } + + ir_fprintf(f, "%%%d = extractvalue ", value->index); GB_ASSERT(is_type_union(t)); + ir_print_type(f, m, et); ir_write_byte(f, ' '); ir_print_value(f, m, instr->UnionTagValue.address, et); |