diff options
| author | Jacob G-W <jacoblevgw@gmail.com> | 2021-07-17 21:16:41 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-07-20 12:19:16 -0700 |
| commit | 414b144257e440be00928290220adcdfcdfb1e77 (patch) | |
| tree | 490eda656717ffdf59bde4468ce446661a9a2325 /src/codegen/c.zig | |
| parent | 4a0f38bb7671750be1590e815def72e3b4a34ccf (diff) | |
| download | zig-414b144257e440be00928290220adcdfcdfb1e77.tar.gz zig-414b144257e440be00928290220adcdfcdfb1e77.zip | |
cbe: fix not (it is a ty_op, not un_op)
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 7137116037..f938b28ec2 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -892,7 +892,8 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM .bit_and => try airBinOp(o, inst, " & "), .bit_or => try airBinOp(o, inst, " | "), .xor => try airBinOp(o, inst, " ^ "), - .not => try airUnOp( o, inst, "!"), + + .not => try airNot( o, inst), .optional_payload => try airOptionalPayload(o, inst), .optional_payload_ptr => try airOptionalPayload(o, inst), @@ -1181,40 +1182,44 @@ fn airWrapOp( return ret; } -fn airBinOp(o: *Object, inst: Air.Inst.Index, operator: [*:0]const u8) !CValue { +fn airNot(o: *Object, inst: Air.Inst.Index) !CValue { if (o.liveness.isUnused(inst)) return CValue.none; - const bin_op = o.air.instructions.items(.data)[inst].bin_op; - const lhs = try o.resolveInst(bin_op.lhs); - const rhs = try o.resolveInst(bin_op.rhs); + const ty_op = o.air.instructions.items(.data)[inst].ty_op; + const op = try o.resolveInst(ty_op.operand); const writer = o.writer(); const inst_ty = o.air.typeOfIndex(inst); const local = try o.allocLocal(inst_ty, .Const); try writer.writeAll(" = "); - try o.writeCValue(writer, lhs); - try writer.print("{s}", .{operator}); - try o.writeCValue(writer, rhs); + if (inst_ty.zigTypeTag() == .Bool) + try writer.writeAll("!") + else + try writer.writeAll("~"); + try o.writeCValue(writer, op); try writer.writeAll(";\n"); return local; } -fn airUnOp(o: *Object, inst: Air.Inst.Index, operator: []const u8) !CValue { +fn airBinOp(o: *Object, inst: Air.Inst.Index, operator: [*:0]const u8) !CValue { if (o.liveness.isUnused(inst)) return CValue.none; - const un_op = o.air.instructions.items(.data)[inst].un_op; - const operand = try o.resolveInst(un_op); + const bin_op = o.air.instructions.items(.data)[inst].bin_op; + const lhs = try o.resolveInst(bin_op.lhs); + const rhs = try o.resolveInst(bin_op.rhs); const writer = o.writer(); const inst_ty = o.air.typeOfIndex(inst); const local = try o.allocLocal(inst_ty, .Const); - try writer.print(" = {s}", .{operator}); - try o.writeCValue(writer, operand); + try writer.writeAll(" = "); + try o.writeCValue(writer, lhs); + try writer.print("{s}", .{operator}); + try o.writeCValue(writer, rhs); try writer.writeAll(";\n"); return local; |
