Further customize max swap/dup.

This commit is contained in:
Daniel Kirchner committed 2022-12-05 14:24:32 +01:00
1 parent a467bdcb3c
commit 3ff457c312
17 files changed
+549 -68

No files matched your search

+6 -6
View File
@@ -475,7 +475,7 @@ void CompilerUtils::encodeToMemory(
m_context << Instruction::DUP1 << u256(32) << Instruction::ADD;
dynPointers++;
assertThrow(
(argSize + dynPointers) < 16,
(argSize + dynPointers) < m_context.assembly().maxSwap(),
StackTooDeepError,
util::stackTooDeepString
);
@@ -536,7 +536,7 @@ void CompilerUtils::encodeToMemory(
{
// copy tail pointer (=mem_end - mem_start) to memory
assertThrow(
(2 + dynPointers) <= 16,
(2 + dynPointers) <= m_context.assembly().maxDup(),
StackTooDeepError,
util::stackTooDeepString
);
@@ -1415,7 +1415,7 @@ void CompilerUtils::moveToStackVariable(VariableDeclaration const& _variable)
unsigned const size = _variable.annotation().type->sizeOnStack();
solAssert(stackPosition >= size, "Variable size and position mismatch.");
// move variable starting from its top end in the stack
if (stackPosition - size + 1 > 16)
if (stackPosition - size + 1 > m_context.assembly().maxSwap())
BOOST_THROW_EXCEPTION(
StackTooDeepError() <<
errinfo_sourceLocation(_variable.location()) <<
@@ -1428,7 +1428,7 @@ void CompilerUtils::moveToStackVariable(VariableDeclaration const& _variable)
void CompilerUtils::copyToStackTop(unsigned _stackDepth, unsigned _itemSize)
{
assertThrow(
_stackDepth <= 16,
_stackDepth <= m_context.assembly().maxDup(),
StackTooDeepError,
util::stackTooDeepString
);
@@ -1454,7 +1454,7 @@ void CompilerUtils::moveIntoStack(unsigned _stackDepth, unsigned _itemSize)
void CompilerUtils::rotateStackUp(unsigned _items)
{
assertThrow(
_items - 1 <= 16,
_items - 1 <= m_context.assembly().maxSwap(),
StackTooDeepError,
util::stackTooDeepString
);
@@ -1465,7 +1465,7 @@ void CompilerUtils::rotateStackUp(unsigned _items)
void CompilerUtils::rotateStackDown(unsigned _items)
{
assertThrow(
_items - 1 <= 16,
_items - 1 <= m_context.assembly().maxSwap(),
StackTooDeepError,
util::stackTooDeepString
);
+10 -8
View File
@@ -48,7 +48,7 @@ StackVariable::StackVariable(CompilerContext& _compilerContext, VariableDeclarat
void StackVariable::retrieveValue(SourceLocation const& _location, bool) const
{
unsigned stackPos = m_context.baseToCurrentStackOffset(m_baseStackOffset);
if (stackPos + 1 > 16) //@todo correct this by fetching earlier or moving to memory
if (stackPos + 1 > m_context.assembly().maxDup()) //@todo correct this by fetching earlier or moving to memory
BOOST_THROW_EXCEPTION(
StackTooDeepError() <<
errinfo_sourceLocation(_location) <<
@@ -62,15 +62,17 @@ void StackVariable::retrieveValue(SourceLocation const& _location, bool) const
void StackVariable::storeValue(Type const&, SourceLocation const& _location, bool _move) const
{
unsigned stackDiff = m_context.baseToCurrentStackOffset(m_baseStackOffset) - m_size + 1;
if (stackDiff > 16)
BOOST_THROW_EXCEPTION(
StackTooDeepError() <<
errinfo_sourceLocation(_location) <<
util::errinfo_comment(util::stackTooDeepString)
);
else if (stackDiff > 0)
if (stackDiff > 0)
{
if (stackDiff > m_context.assembly().maxSwap())
BOOST_THROW_EXCEPTION(
StackTooDeepError() <<
errinfo_sourceLocation(_location) <<
util::errinfo_comment(util::stackTooDeepString)
);
for (unsigned i = 0; i < m_size; ++i)
m_context << AssemblyItem(AssemblyItemType::Swap, stackDiff) << Instruction::POP;
}
if (!_move)
retrieveValue(_location);
}