| ... | ... | @@ -203,23 +203,40 @@ pub const Instruction = union(Opcode) { |
| 203 | 203 | stream: *std.io.FixedBufferStream([]const u8), |
| 204 | 204 | addr_size_bytes: u8, |
| 205 | 205 | endian: std.builtin.Endian, |
| 206 | |
| 206 | 207 | ) !Instruction { |
| 207 | | return switch (try stream.reader().readByte()) { |
| 208 | | inline Opcode.lo_inline...Opcode.hi_inline => |opcode| blk: { |
| 208 | switch (try stream.reader().readByte()) { |
| 209 | Opcode.lo_inline...Opcode.hi_inline => |opcode| { |
| 209 | 210 | const e: Opcode = @enumFromInt(opcode & 0b11000000); |
| 210 | | var result = @unionInit(Instruction, @tagName(e), undefined); |
| 211 | | try result.readOperands(stream, @as(u6, @intCast(opcode & 0b111111)), addr_size_bytes, endian); |
| 212 | | break :blk result; |
| 211 | switch (e) { |
| 212 | inline .advance_loc, |
| 213 | .offset, |
| 214 | .restore, |
| 215 | => |tag| { |
| 216 | var result = @unionInit(Instruction, @tagName(tag), undefined); |
| 217 | try result.readOperands(stream, @as(u6, @intCast(opcode & 0b111111)), addr_size_bytes, endian); |
| 218 | return result; |
| 219 | }, |
| 220 | else => unreachable, |
| 221 | } |
| 213 | 222 | }, |
| 214 | | inline Opcode.lo_reserved...Opcode.hi_reserved => |opcode| blk: { |
| 223 | Opcode.lo_reserved...Opcode.hi_reserved => |opcode| { |
| 215 | 224 | const e: Opcode = @enumFromInt(opcode); |
| 216 | | var result = @unionInit(Instruction, @tagName(e), undefined); |
| 217 | | try result.readOperands(stream, null, addr_size_bytes, endian); |
| 218 | | break :blk result; |
| 225 | switch (e) { |
| 226 | .advance_loc, |
| 227 | .offset, |
| 228 | .restore, |
| 229 | => unreachable, |
| 230 | inline else => |tag| { |
| 231 | var result = @unionInit(Instruction, @tagName(tag), undefined); |
| 232 | try result.readOperands(stream, null, addr_size_bytes, endian); |
| 233 | return result; |
| 234 | }, |
| 235 | } |
| 219 | 236 | }, |
| 220 | | Opcode.lo_user...Opcode.hi_user => error.UnimplementedUserOpcode, |
| 221 | | else => error.InvalidOpcode, |
| 222 | | }; |
| 237 | Opcode.lo_user...Opcode.hi_user => return error.UnimplementedUserOpcode, |
| 238 | else => return error.InvalidOpcode, |
| 239 | } |
| 223 | 240 | } |
| 224 | 241 | }; |
| 225 | 242 | |