aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-22 15:12:22 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-22 15:35:35 -0700
commit069c83d58cebba88275ee76ba01fabcd8e964573 (patch)
treeab7e52f307bd23869e2461189383522dc64f42de /src/value.zig
parent86b92809635607ff357ce96902e2aaf83c3fd029 (diff)
downloadzig-069c83d58cebba88275ee76ba01fabcd8e964573.tar.gz
zig-069c83d58cebba88275ee76ba01fabcd8e964573.zip
stage2: change `@bitCast` to always be by-value
After a discussion about language specs, this seems like the best way to go, because it's simpler to reason about both for humans and compilers. The `bitcast_result_ptr` ZIR instruction is no longer needed. This commit also implements writing enums, arrays, and vectors to virtual memory at compile-time. This unlocked some more of compiler-rt being able to build, which in turn unlocks saturating arithmetic behavior tests. There was also a memory leak in the comptime closure system which is now fixed.
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/value.zig b/src/value.zig
index d4a5e6bbeb..3a4cdb1438 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -1015,6 +1015,14 @@ pub const Value = extern union {
const bits = ty.intInfo(target).bits;
bigint.writeTwosComplement(buffer, bits, target.cpu.arch.endian());
},
+ .Enum => {
+ var enum_buffer: Payload.U64 = undefined;
+ const int_val = val.enumToInt(ty, &enum_buffer);
+ var bigint_buffer: BigIntSpace = undefined;
+ const bigint = int_val.toBigInt(&bigint_buffer);
+ const bits = ty.intInfo(target).bits;
+ bigint.writeTwosComplement(buffer, bits, target.cpu.arch.endian());
+ },
.Float => switch (ty.floatBits(target)) {
16 => return floatWriteToMemory(f16, val.toFloat(f16), target, buffer),
32 => return floatWriteToMemory(f32, val.toFloat(f32), target, buffer),
@@ -1022,6 +1030,19 @@ pub const Value = extern union {
128 => return floatWriteToMemory(f128, val.toFloat(f128), target, buffer),
else => unreachable,
},
+ .Array, .Vector => {
+ const len = ty.arrayLen();
+ const elem_ty = ty.childType();
+ const elem_size = elem_ty.abiSize(target);
+ var elem_i: usize = 0;
+ var elem_value_buf: ElemValueBuffer = undefined;
+ var buf_off: usize = 0;
+ while (elem_i < len) : (elem_i += 1) {
+ const elem_val = val.elemValueBuffer(elem_i, &elem_value_buf);
+ writeToMemory(elem_val, elem_ty, target, buffer[buf_off..]);
+ buf_off += elem_size;
+ }
+ },
else => @panic("TODO implement writeToMemory for more types"),
}
}