| ... | @@ -780,14 +780,22 @@ const Function = struct { | ... | @@ -780,14 +780,22 @@ const Function = struct { |
| 780 | } | 780 | } |
| 781 | | 781 | |
| 782 | fn genBr(self: *Function, inst: *ir.Inst.Br, comptime arch: std.Target.Cpu.Arch) !MCValue { | 782 | fn genBr(self: *Function, inst: *ir.Inst.Br, comptime arch: std.Target.Cpu.Arch) !MCValue { |
| | 783 | if (!inst.args.operand.ty.hasCodeGenBits()) |
| | 784 | return self.brVoid(inst.base.src, inst.args.block, arch); |
| | 785 | |
| | 786 | const operand = try self.resolveInst(inst.args.operand); |
| 783 | switch (arch) { | 787 | switch (arch) { |
| 784 | else => return self.fail(inst.base.src, "TODO implement br for {}", .{self.target.cpu.arch}), | 788 | else => return self.fail(inst.base.src, "TODO implement br for {}", .{self.target.cpu.arch}), |
| 785 | } | 789 | } |
| 786 | } | 790 | } |
| 787 | | 791 | |
| 788 | fn genBrVoid(self: *Function, inst: *ir.Inst.BrVoid, comptime arch: std.Target.Cpu.Arch) !MCValue { | 792 | fn genBrVoid(self: *Function, inst: *ir.Inst.BrVoid, comptime arch: std.Target.Cpu.Arch) !MCValue { |
| | 793 | return self.brVoid(inst.base.src, inst.args.block, arch); |
| | 794 | } |
| | 795 | |
| | 796 | fn brVoid(self: *Function, src: usize, block: *ir.Inst.Block, comptime arch: std.Target.Cpu.Arch) !MCValue { |
| 789 | // Emit a jump with a relocation. It will be patched up after the block ends. | 797 | // Emit a jump with a relocation. It will be patched up after the block ends. |
| 790 | try inst.args.block.codegen.relocs.ensureCapacity(self.gpa, inst.args.block.codegen.relocs.items.len + 1); | 798 | try block.codegen.relocs.ensureCapacity(self.gpa, block.codegen.relocs.items.len + 1); |
| 791 | | 799 | |
| 792 | switch (arch) { | 800 | switch (arch) { |
| 793 | .i386, .x86_64 => { | 801 | .i386, .x86_64 => { |
| ... | @@ -796,9 +804,9 @@ const Function = struct { | ... | @@ -796,9 +804,9 @@ const Function = struct { |
| 796 | try self.code.resize(self.code.items.len + 5); | 804 | try self.code.resize(self.code.items.len + 5); |
| 797 | self.code.items[self.code.items.len - 5] = 0xe9; // jmp rel32 | 805 | self.code.items[self.code.items.len - 5] = 0xe9; // jmp rel32 |
| 798 | // Leave the jump offset undefined | 806 | // Leave the jump offset undefined |
| 799 | inst.args.block.codegen.relocs.appendAssumeCapacity(.{ .rel32 = self.code.items.len - 4 }); | 807 | block.codegen.relocs.appendAssumeCapacity(.{ .rel32 = self.code.items.len - 4 }); |
| 800 | }, | 808 | }, |
| 801 | else => return self.fail(inst.base.src, "TODO implement brvoid for {}", .{self.target.cpu.arch}), | 809 | else => return self.fail(src, "TODO implement brvoid for {}", .{self.target.cpu.arch}), |
| 802 | } | 810 | } |
| 803 | return .none; | 811 | return .none; |
| 804 | } | 812 | } |