Enable the new code generator for "system" inline assembly routines.

This commit is contained in:
Daniel Kirchner 2021-08-10 12:13:39 +02:00
parent 7f50e58dbf
commit b8bf8da514
2 changed files with 37 additions and 19 deletions

View File

@ -23,6 +23,7 @@
#include <libyul/backends/evm/EthAssemblyAdapter.h> #include <libyul/backends/evm/EthAssemblyAdapter.h>
#include <libyul/backends/evm/EVMCodeTransform.h> #include <libyul/backends/evm/EVMCodeTransform.h>
#include <libyul/backends/evm/OptimizedEVMCodeTransform.h>
#include <libyul/AST.h> #include <libyul/AST.h>
#include <libyul/AsmAnalysisInfo.h> #include <libyul/AsmAnalysisInfo.h>
@ -38,28 +39,45 @@ void CodeGenerator::assemble(
evmasm::Assembly& _assembly, evmasm::Assembly& _assembly,
langutil::EVMVersion _evmVersion, langutil::EVMVersion _evmVersion,
ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen, ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
bool _useNamedLabelsForFunctions, bool _system,
bool _optimizeStackAllocation bool _optimizeStackAllocation
) )
{ {
EthAssemblyAdapter assemblyAdapter(_assembly); EthAssemblyAdapter assemblyAdapter(_assembly);
BuiltinContext builtinContext; BuiltinContext builtinContext;
CodeTransform transform( if (_system && _optimizeStackAllocation && _evmVersion > EVMVersion::homestead())
assemblyAdapter, {
_analysisInfo, int oldStackHeight = assemblyAdapter.stackHeight();
_parsedData, assemblyAdapter.setStackHeight(0);
EVMDialect::strictAssemblyForEVM(_evmVersion), auto stackErrors = OptimizedEVMCodeTransform::run(assemblyAdapter, _analysisInfo, _parsedData, EVMDialect::strictAssemblyForEVM(_evmVersion), builtinContext, _system);
builtinContext, assemblyAdapter.setStackHeight(oldStackHeight);
_optimizeStackAllocation, if (!stackErrors.empty())
_identifierAccessCodeGen, assertThrow(
_useNamedLabelsForFunctions false,
); langutil::StackTooDeepError,
transform(_parsedData); "Stack too deep when compiling inline assembly" +
if (!transform.stackErrors().empty()) (stackErrors.front().comment() ? ": " + *stackErrors.front().comment() : ".")
assertThrow( );
false, }
langutil::StackTooDeepError, else
"Stack too deep when compiling inline assembly" + {
(transform.stackErrors().front().comment() ? ": " + *transform.stackErrors().front().comment() : ".") CodeTransform transform(
assemblyAdapter,
_analysisInfo,
_parsedData,
EVMDialect::strictAssemblyForEVM(_evmVersion),
builtinContext,
_optimizeStackAllocation,
_identifierAccessCodeGen,
_system
); );
transform(_parsedData);
if (!transform.stackErrors().empty())
assertThrow(
false,
langutil::StackTooDeepError,
"Stack too deep when compiling inline assembly" +
(transform.stackErrors().front().comment() ? ": " + *transform.stackErrors().front().comment() : ".")
);
}
} }

View File

@ -45,7 +45,7 @@ public:
evmasm::Assembly& _assembly, evmasm::Assembly& _assembly,
langutil::EVMVersion _evmVersion, langutil::EVMVersion _evmVersion,
ExternalIdentifierAccess::CodeGenerator _identifierAccess = {}, ExternalIdentifierAccess::CodeGenerator _identifierAccess = {},
bool _useNamedLabelsForFunctions = false, bool _system = false,
bool _optimizeStackAllocation = false bool _optimizeStackAllocation = false
); );
}; };