| ... | @@ -203,23 +203,40 @@ pub const Instruction = union(Opcode) { | ... | @@ -203,23 +203,40 @@ pub const Instruction = union(Opcode) { |
| 203 | stream: *std.io.FixedBufferStream([]const u8), | 203 | stream: *std.io.FixedBufferStream([]const u8), |
| 204 | addr_size_bytes: u8, | 204 | addr_size_bytes: u8, |
| 205 | endian: std.builtin.Endian, | 205 | endian: std.builtin.Endian, |
| | 206 | |
| 206 | ) !Instruction { | 207 | ) !Instruction { |
| 207 | return switch (try stream.reader().readByte()) { | 208 | switch (try stream.reader().readByte()) { |
| 208 | inline Opcode.lo_inline...Opcode.hi_inline => |opcode| blk: { | 209 | Opcode.lo_inline...Opcode.hi_inline => |opcode| { |
| 209 | const e: Opcode = @enumFromInt(opcode & 0b11000000); | 210 | const e: Opcode = @enumFromInt(opcode & 0b11000000); |
| 210 | var result = @unionInit(Instruction, @tagName(e), undefined); | 211 | switch (e) { |
| 211 | try result.readOperands(stream, @as(u6, @intCast(opcode & 0b111111)), addr_size_bytes, endian); | 212 | inline .advance_loc, |
| 212 | break :blk result; | 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 | const e: Opcode = @enumFromInt(opcode); | 224 | const e: Opcode = @enumFromInt(opcode); |
| 216 | var result = @unionInit(Instruction, @tagName(e), undefined); | 225 | switch (e) { |
| 217 | try result.readOperands(stream, null, addr_size_bytes, endian); | 226 | .advance_loc, |
| 218 | break :blk result; | 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, | 237 | Opcode.lo_user...Opcode.hi_user => return error.UnimplementedUserOpcode, |
| 221 | else => error.InvalidOpcode, | 238 | else => return error.InvalidOpcode, |
| 222 | }; | 239 | } |
| 223 | } | 240 | } |
| 224 | }; | 241 | }; |
| 225 | | 242 | |