aboutsummaryrefslogtreecommitdiff
path: root/src/ir_print.cpp
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-07-20 19:40:51 +0100
committerGinger Bill <bill@gingerbill.org>2017-07-20 19:40:51 +0100
commit9a3b4167bb8495f9422ffa5cb242198fed3a315b (patch)
treed5e1f4fe1ff66282cb67896c7c432a487b5a55df /src/ir_print.cpp
parent13bc6eeea4cc89b06bcfc3aaef7bfb85c1cb5b01 (diff)
Fix polymorphic element types usage; Empty `union` as opaque type
Diffstat (limited to 'src/ir_print.cpp')
-rw-r--r--src/ir_print.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/ir_print.cpp b/src/ir_print.cpp
index 78090e6ac..23c385140 100644
--- a/src/ir_print.cpp
+++ b/src/ir_print.cpp
@@ -282,21 +282,20 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
return;
case Type_Union: {
- // 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(heap_allocator(), t);
- i64 total_size = type_size_of(heap_allocator(), t);
- #if 1
- i64 block_size = t->Union.variant_block_size;
+ if (t->Union.variants.count == 0) {
+ ir_fprintf(f, "%%..opaque");
+ } else {
+ // 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(heap_allocator(), t);
+ i64 total_size = type_size_of(heap_allocator(), t);
+ i64 block_size = t->Union.variant_block_size;
- ir_fprintf(f, "{[0 x <%lld x i8>], ", align);
- ir_fprintf(f, "[%lld x i8], ", block_size);
- ir_print_type(f, m, t_type_info_ptr);
- ir_fprintf(f, "}");
- #else
- i64 block_size = total_size - build_context.word_size;
- ir_fprintf(f, "{[0 x <%lld x i8>], [%lld x i8], i%lld}", align, block_size, word_bits);
- #endif
+ ir_fprintf(f, "{[0 x <%lld x i8>], ", align);
+ ir_fprintf(f, "[%lld x i8], ", block_size);
+ ir_print_type(f, m, t_type_info_ptr);
+ ir_fprintf(f, "}");
+ }
} return;
case Type_Struct: {
@@ -1733,6 +1732,8 @@ void print_llvm_ir(irGen *ir) {
irFileBuffer buf = {}, *f = &buf;
ir_file_buffer_init(f, &ir->output_file);
+ ir_print_encoded_local(f, str_lit("..opaque"));
+ ir_fprintf(f, " = type opaque;\n");
ir_print_encoded_local(f, str_lit("..string"));
ir_fprintf(f, " = type {i8*, ");
ir_print_type(f, m, t_int);