Add --yul-optimizations option to the command-line interface

This commit is contained in:
Kamil Śliwak committed 2020-04-24 17:30:56 +02:00
1 parent c41a832f65
commit 35cc64e33d
20 files changed
+105 -2

No files matched your search

+28 -2
View File
@@ -37,6 +37,7 @@
#include <libsolidity/interface/StorageLayout.h>
#include <libyul/AssemblyStack.h>
#include <libyul/optimiser/Suite.h>
#include <libevmasm/Instruction.h>
#include <libevmasm/GasMeter.h>
@@ -145,6 +146,7 @@ static string const g_strOpcodes = "opcodes";
static string const g_strOptimize = "optimize";
static string const g_strOptimizeRuns = "optimize-runs";
static string const g_strOptimizeYul = "optimize-yul";
static string const g_strYulOptimizations = "yul-optimizations";
static string const g_strOutputDir = "output-dir";
static string const g_strOverwrite = "overwrite";
static string const g_strRevertStrings = "revert-strings";
@@ -781,7 +783,6 @@ Allowed options)",
"Import ASTs to be compiled, assumes input holds the AST in compact JSON format. "
"Supported Inputs is the output of the --standard-json or the one produced by --combined-json ast,compact-format"
)
(
g_argAssemble.c_str(),
"Switch to assembly mode, ignoring all options except --machine, --yul-dialect and --optimize and assumes input is assembly."
@@ -835,7 +836,12 @@ Allowed options)",
"Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage."
)
(g_strOptimizeYul.c_str(), "Legacy option, ignored. Use the general --optimize to enable Yul optimizer.")
(g_strNoOptimizeYul.c_str(), "Disable Yul optimizer in Solidity.");
(g_strNoOptimizeYul.c_str(), "Disable Yul optimizer in Solidity.")
(
g_strYulOptimizations.c_str(),
po::value<string>()->value_name("steps"),
"Forces yul optimizer to use the specified sequence of optimization steps instead of the built-in one."
);
desc.add(optimizerOptions);
po::options_description outputComponents("Output Components");
outputComponents.add_options()
@@ -1168,6 +1174,26 @@ bool CommandLineInterface::processInput()
settings.expectedExecutionsPerDeployment = m_args[g_argOptimizeRuns].as<unsigned>();
if (m_args.count(g_strNoOptimizeYul))
settings.runYulOptimiser = false;
if (m_args.count(g_strYulOptimizations))
{
if (!settings.runYulOptimiser)
{
serr() << "--" << g_strYulOptimizations << " is invalid if Yul optimizer is disabled" << endl;
return false;
}
try
{
yul::OptimiserSuite::validateSequence(m_args[g_strYulOptimizations].as<string>());
}
catch (yul::OptimizerException const& _exception)
{
serr() << "Invalid optimizer step sequence in --" << g_strYulOptimizations << ": " << _exception.what() << endl;
return false;
}
settings.yulOptimiserSteps = m_args[g_strYulOptimizations].as<string>();
}
settings.optimizeStackAllocation = settings.runYulOptimiser;
m_compiler->setOptimiserSettings(settings);