Skip to content

Commit fc6671c

Browse files
authored
Merge pull request #546 from rorye/adding-optimize-runs-parameter
Adding parameter to solcjs for the optimizer run option
2 parents a173d83 + f2995aa commit fc6671c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

solcjs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,31 @@ process.removeAllListeners('uncaughtException');
1515
var commander = require('commander');
1616

1717
const program = new commander.Command();
18+
const commanderParseInt = function(value) {
19+
const parsedValue = parseInt(value, 10);
20+
if (isNaN(parsedValue)) {
21+
throw new commander.InvalidArgumentError("Not a valid integer.");
22+
}
23+
return parsedValue;
24+
};
25+
1826
program.name('solcjs');
1927
program.version(solc.version());
2028
program
2129
.option('--version', 'Show version and exit.')
2230
.option('--optimize', 'Enable bytecode optimizer.', false)
31+
.option(
32+
'--optimize-runs <optimize-runs>',
33+
'The number of runs specifies roughly how often each opcode of the deployed code will be executed across the lifetime of the contract. ' +
34+
'Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage.',
35+
commanderParseInt
36+
)
2337
.option('--bin', 'Binary of the contracts in hex.')
2438
.option('--abi', 'ABI of the contracts.')
2539
.option('--standard-json', 'Turn on Standard JSON Input / Output mode.')
2640
.option('--base-path <path>', 'Automatically resolve all imports inside the given path.')
2741
.option('-o, --output-dir <output-directory>', 'Output directory for the contracts.');
42+
2843
program.parse(process.argv);
2944
const options = program.opts();
3045

@@ -131,7 +146,8 @@ var output = JSON.parse(solc.compile(JSON.stringify({
131146
language: 'Solidity',
132147
settings: {
133148
optimizer: {
134-
enabled: options.optimize
149+
enabled: options.optimize,
150+
runs: options.optimizeRuns,
135151
},
136152
outputSelection: {
137153
'*': {

test/cli.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ tape('CLI', function (t) {
3737
spt.end();
3838
});
3939

40+
t.test('--bin --optimize-runs 666', function (st) {
41+
var spt = spawn(st, './solcjs --bin --optimize-runs 666 test/resources/fixtureSmoke.sol');
42+
spt.stderr.empty();
43+
spt.succeeds();
44+
spt.end();
45+
});
46+
47+
t.test('--bin --optimize-runs not-a-number', function (st) {
48+
var spt = spawn(st, './solcjs --bin --optimize-runs not-a-number test/resources/fixtureSmoke.sol');
49+
spt.stderr.match(/^error: option '--optimize-runs <optimize-runs>' argument 'not-a-number' is invalid/);
50+
spt.end();
51+
});
52+
4053
t.test('invalid file specified', function (st) {
4154
var spt = spawn(st, './solcjs --bin test/fileNotFound.sol');
4255
spt.stderr.match(/^Error reading /);

0 commit comments

Comments
 (0)