Skip to content

Commit 0cbb297

Browse files
committed
Non-interactive mode for yulopti.
1 parent 696964d commit 0cbb297

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

test/tools/yulopti.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,36 @@ class YulOpti
162162
}
163163
}
164164

165+
int runSteps(string source, string steps)
166+
{
167+
if (!parse(source))
168+
return 1;
169+
170+
set<YulString> reservedIdentifiers;
171+
*m_ast = std::get<yul::Block>(Disambiguator(m_dialect, *m_analysisInfo)(*m_ast));
172+
m_analysisInfo.reset();
173+
m_nameDispenser = make_shared<NameDispenser>(m_dialect, *m_ast, reservedIdentifiers);
174+
175+
OptimiserStepContext context{
176+
m_dialect,
177+
*m_nameDispenser,
178+
reservedIdentifiers,
179+
solidity::frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment
180+
};
181+
182+
map<char, string> const& abbreviationMap = OptimiserSuite::stepAbbreviationToNameMap();
183+
for (char stepAbbreviation: steps)
184+
if (auto abbreviationAndName = util::valueOrNullptr(abbreviationMap, stepAbbreviation))
185+
OptimiserSuite::allSteps().at(*abbreviationAndName)->run(context, *m_ast);
186+
else
187+
{
188+
cerr << "Unknown optimizer step." << endl;
189+
return 1;
190+
}
191+
cout << AsmPrinter{m_dialect}(*m_ast) << endl;
192+
return 0;
193+
}
194+
165195
void runInteractive(string source)
166196
{
167197
bool disambiguated = false;
@@ -256,6 +286,11 @@ Allowed options)",
256286
po::value<string>(),
257287
"input file"
258288
)
289+
(
290+
"steps",
291+
po::value<string>(),
292+
"steps to execute non-interactively"
293+
)
259294
("help", "Show this help screen.");
260295

261296
// All positional options should be interpreted as input files
@@ -292,7 +327,12 @@ Allowed options)",
292327
}
293328

294329
if (arguments.count("input-file"))
295-
YulOpti{}.runInteractive(input);
330+
{
331+
if (arguments.count("steps"))
332+
return YulOpti{}.runSteps(input, arguments["steps"].as<string>());
333+
else
334+
YulOpti{}.runInteractive(input);
335+
}
296336
else
297337
cout << options;
298338

0 commit comments

Comments
 (0)