Files
subcoding/instruction.go
Ian Gulliver 6b1da92a3a Split files
2021-11-15 20:44:26 -10:00

31 lines
531 B
Go

package vm
import "bytes"
import "github.com/lunixbochs/struc"
import "github.com/pkg/errors"
const InstructionBytes = 32
type Instruction struct {
OpCode OpCodeType
Reserved [4]byte
Operand1 Operand
Operand2 Operand
opHandler OpHandler `struc:"skip"`
}
func NewInstruction(byteCode []byte) (*Instruction, error) {
instr := &Instruction{}
reader := bytes.NewReader(byteCode)
err := struc.Unpack(reader, instr)
if err != nil {
return nil, errors.Wrap(err, "Error decoding instruction")
}
return instr, nil
}