2020-05-21 10:00:11 +00:00
|
|
|
package opcode
|
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
var stringToOpcode = make(map[string]Opcode)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
for i := 0; i < 255; i++ {
|
|
|
|
op := Opcode(i)
|
|
|
|
stringToOpcode[op.String()] = op
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// FromString converts string representation to an opcode itself.
|
2020-05-21 10:00:11 +00:00
|
|
|
func FromString(s string) (Opcode, error) {
|
|
|
|
if op, ok := stringToOpcode[s]; ok {
|
|
|
|
return op, nil
|
|
|
|
}
|
|
|
|
return 0, errors.New("invalid opcode")
|
|
|
|
}
|