disasm.go 594 B

123456789101112131415161718192021
  1. package vm
  2. import "fmt"
  3. func Disasm(code []byte) []string {
  4. var out []string
  5. for pc := uint64(0); pc < uint64(len(code)); pc++ {
  6. op := OpCode(code[pc])
  7. out = append(out, op.String())
  8. switch op {
  9. case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
  10. a := uint64(op) - uint64(PUSH1) + 1
  11. out = append(out, fmt.Sprintf("0x%x", code[pc+1:pc+1+a]))
  12. pc += a
  13. }
  14. }
  15. return out
  16. }