aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-02-21 08:46:43 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-02-21 08:46:43 -0500
commitdb31c2524df4352593128aaceaa0b085ef8bb674 (patch)
treee748e614ff6c1718bf4580616d1f9c032926a621 /src/ir.cpp
parent3ee9d06cbdb6bcaf561e7215c4c103c7ad65a72d (diff)
downloadzig-db31c2524df4352593128aaceaa0b085ef8bb674.tar.gz
zig-db31c2524df4352593128aaceaa0b085ef8bb674.zip
extern structs support comptime bitcasting
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 177133788f..03555c78f4 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -20923,8 +20923,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
switch (val->type->data.structure.layout) {
case ContainerLayoutAuto:
zig_unreachable();
- case ContainerLayoutExtern:
- zig_panic("TODO buf_write_value_bytes extern struct");
+ case ContainerLayoutExtern: {
+ size_t src_field_count = val->type->data.structure.src_field_count;
+ for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {
+ TypeStructField *type_field = &val->type->data.structure.fields[field_i];
+ if (type_field->gen_index == SIZE_MAX)
+ continue;
+ ConstExprValue *field_val = &val->data.x_struct.fields[field_i];
+ size_t offset = LLVMOffsetOfElement(codegen->target_data_ref, val->type->type_ref,
+ type_field->gen_index);
+ buf_write_value_bytes(codegen, buf + offset, field_val);
+ }
+ return;
+ }
case ContainerLayoutPacked: {
size_t src_field_count = val->type->data.structure.src_field_count;
size_t gen_field_count = val->type->data.structure.gen_field_count;
@@ -20979,9 +20990,9 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
offset += big_int_byte_count;
gen_i += 1;
}
+ return;
}
}
- return;
case ZigTypeIdOptional:
zig_panic("TODO buf_write_value_bytes maybe type");
case ZigTypeIdErrorUnion: