Skip to content

Commit 26fb231

Browse files
authored
Merge pull request #11744 from ethereum/refactor_remove_identifieraccess
Only provide code generator to CodeTransform.
2 parents 2d5b903 + 467cbf9 commit 26fb231

File tree

6 files changed

+22
-26
lines changed

6 files changed

+22
-26
lines changed

libsolidity/codegen/CompilerContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ void CompilerContext::appendInlineAssembly(
520520
analysisInfo,
521521
*m_asm,
522522
m_evmVersion,
523-
identifierAccess,
523+
identifierAccess.generateCode,
524524
_system,
525525
_optimiserSettings.optimizeStackAllocation
526526
);

libsolidity/codegen/ContractCompiler.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,11 @@ bool ContractCompiler::visit(FunctionDefinition const& _function)
702702
bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
703703
{
704704
unsigned startStackHeight = m_context.stackHeight();
705-
yul::ExternalIdentifierAccess identifierAccess;
706-
identifierAccess.resolve = [&](yul::Identifier const& _identifier, yul::IdentifierContext, bool)
707-
{
708-
auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier);
709-
if (ref == _inlineAssembly.annotation().externalReferences.end())
710-
return numeric_limits<size_t>::max();
711-
return ref->second.valueSize;
712-
};
713-
identifierAccess.generateCode = [&](yul::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly)
705+
yul::ExternalIdentifierAccess::CodeGenerator identifierAccessCodeGen = [&](
706+
yul::Identifier const& _identifier,
707+
yul::IdentifierContext _context,
708+
yul::AbstractAssembly& _assembly
709+
)
714710
{
715711
auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier);
716712
solAssert(ref != _inlineAssembly.annotation().externalReferences.end(), "");
@@ -918,7 +914,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly)
918914
*analysisInfo,
919915
*m_context.assemblyPtr(),
920916
m_context.evmVersion(),
921-
identifierAccess,
917+
identifierAccessCodeGen,
922918
false,
923919
m_optimiserSettings.optimizeStackAllocation
924920
);

libyul/backends/evm/AsmCodeGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void CodeGenerator::assemble(
3737
AsmAnalysisInfo& _analysisInfo,
3838
evmasm::Assembly& _assembly,
3939
langutil::EVMVersion _evmVersion,
40-
ExternalIdentifierAccess const& _identifierAccess,
40+
ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
4141
bool _useNamedLabelsForFunctions,
4242
bool _optimizeStackAllocation
4343
)
@@ -51,7 +51,7 @@ void CodeGenerator::assemble(
5151
EVMDialect::strictAssemblyForEVM(_evmVersion),
5252
builtinContext,
5353
_optimizeStackAllocation,
54-
_identifierAccess,
54+
_identifierAccessCodeGen,
5555
_useNamedLabelsForFunctions
5656
);
5757
transform(_parsedData);

libyul/backends/evm/AsmCodeGen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CodeGenerator
4444
AsmAnalysisInfo& _analysisInfo,
4545
evmasm::Assembly& _assembly,
4646
langutil::EVMVersion _evmVersion,
47-
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(),
47+
ExternalIdentifierAccess::CodeGenerator _identifierAccess = {},
4848
bool _useNamedLabelsForFunctions = false,
4949
bool _optimizeStackAllocation = false
5050
);

libyul/backends/evm/EVMCodeTransform.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ CodeTransform::CodeTransform(
6161
bool _allowStackOpt,
6262
EVMDialect const& _dialect,
6363
BuiltinContext& _builtinContext,
64-
ExternalIdentifierAccess _identifierAccess,
64+
ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
6565
bool _useNamedLabelsForFunctions,
6666
shared_ptr<Context> _context,
6767
vector<TypedName> _delayedReturnVariables,
@@ -73,7 +73,7 @@ CodeTransform::CodeTransform(
7373
m_builtinContext(_builtinContext),
7474
m_allowStackOpt(_allowStackOpt),
7575
m_useNamedLabelsForFunctions(_useNamedLabelsForFunctions),
76-
m_identifierAccess(move(_identifierAccess)),
76+
m_identifierAccessCodeGen(move(_identifierAccessCodeGen)),
7777
m_context(move(_context)),
7878
m_delayedReturnVariables(move(_delayedReturnVariables)),
7979
m_functionExitLabel(_functionExitLabel)
@@ -292,10 +292,10 @@ void CodeTransform::operator()(Identifier const& _identifier)
292292
return;
293293
}
294294
yulAssert(
295-
m_identifierAccess.generateCode,
295+
m_identifierAccessCodeGen,
296296
"Identifier not found and no external access available."
297297
);
298-
m_identifierAccess.generateCode(_identifier, IdentifierContext::RValue, m_assembly);
298+
m_identifierAccessCodeGen(_identifier, IdentifierContext::RValue, m_assembly);
299299
}
300300

301301
void CodeTransform::operator()(Literal const& _literal)
@@ -391,7 +391,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
391391
m_allowStackOpt,
392392
m_dialect,
393393
m_builtinContext,
394-
m_identifierAccess,
394+
m_identifierAccessCodeGen,
395395
m_useNamedLabelsForFunctions,
396396
m_context,
397397
_function.returnVariables,
@@ -740,10 +740,10 @@ void CodeTransform::generateAssignment(Identifier const& _variableName)
740740
else
741741
{
742742
yulAssert(
743-
m_identifierAccess.generateCode,
743+
m_identifierAccessCodeGen,
744744
"Identifier not found and no external access available."
745745
);
746-
m_identifierAccess.generateCode(_variableName, IdentifierContext::LValue, m_assembly);
746+
m_identifierAccessCodeGen(_variableName, IdentifierContext::LValue, m_assembly);
747747
}
748748
}
749749

libyul/backends/evm/EVMCodeTransform.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CodeTransform
6565
{
6666
public:
6767
/// Create the code transformer.
68-
/// @param _identifierAccess used to resolve identifiers external to the inline assembly
68+
/// @param _identifierAccessCodeGen used to generate code for identifiers external to the inline assembly
6969
/// As a side-effect of its construction, translates the Yul code and appends it to the
7070
/// given assembly.
7171
/// Throws StackTooDeepError if a variable is not accessible or if a function has too
@@ -77,7 +77,7 @@ class CodeTransform
7777
EVMDialect const& _dialect,
7878
BuiltinContext& _builtinContext,
7979
bool _allowStackOpt = false,
80-
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(),
80+
ExternalIdentifierAccess::CodeGenerator const& _identifierAccessCodeGen = {},
8181
bool _useNamedLabelsForFunctions = false
8282
): CodeTransform(
8383
_assembly,
@@ -86,7 +86,7 @@ class CodeTransform
8686
_allowStackOpt,
8787
_dialect,
8888
_builtinContext,
89-
_identifierAccess,
89+
_identifierAccessCodeGen,
9090
_useNamedLabelsForFunctions,
9191
nullptr,
9292
{},
@@ -107,7 +107,7 @@ class CodeTransform
107107
bool _allowStackOpt,
108108
EVMDialect const& _dialect,
109109
BuiltinContext& _builtinContext,
110-
ExternalIdentifierAccess _identifierAccess,
110+
ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
111111
bool _useNamedLabelsForFunctions,
112112
std::shared_ptr<Context> _context,
113113
std::vector<TypedName> _delayedReturnVariables,
@@ -193,7 +193,7 @@ class CodeTransform
193193
BuiltinContext& m_builtinContext;
194194
bool const m_allowStackOpt = true;
195195
bool const m_useNamedLabelsForFunctions = false;
196-
ExternalIdentifierAccess m_identifierAccess;
196+
ExternalIdentifierAccess::CodeGenerator m_identifierAccessCodeGen;
197197
std::shared_ptr<Context> m_context;
198198

199199
/// Set of variables whose reference counter has reached zero,

0 commit comments

Comments
 (0)