authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-25 20:05:10-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-25 20:05:10-04:00
logdb613d38f07da20385709b8250d1a3e83b96337d
tree5970e02cc586797713da73c5c113147391b45018
parent4d8269f69f530fe251e3132a95285c0af9d3aaab

implement comptime bitcasting from array


2 files changed, 11 insertions(+), 2 deletions(-)

src/ir.cpp+10-1
...@@ -14364,7 +14364,16 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -14364,7 +14364,16 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
14364 zig_unreachable();14364 zig_unreachable();
14365 }14365 }
14366 case TypeTableEntryIdArray:14366 case TypeTableEntryIdArray:
14367 zig_panic("TODO buf_write_value_bytes array type");14367 {
14368 size_t buf_i = 0;
14369 expand_undef_array(codegen, val);
14370 for (size_t elem_i = 0; elem_i < val->type->data.array.len; elem_i += 1) {
14371 ConstExprValue *elem = &val->data.x_array.s_none.elements[elem_i];
14372 buf_write_value_bytes(codegen, &buf[buf_i], elem);
14373 buf_i += type_size(codegen, elem->type);
14374 }
14375 }
14376 return;
14368 case TypeTableEntryIdStruct:14377 case TypeTableEntryIdStruct:
14369 zig_panic("TODO buf_write_value_bytes struct type");14378 zig_panic("TODO buf_write_value_bytes struct type");
14370 case TypeTableEntryIdMaybe:14379 case TypeTableEntryIdMaybe:
test/cases/cast.zig+1-1
...@@ -282,5 +282,5 @@ test "const slice widen cast" {...@@ -282,5 +282,5 @@ test "const slice widen cast" {
282 const u32_value = ([]const u32)(bytes[0..])[0];282 const u32_value = ([]const u32)(bytes[0..])[0];
283 assert(u32_value == 0x12121212);283 assert(u32_value == 0x12121212);
284284
285 //assert(@bitCast(u32, bytes) == 0x12121212);285 assert(@bitCast(u32, bytes) == 0x12121212);
286}286}