Skip to content

Commit

Permalink
riscv: implement airArrayToSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Jun 13, 2024
1 parent a270c6f commit a9ef016
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/arch/riscv64/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5880,10 +5880,25 @@ fn airBitCast(func: *Func, inst: Air.Inst.Index) !void {
}

fn airArrayToSlice(func: *Func, inst: Air.Inst.Index) !void {
const zcu = func.bin_file.comp.module.?;
const ty_op = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_op;
const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else return func.fail("TODO implement airArrayToSlice for {}", .{
func.target.cpu.arch,
});

const slice_ty = func.typeOfIndex(inst);
const ptr_ty = func.typeOf(ty_op.operand);
const ptr = try func.resolveInst(ty_op.operand);
const array_ty = ptr_ty.childType(zcu);
const array_len = array_ty.arrayLen(zcu);

const frame_index = try func.allocFrameIndex(FrameAlloc.initSpill(slice_ty, zcu));
try func.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
try func.genSetMem(
.{ .frame = frame_index },
@intCast(ptr_ty.abiSize(zcu)),
Type.usize,
.{ .immediate = array_len },
);

const result = MCValue{ .load_frame = .{ .index = frame_index } };
return func.finishAir(inst, result, .{ ty_op.operand, .none, .none });
}

Expand Down

0 comments on commit a9ef016

Please sign in to comment.