mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Some more compression.
This commit is contained in:
parent
c6b9fa96ae
commit
d3d205b6eb
@ -419,64 +419,30 @@ string YulUtilFunctions::arrayDataAreaFunction(ArrayType const& _type)
|
|||||||
{
|
{
|
||||||
string functionName = "array_dataslot_" + _type.identifier();
|
string functionName = "array_dataslot_" + _type.identifier();
|
||||||
return m_functionCollector->createFunction(functionName, [&]() {
|
return m_functionCollector->createFunction(functionName, [&]() {
|
||||||
switch (_type.location())
|
// No special processing for calldata arrays, because they are stored as
|
||||||
{
|
// offset of the data area and length on the stack, so the offset already
|
||||||
case DataLocation::Memory:
|
// points to the data area.
|
||||||
if (_type.isDynamicallySized())
|
// This might change, if calldata arrays are stored in a single
|
||||||
return Whiskers(R"(
|
// stack slot at some point.
|
||||||
function <functionName>(memPtr) -> dataPtr {
|
return Whiskers(R"(
|
||||||
dataPtr := add(memPtr, 0x20)
|
function <functionName>(ptr) -> data {
|
||||||
}
|
data := ptr
|
||||||
)")
|
<?dynamic>
|
||||||
("functionName", functionName)
|
<?memory>
|
||||||
.render();
|
data := add(ptr, 0x20)
|
||||||
else
|
</memory>
|
||||||
return Whiskers(R"(
|
<?storage>
|
||||||
function <functionName>(memPtr) -> dataPtr {
|
mstore(0, ptr)
|
||||||
dataPtr := memPtr
|
data := keccak256(0, 0x20)
|
||||||
}
|
</storage>
|
||||||
)")
|
</dynamic>
|
||||||
("functionName", functionName)
|
|
||||||
.render();
|
|
||||||
case DataLocation::Storage:
|
|
||||||
if (_type.isDynamicallySized())
|
|
||||||
{
|
|
||||||
Whiskers w(R"(
|
|
||||||
function <functionName>(slot) -> dataSlot {
|
|
||||||
mstore(0, slot)
|
|
||||||
dataSlot := keccak256(0, 0x20)
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
w("functionName", functionName);
|
|
||||||
return w.render();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Whiskers w(R"(
|
|
||||||
function <functionName>(slot) -> dataSlot {
|
|
||||||
dataSlot := slot
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
w("functionName", functionName);
|
|
||||||
return w.render();
|
|
||||||
}
|
|
||||||
case DataLocation::CallData:
|
|
||||||
{
|
|
||||||
// Calldata arrays are stored as offset of the data area and length
|
|
||||||
// on the stack, so the offset already points to the data area.
|
|
||||||
// This might change, if calldata arrays are stored in a single
|
|
||||||
// stack slot at some point.
|
|
||||||
Whiskers w(R"(
|
|
||||||
function <functionName>(slot) -> dataSlot {
|
|
||||||
dataSlot := slot
|
|
||||||
}
|
|
||||||
)");
|
|
||||||
w("functionName", functionName);
|
|
||||||
return w.render();
|
|
||||||
}
|
}
|
||||||
default:
|
)")
|
||||||
solAssert(false, "");
|
("functionName", functionName)
|
||||||
}
|
("dynamic", _type.isDynamicallySized())
|
||||||
|
("memory", _type.location() == DataLocation::Memory)
|
||||||
|
("storage", _type.location() == DataLocation::Storage)
|
||||||
|
.render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,36 +453,25 @@ string YulUtilFunctions::nextArrayElementFunction(ArrayType const& _type)
|
|||||||
solAssert(_type.baseType()->storageBytes() > 16, "");
|
solAssert(_type.baseType()->storageBytes() > 16, "");
|
||||||
string functionName = "array_nextElement_" + _type.identifier();
|
string functionName = "array_nextElement_" + _type.identifier();
|
||||||
return m_functionCollector->createFunction(functionName, [&]() {
|
return m_functionCollector->createFunction(functionName, [&]() {
|
||||||
switch (_type.location())
|
Whiskers templ(R"(
|
||||||
{
|
function <functionName>(ptr) -> next {
|
||||||
case DataLocation::Memory:
|
next := add(ptr, <advance>)
|
||||||
return Whiskers(R"(
|
}
|
||||||
function <functionName>(memPtr) -> nextPtr {
|
)");
|
||||||
nextPtr := add(memPtr, 0x20)
|
templ("functionName", functionName);
|
||||||
}
|
if (_type.location() == DataLocation::Memory)
|
||||||
)")
|
templ("advance", "0x20");
|
||||||
("functionName", functionName)
|
else if (_type.location() == DataLocation::Storage)
|
||||||
.render();
|
templ("advance", "1");
|
||||||
case DataLocation::Storage:
|
else if (_type.location() == DataLocation::CallData)
|
||||||
return Whiskers(R"(
|
templ("advance", toCompactHexWithPrefix(
|
||||||
function <functionName>(slot) -> nextSlot {
|
_type.baseType()->isDynamicallyEncoded() ?
|
||||||
nextSlot := add(slot, 1)
|
32 :
|
||||||
}
|
_type.baseType()->calldataEncodedSize()
|
||||||
)")
|
));
|
||||||
("functionName", functionName)
|
else
|
||||||
.render();
|
solAssert(false, "");
|
||||||
case DataLocation::CallData:
|
return templ.render();
|
||||||
return Whiskers(R"(
|
|
||||||
function <functionName>(calldataPtr) -> nextPtr {
|
|
||||||
nextPtr := add(calldataPtr, <stride>)
|
|
||||||
}
|
|
||||||
)")
|
|
||||||
("stride", toCompactHexWithPrefix(_type.baseType()->isDynamicallyEncoded() ? 32 : _type.baseType()->calldataEncodedSize()))
|
|
||||||
("functionName", functionName)
|
|
||||||
.render();
|
|
||||||
default:
|
|
||||||
solAssert(false, "");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user