zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 414b144257e440be00928290220adcdfcdfb1e77 (tree)
parent 4a0f38bb7671750be1590e815def72e3b4a34ccf
Author: Jacob G-W <jacoblevgw@gmail.com>
Date:   Sat, 17 Jul 2021 21:16:41 -0400

cbe: fix not (it is a ty_op, not un_op)

Diffstat:
Msrc/codegen/c.zig | 31++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)

diff --git 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;