| ... | ... | @@ -5880,10 +5880,25 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void { |
| 5880 | 5880 | } |
| 5881 | 5881 | |
| 5882 | 5882 | fn airArrayToSlice(func: *Func, inst: Air.Inst.Index) !void { |
| 5883 | const zcu = func.bin_file.comp.module.?; |
| 5883 | 5884 | const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op; |
| 5884 | | const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else return func.fail("TODO implement airArrayToSlice for {}", .{ |
| 5885 | | func.target.cpu.arch, |
| 5886 | | }); |
| 5885 | |
| 5886 | const slice_ty = func.typeOfIndex(inst); |
| 5887 | const ptr_ty = func.typeOf(ty_op.operand); |
| 5888 | const ptr = try func.resolveInst(ty_op.operand); |
| 5889 | const array_ty = ptr_ty.childType(zcu); |
| 5890 | const array_len = array_ty.arrayLen(zcu); |
| 5891 | |
| 5892 | const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(slice_ty, zcu)); |
| 5893 | try func.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr); |
| 5894 | try func.genSetMem( |
| 5895 | .{ .frame = frame_index }, |
| 5896 | @intCast(ptr_ty.abiSize(zcu)), |
| 5897 | Type.usize, |
| 5898 | .{ .immediate = array_len }, |
| 5899 | ); |
| 5900 | |
| 5901 | const result = MCValue{ .load_frame = .{ .index = frame_index } }; |
| 5887 | 5902 | return func.finishAir(inst, result, .{ ty_op.operand, .none, .none }); |
| 5888 | 5903 | } |
| 5889 | 5904 | |