aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKoakuma <koachan@protonmail.com>2022-06-06 06:09:01 +0700
committerKoakuma <koachan@protonmail.com>2022-06-06 21:17:09 +0700
commitf6eb83c91cce2419a01f217b9d4c989e08e6e729 (patch)
tree0d79234853fd1ff40627279afd3ed5a744968a6f /src
parentf87dd285bbbea90ee186550e5ca64b743b05451d (diff)
downloadzig-f6eb83c91cce2419a01f217b9d4c989e08e6e729.tar.gz
zig-f6eb83c91cce2419a01f217b9d4c989e08e6e729.zip
stage2: sparc64: Implement airArrayToSlice
Diffstat (limited to 'src')
-rw-r--r--src/arch/sparc64/CodeGen.zig21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig
index 2b6945810c..c02d279631 100644
--- a/src/arch/sparc64/CodeGen.zig
+++ b/src/arch/sparc64/CodeGen.zig
@@ -593,7 +593,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
.store => try self.airStore(inst),
.struct_field_ptr=> @panic("TODO try self.airStructFieldPtr(inst)"),
.struct_field_val=> try self.airStructFieldVal(inst),
- .array_to_slice => @panic("TODO try self.airArrayToSlice(inst)"),
+ .array_to_slice => try self.airArrayToSlice(inst),
.int_to_float => @panic("TODO try self.airIntToFloat(inst)"),
.float_to_int => @panic("TODO try self.airFloatToInt(inst)"),
.cmpxchg_strong => @panic("TODO try self.airCmpxchg(inst)"),
@@ -783,6 +783,25 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
return self.finishAir(inst, .{ .ptr_stack_offset = stack_offset }, .{ .none, .none, .none });
}
+fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
+ const ty_op = self.air.instructions.items(.data)[inst].ty_op;
+ const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
+ const ptr_ty = self.air.typeOf(ty_op.operand);
+ const ptr = try self.resolveInst(ty_op.operand);
+ const array_ty = ptr_ty.childType();
+ const array_len = @intCast(u32, array_ty.arrayLen());
+
+ const ptr_bits = self.target.cpu.arch.ptrBitWidth();
+ const ptr_bytes = @divExact(ptr_bits, 8);
+
+ const stack_offset = try self.allocMem(inst, ptr_bytes * 2, ptr_bytes * 2);
+ try self.genSetStack(ptr_ty, stack_offset, ptr);
+ try self.genSetStack(Type.initTag(.usize), stack_offset - ptr_bytes, .{ .immediate = array_len });
+ break :result MCValue{ .stack_offset = stack_offset };
+ };
+ return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
+}
+
fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
const extra = self.air.extraData(Air.Asm, ty_pl.payload);