authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-20 00:08:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-20 00:08:05-07:00
log01638c250fa270c8cb3b3416ea55e22988cd32a2
tree668943f9135629f88b789b195dce1046d5eb2ba9
parentbfff8544e1049fc7aa3310883f619efb3f394948

Sema: implement readFromMemory for arrays


1 files changed, 17 insertions(+), 1 deletions(-)

src/value.zig+17-1
......@@ -1090,7 +1090,12 @@ pub const Value = extern union {
10901090 }
10911091 }
10921092
1093 pub fn readFromMemory(ty: Type, target: Target, buffer: []const u8, arena: Allocator) !Value {
1093 pub fn readFromMemory(
1094 ty: Type,
1095 target: Target,
1096 buffer: []const u8,
1097 arena: Allocator,
1098 ) Allocator.Error!Value {
10941099 switch (ty.zigTypeTag()) {
10951100 .Int => {
10961101 const int_info = ty.intInfo(target);
......@@ -1111,6 +1116,17 @@ pub const Value = extern union {
11111116 128 => return Value.Tag.float_128.create(arena, floatReadFromMemory(f128, target, buffer)),
11121117 else => unreachable,
11131118 },
1119 .Array => {
1120 const elem_ty = ty.childType();
1121 const elem_size = elem_ty.abiSize(target);
1122 const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen()));
1123 var offset: usize = 0;
1124 for (elems) |*elem| {
1125 elem.* = try readFromMemory(elem_ty, target, buffer[offset..], arena);
1126 offset += elem_size;
1127 }
1128 return Tag.array.create(arena, elems);
1129 },
11141130 else => @panic("TODO implement readFromMemory for more types"),
11151131 }
11161132 }