aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.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/c.zig
parent6ae0825e7f87fc9b73a4b968964196b0e164f062 (diff)
downloadzig-ddf14323ea9b2c75ac5ed286525d27730a192b53.tar.gz
zig-ddf14323ea9b2c75ac5ed286525d27730a192b53.zip
stage2: implement `@truncate`
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 826b73317c..22420aca45 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -900,6 +900,7 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM
.call => try airCall(o, inst),
.dbg_stmt => try airDbgStmt(o, inst),
.intcast => try airIntCast(o, inst),
+ .trunc => try airTrunc(o, inst),
.bool_to_int => try airBoolToInt(o, inst),
.load => try airLoad(o, inst),
.ret => try airRet(o, inst),
@@ -1038,7 +1039,7 @@ fn airIntCast(o: *Object, inst: Air.Inst.Index) !CValue {
return CValue.none;
const ty_op = o.air.instructions.items(.data)[inst].ty_op;
- const from = try o.resolveInst(ty_op.operand);
+ const operand = try o.resolveInst(ty_op.operand);
const writer = o.writer();
const inst_ty = o.air.typeOfIndex(inst);
@@ -1046,11 +1047,21 @@ fn airIntCast(o: *Object, inst: Air.Inst.Index) !CValue {
try writer.writeAll(" = (");
try o.dg.renderType(writer, inst_ty);
try writer.writeAll(")");
- try o.writeCValue(writer, from);
+ try o.writeCValue(writer, operand);
try writer.writeAll(";\n");
return local;
}
+fn airTrunc(o: *Object, inst: Air.Inst.Index) !CValue {
+ if (o.liveness.isUnused(inst))
+ return CValue.none;
+
+ const ty_op = o.air.instructions.items(.data)[inst].ty_op;
+ const operand = try o.resolveInst(ty_op.operand);
+ _ = operand;
+ return o.dg.fail("TODO: C backend: airTrunc", .{});
+}
+
fn airBoolToInt(o: *Object, inst: Air.Inst.Index) !CValue {
if (o.liveness.isUnused(inst))
return CValue.none;