| ... | ... | @@ -1033,6 +1033,11 @@ pub const Value = extern union { |
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | 1035 | pub fn writeToMemory(val: Value, ty: Type, target: Target, buffer: []u8) void { |
| 1036 | if (val.isUndef()) { |
| 1037 | const size = @intCast(usize, ty.abiSize(target)); |
| 1038 | std.mem.set(u8, buffer[0..size], 0xaa); |
| 1039 | return; |
| 1040 | } |
| 1036 | 1041 | switch (ty.zigTypeTag()) { |
| 1037 | 1042 | .Int => { |
| 1038 | 1043 | var bigint_buffer: BigIntSpace = undefined; |
| ... | ... | @@ -1068,6 +1073,14 @@ pub const Value = extern union { |
| 1068 | 1073 | buf_off += elem_size; |
| 1069 | 1074 | } |
| 1070 | 1075 | }, |
| 1076 | .Struct => { |
| 1077 | const fields = ty.structFields().values(); |
| 1078 | const field_vals = val.castTag(.@"struct").?.data; |
| 1079 | for (fields) |field, i| { |
| 1080 | const off = @intCast(usize, ty.structFieldOffset(i, target)); |
| 1081 | writeToMemory(field_vals[i], field.ty, target, buffer[off..]); |
| 1082 | } |
| 1083 | }, |
| 1071 | 1084 | else => @panic("TODO implement writeToMemory for more types"), |
| 1072 | 1085 | } |
| 1073 | 1086 | } |
| ... | ... | @@ -1106,7 +1119,7 @@ pub const Value = extern union { |
| 1106 | 1119 | |
| 1107 | 1120 | fn floatReadFromMemory(comptime F: type, target: Target, buffer: []const u8) F { |
| 1108 | 1121 | if (F == f80) { |
| 1109 | | // TODO: use std.math.F80Repr |
| 1122 | // TODO: use std.math.F80Repr? |
| 1110 | 1123 | const big_int = std.mem.readInt(u128, buffer[0..16], target.cpu.arch.endian()); |
| 1111 | 1124 | const int = @truncate(u80, big_int); |
| 1112 | 1125 | return @bitCast(F, int); |