github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/cmd/evm/compiler.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:27</date> 10 //</624342589776072704> 11 12 13 package main 14 15 import ( 16 "errors" 17 "fmt" 18 "io/ioutil" 19 20 "github.com/ethereum/go-ethereum/cmd/evm/internal/compiler" 21 22 cli "gopkg.in/urfave/cli.v1" 23 ) 24 25 var compileCommand = cli.Command{ 26 Action: compileCmd, 27 Name: "compile", 28 Usage: "compiles easm source to evm binary", 29 ArgsUsage: "<file>", 30 } 31 32 func compileCmd(ctx *cli.Context) error { 33 debug := ctx.GlobalBool(DebugFlag.Name) 34 35 if len(ctx.Args().First()) == 0 { 36 return errors.New("filename required") 37 } 38 39 fn := ctx.Args().First() 40 src, err := ioutil.ReadFile(fn) 41 if err != nil { 42 return err 43 } 44 45 bin, err := compiler.Compile(fn, src, debug) 46 if err != nil { 47 return err 48 } 49 fmt.Println(bin) 50 return nil 51 } 52