| ... | ... | @@ -892,7 +892,8 @@ fn genBody(o: *Object, body: []const Air.Inst.Index) error{ AnalysisFail, OutOfM |
| 892 | 892 | .bit_and => try airBinOp(o, inst, " & "), |
| 893 | 893 | .bit_or => try airBinOp(o, inst, " | "), |
| 894 | 894 | .xor => try airBinOp(o, inst, " ^ "), |
| 895 | | .not => try airUnOp( o, inst, "!"), |
| 895 | |
| 896 | .not => try airNot( o, inst), |
| 896 | 897 | |
| 897 | 898 | .optional_payload => try airOptionalPayload(o, inst), |
| 898 | 899 | .optional_payload_ptr => try airOptionalPayload(o, inst), |
| ... | ... | @@ -1181,40 +1182,44 @@ fn airWrapOp( |
| 1181 | 1182 | return ret; |
| 1182 | 1183 | } |
| 1183 | 1184 | |
| 1184 | | fn airBinOp(o: *Object, inst: Air.Inst.Index, operator: [*:0]const u8) !CValue { |
| 1185 | fn airNot(o: *Object, inst: Air.Inst.Index) !CValue { |
| 1185 | 1186 | if (o.liveness.isUnused(inst)) |
| 1186 | 1187 | return CValue.none; |
| 1187 | 1188 | |
| 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); |
| 1191 | 1191 | |
| 1192 | 1192 | const writer = o.writer(); |
| 1193 | 1193 | const inst_ty = o.air.typeOfIndex(inst); |
| 1194 | 1194 | const local = try o.allocLocal(inst_ty, .Const); |
| 1195 | 1195 | |
| 1196 | 1196 | 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); |
| 1200 | 1202 | try writer.writeAll(";\n"); |
| 1201 | 1203 | |
| 1202 | 1204 | return local; |
| 1203 | 1205 | } |
| 1204 | 1206 | |
| 1205 | | fn airUnOp(o: *Object, inst: Air.Inst.Index, operator: []const u8) !CValue { |
| 1207 | fn airBinOp(o: *Object, inst: Air.Inst.Index, operator: [*:0]const u8) !CValue { |
| 1206 | 1208 | if (o.liveness.isUnused(inst)) |
| 1207 | 1209 | return CValue.none; |
| 1208 | 1210 | |
| 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); |
| 1211 | 1214 | |
| 1212 | 1215 | const writer = o.writer(); |
| 1213 | 1216 | const inst_ty = o.air.typeOfIndex(inst); |
| 1214 | 1217 | const local = try o.allocLocal(inst_ty, .Const); |
| 1215 | 1218 | |
| 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); |
| 1218 | 1223 | try writer.writeAll(";\n"); |
| 1219 | 1224 | |
| 1220 | 1225 | return local; |