From 0cbb297c7bf7a81b54ec7c429e65367a78e901d6 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Tue, 2 Nov 2021 11:07:52 +0100 Subject: [PATCH] Non-interactive mode for yulopti. --- test/tools/yulopti.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index 752aaafa6..da5ae4871 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -162,6 +162,36 @@ public: } } + int runSteps(string source, string steps) + { + if (!parse(source)) + return 1; + + set reservedIdentifiers; + *m_ast = std::get(Disambiguator(m_dialect, *m_analysisInfo)(*m_ast)); + m_analysisInfo.reset(); + m_nameDispenser = make_shared(m_dialect, *m_ast, reservedIdentifiers); + + OptimiserStepContext context{ + m_dialect, + *m_nameDispenser, + reservedIdentifiers, + solidity::frontend::OptimiserSettings::standard().expectedExecutionsPerDeployment + }; + + map const& abbreviationMap = OptimiserSuite::stepAbbreviationToNameMap(); + for (char stepAbbreviation: steps) + if (auto abbreviationAndName = util::valueOrNullptr(abbreviationMap, stepAbbreviation)) + OptimiserSuite::allSteps().at(*abbreviationAndName)->run(context, *m_ast); + else + { + cerr << "Unknown optimizer step." << endl; + return 1; + } + cout << AsmPrinter{m_dialect}(*m_ast) << endl; + return 0; + } + void runInteractive(string source) { bool disambiguated = false; @@ -256,6 +286,11 @@ Allowed options)", po::value(), "input file" ) + ( + "steps", + po::value(), + "steps to execute non-interactively" + ) ("help", "Show this help screen."); // All positional options should be interpreted as input files @@ -292,7 +327,12 @@ Allowed options)", } if (arguments.count("input-file")) - YulOpti{}.runInteractive(input); + { + if (arguments.count("steps")) + return YulOpti{}.runSteps(input, arguments["steps"].as()); + else + YulOpti{}.runInteractive(input); + } else cout << options;