aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-08-01 16:13:58 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-08-01 16:13:58 -0700
commitddf14323ea9b2c75ac5ed286525d27730a192b53 (patch)
treea8b586e69bef580747553f63da828f947f28aa21 /src/codegen.zig
parent6ae0825e7f87fc9b73a4b968964196b0e164f062 (diff)
downloadzig-ddf14323ea9b2c75ac5ed286525d27730a192b53.tar.gz
zig-ddf14323ea9b2c75ac5ed286525d27730a192b53.zip
stage2: implement `@truncate`
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index 8c56ab4431..3864479d2d 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -835,6 +835,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
.dbg_stmt => try self.airDbgStmt(inst),
.floatcast => try self.airFloatCast(inst),
.intcast => try self.airIntCast(inst),
+ .trunc => try self.airTrunc(inst),
.bool_to_int => try self.airBoolToInt(inst),
.is_non_null => try self.airIsNonNull(inst),
.is_non_null_ptr => try self.airIsNonNullPtr(inst),
@@ -1109,6 +1110,19 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
}
+ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
+ const ty_op = self.air.instructions.items(.data)[inst].ty_op;
+ if (self.liveness.isUnused(inst))
+ return self.finishAir(inst, .dead, .{ ty_op.operand, .none, .none });
+
+ const operand = try self.resolveInst(ty_op.operand);
+ _ = operand;
+ const result: MCValue = switch (arch) {
+ else => return self.fail("TODO implement trunc for {}", .{self.target.cpu.arch}),
+ };
+ return self.finishAir(inst, result, .{ ty_op.operand, .none, .none });
+ }
+
fn airBoolToInt(self: *Self, inst: Air.Inst.Index) !void {
const un_op = self.air.instructions.items(.data)[inst].un_op;
const operand = try self.resolveInst(un_op);