Split files
This commit is contained in:
30
instruction.go
Normal file
30
instruction.go
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user