diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2017-01-05 18:52:10 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-01-05 18:52:10 +0800 |
commit | bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88 (patch) | |
tree | d4743eaa073d1bc7788f5d4fc3771da37f3cb0b5 /core/vm/jit_util.go | |
parent | 2126d8148806b6d8597d6a1c761080e9dc98d745 (diff) | |
download | go-tangerine-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar go-tangerine-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.gz go-tangerine-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.bz2 go-tangerine-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.lz go-tangerine-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.xz go-tangerine-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.zst go-tangerine-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.zip |
core/vm: improved EVM run loop & instruction calling (#3378)
The run loop, which previously contained custom opcode executes have been
removed and has been simplified to a few checks.
Each operation consists of 4 elements: execution function, gas cost function,
stack validation function and memory size function. The execution function
implements the operation's runtime behaviour, the gas cost function implements
the operation gas costs function and greatly depends on the memory and stack,
the stack validation function validates the stack and makes sure that enough
items can be popped off and pushed on and the memory size function calculates
the memory required for the operation and returns it.
This commit also allows the EVM to go unmetered. This is helpful for offline
operations such as contract calls.
Diffstat (limited to 'core/vm/jit_util.go')
-rw-r--r-- | core/vm/jit_util.go | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/core/vm/jit_util.go b/core/vm/jit_util.go deleted file mode 100644 index 947dae88f..000000000 --- a/core/vm/jit_util.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -package vm - -// Parse parses all opcodes from the given code byte slice. This function -// performs no error checking and may return non-existing opcodes. -func Parse(code []byte) (opcodes []OpCode) { - for pc := uint64(0); pc < uint64(len(code)); pc++ { - op := OpCode(code[pc]) - - switch op { - 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: - a := uint64(op) - uint64(PUSH1) + 1 - pc += a - opcodes = append(opcodes, PUSH) - case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16: - opcodes = append(opcodes, DUP) - case SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16: - opcodes = append(opcodes, SWAP) - default: - opcodes = append(opcodes, op) - } - } - - return opcodes -} - -// MatchFn searcher for match in the given input and calls matcheFn if it finds -// an appropriate match. matcherFn yields the starting position in the input. -// MatchFn will continue to search for a match until it reaches the end of the -// buffer or if matcherFn return false. -func MatchFn(input, match []OpCode, matcherFn func(int) bool) { - // short circuit if either input or match is empty or if the match is - // greater than the input - if len(input) == 0 || len(match) == 0 || len(match) > len(input) { - return - } - -main: - for i, op := range input[:len(input)+1-len(match)] { - // match first opcode and continue search - if op == match[0] { - for j := 1; j < len(match); j++ { - if input[i+j] != match[j] { - continue main - } - } - // check for abort instruction - if !matcherFn(i) { - return - } - } - } -} |