@@ -29,7 +29,6 @@ import (
29
29
"github.com/ethereum/evmc/bindings/go/evmc"
30
30
"github.com/ethereum/go-ethereum/common"
31
31
"github.com/ethereum/go-ethereum/core/types"
32
- "github.com/ethereum/go-ethereum/log"
33
32
"github.com/ethereum/go-ethereum/params"
34
33
)
35
34
@@ -47,48 +46,45 @@ var (
47
46
evmcInstance * evmc.Instance // The EVMC VM instance.
48
47
)
49
48
50
- // NewEVMC creates new EVMC-based VM execution context.
51
- func NewEVMC (config string , env * EVM ) * EVMC {
52
- createMu .Lock ()
53
- defer createMu .Unlock ()
54
-
55
- if evmcInstance == nil {
56
- options := strings .Split (config , "," )
57
- path := options [0 ]
49
+ func initEvmcModule (config string ) (* evmc.Instance , error ) {
50
+ options := strings .Split (config , "," )
51
+ path := options [0 ]
58
52
59
- if path == "" {
60
- panic ("EVMC VM path not provided, set --vm.(evm|ewasm)=/path/to/vm" )
61
- }
53
+ instance , err := evmc .Load (path )
54
+ if err != nil {
55
+ return nil , err
56
+ }
62
57
63
- var err error
64
- evmcInstance , err = evmc .Load (path )
65
- if err != nil {
66
- panic (err .Error ())
67
- }
68
- log .Info ("EVMC VM loaded" , "name" , evmcInstance .Name (), "version" , evmcInstance .Version (), "path" , path )
69
-
70
- for _ , option := range options [1 :] {
71
- if idx := strings .Index (option , "=" ); idx >= 0 {
72
- name := option [:idx ]
73
- value := option [idx + 1 :]
74
- err := evmcInstance .SetOption (name , value )
75
- if err == nil {
76
- log .Info ("EVMC VM option set" , "name" , name , "value" , value )
77
- } else {
78
- log .Warn ("EVMC VM option setting failed" , "name" , name , "error" , err )
79
- }
58
+ // log.Info("EVMC VM loaded", "name", instance.Name(), "version", instance.Version(), "path", path)
59
+ fmt .Printf ("EVMC VM loaded %s %s %s\n " , instance .Name (), instance .Version (), path )
60
+
61
+ for _ , option := range options [1 :] {
62
+ if idx := strings .Index (option , "=" ); idx >= 0 {
63
+ name := option [:idx ]
64
+ value := option [idx + 1 :]
65
+ err := instance .SetOption (name , value )
66
+ if err == nil {
67
+ // log.Info("EVMC VM option set", "name", name, "value", value)
68
+ fmt .Printf ("EVMC VM option set %s=%s\n " , name , value )
69
+ } else {
70
+ return nil , fmt .Errorf ("EVMC VM option setting failed '%s=%s'" , name , value )
80
71
}
81
72
}
73
+ }
82
74
83
- evm1Cap := evmcInstance .HasCapability (evmc .CapabilityEVM1 )
84
- ewasmCap := evmcInstance .HasCapability (evmc .CapabilityEWASM )
85
- log .Info ("EVMC VM capabilities" , "evm1" , evm1Cap , "ewasm" , ewasmCap )
75
+ evm1Cap := instance .HasCapability (evmc .CapabilityEVM1 )
76
+ ewasmCap := instance .HasCapability (evmc .CapabilityEWASM )
77
+ // log.Info("EVMC VM capabilities", "evm1", evm1Cap, "ewasm", ewasmCap)
78
+ fmt .Printf ("EVMC VM capabilities: evm=%t ewasm=%t\n " , evm1Cap , ewasmCap )
86
79
87
- evmcConfig = config // Remember the config.
88
- } else if evmcConfig != config {
89
- log .Error ("New EVMC VM requested" , "newconfig" , config , "oldconfig" , evmcConfig )
90
- }
80
+ return instance , nil
81
+ }
91
82
83
+ // NewEVMC creates new EVMC-based VM execution context.
84
+ func NewEVMC (config string , env * EVM ) * EVMC {
85
+ if evmcInstance == nil {
86
+ panic ("EVMC module not loaded" )
87
+ }
92
88
return & EVMC {evmcInstance , env , false }
93
89
}
94
90
0 commit comments