authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-01-04 01:21:02+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-01-04 01:21:24+01:00
logaad20ce92c5379b0379964ea3b22d81628a640ad
treee48b7d9fbd8ea84569ee16afe065adfb20d69fec
parent47ed87dab8ab525fa3d284b9d0e61b244ec75f82

stage2: pass empty zig test


1 files changed, 21 insertions(+), 10 deletions(-)

src/arch/x86_64/CodeGen.zig+21-10
......@@ -2056,7 +2056,9 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
20562056 return self.fail("TODO implement calling bitcasted functions", .{});
20572057 }
20582058 } else {
2059 return self.fail("TODO implement calling runtime known function pointer", .{});
2059 assert(ty.zigTypeTag() == .Pointer);
2060 const mcv = try self.resolveInst(callee);
2061 try self.genSetReg(Type.initTag(.usize), .rax, mcv);
20602062 }
20612063 } else if (self.bin_file.cast(link.File.MachO)) |macho_file| {
20622064 for (info.args) |mc_arg, arg_i| {
......@@ -2099,7 +2101,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
20992101 const func = func_payload.data;
21002102 // TODO I'm hacking my way through here by repurposing .memory for storing
21012103 // index to the GOT target symbol index.
2102 try self.genSetReg(Type.initTag(.u64), .rax, .{
2104 try self.genSetReg(Type.initTag(.usize), .rax, .{
21032105 .memory = func.owner_decl.link.macho.local_sym_index,
21042106 });
21052107 // callq *%rax
......@@ -2123,7 +2125,9 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
21232125 return self.fail("TODO implement calling bitcasted functions", .{});
21242126 }
21252127 } else {
2126 return self.fail("TODO implement calling runtime known function pointer", .{});
2128 assert(ty.zigTypeTag() == .Pointer);
2129 const mcv = try self.resolveInst(callee);
2130 try self.genSetReg(Type.initTag(.usize), .rax, mcv);
21272131 }
21282132 } else if (self.bin_file.cast(link.File.Plan9)) |p9| {
21292133 for (info.args) |mc_arg, arg_i| {
......@@ -2241,12 +2245,19 @@ fn airRetLoad(self: *Self, inst: Air.Inst.Index) !void {
22412245
22422246fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
22432247 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2244 if (self.liveness.isUnused(inst))
2248
2249 if (self.liveness.isUnused(inst)) {
22452250 return self.finishAir(inst, .dead, .{ bin_op.lhs, bin_op.rhs, .none });
2251 }
2252
22462253 const ty = self.air.typeOf(bin_op.lhs);
2247 assert(ty.eql(self.air.typeOf(bin_op.rhs)));
2248 if (ty.zigTypeTag() == .ErrorSet)
2249 return self.fail("TODO implement cmp for errors", .{});
2254 const signedness: std.builtin.Signedness = blk: {
2255 // For non-int types, we treat the values as unsigned
2256 if (ty.zigTypeTag() != .Int) break :blk .unsigned;
2257
2258 // Otherwise, we take the signedness of the actual int
2259 break :blk ty.intInfo(self.target.*).signedness;
2260 };
22502261
22512262 const lhs = try self.resolveInst(bin_op.lhs);
22522263 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -2262,9 +2273,9 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
22622273 const src_mcv = try self.limitImmediateType(bin_op.rhs, i32);
22632274
22642275 try self.genBinMathOpMir(.cmp, ty, dst_mcv, src_mcv);
2265 break :result switch (ty.isSignedInt()) {
2266 true => MCValue{ .compare_flags_signed = op },
2267 false => MCValue{ .compare_flags_unsigned = op },
2276 break :result switch (signedness) {
2277 .signed => MCValue{ .compare_flags_signed = op },
2278 .unsigned => MCValue{ .compare_flags_unsigned = op },
22682279 };
22692280 };
22702281 return self.finishAir(inst, result, .{ bin_op.lhs, bin_op.rhs, .none });