authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-07-17 21:16:41-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-20 12:19:16-07:00
log414b144257e440be00928290220adcdfcdfb1e77
tree490eda656717ffdf59bde4468ce446661a9a2325
parent4a0f38bb7671750be1590e815def72e3b4a34ccf

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


1 files changed, 18 insertions(+), 13 deletions(-)

src/codegen/c.zig+18-13
......@@ -892,7 +892,8 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM
892892 .bit_and => try airBinOp(o, inst, " & "),
893893 .bit_or => try airBinOp(o, inst, " | "),
894894 .xor => try airBinOp(o, inst, " ^ "),
895 .not => try airUnOp( o, inst, "!"),
895
896 .not => try airNot( o, inst),
896897
897898 .optional_payload => try airOptionalPayload(o, inst),
898899 .optional_payload_ptr => try airOptionalPayload(o, inst),
......@@ -1181,40 +1182,44 @@ fn airWrapOp(
11811182 return ret;
11821183}
11831184
1184fn airBinOp(o: *Object, inst: Air.Inst.Index, operator: [*:0]const u8) !CValue {
1185fn airNot(o: *Object, inst: Air.Inst.Index) !CValue {
11851186 if (o.liveness.isUnused(inst))
11861187 return CValue.none;
11871188
1188 const bin_op = o.air.instructions.items(.data)[inst].bin_op;
1189 const lhs = try o.resolveInst(bin_op.lhs);
1190 const rhs = try o.resolveInst(bin_op.rhs);
1189 const ty_op = o.air.instructions.items(.data)[inst].ty_op;
1190 const op = try o.resolveInst(ty_op.operand);
11911191
11921192 const writer = o.writer();
11931193 const inst_ty = o.air.typeOfIndex(inst);
11941194 const local = try o.allocLocal(inst_ty, .Const);
11951195
11961196 try writer.writeAll(" = ");
1197 try o.writeCValue(writer, lhs);
1198 try writer.print("{s}", .{operator});
1199 try o.writeCValue(writer, rhs);
1197 if (inst_ty.zigTypeTag() == .Bool)
1198 try writer.writeAll("!")
1199 else
1200 try writer.writeAll("~");
1201 try o.writeCValue(writer, op);
12001202 try writer.writeAll(";\n");
12011203
12021204 return local;
12031205}
12041206
1205fn airUnOp(o: *Object, inst: Air.Inst.Index, operator: []const u8) !CValue {
1207fn airBinOp(o: *Object, inst: Air.Inst.Index, operator: [*:0]const u8) !CValue {
12061208 if (o.liveness.isUnused(inst))
12071209 return CValue.none;
12081210
1209 const un_op = o.air.instructions.items(.data)[inst].un_op;
1210 const operand = try o.resolveInst(un_op);
1211 const bin_op = o.air.instructions.items(.data)[inst].bin_op;
1212 const lhs = try o.resolveInst(bin_op.lhs);
1213 const rhs = try o.resolveInst(bin_op.rhs);
12111214
12121215 const writer = o.writer();
12131216 const inst_ty = o.air.typeOfIndex(inst);
12141217 const local = try o.allocLocal(inst_ty, .Const);
12151218
1216 try writer.print(" = {s}", .{operator});
1217 try o.writeCValue(writer, operand);
1219 try writer.writeAll(" = ");
1220 try o.writeCValue(writer, lhs);
1221 try writer.print("{s}", .{operator});
1222 try o.writeCValue(writer, rhs);
12181223 try writer.writeAll(";\n");
12191224
12201225 return local;