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

This commit is contained in:
Jacob G-W 2021-07-17 21:16:41 -04:00 committed by Andrew Kelley
parent 4a0f38bb76
commit 414b144257

View File

@ -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,6 +1182,28 @@ fn airWrapOp(
return ret;
}
fn airNot(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 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(" = ");
if (inst_ty.zigTypeTag() == .Bool)
try writer.writeAll("!")
else
try writer.writeAll("~");
try o.writeCValue(writer, op);
try writer.writeAll(";\n");
return local;
}
fn airBinOp(o: *Object, inst: Air.Inst.Index, operator: [*:0]const u8) !CValue {
if (o.liveness.isUnused(inst))
return CValue.none;
@ -1202,24 +1225,6 @@ fn airBinOp(o: *Object, inst: Air.Inst.Index, operator: [*:0]const u8) !CValue {
return local;
}
fn airUnOp(o: *Object, inst: Air.Inst.Index, operator: []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 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(";\n");
return local;
}
fn airCall(o: *Object, inst: Air.Inst.Index) !CValue {
const pl_op = o.air.instructions.items(.data)[inst].pl_op;
const extra = o.air.extraData(Air.Call, pl_op.payload);