github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/cmd/evm/compiler.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package main 13 14 import ( 15 "errors" 16 "fmt" 17 "io/ioutil" 18 19 "github.com/Sberex/go-sberex/cmd/evm/internal/compiler" 20 21 cli "gopkg.in/urfave/cli.v1" 22 ) 23 24 var compileCommand = cli.Command{ 25 Action: compileCmd, 26 Name: "compile", 27 Usage: "compiles easm source to evm binary", 28 ArgsUsage: "<file>", 29 } 30 31 func compileCmd(ctx *cli.Context) error { 32 debug := ctx.GlobalBool(DebugFlag.Name) 33 34 if len(ctx.Args().First()) == 0 { 35 return errors.New("filename required") 36 } 37 38 fn := ctx.Args().First() 39 src, err := ioutil.ReadFile(fn) 40 if err != nil { 41 return err 42 } 43 44 bin, err := compiler.Compile(fn, src, debug) 45 if err != nil { 46 return err 47 } 48 fmt.Println(bin) 49 return nil 50 }