From da29332c5f4c368ff03ec4e7132eefac48fed1ae Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Thu, 20 Sep 2018 09:44:35 +0200 Subject: core/vm: add switches to select evm+ewasm interpreters (#17687) Interpreter initialization is left to the PRs implementing them. Options for external interpreters are passed after a colon in the `--vm.ewasm` and `--vm.evm` switches. --- core/vm/evm.go | 22 ++++++++++++++++++++-- core/vm/interpreter.go | 5 +++++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'core/vm') diff --git a/core/vm/evm.go b/core/vm/evm.go index 58618f811..fc040c621 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -136,10 +136,28 @@ func NewEVM(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmCon vmConfig: vmConfig, chainConfig: chainConfig, chainRules: chainConfig.Rules(ctx.BlockNumber), - interpreters: make([]Interpreter, 1), + interpreters: make([]Interpreter, 0, 1), } - evm.interpreters[0] = NewEVMInterpreter(evm, vmConfig) + if chainConfig.IsEWASM(ctx.BlockNumber) { + // to be implemented by EVM-C and Wagon PRs. + // if vmConfig.EWASMInterpreter != "" { + // extIntOpts := strings.Split(vmConfig.EWASMInterpreter, ":") + // path := extIntOpts[0] + // options := []string{} + // if len(extIntOpts) > 1 { + // options = extIntOpts[1..] + // } + // evm.interpreters = append(evm.interpreters, NewEVMVCInterpreter(evm, vmConfig, options)) + // } else { + // evm.interpreters = append(evm.interpreters, NewEWASMInterpreter(evm, vmConfig)) + // } + panic("No supported ewasm interpreter yet.") + } + + // vmConfig.EVMInterpreter will be used by EVM-C, it won't be checked here + // as we always want to have the built-in EVM as the failover option. + evm.interpreters = append(evm.interpreters, NewEVMInterpreter(evm, vmConfig)) evm.interpreter = evm.interpreters[0] return evm diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 0f1b07342..8e934f60e 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -39,6 +39,11 @@ type Config struct { // may be left uninitialised and will be set to the default // table. JumpTable [256]operation + + // Type of the EWASM interpreter + EWASMInterpreter string + // Type of the EVM interpreter + EVMInterpreter string } // Interpreter is used to run Ethereum based contracts and will utilise the -- cgit v1.2.3