jump_table.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package vm
  17. import (
  18. "math/big"
  19. "github.com/ethereum/go-ethereum/params"
  20. )
  21. type jumpPtr struct {
  22. fn instrFn
  23. valid bool
  24. }
  25. type vmJumpTable [256]jumpPtr
  26. func newJumpTable(ruleset *params.ChainConfig, blockNumber *big.Int) vmJumpTable {
  27. var jumpTable vmJumpTable
  28. // when initialising a new VM execution we must first check the homestead
  29. // changes.
  30. if ruleset.IsHomestead(blockNumber) {
  31. jumpTable[DELEGATECALL] = jumpPtr{opDelegateCall, true}
  32. }
  33. jumpTable[ADD] = jumpPtr{opAdd, true}
  34. jumpTable[SUB] = jumpPtr{opSub, true}
  35. jumpTable[MUL] = jumpPtr{opMul, true}
  36. jumpTable[DIV] = jumpPtr{opDiv, true}
  37. jumpTable[SDIV] = jumpPtr{opSdiv, true}
  38. jumpTable[MOD] = jumpPtr{opMod, true}
  39. jumpTable[SMOD] = jumpPtr{opSmod, true}
  40. jumpTable[EXP] = jumpPtr{opExp, true}
  41. jumpTable[SIGNEXTEND] = jumpPtr{opSignExtend, true}
  42. jumpTable[NOT] = jumpPtr{opNot, true}
  43. jumpTable[LT] = jumpPtr{opLt, true}
  44. jumpTable[GT] = jumpPtr{opGt, true}
  45. jumpTable[SLT] = jumpPtr{opSlt, true}
  46. jumpTable[SGT] = jumpPtr{opSgt, true}
  47. jumpTable[EQ] = jumpPtr{opEq, true}
  48. jumpTable[ISZERO] = jumpPtr{opIszero, true}
  49. jumpTable[AND] = jumpPtr{opAnd, true}
  50. jumpTable[OR] = jumpPtr{opOr, true}
  51. jumpTable[XOR] = jumpPtr{opXor, true}
  52. jumpTable[BYTE] = jumpPtr{opByte, true}
  53. jumpTable[ADDMOD] = jumpPtr{opAddmod, true}
  54. jumpTable[MULMOD] = jumpPtr{opMulmod, true}
  55. jumpTable[SHA3] = jumpPtr{opSha3, true}
  56. jumpTable[ADDRESS] = jumpPtr{opAddress, true}
  57. jumpTable[BALANCE] = jumpPtr{opBalance, true}
  58. jumpTable[ORIGIN] = jumpPtr{opOrigin, true}
  59. jumpTable[CALLER] = jumpPtr{opCaller, true}
  60. jumpTable[CALLVALUE] = jumpPtr{opCallValue, true}
  61. jumpTable[CALLDATALOAD] = jumpPtr{opCalldataLoad, true}
  62. jumpTable[CALLDATASIZE] = jumpPtr{opCalldataSize, true}
  63. jumpTable[CALLDATACOPY] = jumpPtr{opCalldataCopy, true}
  64. jumpTable[CODESIZE] = jumpPtr{opCodeSize, true}
  65. jumpTable[EXTCODESIZE] = jumpPtr{opExtCodeSize, true}
  66. jumpTable[CODECOPY] = jumpPtr{opCodeCopy, true}
  67. jumpTable[EXTCODECOPY] = jumpPtr{opExtCodeCopy, true}
  68. jumpTable[GASPRICE] = jumpPtr{opGasprice, true}
  69. jumpTable[BLOCKHASH] = jumpPtr{opBlockhash, true}
  70. jumpTable[COINBASE] = jumpPtr{opCoinbase, true}
  71. jumpTable[TIMESTAMP] = jumpPtr{opTimestamp, true}
  72. jumpTable[NUMBER] = jumpPtr{opNumber, true}
  73. jumpTable[DIFFICULTY] = jumpPtr{opDifficulty, true}
  74. jumpTable[GASLIMIT] = jumpPtr{opGasLimit, true}
  75. jumpTable[POP] = jumpPtr{opPop, true}
  76. jumpTable[MLOAD] = jumpPtr{opMload, true}
  77. jumpTable[MSTORE] = jumpPtr{opMstore, true}
  78. jumpTable[MSTORE8] = jumpPtr{opMstore8, true}
  79. jumpTable[SLOAD] = jumpPtr{opSload, true}
  80. jumpTable[SSTORE] = jumpPtr{opSstore, true}
  81. jumpTable[JUMPDEST] = jumpPtr{opJumpdest, true}
  82. jumpTable[PC] = jumpPtr{nil, true}
  83. jumpTable[MSIZE] = jumpPtr{opMsize, true}
  84. jumpTable[GAS] = jumpPtr{opGas, true}
  85. jumpTable[CREATE] = jumpPtr{opCreate, true}
  86. jumpTable[CALL] = jumpPtr{opCall, true}
  87. jumpTable[CALLCODE] = jumpPtr{opCallCode, true}
  88. jumpTable[LOG0] = jumpPtr{makeLog(0), true}
  89. jumpTable[LOG1] = jumpPtr{makeLog(1), true}
  90. jumpTable[LOG2] = jumpPtr{makeLog(2), true}
  91. jumpTable[LOG3] = jumpPtr{makeLog(3), true}
  92. jumpTable[LOG4] = jumpPtr{makeLog(4), true}
  93. jumpTable[SWAP1] = jumpPtr{makeSwap(1), true}
  94. jumpTable[SWAP2] = jumpPtr{makeSwap(2), true}
  95. jumpTable[SWAP3] = jumpPtr{makeSwap(3), true}
  96. jumpTable[SWAP4] = jumpPtr{makeSwap(4), true}
  97. jumpTable[SWAP5] = jumpPtr{makeSwap(5), true}
  98. jumpTable[SWAP6] = jumpPtr{makeSwap(6), true}
  99. jumpTable[SWAP7] = jumpPtr{makeSwap(7), true}
  100. jumpTable[SWAP8] = jumpPtr{makeSwap(8), true}
  101. jumpTable[SWAP9] = jumpPtr{makeSwap(9), true}
  102. jumpTable[SWAP10] = jumpPtr{makeSwap(10), true}
  103. jumpTable[SWAP11] = jumpPtr{makeSwap(11), true}
  104. jumpTable[SWAP12] = jumpPtr{makeSwap(12), true}
  105. jumpTable[SWAP13] = jumpPtr{makeSwap(13), true}
  106. jumpTable[SWAP14] = jumpPtr{makeSwap(14), true}
  107. jumpTable[SWAP15] = jumpPtr{makeSwap(15), true}
  108. jumpTable[SWAP16] = jumpPtr{makeSwap(16), true}
  109. jumpTable[PUSH1] = jumpPtr{makePush(1, big.NewInt(1)), true}
  110. jumpTable[PUSH2] = jumpPtr{makePush(2, big.NewInt(2)), true}
  111. jumpTable[PUSH3] = jumpPtr{makePush(3, big.NewInt(3)), true}
  112. jumpTable[PUSH4] = jumpPtr{makePush(4, big.NewInt(4)), true}
  113. jumpTable[PUSH5] = jumpPtr{makePush(5, big.NewInt(5)), true}
  114. jumpTable[PUSH6] = jumpPtr{makePush(6, big.NewInt(6)), true}
  115. jumpTable[PUSH7] = jumpPtr{makePush(7, big.NewInt(7)), true}
  116. jumpTable[PUSH8] = jumpPtr{makePush(8, big.NewInt(8)), true}
  117. jumpTable[PUSH9] = jumpPtr{makePush(9, big.NewInt(9)), true}
  118. jumpTable[PUSH10] = jumpPtr{makePush(10, big.NewInt(10)), true}
  119. jumpTable[PUSH11] = jumpPtr{makePush(11, big.NewInt(11)), true}
  120. jumpTable[PUSH12] = jumpPtr{makePush(12, big.NewInt(12)), true}
  121. jumpTable[PUSH13] = jumpPtr{makePush(13, big.NewInt(13)), true}
  122. jumpTable[PUSH14] = jumpPtr{makePush(14, big.NewInt(14)), true}
  123. jumpTable[PUSH15] = jumpPtr{makePush(15, big.NewInt(15)), true}
  124. jumpTable[PUSH16] = jumpPtr{makePush(16, big.NewInt(16)), true}
  125. jumpTable[PUSH17] = jumpPtr{makePush(17, big.NewInt(17)), true}
  126. jumpTable[PUSH18] = jumpPtr{makePush(18, big.NewInt(18)), true}
  127. jumpTable[PUSH19] = jumpPtr{makePush(19, big.NewInt(19)), true}
  128. jumpTable[PUSH20] = jumpPtr{makePush(20, big.NewInt(20)), true}
  129. jumpTable[PUSH21] = jumpPtr{makePush(21, big.NewInt(21)), true}
  130. jumpTable[PUSH22] = jumpPtr{makePush(22, big.NewInt(22)), true}
  131. jumpTable[PUSH23] = jumpPtr{makePush(23, big.NewInt(23)), true}
  132. jumpTable[PUSH24] = jumpPtr{makePush(24, big.NewInt(24)), true}
  133. jumpTable[PUSH25] = jumpPtr{makePush(25, big.NewInt(25)), true}
  134. jumpTable[PUSH26] = jumpPtr{makePush(26, big.NewInt(26)), true}
  135. jumpTable[PUSH27] = jumpPtr{makePush(27, big.NewInt(27)), true}
  136. jumpTable[PUSH28] = jumpPtr{makePush(28, big.NewInt(28)), true}
  137. jumpTable[PUSH29] = jumpPtr{makePush(29, big.NewInt(29)), true}
  138. jumpTable[PUSH30] = jumpPtr{makePush(30, big.NewInt(30)), true}
  139. jumpTable[PUSH31] = jumpPtr{makePush(31, big.NewInt(31)), true}
  140. jumpTable[PUSH32] = jumpPtr{makePush(32, big.NewInt(32)), true}
  141. jumpTable[DUP1] = jumpPtr{makeDup(1), true}
  142. jumpTable[DUP2] = jumpPtr{makeDup(2), true}
  143. jumpTable[DUP3] = jumpPtr{makeDup(3), true}
  144. jumpTable[DUP4] = jumpPtr{makeDup(4), true}
  145. jumpTable[DUP5] = jumpPtr{makeDup(5), true}
  146. jumpTable[DUP6] = jumpPtr{makeDup(6), true}
  147. jumpTable[DUP7] = jumpPtr{makeDup(7), true}
  148. jumpTable[DUP8] = jumpPtr{makeDup(8), true}
  149. jumpTable[DUP9] = jumpPtr{makeDup(9), true}
  150. jumpTable[DUP10] = jumpPtr{makeDup(10), true}
  151. jumpTable[DUP11] = jumpPtr{makeDup(11), true}
  152. jumpTable[DUP12] = jumpPtr{makeDup(12), true}
  153. jumpTable[DUP13] = jumpPtr{makeDup(13), true}
  154. jumpTable[DUP14] = jumpPtr{makeDup(14), true}
  155. jumpTable[DUP15] = jumpPtr{makeDup(15), true}
  156. jumpTable[DUP16] = jumpPtr{makeDup(16), true}
  157. jumpTable[RETURN] = jumpPtr{nil, true}
  158. jumpTable[SUICIDE] = jumpPtr{nil, true}
  159. jumpTable[JUMP] = jumpPtr{nil, true}
  160. jumpTable[JUMPI] = jumpPtr{nil, true}
  161. jumpTable[STOP] = jumpPtr{nil, true}
  162. return jumpTable
  163. }