mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
core/vm: Add support for --vm.ewasm option for EVMC
This commit is contained in:
parent
abe7715f1f
commit
651c2a9b89
2 changed files with 22 additions and 19 deletions
|
|
@ -19,6 +19,7 @@ package vm
|
|||
import (
|
||||
"math/big"
|
||||
"os"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
|
|
@ -141,23 +142,21 @@ func NewEVM(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmCon
|
|||
}
|
||||
|
||||
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))
|
||||
// }
|
||||
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, NewEVMC(path, options, evm))
|
||||
} else {
|
||||
panic("No supported ewasm interpreter yet.")
|
||||
}
|
||||
}
|
||||
|
||||
if len(vmConfig.EVMInterpreter) != 0 || len(os.Getenv("EVMC_PATH")) != 0 {
|
||||
evm.interpreters = append(evm.interpreters, NewEVMC(vmConfig.EVMInterpreter, evm))
|
||||
evm.interpreters = append(evm.interpreters, NewEVMC(vmConfig.EVMInterpreter, nil, evm))
|
||||
}
|
||||
|
||||
// vmConfig.EVMInterpreter will be used by EVM-C, it won't be checked here
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ var (
|
|||
evmcInstance *evmc.Instance
|
||||
)
|
||||
|
||||
func createVM(path string) *evmc.Instance {
|
||||
func createVM(path string, options []string) *evmc.Instance {
|
||||
createMu.Lock()
|
||||
defer createMu.Unlock()
|
||||
|
||||
|
|
@ -62,7 +62,10 @@ func createVM(path string) *evmc.Instance {
|
|||
}
|
||||
log.Info("EVMC VM loaded", "name", evmcInstance.Name(), "version", evmcInstance.Version(), "path", vmPath)
|
||||
|
||||
for _, option := range strings.Split(os.Getenv("EVMC_OPTIONS"), " ") {
|
||||
opts := strings.Split(os.Getenv("EVMC_OPTIONS"), " ")
|
||||
opts = append(opts, options...)
|
||||
|
||||
for _, option := range opts {
|
||||
if idx := strings.Index(option, "="); idx >= 0 {
|
||||
name := option[:idx]
|
||||
value := option[idx+1:]
|
||||
|
|
@ -78,8 +81,8 @@ func createVM(path string) *evmc.Instance {
|
|||
return evmcInstance
|
||||
}
|
||||
|
||||
func NewEVMC(path string, env *EVM) *EVMC {
|
||||
return &EVMC{createVM(path), env, false}
|
||||
func NewEVMC(path string, options []string, env *EVM) *EVMC {
|
||||
return &EVMC{createVM(path, options), env, false}
|
||||
}
|
||||
|
||||
// Implements evmc.HostContext interface.
|
||||
|
|
@ -309,7 +312,8 @@ func (evm *EVMC) Run(contract *Contract, input []byte, readOnly bool) (ret []byt
|
|||
|
||||
func (evm *EVMC) CanRun(code []byte) bool {
|
||||
cap := evmc.CapabilityEVM1
|
||||
if (bytes.Equal(code[0:4], []byte("\x00asm"))) {
|
||||
wasmPreamble := []byte("\x00asm\x01\x00\x00\x00")
|
||||
if (bytes.HasPrefix(code, wasmPreamble)) {
|
||||
cap = evmc.CapabilityEWASM
|
||||
}
|
||||
// FIXME: Optimize. Access capabilities once.
|
||||
|
|
|
|||
Loading…
Reference in a new issue