| ... | @@ -105,6 +105,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct { | ... | @@ -105,6 +105,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct { |
| 105 | } | 105 | } |
| 106 | | 106 | |
| 107 | if (count == 0) return null; | 107 | if (count == 0) return null; |
| | 108 | if (count == 1) return candidates[0]; |
| 108 | | 109 | |
| 109 | const EncodingLength = struct { | 110 | const EncodingLength = struct { |
| 110 | fn estimate(encoding: Encoding, params: struct { | 111 | fn estimate(encoding: Encoding, params: struct { |
| ... | @@ -112,7 +113,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct { | ... | @@ -112,7 +113,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct { |
| 112 | op2: Instruction.Operand, | 113 | op2: Instruction.Operand, |
| 113 | op3: Instruction.Operand, | 114 | op3: Instruction.Operand, |
| 114 | op4: Instruction.Operand, | 115 | op4: Instruction.Operand, |
| 115 | }) !usize { | 116 | }) usize { |
| 116 | var inst = Instruction{ | 117 | var inst = Instruction{ |
| 117 | .op1 = params.op1, | 118 | .op1 = params.op1, |
| 118 | .op2 = params.op2, | 119 | .op2 = params.op2, |
| ... | @@ -122,7 +123,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct { | ... | @@ -122,7 +123,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct { |
| 122 | }; | 123 | }; |
| 123 | var cwriter = std.io.countingWriter(std.io.null_writer); | 124 | var cwriter = std.io.countingWriter(std.io.null_writer); |
| 124 | inst.encode(cwriter.writer()) catch unreachable; // Not allowed to fail here unless OOM. | 125 | inst.encode(cwriter.writer()) catch unreachable; // Not allowed to fail here unless OOM. |
| 125 | return cwriter.bytes_written; | 126 | return @intCast(usize, cwriter.bytes_written); |
| 126 | } | 127 | } |
| 127 | }; | 128 | }; |
| 128 | | 129 | |
| ... | @@ -138,7 +139,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct { | ... | @@ -138,7 +139,7 @@ pub fn findByMnemonic(mnemonic: Mnemonic, args: struct { |
| 138 | else => {}, | 139 | else => {}, |
| 139 | } | 140 | } |
| 140 | | 141 | |
| 141 | const len = try EncodingLength.estimate(candidate, .{ | 142 | const len = EncodingLength.estimate(candidate, .{ |
| 142 | .op1 = args.op1, | 143 | .op1 = args.op1, |
| 143 | .op2 = args.op2, | 144 | .op2 = args.op2, |
| 144 | .op3 = args.op3, | 145 | .op3 = args.op3, |