diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 549991d61..275451114 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -551,13 +551,7 @@ bool CommandLineInterface::processInput() } case InputMode::Assembler: { - return assemble( - m_options.assembly.inputLanguage, - m_options.assembly.targetMachine, - m_options.optimizer.enabled, - m_options.optimizer.expectedExecutionsPerDeployment, - m_options.optimizer.yulSteps - ); + return assemble(m_options.assembly.inputLanguage, m_options.assembly.targetMachine); } case InputMode::Linker: return link(); @@ -595,16 +589,7 @@ bool CommandLineInterface::compile() m_compiler->enableIRGeneration(m_options.compiler.outputs.ir || m_options.compiler.outputs.irOptimized); m_compiler->enableEwasmGeneration(m_options.compiler.outputs.ewasm); - OptimiserSettings settings = m_options.optimizer.enabled ? OptimiserSettings::standard() : OptimiserSettings::minimal(); - if (m_options.optimizer.expectedExecutionsPerDeployment.has_value()) - settings.expectedExecutionsPerDeployment = m_options.optimizer.expectedExecutionsPerDeployment.value(); - if (m_options.optimizer.noOptimizeYul) - settings.runYulOptimiser = false; - - if (m_options.optimizer.yulSteps.has_value()) - settings.yulOptimiserSteps = m_options.optimizer.yulSteps.value(); - settings.optimizeStackAllocation = settings.runYulOptimiser; - m_compiler->setOptimiserSettings(settings); + m_compiler->setOptimiserSettings(m_options.optimiserSettings()); if (m_options.input.mode == InputMode::CompilerWithASTImport) { @@ -939,27 +924,21 @@ string CommandLineInterface::objectWithLinkRefsHex(evmasm::LinkerObject const& _ return out; } -bool CommandLineInterface::assemble( - yul::AssemblyStack::Language _language, - yul::AssemblyStack::Machine _targetMachine, - bool _optimize, - optional _expectedExecutionsPerDeployment, - optional _yulOptimiserSteps -) +bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul::AssemblyStack::Machine _targetMachine) { - solAssert(_optimize || !_yulOptimiserSteps.has_value(), ""); - bool successful = true; map assemblyStacks; for (auto const& src: m_fileReader.sourceCodes()) { - OptimiserSettings settings = _optimize ? OptimiserSettings::full() : OptimiserSettings::minimal(); - if (_expectedExecutionsPerDeployment.has_value()) - settings.expectedExecutionsPerDeployment = _expectedExecutionsPerDeployment.value(); - if (_yulOptimiserSteps.has_value()) - settings.yulOptimiserSteps = _yulOptimiserSteps.value(); + // --no-optimize-yul option is not accepted in assembly mode. + solAssert(!m_options.optimizer.noOptimizeYul, ""); + + auto& stack = assemblyStacks[src.first] = yul::AssemblyStack( + m_options.output.evmVersion, + _language, + m_options.optimiserSettings() + ); - auto& stack = assemblyStacks[src.first] = yul::AssemblyStack(m_options.output.evmVersion, _language, settings); try { if (!stack.parseAndAnalyze(src.first, src.second)) diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index 488ec1d71..582b8f2a4 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -74,13 +74,7 @@ private: /// @returns the full object with library placeholder hints in hex. static std::string objectWithLinkRefsHex(evmasm::LinkerObject const& _obj); - bool assemble( - yul::AssemblyStack::Language _language, - yul::AssemblyStack::Machine _targetMachine, - bool _optimize, - std::optional _expectedExecutionsPerDeployment = std::nullopt, - std::optional _yulOptimiserSteps = std::nullopt - ); + bool assemble(yul::AssemblyStack::Language _language, yul::AssemblyStack::Machine _targetMachine); void outputCompilationResults(); diff --git a/solc/CommandLineParser.cpp b/solc/CommandLineParser.cpp index 547bba399..bccd95a0b 100644 --- a/solc/CommandLineParser.cpp +++ b/solc/CommandLineParser.cpp @@ -302,6 +302,29 @@ bool CommandLineOptions::operator==(CommandLineOptions const& _other) const noex modelChecker.settings == _other.modelChecker.settings; } +OptimiserSettings CommandLineOptions::optimiserSettings() const +{ + OptimiserSettings settings; + + if (optimizer.enabled && input.mode == InputMode::Assembler) + settings = OptimiserSettings::full(); + else if (optimizer.enabled) + settings = OptimiserSettings::standard(); + else + settings = OptimiserSettings::minimal(); + + if (optimizer.noOptimizeYul) + settings.runYulOptimiser = false; + + if (optimizer.expectedExecutionsPerDeployment.has_value()) + settings.expectedExecutionsPerDeployment = optimizer.expectedExecutionsPerDeployment.value(); + + if (optimizer.yulSteps.has_value()) + settings.yulOptimiserSteps = optimizer.yulSteps.value(); + + return settings; +} + bool CommandLineParser::parseInputPathsAndRemappings() { m_options.input.ignoreMissingFiles = (m_args.count(g_strIgnoreMissingFiles) > 0); @@ -988,19 +1011,9 @@ General Information)").c_str(), if (!m_args[g_strOptimizeRuns].defaulted()) m_options.optimizer.expectedExecutionsPerDeployment = m_args.at(g_strOptimizeRuns).as(); - OptimiserSettings optimiserSettings; - if (m_options.optimizer.enabled && m_options.input.mode == InputMode::Assembler) - optimiserSettings = OptimiserSettings::full(); - else if (m_options.optimizer.enabled) - optimiserSettings = OptimiserSettings::standard(); - else - optimiserSettings = OptimiserSettings::minimal(); - - if (m_options.optimizer.noOptimizeYul) - optimiserSettings.runYulOptimiser = false; - if (m_args.count(g_strYulOptimizations)) { + OptimiserSettings optimiserSettings = m_options.optimiserSettings(); if (!optimiserSettings.runYulOptimiser) { serr() << "--" << g_strYulOptimizations << " is invalid if Yul optimizer is disabled" << endl; diff --git a/solc/CommandLineParser.h b/solc/CommandLineParser.h index 423dacb5f..ac80f6f0d 100644 --- a/solc/CommandLineParser.h +++ b/solc/CommandLineParser.h @@ -102,6 +102,7 @@ struct CommandLineOptions bool operator==(CommandLineOptions const& _other) const noexcept; bool operator!=(CommandLineOptions const& _other) const noexcept { return !(*this == _other); } + OptimiserSettings optimiserSettings() const; struct { @@ -169,7 +170,6 @@ struct CommandLineOptions bool initialize = false; ModelCheckerSettings settings; } modelChecker; - }; /// Parses the command-line arguments and produces a filled-out CommandLineOptions structure.