mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Only provide code generator to CodeTransform.
This commit is contained in:
parent
2d5b9036c2
commit
467cbf92bc
@ -520,7 +520,7 @@ void CompilerContext::appendInlineAssembly(
|
||||
analysisInfo,
|
||||
*m_asm,
|
||||
m_evmVersion,
|
||||
identifierAccess,
|
||||
identifierAccess.generateCode,
|
||||
_system,
|
||||
_optimiserSettings.optimizeStackAllocation
|
||||
);
|
||||
|
@ -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<size_t>::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
|
||||
);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -61,7 +61,7 @@ CodeTransform::CodeTransform(
|
||||
bool _allowStackOpt,
|
||||
EVMDialect const& _dialect,
|
||||
BuiltinContext& _builtinContext,
|
||||
ExternalIdentifierAccess _identifierAccess,
|
||||
ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
|
||||
bool _useNamedLabelsForFunctions,
|
||||
shared_ptr<Context> _context,
|
||||
vector<TypedName> _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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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> _context,
|
||||
std::vector<TypedName> _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<Context> m_context;
|
||||
|
||||
/// Set of variables whose reference counter has reached zero,
|
||||
|
Loading…
Reference in New Issue
Block a user