aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index fa254af293..7299b21a61 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -925,6 +925,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),
+ .bool_to_int => try airBoolToInt(o, inst),
.load => try airLoad(o, inst),
.ret => try airRet(o, inst),
.store => try airStore(o, inst),
@@ -1083,6 +1084,20 @@ fn airIntCast(o: *Object, inst: Air.Inst.Index) !CValue {
return local;
}
+fn airBoolToInt(o: *Object, inst: Air.Inst.Index) !CValue {
+ if (o.liveness.isUnused(inst))
+ return CValue.none;
+ const un_op = o.air.instructions.items(.data)[inst].un_op;
+ const writer = o.writer();
+ const inst_ty = o.air.typeOfIndex(inst);
+ const operand = try o.resolveInst(un_op);
+ const local = try o.allocLocal(inst_ty, .Const);
+ try writer.writeAll(" = ");
+ try o.writeCValue(writer, operand);
+ try writer.writeAll(";\n");
+ return local;
+}
+
fn airStore(o: *Object, inst: Air.Inst.Index) !CValue {
// *a = b;
const bin_op = o.air.instructions.items(.data)[inst].bin_op;