mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol->Yul] Implementing bytes.concat in IR codegen.
Co-authored-by: Daniel Kirchner <daniel@ekpyron.org>
This commit is contained in:
1 parent
e7da9f3d52
commit
80866d3ee4
3 files changed
+73
-1
No files matched your search
@@ -2351,6 +2351,60 @@ string YulUtilFunctions::copyArrayFromStorageToMemoryFunction(ArrayType const& _
|
||||
});
|
||||
}
|
||||
|
||||
string YulUtilFunctions::bytesConcatFunction(vector<Type const*> const& _argumentTypes)
|
||||
{
|
||||
string functionName = "bytes_concat";
|
||||
size_t totalParams = 0;
|
||||
vector<Type const*> targetTypes;
|
||||
for (Type const* argumentType: _argumentTypes)
|
||||
{
|
||||
solAssert(
|
||||
argumentType->isImplicitlyConvertibleTo(*TypeProvider::bytesMemory()) ||
|
||||
argumentType->isImplicitlyConvertibleTo(*TypeProvider::fixedBytes(32)),
|
||||
""
|
||||
);
|
||||
if (argumentType->category() == Type::Category::FixedBytes)
|
||||
targetTypes.emplace_back(argumentType);
|
||||
else if (
|
||||
auto const* literalType = dynamic_cast<StringLiteralType const*>(argumentType);
|
||||
literalType && literalType->value().size() <= 32
|
||||
)
|
||||
targetTypes.emplace_back(TypeProvider::fixedBytes(static_cast<unsigned>(literalType->value().size())));
|
||||
else
|
||||
{
|
||||
solAssert(argumentType->isImplicitlyConvertibleTo(*TypeProvider::bytesMemory()), "");
|
||||
targetTypes.emplace_back(TypeProvider::bytesMemory());
|
||||
}
|
||||
|
||||
totalParams += argumentType->sizeOnStack();
|
||||
functionName += "_" + argumentType->identifier();
|
||||
}
|
||||
|
||||
return m_functionCollector.createFunction(functionName, [&]() {
|
||||
Whiskers templ(R"(
|
||||
function <functionName>(<parameters>) -> outPtr {
|
||||
outPtr := <allocateUnbounded>()
|
||||
let dataStart := add(outPtr, 0x20)
|
||||
let dataEnd := <encodePacked>(dataStart<?+parameters>, <parameters></+parameters>)
|
||||
mstore(outPtr, sub(dataEnd, dataStart))
|
||||
<finalizeAllocation>(outPtr, sub(dataEnd, outPtr))
|
||||
}
|
||||
)");
|
||||
templ("functionName", functionName);
|
||||
templ("parameters", suffixedVariableNameList("param_", 0, totalParams));
|
||||
templ("allocateUnbounded", allocateUnboundedFunction());
|
||||
templ("finalizeAllocation", finalizeAllocationFunction());
|
||||
templ(
|
||||
"encodePacked",
|
||||
ABIFunctions{m_evmVersion, m_revertStrings, m_functionCollector}.tupleEncoderPacked(
|
||||
_argumentTypes,
|
||||
targetTypes
|
||||
)
|
||||
);
|
||||
return templ.render();
|
||||
});
|
||||
}
|
||||
|
||||
string YulUtilFunctions::mappingIndexAccessFunction(MappingType const& _mappingType, Type const& _keyType)
|
||||
{
|
||||
string functionName = "mapping_index_access_" + _mappingType.identifier() + "_of_" + _keyType.identifier();
|
||||
|
||||
Reference in new issue
Block a user