| ... | @@ -49,8 +49,9 @@ pub fn emitRaw( | ... | @@ -49,8 +49,9 @@ pub fn emitRaw( |
| 49 | operand_words: usize, | 49 | operand_words: usize, |
| 50 | ) !void { | 50 | ) !void { |
| 51 | const word_count = 1 + operand_words; | 51 | const word_count = 1 + operand_words; |
| | 52 | if (word_count > std.math.maxInt(u16)) return error.OutOfMemory; |
| 52 | try section.instructions.ensureUnusedCapacity(allocator, word_count); | 53 | try section.instructions.ensureUnusedCapacity(allocator, word_count); |
| 53 | section.writeWord((@as(Word, @intCast(word_count << 16))) | @backingInt(opcode)); | 54 | section.writeWord((@as(Word, @intCast(word_count)) << 16) | @backingInt(opcode)); |
| 54 | } | 55 | } |
| 55 | | 56 | |
| 56 | /// Write an entire instruction, including all operands | 57 | /// Write an entire instruction, including all operands |
| ... | @@ -70,7 +71,8 @@ pub fn emitAssumeCapacity( | ... | @@ -70,7 +71,8 @@ pub fn emitAssumeCapacity( |
| 70 | operands: opcode.Operands(), | 71 | operands: opcode.Operands(), |
| 71 | ) !void { | 72 | ) !void { |
| 72 | const word_count = instructionSize(opcode, operands); | 73 | const word_count = instructionSize(opcode, operands); |
| 73 | section.writeWord(@as(Word, @intCast(word_count << 16)) | @backingInt(opcode)); | 74 | if (word_count > std.math.maxInt(u16)) return error.OutOfMemory; |
| | 75 | section.writeWord((@as(Word, @intCast(word_count)) << 16) | @backingInt(opcode)); |
| 74 | section.writeOperands(opcode.Operands(), operands); | 76 | section.writeOperands(opcode.Operands(), operands); |
| 75 | } | 77 | } |
| 76 | | 78 | |
| ... | @@ -81,8 +83,9 @@ pub fn emit( | ... | @@ -81,8 +83,9 @@ pub fn emit( |
| 81 | operands: opcode.Operands(), | 83 | operands: opcode.Operands(), |
| 82 | ) !void { | 84 | ) !void { |
| 83 | const word_count = instructionSize(opcode, operands); | 85 | const word_count = instructionSize(opcode, operands); |
| | 86 | if (word_count > std.math.maxInt(u16)) return error.OutOfMemory; |
| 84 | try section.instructions.ensureUnusedCapacity(allocator, word_count); | 87 | try section.instructions.ensureUnusedCapacity(allocator, word_count); |
| 85 | section.writeWord(@as(Word, @intCast(word_count << 16)) | @backingInt(opcode)); | 88 | section.writeWord((@as(Word, @intCast(word_count)) << 16) | @backingInt(opcode)); |
| 86 | section.writeOperands(opcode.Operands(), operands); | 89 | section.writeOperands(opcode.Operands(), operands); |
| 87 | } | 90 | } |
| 88 | | 91 | |