diff --git a/libyul/AssemblyStack.h b/libyul/AssemblyStack.h index 91ca78af7..52bfc518e 100644 --- a/libyul/AssemblyStack.h +++ b/libyul/AssemblyStack.h @@ -124,9 +124,9 @@ public: private: bool analyzeParsed(); bool analyzeParsed(yul::Object& _object); - +public: void compileEVM(yul::AbstractAssembly& _assembly, bool _optimize) const; - +private: void optimize(yul::Object& _object, bool _isCreation); Language m_language = Language::Assembly; diff --git a/libyul/backends/evm/EVMObjectCompiler.cpp b/libyul/backends/evm/EVMObjectCompiler.cpp index f65f7f1e3..7110d7e48 100644 --- a/libyul/backends/evm/EVMObjectCompiler.cpp +++ b/libyul/backends/evm/EVMObjectCompiler.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -62,10 +63,20 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize) yulAssert(_object.analysisInfo, "No analysis info."); yulAssert(_object.code, "No code."); - // We do not catch and re-throw the stack too deep exception here because it is a YulException, - // which should be native to this part of the code. - CodeTransform transform{m_assembly, *_object.analysisInfo, *_object.code, m_dialect, context, _optimize}; - transform(*_object.code); - if (!transform.stackErrors().empty()) - BOOST_THROW_EXCEPTION(transform.stackErrors().front()); + if (_optimize && m_dialect.evmVersion().canOverchargeGasForCall()) + { + + auto stackErrors = OptimizedEVMCodeTransform::run(m_assembly, *_object.analysisInfo, *_object.code, m_dialect, context); + if (!stackErrors.empty()) + BOOST_THROW_EXCEPTION(stackErrors.front()); + } + else + { + // We do not catch and re-throw the stack too deep exception here because it is a YulException, + // which should be native to this part of the code. + CodeTransform transform{m_assembly, *_object.analysisInfo, *_object.code, m_dialect, context, _optimize}; + transform(*_object.code); + if (!transform.stackErrors().empty()) + BOOST_THROW_EXCEPTION(transform.stackErrors().front()); + } }