mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
common/compiler: support 'optimize-runs' arg for solc
This commit is contained in:
parent
6a2d2869f6
commit
b940dd529a
2 changed files with 11 additions and 1 deletions
|
|
@ -31,6 +31,8 @@ import (
|
||||||
|
|
||||||
var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
|
var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
|
||||||
|
|
||||||
|
var optimizeRuns int64 = 200
|
||||||
|
|
||||||
type Contract struct {
|
type Contract struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Info ContractInfo `json:"info"`
|
Info ContractInfo `json:"info"`
|
||||||
|
|
@ -67,12 +69,20 @@ func (s *Solidity) makeArgs() []string {
|
||||||
"--combined-json", "bin,abi,userdoc,devdoc",
|
"--combined-json", "bin,abi,userdoc,devdoc",
|
||||||
"--optimize", // code optimizer switched on
|
"--optimize", // code optimizer switched on
|
||||||
}
|
}
|
||||||
|
if optimizeRuns != 200 {
|
||||||
|
p = append(p, "-optimize-runs",strconv.FormatInt(optimizeRuns, 10))
|
||||||
|
}
|
||||||
if s.Major > 0 || s.Minor > 4 || s.Patch > 6 {
|
if s.Major > 0 || s.Minor > 4 || s.Patch > 6 {
|
||||||
p[1] += ",metadata"
|
p[1] += ",metadata"
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetOptimizeRuns set the number of optimize runs for solc
|
||||||
|
func SetOptimizeRuns(_optimizeRuns int64) {
|
||||||
|
optimizeRuns = _optimizeRuns
|
||||||
|
}
|
||||||
|
|
||||||
// SolidityVersion runs solc and parses its version output.
|
// SolidityVersion runs solc and parses its version output.
|
||||||
func SolidityVersion(solc string) (*Solidity, error) {
|
func SolidityVersion(solc string) (*Solidity, error) {
|
||||||
if solc == "" {
|
if solc == "" {
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ func skipWithoutSolc(t *testing.T) {
|
||||||
|
|
||||||
func TestCompiler(t *testing.T) {
|
func TestCompiler(t *testing.T) {
|
||||||
skipWithoutSolc(t)
|
skipWithoutSolc(t)
|
||||||
|
SetOptimizeRuns(2000)
|
||||||
contracts, err := CompileSolidityString("", testSource)
|
contracts, err := CompileSolidityString("", testSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error compiling source. result %v: %v", contracts, err)
|
t.Fatalf("error compiling source. result %v: %v", contracts, err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue