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...@@ -892,7 +892,8 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM
892 .bit_and => try airBinOp(o, inst, " & "),892 .bit_and => try airBinOp(o, inst, " & "),
893 .bit_or => try airBinOp(o, inst, " | "),893 .bit_or => try airBinOp(o, inst, " | "),
894 .xor => try airBinOp(o, inst, " ^ "),894 .xor => try airBinOp(o, inst, " ^ "),
895 .not => try airUnOp( o, inst, "!"),895
896 .not => try airNot( o, inst),
896897
897 .optional_payload => try airOptionalPayload(o, inst),898 .optional_payload => try airOptionalPayload(o, inst),
898 .optional_payload_ptr => try airOptionalPayload(o, inst),899 .optional_payload_ptr => try airOptionalPayload(o, inst),
...@@ -1181,40 +1182,44 @@ fn airWrapOp(...@@ -1181,40 +1182,44 @@ fn airWrapOp(
1181 return ret;1182 return ret;
1182}1183}
11831184
1184fn airBinOp(o: *Object, inst: Air.Inst.Index, operator: [*:0]const u8) !CValue {1185fn airNot(o: *Object, inst: Air.Inst.Index) !CValue {
1185 if (o.liveness.isUnused(inst))1186 if (o.liveness.isUnused(inst))
1186 return CValue.none;1187 return CValue.none;
11871188
1188 const bin_op = o.air.instructions.items(.data)[inst].bin_op;1189 const ty_op = o.air.instructions.items(.data)[inst].ty_op;
1189 const lhs = try o.resolveInst(bin_op.lhs);1190 const op = try o.resolveInst(ty_op.operand);
1190 const rhs = try o.resolveInst(bin_op.rhs);
11911191
1192 const writer = o.writer();1192 const writer = o.writer();
1193 const inst_ty = o.air.typeOfIndex(inst);1193 const inst_ty = o.air.typeOfIndex(inst);
1194 const local = try o.allocLocal(inst_ty, .Const);1194 const local = try o.allocLocal(inst_ty, .Const);
11951195
1196 try writer.writeAll(" = ");1196 try writer.writeAll(" = ");
1197 try o.writeCValue(writer, lhs);1197 if (inst_ty.zigTypeTag() == .Bool)
1198 try writer.print("{s}", .{operator});1198 try writer.writeAll("!")
1199 try o.writeCValue(writer, rhs);1199 else
1200 try writer.writeAll("~");
1201 try o.writeCValue(writer, op);
1200 try writer.writeAll(";\n");1202 try writer.writeAll(";\n");
12011203
1202 return local;1204 return local;
1203}1205}
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 {
1206 if (o.liveness.isUnused(inst))1208 if (o.liveness.isUnused(inst))
1207 return CValue.none;1209 return CValue.none;
12081210
1209 const un_op = o.air.instructions.items(.data)[inst].un_op;1211 const bin_op = o.air.instructions.items(.data)[inst].bin_op;
1210 const operand = try o.resolveInst(un_op);1212 const lhs = try o.resolveInst(bin_op.lhs);
1213 const rhs = try o.resolveInst(bin_op.rhs);
12111214
1212 const writer = o.writer();1215 const writer = o.writer();
1213 const inst_ty = o.air.typeOfIndex(inst);1216 const inst_ty = o.air.typeOfIndex(inst);
1214 const local = try o.allocLocal(inst_ty, .Const);1217 const local = try o.allocLocal(inst_ty, .Const);
12151218
1216 try writer.print(" = {s}", .{operator});1219 try writer.writeAll(" = ");
1217 try o.writeCValue(writer, operand);1220 try o.writeCValue(writer, lhs);
1221 try writer.print("{s}", .{operator});
1222 try o.writeCValue(writer, rhs);
1218 try writer.writeAll(";\n");1223 try writer.writeAll(";\n");
12191224
1220 return local;1225 return local;