mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use index into m_asm->items() to modify free memory push.
This commit is contained in:
parent
abf0e47e0a
commit
0f09b850fc
@ -62,9 +62,6 @@ public:
|
||||
|
||||
AssemblyItem(u256 _push, langutil::SourceLocation _location = langutil::SourceLocation()):
|
||||
AssemblyItem(Push, std::move(_push), std::move(_location)) { }
|
||||
/// Used only for the free memory pointer as "memoryguard". Should probably be replaced by a separate AssemblyItemType.
|
||||
AssemblyItem(std::shared_ptr<u256> _pushData, langutil::SourceLocation _location = langutil::SourceLocation()):
|
||||
m_type(Push), m_data(std::move(_pushData)), m_location(std::move(_location)) { }
|
||||
AssemblyItem(Instruction _i, langutil::SourceLocation _location = langutil::SourceLocation()):
|
||||
m_type(Operation),
|
||||
m_instruction(_i),
|
||||
|
@ -545,7 +545,13 @@ void CompilerContext::optimizeYul(
|
||||
|
||||
bool const isCreation = runtimeContext() != nullptr;
|
||||
yul::GasMeter meter(_dialect, isCreation, _optimiserSettings.expectedExecutionsPerDeployment);
|
||||
solAssert(m_freeMemoryInitPush, "");
|
||||
unique_ptr<u256> freeMemoryInitPushValue;
|
||||
if (_system)
|
||||
{
|
||||
solAssert(m_freeMemoryInitPush, "");
|
||||
solAssert(m_asm->items().size() > *m_freeMemoryInitPush, "");
|
||||
freeMemoryInitPushValue = make_unique<u256>(m_asm->items().at(*m_freeMemoryInitPush).data());
|
||||
}
|
||||
yul::OptimiserSuite::run(
|
||||
_dialect,
|
||||
&meter,
|
||||
@ -554,8 +560,10 @@ void CompilerContext::optimizeYul(
|
||||
_optimiserSettings.yulOptimiserSteps,
|
||||
isCreation? nullopt : make_optional(_optimiserSettings.expectedExecutionsPerDeployment),
|
||||
_externalIdentifiers,
|
||||
_system ? m_freeMemoryInitPush : shared_ptr<u256>{}
|
||||
freeMemoryInitPushValue.get()
|
||||
);
|
||||
if (_system)
|
||||
m_asm->items().at(*m_freeMemoryInitPush).setData(*freeMemoryInitPushValue);
|
||||
|
||||
#ifdef SOL_OUTPUT_ASM
|
||||
cout << "After optimizer:" << endl;
|
||||
@ -572,6 +580,12 @@ string CompilerContext::revertReasonIfDebug(string const& _message)
|
||||
);
|
||||
}
|
||||
|
||||
void CompilerContext::appendFreeMemoryInitPush(u256 _value)
|
||||
{
|
||||
m_freeMemoryInitPush = m_asm->items().size();
|
||||
m_asm->append(AssemblyItem(_value));
|
||||
}
|
||||
|
||||
void CompilerContext::updateSourceLocation()
|
||||
{
|
||||
m_asm->setSourceLocation(m_visitedNodes.empty() ? SourceLocation() : m_visitedNodes.top()->location());
|
||||
|
@ -315,11 +315,7 @@ public:
|
||||
|
||||
RevertStrings revertStrings() const { return m_revertStrings; }
|
||||
|
||||
evmasm::AssemblyItem makeFreeMemoryInitPush(u256 _value)
|
||||
{
|
||||
m_freeMemoryInitPush = std::make_shared<u256>(_value);
|
||||
return evmasm::AssemblyItem(m_freeMemoryInitPush);
|
||||
}
|
||||
void appendFreeMemoryInitPush(u256 _value);
|
||||
|
||||
private:
|
||||
/// Updates source location set in the assembly.
|
||||
@ -406,8 +402,8 @@ private:
|
||||
std::queue<std::tuple<std::string, unsigned, unsigned, std::function<void(CompilerContext&)>>> m_lowLevelFunctionGenerationQueue;
|
||||
/// Flag to check that appendYulUtilityFunctions() was called exactly once
|
||||
bool m_appendYulUtilityFunctionsRan = false;
|
||||
/// The assembly item that pushes the initial value of the free memory pointer.
|
||||
std::shared_ptr<u256> m_freeMemoryInitPush;
|
||||
/// The index of the assembly item that pushes the initial value of the free memory pointer.
|
||||
std::optional<size_t> m_freeMemoryInitPush;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ void CompilerUtils::initialiseFreeMemoryPointer()
|
||||
{
|
||||
size_t reservedMemory = m_context.reservedMemory();
|
||||
solAssert(bigint(generalPurposeMemoryStart) + bigint(reservedMemory) < bigint(1) << 63, "");
|
||||
m_context << m_context.makeFreeMemoryInitPush((u256(generalPurposeMemoryStart) + reservedMemory));
|
||||
m_context.appendFreeMemoryInitPush((u256(generalPurposeMemoryStart) + reservedMemory));
|
||||
storeFreeMemoryPointer();
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ struct OptimiserStepContext
|
||||
std::set<YulString> const& reservedIdentifiers;
|
||||
/// The value nullopt represents creation code
|
||||
std::optional<size_t> expectedExecutionsPerDeployment;
|
||||
std::shared_ptr<u256> externalFreeMemoryPointerInitializer{};
|
||||
u256* externalFreeMemoryPointerInitializer = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
@ -90,7 +90,7 @@ void OptimiserSuite::run(
|
||||
string const& _optimisationSequence,
|
||||
optional<size_t> _expectedExecutionsPerDeployment,
|
||||
set<YulString> const& _externallyUsedIdentifiers,
|
||||
std::shared_ptr<u256> _externalFreeMemoryPointerInitializer
|
||||
u256* _externalFreeMemoryPointerInitializer
|
||||
)
|
||||
{
|
||||
EVMDialect const* evmDialect = dynamic_cast<EVMDialect const*>(&_dialect);
|
||||
|
@ -67,7 +67,7 @@ public:
|
||||
std::string const& _optimisationSequence,
|
||||
std::optional<size_t> _expectedExecutionsPerDeployment,
|
||||
std::set<YulString> const& _externallyUsedIdentifiers = {},
|
||||
std::shared_ptr<u256> _externalFreeMemoryPointerInitializer = {}
|
||||
u256* _externalFreeMemoryPointerInitializer = nullptr
|
||||
);
|
||||
|
||||
/// Ensures that specified sequence of step abbreviations is well-formed and can be executed.
|
||||
@ -93,7 +93,7 @@ private:
|
||||
Debug _debug,
|
||||
Block& _ast,
|
||||
std::optional<size_t> expectedExecutionsPerDeployment,
|
||||
std::shared_ptr<u256> _externalFreeMemoryPointerInitializer = {}
|
||||
u256* _externalFreeMemoryPointerInitializer = nullptr
|
||||
|
||||
):
|
||||
m_dispenser{_dialect, _ast, _externallyUsedIdentifiers},
|
||||
|
Loading…
Reference in New Issue
Block a user