Source
pub fn cast(
self: *WipFunction,
tag: Instruction.Tag,
val: Value,
ty: Type,
name: []const u8,
) Allocator.Error!Value {
switch (tag) {
.addrspacecast,
.bitcast,
.fpext,
.fptosi,
.fptoui,
.fptrunc,
.inttoptr,
.ptrtoint,
.sext,
.sitofp,
.trunc,
.uitofp,
.zext,
=> {},
else => unreachable,
}
if (val.typeOfWip(self) == ty) return val;
try self.ensureUnusedExtraCapacity(1, Instruction.Cast, 0);
const instruction = try self.addInst(name, .{
.tag = tag,
.data = self.addExtraAssumeCapacity(Instruction.Cast{
.val = val,
.type = ty,
}),
});
return instruction.toValue();
}