jump_table.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package vm
  2. import "math/big"
  3. type jumpPtr struct {
  4. fn instrFn
  5. valid bool
  6. }
  7. var jumpTable [256]jumpPtr
  8. func init() {
  9. jumpTable[ADD] = jumpPtr{opAdd, true}
  10. jumpTable[SUB] = jumpPtr{opSub, true}
  11. jumpTable[MUL] = jumpPtr{opMul, true}
  12. jumpTable[DIV] = jumpPtr{opDiv, true}
  13. jumpTable[SDIV] = jumpPtr{opSdiv, true}
  14. jumpTable[MOD] = jumpPtr{opMod, true}
  15. jumpTable[SMOD] = jumpPtr{opSmod, true}
  16. jumpTable[EXP] = jumpPtr{opExp, true}
  17. jumpTable[SIGNEXTEND] = jumpPtr{opSignExtend, true}
  18. jumpTable[NOT] = jumpPtr{opNot, true}
  19. jumpTable[LT] = jumpPtr{opLt, true}
  20. jumpTable[GT] = jumpPtr{opGt, true}
  21. jumpTable[SLT] = jumpPtr{opSlt, true}
  22. jumpTable[SGT] = jumpPtr{opSgt, true}
  23. jumpTable[EQ] = jumpPtr{opEq, true}
  24. jumpTable[ISZERO] = jumpPtr{opIszero, true}
  25. jumpTable[AND] = jumpPtr{opAnd, true}
  26. jumpTable[OR] = jumpPtr{opOr, true}
  27. jumpTable[XOR] = jumpPtr{opXor, true}
  28. jumpTable[BYTE] = jumpPtr{opByte, true}
  29. jumpTable[ADDMOD] = jumpPtr{opAddmod, true}
  30. jumpTable[MULMOD] = jumpPtr{opMulmod, true}
  31. jumpTable[SHA3] = jumpPtr{opSha3, true}
  32. jumpTable[ADDRESS] = jumpPtr{opAddress, true}
  33. jumpTable[BALANCE] = jumpPtr{opBalance, true}
  34. jumpTable[ORIGIN] = jumpPtr{opOrigin, true}
  35. jumpTable[CALLER] = jumpPtr{opCaller, true}
  36. jumpTable[CALLVALUE] = jumpPtr{opCallValue, true}
  37. jumpTable[CALLDATALOAD] = jumpPtr{opCalldataLoad, true}
  38. jumpTable[CALLDATASIZE] = jumpPtr{opCalldataSize, true}
  39. jumpTable[CALLDATACOPY] = jumpPtr{opCalldataCopy, true}
  40. jumpTable[CODESIZE] = jumpPtr{opCodeSize, true}
  41. jumpTable[EXTCODESIZE] = jumpPtr{opExtCodeSize, true}
  42. jumpTable[CODECOPY] = jumpPtr{opCodeCopy, true}
  43. jumpTable[EXTCODECOPY] = jumpPtr{opExtCodeCopy, true}
  44. jumpTable[GASPRICE] = jumpPtr{opGasprice, true}
  45. jumpTable[BLOCKHASH] = jumpPtr{opBlockhash, true}
  46. jumpTable[COINBASE] = jumpPtr{opCoinbase, true}
  47. jumpTable[TIMESTAMP] = jumpPtr{opTimestamp, true}
  48. jumpTable[NUMBER] = jumpPtr{opNumber, true}
  49. jumpTable[DIFFICULTY] = jumpPtr{opDifficulty, true}
  50. jumpTable[GASLIMIT] = jumpPtr{opGasLimit, true}
  51. jumpTable[POP] = jumpPtr{opPop, true}
  52. jumpTable[MLOAD] = jumpPtr{opMload, true}
  53. jumpTable[MSTORE] = jumpPtr{opMstore, true}
  54. jumpTable[MSTORE8] = jumpPtr{opMstore8, true}
  55. jumpTable[SLOAD] = jumpPtr{opSload, true}
  56. jumpTable[SSTORE] = jumpPtr{opSstore, true}
  57. jumpTable[JUMPDEST] = jumpPtr{opJumpdest, true}
  58. jumpTable[PC] = jumpPtr{nil, true}
  59. jumpTable[MSIZE] = jumpPtr{opMsize, true}
  60. jumpTable[GAS] = jumpPtr{opGas, true}
  61. jumpTable[CREATE] = jumpPtr{nil, true}
  62. jumpTable[CALL] = jumpPtr{opCall, true}
  63. jumpTable[CALLCODE] = jumpPtr{opCallCode, true}
  64. jumpTable[DELEGATECALL] = jumpPtr{opDelegateCall, true}
  65. jumpTable[LOG0] = jumpPtr{makeLog(0), true}
  66. jumpTable[LOG1] = jumpPtr{makeLog(1), true}
  67. jumpTable[LOG2] = jumpPtr{makeLog(2), true}
  68. jumpTable[LOG3] = jumpPtr{makeLog(3), true}
  69. jumpTable[LOG4] = jumpPtr{makeLog(4), true}
  70. jumpTable[SWAP1] = jumpPtr{makeSwap(1), true}
  71. jumpTable[SWAP2] = jumpPtr{makeSwap(2), true}
  72. jumpTable[SWAP3] = jumpPtr{makeSwap(3), true}
  73. jumpTable[SWAP4] = jumpPtr{makeSwap(4), true}
  74. jumpTable[SWAP5] = jumpPtr{makeSwap(5), true}
  75. jumpTable[SWAP6] = jumpPtr{makeSwap(6), true}
  76. jumpTable[SWAP7] = jumpPtr{makeSwap(7), true}
  77. jumpTable[SWAP8] = jumpPtr{makeSwap(8), true}
  78. jumpTable[SWAP9] = jumpPtr{makeSwap(9), true}
  79. jumpTable[SWAP10] = jumpPtr{makeSwap(10), true}
  80. jumpTable[SWAP11] = jumpPtr{makeSwap(11), true}
  81. jumpTable[SWAP12] = jumpPtr{makeSwap(12), true}
  82. jumpTable[SWAP13] = jumpPtr{makeSwap(13), true}
  83. jumpTable[SWAP14] = jumpPtr{makeSwap(14), true}
  84. jumpTable[SWAP15] = jumpPtr{makeSwap(15), true}
  85. jumpTable[SWAP16] = jumpPtr{makeSwap(16), true}
  86. jumpTable[PUSH1] = jumpPtr{makePush(1, big.NewInt(1)), true}
  87. jumpTable[PUSH2] = jumpPtr{makePush(2, big.NewInt(2)), true}
  88. jumpTable[PUSH3] = jumpPtr{makePush(3, big.NewInt(3)), true}
  89. jumpTable[PUSH4] = jumpPtr{makePush(4, big.NewInt(4)), true}
  90. jumpTable[PUSH5] = jumpPtr{makePush(5, big.NewInt(5)), true}
  91. jumpTable[PUSH6] = jumpPtr{makePush(6, big.NewInt(6)), true}
  92. jumpTable[PUSH7] = jumpPtr{makePush(7, big.NewInt(7)), true}
  93. jumpTable[PUSH8] = jumpPtr{makePush(8, big.NewInt(8)), true}
  94. jumpTable[PUSH9] = jumpPtr{makePush(9, big.NewInt(9)), true}
  95. jumpTable[PUSH10] = jumpPtr{makePush(10, big.NewInt(10)), true}
  96. jumpTable[PUSH11] = jumpPtr{makePush(11, big.NewInt(11)), true}
  97. jumpTable[PUSH12] = jumpPtr{makePush(12, big.NewInt(12)), true}
  98. jumpTable[PUSH13] = jumpPtr{makePush(13, big.NewInt(13)), true}
  99. jumpTable[PUSH14] = jumpPtr{makePush(14, big.NewInt(14)), true}
  100. jumpTable[PUSH15] = jumpPtr{makePush(15, big.NewInt(15)), true}
  101. jumpTable[PUSH16] = jumpPtr{makePush(16, big.NewInt(16)), true}
  102. jumpTable[PUSH17] = jumpPtr{makePush(17, big.NewInt(17)), true}
  103. jumpTable[PUSH18] = jumpPtr{makePush(18, big.NewInt(18)), true}
  104. jumpTable[PUSH19] = jumpPtr{makePush(19, big.NewInt(19)), true}
  105. jumpTable[PUSH20] = jumpPtr{makePush(20, big.NewInt(20)), true}
  106. jumpTable[PUSH21] = jumpPtr{makePush(21, big.NewInt(21)), true}
  107. jumpTable[PUSH22] = jumpPtr{makePush(22, big.NewInt(22)), true}
  108. jumpTable[PUSH23] = jumpPtr{makePush(23, big.NewInt(23)), true}
  109. jumpTable[PUSH24] = jumpPtr{makePush(24, big.NewInt(24)), true}
  110. jumpTable[PUSH25] = jumpPtr{makePush(25, big.NewInt(25)), true}
  111. jumpTable[PUSH26] = jumpPtr{makePush(26, big.NewInt(26)), true}
  112. jumpTable[PUSH27] = jumpPtr{makePush(27, big.NewInt(27)), true}
  113. jumpTable[PUSH28] = jumpPtr{makePush(28, big.NewInt(28)), true}
  114. jumpTable[PUSH29] = jumpPtr{makePush(29, big.NewInt(29)), true}
  115. jumpTable[PUSH30] = jumpPtr{makePush(30, big.NewInt(30)), true}
  116. jumpTable[PUSH31] = jumpPtr{makePush(31, big.NewInt(31)), true}
  117. jumpTable[PUSH32] = jumpPtr{makePush(32, big.NewInt(32)), true}
  118. jumpTable[DUP1] = jumpPtr{makeDup(1), true}
  119. jumpTable[DUP2] = jumpPtr{makeDup(2), true}
  120. jumpTable[DUP3] = jumpPtr{makeDup(3), true}
  121. jumpTable[DUP4] = jumpPtr{makeDup(4), true}
  122. jumpTable[DUP5] = jumpPtr{makeDup(5), true}
  123. jumpTable[DUP6] = jumpPtr{makeDup(6), true}
  124. jumpTable[DUP7] = jumpPtr{makeDup(7), true}
  125. jumpTable[DUP8] = jumpPtr{makeDup(8), true}
  126. jumpTable[DUP9] = jumpPtr{makeDup(9), true}
  127. jumpTable[DUP10] = jumpPtr{makeDup(10), true}
  128. jumpTable[DUP11] = jumpPtr{makeDup(11), true}
  129. jumpTable[DUP12] = jumpPtr{makeDup(12), true}
  130. jumpTable[DUP13] = jumpPtr{makeDup(13), true}
  131. jumpTable[DUP14] = jumpPtr{makeDup(14), true}
  132. jumpTable[DUP15] = jumpPtr{makeDup(15), true}
  133. jumpTable[DUP16] = jumpPtr{makeDup(16), true}
  134. jumpTable[RETURN] = jumpPtr{nil, true}
  135. jumpTable[SUICIDE] = jumpPtr{nil, true}
  136. jumpTable[JUMP] = jumpPtr{nil, true}
  137. jumpTable[JUMPI] = jumpPtr{nil, true}
  138. jumpTable[STOP] = jumpPtr{nil, true}
  139. }