authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-06-06 06:09:01+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2022-06-06 21:17:09+07:00
logf6eb83c91cce2419a01f217b9d4c989e08e6e729
tree0d79234853fd1ff40627279afd3ed5a744968a6f
parentf87dd285bbbea90ee186550e5ca64b743b05451d

stage2: sparc64: Implement airArrayToSlice


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

src/arch/sparc64/CodeGen.zig+20-1
...@@ -593,7 +593,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -593,7 +593,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
593 .store => try self.airStore(inst),593 .store => try self.airStore(inst),
594 .struct_field_ptr=> @panic("TODO try self.airStructFieldPtr(inst)"),594 .struct_field_ptr=> @panic("TODO try self.airStructFieldPtr(inst)"),
595 .struct_field_val=> try self.airStructFieldVal(inst),595 .struct_field_val=> try self.airStructFieldVal(inst),
596 .array_to_slice => @panic("TODO try self.airArrayToSlice(inst)"),596 .array_to_slice => try self.airArrayToSlice(inst),
597 .int_to_float => @panic("TODO try self.airIntToFloat(inst)"),597 .int_to_float => @panic("TODO try self.airIntToFloat(inst)"),
598 .float_to_int => @panic("TODO try self.airFloatToInt(inst)"),598 .float_to_int => @panic("TODO try self.airFloatToInt(inst)"),
599 .cmpxchg_strong => @panic("TODO try self.airCmpxchg(inst)"),599 .cmpxchg_strong => @panic("TODO try self.airCmpxchg(inst)"),
...@@ -783,6 +783,25 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {...@@ -783,6 +783,25 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
783 return self.finishAir(inst, .{ .ptr_stack_offset = stack_offset }, .{ .none, .none, .none });783 return self.finishAir(inst, .{ .ptr_stack_offset = stack_offset }, .{ .none, .none, .none });
784}784}
785785
786fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
787 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
788 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
789 const ptr_ty = self.air.typeOf(ty_op.operand);
790 const ptr = try self.resolveInst(ty_op.operand);
791 const array_ty = ptr_ty.childType();
792 const array_len = @intCast(u32, array_ty.arrayLen());
793
794 const ptr_bits = self.target.cpu.arch.ptrBitWidth();
795 const ptr_bytes = @divExact(ptr_bits, 8);
796
797 const stack_offset = try self.allocMem(inst, ptr_bytes * 2, ptr_bytes * 2);
798 try self.genSetStack(ptr_ty, stack_offset, ptr);
799 try self.genSetStack(Type.initTag(.usize), stack_offset - ptr_bytes, .{ .immediate = array_len });
800 break :result MCValue{ .stack_offset = stack_offset };
801 };
802 return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
803}
804
786fn airAsm(self: *Self, inst: Air.Inst.Index) !void {805fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
787 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;806 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
788 const extra = self.air.extraData(Air.Asm, ty_pl.payload);807 const extra = self.air.extraData(Air.Asm, ty_pl.payload);