Introduce non-reversed version of tupleEncoder.

This commit is contained in:
chriseth
2020-05-07 15:08:09 +02:00
parent 5e46ef7df5
commit e986fde0c1
13 changed files with 63 additions and 30 deletions
+16 -4
View File
@@ -38,7 +38,8 @@ using namespace solidity::frontend;
string ABIFunctions::tupleEncoder(
TypePointers const& _givenTypes,
TypePointers const& _targetTypes,
bool _encodeAsLibraryTypes
bool _encodeAsLibraryTypes,
bool _reversed
)
{
EncodingOptions options;
@@ -54,6 +55,8 @@ string ABIFunctions::tupleEncoder(
for (auto const& t: _targetTypes)
functionName += t->identifier() + "_";
functionName += options.toFunctionNameSuffix();
if (_reversed)
functionName += "_reversed";
return createFunction(functionName, [&]() {
// Note that the values are in reverse due to the difference in calling semantics.
@@ -94,7 +97,10 @@ string ABIFunctions::tupleEncoder(
stackPos += sizeOnStack;
}
solAssert(headPos == headSize_, "");
string valueParams = suffixedVariableNameList("value", stackPos, 0);
string valueParams =
_reversed ?
suffixedVariableNameList("value", stackPos, 0) :
suffixedVariableNameList("value", 0, stackPos);
templ("valueParams", valueParams.empty() ? "" : ", " + valueParams);
templ("encodeElements", encodeElements);
@@ -104,7 +110,8 @@ string ABIFunctions::tupleEncoder(
string ABIFunctions::tupleEncoderPacked(
TypePointers const& _givenTypes,
TypePointers const& _targetTypes
TypePointers const& _targetTypes,
bool _reversed
)
{
EncodingOptions options;
@@ -120,6 +127,8 @@ string ABIFunctions::tupleEncoderPacked(
for (auto const& t: _targetTypes)
functionName += t->identifier() + "_";
functionName += options.toFunctionNameSuffix();
if (_reversed)
functionName += "_reversed";
return createFunction(functionName, [&]() {
solAssert(!_givenTypes.empty(), "");
@@ -158,7 +167,10 @@ string ABIFunctions::tupleEncoderPacked(
encodeElements += elementTempl.render();
stackPos += sizeOnStack;
}
string valueParams = suffixedVariableNameList("value", stackPos, 0);
string valueParams =
_reversed ?
suffixedVariableNameList("value", stackPos, 0) :
suffixedVariableNameList("value", 0, stackPos);
templ("valueParams", valueParams.empty() ? "" : ", " + valueParams);
templ("encodeElements", encodeElements);