From 467cbf92bc2f506df0f04cd485daaa1f7ff73525 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 4 Aug 2021 18:38:10 +0200 Subject: [PATCH] Only provide code generator to CodeTransform. --- libsolidity/codegen/CompilerContext.cpp | 2 +- libsolidity/codegen/ContractCompiler.cpp | 16 ++++++---------- libyul/backends/evm/AsmCodeGen.cpp | 4 ++-- libyul/backends/evm/AsmCodeGen.h | 2 +- libyul/backends/evm/EVMCodeTransform.cpp | 14 +++++++------- libyul/backends/evm/EVMCodeTransform.h | 10 +++++----- 6 files changed, 22 insertions(+), 26 deletions(-) diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 291bbc255..3a939dcd7 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -520,7 +520,7 @@ void CompilerContext::appendInlineAssembly( analysisInfo, *m_asm, m_evmVersion, - identifierAccess, + identifierAccess.generateCode, _system, _optimiserSettings.optimizeStackAllocation ); diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index fca076b65..378179d5e 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -702,15 +702,11 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) { unsigned startStackHeight = m_context.stackHeight(); - yul::ExternalIdentifierAccess identifierAccess; - identifierAccess.resolve = [&](yul::Identifier const& _identifier, yul::IdentifierContext, bool) - { - auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier); - if (ref == _inlineAssembly.annotation().externalReferences.end()) - return numeric_limits::max(); - return ref->second.valueSize; - }; - identifierAccess.generateCode = [&](yul::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly) + yul::ExternalIdentifierAccess::CodeGenerator identifierAccessCodeGen = [&]( + yul::Identifier const& _identifier, + yul::IdentifierContext _context, + yul::AbstractAssembly& _assembly + ) { auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier); solAssert(ref != _inlineAssembly.annotation().externalReferences.end(), ""); @@ -918,7 +914,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) *analysisInfo, *m_context.assemblyPtr(), m_context.evmVersion(), - identifierAccess, + identifierAccessCodeGen, false, m_optimiserSettings.optimizeStackAllocation ); diff --git a/libyul/backends/evm/AsmCodeGen.cpp b/libyul/backends/evm/AsmCodeGen.cpp index bda3ad9e7..5c7865c01 100644 --- a/libyul/backends/evm/AsmCodeGen.cpp +++ b/libyul/backends/evm/AsmCodeGen.cpp @@ -37,7 +37,7 @@ void CodeGenerator::assemble( AsmAnalysisInfo& _analysisInfo, evmasm::Assembly& _assembly, langutil::EVMVersion _evmVersion, - ExternalIdentifierAccess const& _identifierAccess, + ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen, bool _useNamedLabelsForFunctions, bool _optimizeStackAllocation ) @@ -51,7 +51,7 @@ void CodeGenerator::assemble( EVMDialect::strictAssemblyForEVM(_evmVersion), builtinContext, _optimizeStackAllocation, - _identifierAccess, + _identifierAccessCodeGen, _useNamedLabelsForFunctions ); transform(_parsedData); diff --git a/libyul/backends/evm/AsmCodeGen.h b/libyul/backends/evm/AsmCodeGen.h index 35db4e7a0..b79338074 100644 --- a/libyul/backends/evm/AsmCodeGen.h +++ b/libyul/backends/evm/AsmCodeGen.h @@ -44,7 +44,7 @@ public: AsmAnalysisInfo& _analysisInfo, evmasm::Assembly& _assembly, langutil::EVMVersion _evmVersion, - ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(), + ExternalIdentifierAccess::CodeGenerator _identifierAccess = {}, bool _useNamedLabelsForFunctions = false, bool _optimizeStackAllocation = false ); diff --git a/libyul/backends/evm/EVMCodeTransform.cpp b/libyul/backends/evm/EVMCodeTransform.cpp index bc41eb9b2..c837c8b1a 100644 --- a/libyul/backends/evm/EVMCodeTransform.cpp +++ b/libyul/backends/evm/EVMCodeTransform.cpp @@ -61,7 +61,7 @@ CodeTransform::CodeTransform( bool _allowStackOpt, EVMDialect const& _dialect, BuiltinContext& _builtinContext, - ExternalIdentifierAccess _identifierAccess, + ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen, bool _useNamedLabelsForFunctions, shared_ptr _context, vector _delayedReturnVariables, @@ -73,7 +73,7 @@ CodeTransform::CodeTransform( m_builtinContext(_builtinContext), m_allowStackOpt(_allowStackOpt), m_useNamedLabelsForFunctions(_useNamedLabelsForFunctions), - m_identifierAccess(move(_identifierAccess)), + m_identifierAccessCodeGen(move(_identifierAccessCodeGen)), m_context(move(_context)), m_delayedReturnVariables(move(_delayedReturnVariables)), m_functionExitLabel(_functionExitLabel) @@ -292,10 +292,10 @@ void CodeTransform::operator()(Identifier const& _identifier) return; } yulAssert( - m_identifierAccess.generateCode, + m_identifierAccessCodeGen, "Identifier not found and no external access available." ); - m_identifierAccess.generateCode(_identifier, IdentifierContext::RValue, m_assembly); + m_identifierAccessCodeGen(_identifier, IdentifierContext::RValue, m_assembly); } void CodeTransform::operator()(Literal const& _literal) @@ -391,7 +391,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) m_allowStackOpt, m_dialect, m_builtinContext, - m_identifierAccess, + m_identifierAccessCodeGen, m_useNamedLabelsForFunctions, m_context, _function.returnVariables, @@ -740,10 +740,10 @@ void CodeTransform::generateAssignment(Identifier const& _variableName) else { yulAssert( - m_identifierAccess.generateCode, + m_identifierAccessCodeGen, "Identifier not found and no external access available." ); - m_identifierAccess.generateCode(_variableName, IdentifierContext::LValue, m_assembly); + m_identifierAccessCodeGen(_variableName, IdentifierContext::LValue, m_assembly); } } diff --git a/libyul/backends/evm/EVMCodeTransform.h b/libyul/backends/evm/EVMCodeTransform.h index 894a6d077..8bbd3b818 100644 --- a/libyul/backends/evm/EVMCodeTransform.h +++ b/libyul/backends/evm/EVMCodeTransform.h @@ -65,7 +65,7 @@ class CodeTransform { public: /// Create the code transformer. - /// @param _identifierAccess used to resolve identifiers external to the inline assembly + /// @param _identifierAccessCodeGen used to generate code for identifiers external to the inline assembly /// As a side-effect of its construction, translates the Yul code and appends it to the /// given assembly. /// Throws StackTooDeepError if a variable is not accessible or if a function has too @@ -77,7 +77,7 @@ public: EVMDialect const& _dialect, BuiltinContext& _builtinContext, bool _allowStackOpt = false, - ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(), + ExternalIdentifierAccess::CodeGenerator const& _identifierAccessCodeGen = {}, bool _useNamedLabelsForFunctions = false ): CodeTransform( _assembly, @@ -86,7 +86,7 @@ public: _allowStackOpt, _dialect, _builtinContext, - _identifierAccess, + _identifierAccessCodeGen, _useNamedLabelsForFunctions, nullptr, {}, @@ -107,7 +107,7 @@ protected: bool _allowStackOpt, EVMDialect const& _dialect, BuiltinContext& _builtinContext, - ExternalIdentifierAccess _identifierAccess, + ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen, bool _useNamedLabelsForFunctions, std::shared_ptr _context, std::vector _delayedReturnVariables, @@ -193,7 +193,7 @@ private: BuiltinContext& m_builtinContext; bool const m_allowStackOpt = true; bool const m_useNamedLabelsForFunctions = false; - ExternalIdentifierAccess m_identifierAccess; + ExternalIdentifierAccess::CodeGenerator m_identifierAccessCodeGen; std::shared_ptr m_context; /// Set of variables whose reference counter has reached zero,