Skip to content

Commit f30733c

Browse files
committed
cmd/evm: removed -sysstat and moved content to -debug flag
Added the ability to directly compile and run ethereum assembly using the evm utility: `evm run <file>`. This is equivalant to `evm compile <file> | evm run`.
1 parent bf41558 commit f30733c

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

‎cmd/evm/main.go‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ var (
6666
Name: "input",
6767
Usage: "input for the EVM",
6868
}
69-
SysStatFlag = cli.BoolFlag{
70-
Name: "sysstat",
71-
Usage: "display system stats",
72-
}
7369
VerbosityFlag = cli.IntFlag{
7470
Name: "verbosity",
7571
Usage: "sets the verbosity level",
@@ -89,7 +85,6 @@ func init() {
8985
CreateFlag,
9086
DebugFlag,
9187
VerbosityFlag,
92-
SysStatFlag,
9388
CodeFlag,
9489
CodeFileFlag,
9590
GasFlag,

‎cmd/evm/runner.go‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
goruntime "runtime"
2727

28+
"github.com/ethereum/go-ethereum/cmd/evm/internal/compiler"
2829
"github.com/ethereum/go-ethereum/cmd/utils"
2930
"github.com/ethereum/go-ethereum/common"
3031
"github.com/ethereum/go-ethereum/core/state"
@@ -61,7 +62,18 @@ func runCmd(ctx *cli.Context) error {
6162
ret []byte
6263
err error
6364
)
64-
if ctx.GlobalString(CodeFlag.Name) != "" {
65+
if fn := ctx.Args().First(); len(fn) > 0 {
66+
src, err := ioutil.ReadFile(fn)
67+
if err != nil {
68+
return err
69+
}
70+
71+
bin, err := compiler.Compile(fn, src, false)
72+
if err != nil {
73+
return err
74+
}
75+
code = common.Hex2Bytes(bin)
76+
} else if ctx.GlobalString(CodeFlag.Name) != "" {
6577
code = common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name))
6678
} else {
6779
var hexcode []byte
@@ -106,7 +118,7 @@ func runCmd(ctx *cli.Context) error {
106118

107119
ret, err = runtime.Call(receiver, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), &runtimeConfig)
108120
}
109-
vmdone := time.Since(tstart)
121+
execTime := time.Since(tstart)
110122

111123
if ctx.GlobalBool(DumpFlag.Name) {
112124
statedb.Commit(true)
@@ -118,19 +130,16 @@ func runCmd(ctx *cli.Context) error {
118130
vm.WriteTrace(os.Stderr, logger.StructLogs())
119131
fmt.Fprintln(os.Stderr, "#### LOGS ####")
120132
vm.WriteLogs(os.Stderr, statedb.Logs())
121-
}
122133

123-
if ctx.GlobalBool(SysStatFlag.Name) {
124134
var mem goruntime.MemStats
125135
goruntime.ReadMemStats(&mem)
126-
fmt.Printf("vm took %v\n", vmdone)
127-
fmt.Printf(`alloc: %d
128-
tot alloc: %d
129-
no. malloc: %d
130-
heap alloc: %d
131-
heap objs: %d
132-
num gc: %d
133-
`, mem.Alloc, mem.TotalAlloc, mem.Mallocs, mem.HeapAlloc, mem.HeapObjects, mem.NumGC)
136+
fmt.Fprintf(os.Stderr, `evm execution time: %v
137+
heap objects: %d
138+
allocations: %d
139+
total allocations: %d
140+
GC calls: %d
141+
142+
`, execTime, mem.HeapObjects, mem.Alloc, mem.TotalAlloc, mem.NumGC)
134143
}
135144

136145
fmt.Printf("0x%x", ret)

0 commit comments

Comments
 (0)