mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10769 from ethereum/allocationCleanup
Cleanup allocation.
This commit is contained in:
commit
4697beeab2
libsolidity/codegen
test
cmdlineTests
exp_base_literal
ir_compiler_subobjects
name_simplifier
optimizer_array_sload
standard_generatedSources
standard_irOptimized_requested
standard_ir_requested
standard_viair_requested
viair_abicoder_v1
viair_subobjects
yul_string_format_ascii
yul_string_format_ascii_bytes32
yul_string_format_ascii_bytes32_from_number
yul_string_format_ascii_long
yul_string_format_hex
libsolidity
@ -183,15 +183,15 @@ string YulUtilFunctions::requireOrAssertFunction(bool _assert, Type const* _mess
|
||||
return Whiskers(R"(
|
||||
function <functionName>(condition <messageVars>) {
|
||||
if iszero(condition) {
|
||||
let fmp := mload(<freeMemPointer>)
|
||||
mstore(fmp, <errorHash>)
|
||||
let end := <abiEncodeFunc>(add(fmp, <hashHeaderSize>) <messageVars>)
|
||||
revert(fmp, sub(end, fmp))
|
||||
let memPtr := <allocateUnbounded>()
|
||||
mstore(memPtr, <errorHash>)
|
||||
let end := <abiEncodeFunc>(add(memPtr, <hashHeaderSize>) <messageVars>)
|
||||
revert(memPtr, sub(end, memPtr))
|
||||
}
|
||||
}
|
||||
)")
|
||||
("functionName", functionName)
|
||||
("freeMemPointer", to_string(CompilerUtils::freeMemoryPointer))
|
||||
("allocateUnbounded", allocateUnboundedFunction())
|
||||
("errorHash", formatNumber(errorHash))
|
||||
("abiEncodeFunc", encodeFunc)
|
||||
("hashHeaderSize", to_string(hashHeaderSize))
|
||||
@ -2301,19 +2301,19 @@ string YulUtilFunctions::copyArrayFromStorageToMemoryFunction(ArrayType const& _
|
||||
solAssert(_from.baseType() == _to.baseType(), "");
|
||||
ABIFunctions abi(m_evmVersion, m_revertStrings, m_functionCollector);
|
||||
return Whiskers(R"(
|
||||
function <functionName>(slot) -> memptr {
|
||||
memptr := <allocateTemp>()
|
||||
let end := <encode>(slot, memptr)
|
||||
mstore(<freeMemoryPointer>, end)
|
||||
function <functionName>(slot) -> memPtr {
|
||||
memPtr := <allocateUnbounded>()
|
||||
let end := <encode>(slot, memPtr)
|
||||
<finalizeAllocation>(memPtr, sub(end, memPtr))
|
||||
}
|
||||
)")
|
||||
("functionName", functionName)
|
||||
("allocateTemp", allocationTemporaryMemoryFunction())
|
||||
("allocateUnbounded", allocateUnboundedFunction())
|
||||
(
|
||||
"encode",
|
||||
abi.abiEncodeAndReturnUpdatedPosFunction(_from, _to, ABIFunctions::EncodingOptions{})
|
||||
)
|
||||
("freeMemoryPointer", to_string(CompilerUtils::freeMemoryPointer))
|
||||
("finalizeAllocation", finalizeAllocationFunction())
|
||||
.render();
|
||||
}
|
||||
else
|
||||
@ -2324,10 +2324,10 @@ string YulUtilFunctions::copyArrayFromStorageToMemoryFunction(ArrayType const& _
|
||||
solAssert(!_from.isByteArray(), "");
|
||||
solAssert(*_to.withLocation(DataLocation::Storage, _from.isPointer()) == _from, "");
|
||||
return Whiskers(R"(
|
||||
function <functionName>(slot) -> memptr {
|
||||
function <functionName>(slot) -> memPtr {
|
||||
let length := <lengthFunction>(slot)
|
||||
memptr := <allocateArray>(length)
|
||||
let mpos := memptr
|
||||
memPtr := <allocateArray>(length)
|
||||
let mpos := memPtr
|
||||
<?dynamic>mpos := add(mpos, 0x20)</dynamic>
|
||||
let spos := <arrayDataArea>(slot)
|
||||
for { let i := 0 } lt(i, length) { i := add(i, 1) } {
|
||||
@ -2793,28 +2793,24 @@ string YulUtilFunctions::prepareStoreFunction(Type const& _type)
|
||||
|
||||
string YulUtilFunctions::allocationFunction()
|
||||
{
|
||||
string functionName = "allocateMemory";
|
||||
string functionName = "allocate_memory";
|
||||
return m_functionCollector.createFunction(functionName, [&]() {
|
||||
return Whiskers(R"(
|
||||
function <functionName>(size) -> memPtr {
|
||||
memPtr := mload(<freeMemoryPointer>)
|
||||
let newFreePtr := add(memPtr, <roundUp>(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { <panic>() }
|
||||
mstore(<freeMemoryPointer>, newFreePtr)
|
||||
memPtr := <allocateUnbounded>()
|
||||
<finalizeAllocation>(memPtr, size)
|
||||
}
|
||||
)")
|
||||
("functionName", functionName)
|
||||
("freeMemoryPointer", to_string(CompilerUtils::freeMemoryPointer))
|
||||
("roundUp", roundUpFunction())
|
||||
("panic", panicFunction(PanicCode::ResourceError))
|
||||
("allocateUnbounded", allocateUnboundedFunction())
|
||||
("finalizeAllocation", finalizeAllocationFunction())
|
||||
.render();
|
||||
});
|
||||
}
|
||||
|
||||
string YulUtilFunctions::allocationTemporaryMemoryFunction()
|
||||
string YulUtilFunctions::allocateUnboundedFunction()
|
||||
{
|
||||
string functionName = "allocateTemporaryMemory";
|
||||
string functionName = "allocate_unbounded";
|
||||
return m_functionCollector.createFunction(functionName, [&]() {
|
||||
return Whiskers(R"(
|
||||
function <functionName>() -> memPtr {
|
||||
@ -2827,15 +2823,22 @@ string YulUtilFunctions::allocationTemporaryMemoryFunction()
|
||||
});
|
||||
}
|
||||
|
||||
string YulUtilFunctions::releaseTemporaryMemoryFunction()
|
||||
string YulUtilFunctions::finalizeAllocationFunction()
|
||||
{
|
||||
string functionName = "releaseTemporaryMemory";
|
||||
return m_functionCollector.createFunction(functionName, [&](){
|
||||
string functionName = "finalize_allocation";
|
||||
return m_functionCollector.createFunction(functionName, [&]() {
|
||||
return Whiskers(R"(
|
||||
function <functionName>() {
|
||||
function <functionName>(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, <roundUp>(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { <panic>() }
|
||||
mstore(<freeMemoryPointer>, newFreePtr)
|
||||
}
|
||||
)")
|
||||
("functionName", functionName)
|
||||
("freeMemoryPointer", to_string(CompilerUtils::freeMemoryPointer))
|
||||
("roundUp", roundUpFunction())
|
||||
("panic", panicFunction(PanicCode::ResourceError))
|
||||
.render();
|
||||
});
|
||||
}
|
||||
@ -3625,7 +3628,7 @@ string YulUtilFunctions::packedHashFunction(
|
||||
return m_functionCollector.createFunction(functionName, [&]() {
|
||||
Whiskers templ(R"(
|
||||
function <functionName>(<variables>) -> hash {
|
||||
let pos := mload(<freeMemoryPointer>)
|
||||
let pos := <allocateUnbounded>()
|
||||
let end := <packedEncode>(pos <comma> <variables>)
|
||||
hash := keccak256(pos, sub(end, pos))
|
||||
}
|
||||
@ -3633,7 +3636,7 @@ string YulUtilFunctions::packedHashFunction(
|
||||
templ("functionName", functionName);
|
||||
templ("variables", suffixedVariableNameList("var_", 1, 1 + sizeOnStack));
|
||||
templ("comma", sizeOnStack > 0 ? "," : "");
|
||||
templ("freeMemoryPointer", to_string(CompilerUtils::freeMemoryPointer));
|
||||
templ("allocateUnbounded", allocateUnboundedFunction());
|
||||
templ("packedEncode", ABIFunctions(m_evmVersion, m_revertStrings, m_functionCollector).tupleEncoderPacked(_givenTypes, _targetTypes));
|
||||
return templ.render();
|
||||
});
|
||||
@ -4149,7 +4152,7 @@ string YulUtilFunctions::tryDecodeErrorMessageFunction()
|
||||
function <functionName>() -> ret {
|
||||
if lt(returndatasize(), 0x44) { leave }
|
||||
|
||||
let data := mload(<freeMemoryPointer>)
|
||||
let data := <allocateUnbounded>()
|
||||
returndatacopy(data, 4, sub(returndatasize(), 4))
|
||||
|
||||
let offset := mload(data)
|
||||
@ -4167,13 +4170,13 @@ string YulUtilFunctions::tryDecodeErrorMessageFunction()
|
||||
let end := add(add(msg, 0x20), length)
|
||||
if gt(end, add(data, sub(returndatasize(), 4))) { leave }
|
||||
|
||||
mstore(<freeMemoryPointer>, add(add(msg, 0x20), <roundUp>(length)))
|
||||
<finalizeAllocation>(data, add(offset, add(0x20, length)))
|
||||
ret := msg
|
||||
}
|
||||
)")
|
||||
("functionName", functionName)
|
||||
("freeMemoryPointer", to_string(CompilerUtils::freeMemoryPointer))
|
||||
("roundUp", roundUpFunction())
|
||||
("allocateUnbounded", allocateUnboundedFunction())
|
||||
("finalizeAllocation", finalizeAllocationFunction())
|
||||
.render();
|
||||
});
|
||||
}
|
||||
|
@ -352,16 +352,20 @@ public:
|
||||
|
||||
/// @returns the name of a function that allocates memory.
|
||||
/// Modifies the "free memory pointer"
|
||||
/// Arguments: size
|
||||
/// Return value: pointer
|
||||
/// signature: (size) -> memPtr
|
||||
std::string allocationFunction();
|
||||
|
||||
/// @returns the name of the function that allocates temporary memory with predefined size
|
||||
/// Return value: pointer
|
||||
std::string allocationTemporaryMemoryFunction();
|
||||
/// @returns the name of the function that allocates memory whose size might be defined later.
|
||||
/// The allocation can be finalized using finalizeAllocationFunction.
|
||||
/// Any other allocation will invalidate the memory pointer unless finalizeAllocationFunction
|
||||
/// is called.
|
||||
/// signature: () -> memPtr
|
||||
std::string allocateUnboundedFunction();
|
||||
|
||||
/// @returns the name of the function that releases previously allocated temporary memory
|
||||
std::string releaseTemporaryMemoryFunction();
|
||||
/// @returns the name of the function that finalizes an unbounded memory allocation,
|
||||
/// i.e. sets its size and makes the allocation permanent.
|
||||
/// signature: (memPtr, size) ->
|
||||
std::string finalizeAllocationFunction();
|
||||
|
||||
/// @returns the name of a function that zeroes an array.
|
||||
/// signature: (dataStart, dataSizeInBytes) ->
|
||||
|
@ -1035,13 +1035,13 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
}
|
||||
solAssert(indexedArgs.size() <= 4, "Too many indexed arguments.");
|
||||
Whiskers templ(R"({
|
||||
let <pos> := <freeMemory>
|
||||
let <pos> := <allocateUnbounded>()
|
||||
let <end> := <encode>(<pos> <nonIndexedArgs>)
|
||||
<log>(<pos>, sub(<end>, <pos>) <indexedArgs>)
|
||||
})");
|
||||
templ("pos", m_context.newYulVariable());
|
||||
templ("end", m_context.newYulVariable());
|
||||
templ("freeMemory", freeMemory());
|
||||
templ("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
||||
templ("encode", abi.tupleEncoder(nonIndexedArgTypes, nonIndexedParamTypes));
|
||||
templ("nonIndexedArgs", joinHumanReadablePrefixed(nonIndexedArgs));
|
||||
templ("log", "log" + to_string(indexedArgs.size()));
|
||||
@ -1107,8 +1107,11 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
else
|
||||
{
|
||||
// Used to reset the free memory pointer later.
|
||||
// TODO This is an abuse of the `allocateUnbounded` function.
|
||||
// We might want to introduce a new set of memory handling functions here
|
||||
// a la "setMemoryCheckPoint" and "freeUntilCheckPoint".
|
||||
string freeMemoryPre = m_context.newYulVariable();
|
||||
m_code << "let " << freeMemoryPre << " := " << freeMemory() << "\n";
|
||||
m_code << "let " << freeMemoryPre << " := " << m_utils.allocateUnboundedFunction() << "()\n";
|
||||
IRVariable array = convert(*arguments[0], *TypeProvider::bytesMemory());
|
||||
IRVariable hashVariable(m_context.newYulVariable(), *TypeProvider::fixedBytes(32));
|
||||
|
||||
@ -1125,26 +1128,26 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
IRVariable selectorVariable(m_context.newYulVariable(), *TypeProvider::fixedBytes(4));
|
||||
define(selectorVariable, hashVariable);
|
||||
selector = selectorVariable.name();
|
||||
m_code << "mstore(" << to_string(CompilerUtils::freeMemoryPointer) << ", " << freeMemoryPre << ")\n";
|
||||
m_code << m_utils.finalizeAllocationFunction() << "(" << freeMemoryPre << ", 0)\n";
|
||||
}
|
||||
}
|
||||
else if (functionType->kind() == FunctionType::Kind::ABIEncodeWithSelector)
|
||||
selector = convert(*arguments.front(), *TypeProvider::fixedBytes(4)).name();
|
||||
|
||||
Whiskers templ(R"(
|
||||
let <data> := <allocateTemporary>()
|
||||
let <mpos> := add(<data>, 0x20)
|
||||
let <data> := <allocateUnbounded>()
|
||||
let <memPtr> := add(<data>, 0x20)
|
||||
<?+selector>
|
||||
mstore(<mpos>, <selector>)
|
||||
<mpos> := add(<mpos>, 4)
|
||||
mstore(<memPtr>, <selector>)
|
||||
<memPtr> := add(<memPtr>, 4)
|
||||
</+selector>
|
||||
let <mend> := <encode>(<mpos><arguments>)
|
||||
let <mend> := <encode>(<memPtr><arguments>)
|
||||
mstore(<data>, sub(<mend>, add(<data>, 0x20)))
|
||||
mstore(<freeMemPtr>, <roundUp>(<mend>))
|
||||
<finalizeAllocation>(<data>, sub(<mend>, <data>))
|
||||
)");
|
||||
templ("data", IRVariable(_functionCall).part("mpos").name());
|
||||
templ("allocateTemporary", m_utils.allocationTemporaryMemoryFunction());
|
||||
templ("mpos", m_context.newYulVariable());
|
||||
templ("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
||||
templ("memPtr", m_context.newYulVariable());
|
||||
templ("mend", m_context.newYulVariable());
|
||||
templ("selector", selector);
|
||||
templ("encode",
|
||||
@ -1153,8 +1156,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
m_context.abiFunctions().tupleEncoder(argumentTypes, targetTypes, false)
|
||||
);
|
||||
templ("arguments", joinHumanReadablePrefixed(argumentVars));
|
||||
templ("freeMemPtr", to_string(CompilerUtils::freeMemoryPointer));
|
||||
templ("roundUp", m_utils.roundUpFunction());
|
||||
templ("finalizeAllocation", m_utils.finalizeAllocationFunction());
|
||||
|
||||
m_code << templ.render();
|
||||
break;
|
||||
@ -1214,7 +1216,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
solAssert(type(*arguments.front()).isImplicitlyConvertibleTo(*TypeProvider::stringMemory()),"");
|
||||
|
||||
Whiskers templ(R"({
|
||||
let <pos> := <allocateTemporary>()
|
||||
let <pos> := <allocateUnbounded>()
|
||||
mstore(<pos>, <hash>)
|
||||
let <end> := <encode>(add(<pos>, 4) <argumentVars>)
|
||||
revert(<pos>, sub(<end>, <pos>))
|
||||
@ -1222,7 +1224,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
templ("pos", m_context.newYulVariable());
|
||||
templ("end", m_context.newYulVariable());
|
||||
templ("hash", util::selectorFromSignature("Error(string)").str());
|
||||
templ("allocateTemporary", m_utils.allocationTemporaryMemoryFunction());
|
||||
templ("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
||||
templ(
|
||||
"argumentVars",
|
||||
joinHumanReadablePrefixed(IRVariable{*arguments.front()}.stackSlots())
|
||||
@ -1396,7 +1398,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
m_context.subObjectsCreated().insert(contract);
|
||||
|
||||
Whiskers t(R"(
|
||||
let <memPos> := <allocateTemporaryMemory>()
|
||||
let <memPos> := <allocateUnbounded>()
|
||||
let <memEnd> := add(<memPos>, datasize("<object>"))
|
||||
if or(gt(<memEnd>, 0xffffffffffffffff), lt(<memEnd>, <memPos>)) { <panic>() }
|
||||
datacopy(<memPos>, dataoffset("<object>"), datasize("<object>"))
|
||||
@ -1411,12 +1413,10 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
<!isTryCall>
|
||||
if iszero(<address>) { <forwardingRevert>() }
|
||||
</isTryCall>
|
||||
<releaseTemporaryMemory>()
|
||||
)");
|
||||
t("memPos", m_context.newYulVariable());
|
||||
t("memEnd", m_context.newYulVariable());
|
||||
t("allocateTemporaryMemory", m_utils.allocationTemporaryMemoryFunction());
|
||||
t("releaseTemporaryMemory", m_utils.releaseTemporaryMemoryFunction());
|
||||
t("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
||||
t("object", IRNames::creationObject(*contract));
|
||||
t("panic", m_utils.panicFunction(PanicCode::ResourceError));
|
||||
t("abiEncode",
|
||||
@ -1489,7 +1489,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
argumentStrings += IRVariable(*arg).stackSlots();
|
||||
}
|
||||
Whiskers templ(R"(
|
||||
let <pos> := <allocateTemporary>()
|
||||
let <pos> := <allocateUnbounded>()
|
||||
let <end> := <encodeArgs>(<pos> <argumentString>)
|
||||
<?isECRecover>
|
||||
mstore(0, 0)
|
||||
@ -1501,7 +1501,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
templ("call", m_context.evmVersion().hasStaticCall() ? "staticcall" : "call");
|
||||
templ("isCall", !m_context.evmVersion().hasStaticCall());
|
||||
templ("shl", m_utils.shiftLeftFunction(offset * 8));
|
||||
templ("allocateTemporary", m_utils.allocationTemporaryMemoryFunction());
|
||||
templ("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
||||
templ("pos", m_context.newYulVariable());
|
||||
templ("end", m_context.newYulVariable());
|
||||
templ("isECRecover", FunctionType::Kind::ECRecover == functionType->kind());
|
||||
@ -2398,14 +2398,14 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
|
||||
// We could also just use MLOAD; POP right before the gas calculation, but the optimizer
|
||||
// would remove that, so we use MSTORE here.
|
||||
if (!funType.gasSet() && returnInfo.estimatedReturnSize > 0)
|
||||
m_code << "mstore(add(" << freeMemory() << ", " << to_string(returnInfo.estimatedReturnSize) << "), 0)\n";
|
||||
m_code << "mstore(add(" << m_utils.allocateUnboundedFunction() << "() , " << to_string(returnInfo.estimatedReturnSize) << "), 0)\n";
|
||||
}
|
||||
|
||||
Whiskers templ(R"(
|
||||
if iszero(extcodesize(<address>)) { <revertNoCode> }
|
||||
|
||||
// storage for arguments and returned data
|
||||
let <pos> := <freeMemory>
|
||||
let <pos> := <allocateUnbounded>()
|
||||
mstore(<pos>, <shl28>(<funSel>))
|
||||
let <end> := <encodeArgs>(add(<pos>, 4) <argumentString>)
|
||||
|
||||
@ -2421,7 +2421,7 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
|
||||
</dynamicReturnSize>
|
||||
|
||||
// update freeMemoryPointer according to dynamic return size
|
||||
mstore(<freeMemoryPointer>, add(<pos>, <roundUp>(<returnSize>)))
|
||||
<finalizeAllocation>(<pos>, <returnSize>)
|
||||
|
||||
// decode return parameters from external try-call into retVars
|
||||
<?+retVars> <retVars> := </+retVars> <abiDecode>(<pos>, add(<pos>, <returnSize>))
|
||||
@ -2434,7 +2434,8 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
|
||||
templ("success", IRNames::trySuccessConditionVariable(_functionCall));
|
||||
else
|
||||
templ("success", m_context.newYulVariable());
|
||||
templ("freeMemory", freeMemory());
|
||||
templ("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
||||
templ("finalizeAllocation", m_utils.finalizeAllocationFunction());
|
||||
templ("shl28", m_utils.shiftLeftFunction(8 * (32 - 4)));
|
||||
|
||||
templ("funSel", IRVariable(_functionCall.expression()).part("functionSelector").name());
|
||||
@ -2456,7 +2457,6 @@ void IRGeneratorForStatements::appendExternalFunctionCall(
|
||||
templ("roundUp", m_utils.roundUpFunction());
|
||||
templ("abiDecode", m_context.abiFunctions().tupleDecoder(returnInfo.returnTypes, true));
|
||||
templ("dynamicReturnSize", returnInfo.dynamicReturnSize);
|
||||
templ("freeMemoryPointer", to_string(CompilerUtils::freeMemoryPointer));
|
||||
|
||||
templ("noTryCall", !_functionCall.annotation().tryCall);
|
||||
|
||||
@ -2524,7 +2524,7 @@ void IRGeneratorForStatements::appendBareCall(
|
||||
solAssert(!_functionCall.annotation().tryCall, "");
|
||||
Whiskers templ(R"(
|
||||
<?needsEncoding>
|
||||
let <pos> := mload(<freeMemoryPointer>)
|
||||
let <pos> := <allocateUnbounded>()
|
||||
let <length> := sub(<encode>(<pos> <?+arg>,</+arg> <arg>), <pos>)
|
||||
<!needsEncoding>
|
||||
let <pos> := add(<arg>, 0x20)
|
||||
@ -2537,7 +2537,7 @@ void IRGeneratorForStatements::appendBareCall(
|
||||
</+returndataVar>
|
||||
)");
|
||||
|
||||
templ("freeMemoryPointer", to_string(CompilerUtils::freeMemoryPointer));
|
||||
templ("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
||||
templ("pos", m_context.newYulVariable());
|
||||
templ("length", m_context.newYulVariable());
|
||||
|
||||
@ -2597,11 +2597,6 @@ void IRGeneratorForStatements::appendBareCall(
|
||||
m_code << templ.render();
|
||||
}
|
||||
|
||||
string IRGeneratorForStatements::freeMemory()
|
||||
{
|
||||
return "mload(" + to_string(CompilerUtils::freeMemoryPointer) + ")";
|
||||
}
|
||||
|
||||
IRVariable IRGeneratorForStatements::convert(IRVariable const& _from, Type const& _to)
|
||||
{
|
||||
if (_from.type() == _to)
|
||||
|
@ -125,10 +125,6 @@ private:
|
||||
std::vector<ASTPointer<Expression const>> const& _arguments
|
||||
);
|
||||
|
||||
/// @returns code that evaluates to the first unused memory slot (which does not have to
|
||||
/// be empty).
|
||||
static std::string freeMemory();
|
||||
|
||||
/// Generates the required conversion code and @returns an IRVariable referring to the value of @a _variable
|
||||
/// converted to type @a _to.
|
||||
IRVariable convert(IRVariable const& _variable, Type const& _to);
|
||||
|
@ -39,7 +39,7 @@ object "C_81" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
let param_0, param_1, param_2, param_3 := abi_decode_tuple_t_uint256t_uint256t_uint256t_uint256(4, calldatasize())
|
||||
let ret_0, ret_1, ret_2, ret_3 := fun_f_80(param_0, param_1, param_2, param_3)
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple_t_uint256_t_int256_t_uint256_t_uint256__to_t_uint256_t_int256_t_uint256_t_uint256__fromStack(memPos , ret_0, ret_1, ret_2, ret_3)
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -108,12 +108,13 @@ object "C_81" {
|
||||
|
||||
}
|
||||
|
||||
function allocateMemory(size) -> memPtr {
|
||||
function allocate_memory(size) -> memPtr {
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
|
||||
function allocate_unbounded() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function checked_exp_t_rational_0_by_1_t_uint256(exponent) -> power {
|
||||
@ -202,6 +203,13 @@ object "C_81" {
|
||||
converted := cleanup_t_int256(value)
|
||||
}
|
||||
|
||||
function finalize_allocation(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function fun_f_80(vloc_a_4, vloc_b_6, vloc_c_8, vloc_d_10) -> vloc__13, vloc__15, vloc__17, vloc__19 {
|
||||
let zero_value_for_type_t_uint256_1 := zero_value_for_split_t_uint256()
|
||||
vloc__13 := zero_value_for_type_t_uint256_1
|
||||
|
@ -64,12 +64,12 @@ object "D_16" {
|
||||
returndatacopy(_1, _1, returndatasize())
|
||||
revert(_1, returndatasize())
|
||||
}
|
||||
return(allocateMemory(_1), _1)
|
||||
return(allocate_memory(_1), _1)
|
||||
}
|
||||
}
|
||||
revert(0, 0)
|
||||
}
|
||||
function allocateMemory(size) -> memPtr
|
||||
function allocate_memory(size) -> memPtr
|
||||
{
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, and(add(size, 31), not(31)))
|
||||
|
@ -35,7 +35,7 @@ object "C_59" {
|
||||
let _4 := calldataload(add(4, offset))
|
||||
if gt(_4, _3) { panic_error_0x41() }
|
||||
let _5 := mul(_4, _2)
|
||||
let dst := allocateMemory(add(_5, _2))
|
||||
let dst := allocate_memory(add(_5, _2))
|
||||
let dst_1 := dst
|
||||
mstore(dst, _4)
|
||||
dst := add(dst, _2)
|
||||
@ -45,14 +45,14 @@ object "C_59" {
|
||||
for { } lt(i, _4) { i := add(i, 1) }
|
||||
{
|
||||
if slt(sub(calldatasize(), src), _2) { revert(_1, _1) }
|
||||
let value := allocateMemory(_2)
|
||||
let value := allocate_memory(_2)
|
||||
mstore(value, calldataload(src))
|
||||
mstore(dst, value)
|
||||
dst := add(dst, _2)
|
||||
src := add(src, _2)
|
||||
}
|
||||
let ret, ret_1 := fun_sumArray_58(dst_1)
|
||||
let memPos := allocateMemory(_1)
|
||||
let memPos := allocate_memory(_1)
|
||||
return(memPos, sub(abi_encode_uint256_t_string(memPos, ret, ret_1), memPos))
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,7 @@ object "C_59" {
|
||||
}
|
||||
tail := add(add(headStart, and(add(length, 31), not(31))), 96)
|
||||
}
|
||||
function allocateMemory(size) -> memPtr
|
||||
function allocate_memory(size) -> memPtr
|
||||
{
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, and(add(size, 31), not(31)))
|
||||
@ -85,7 +85,7 @@ object "C_59" {
|
||||
}
|
||||
function copy_literal_to_memory_64902fd228f7ef267f3b474dd6ef84bae434cf5546eee948e7ca26df3eda1927() -> memPtr
|
||||
{
|
||||
let memPtr_1 := allocateMemory(160)
|
||||
let memPtr_1 := allocate_memory(160)
|
||||
mstore(memPtr_1, 100)
|
||||
memPtr := memPtr_1
|
||||
mstore(add(memPtr_1, 0x20), "longstringlongstringlongstringlo")
|
||||
|
@ -40,7 +40,7 @@ object "Arraysum_34" {
|
||||
mstore(_1, _1)
|
||||
vloc_sum := checked_add_t_uint256(vloc_sum, sload(add(keccak256(_1, 0x20), vloc_i)))
|
||||
}
|
||||
let memPos := allocateMemory(_1)
|
||||
let memPos := allocate_memory(_1)
|
||||
return(memPos, sub(abi_encode_uint(memPos, vloc_sum), memPos))
|
||||
}
|
||||
}
|
||||
@ -51,7 +51,7 @@ object "Arraysum_34" {
|
||||
tail := add(headStart, 32)
|
||||
mstore(headStart, value0)
|
||||
}
|
||||
function allocateMemory(size) -> memPtr
|
||||
function allocate_memory(size) -> memPtr
|
||||
{
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, and(add(size, 31), not(31)))
|
||||
|
File diff suppressed because one or more lines are too long
@ -26,7 +26,7 @@ object \"C_7\" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
abi_decode_tuple_(4, calldatasize())
|
||||
fun_f_6()
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple__to__fromStack(memPos)
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -40,9 +40,15 @@ object \"C_7\" {
|
||||
}
|
||||
function abi_encode_tuple__to__fromStack(headStart) -> tail
|
||||
{ tail := add(headStart, 0) }
|
||||
function allocateMemory(size) -> memPtr
|
||||
function allocate_memory(size) -> memPtr
|
||||
{
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
function allocate_unbounded() -> memPtr
|
||||
{ memPtr := mload(64) }
|
||||
function finalize_allocation(memPtr, size)
|
||||
{
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
|
@ -38,7 +38,7 @@ object \"C_7\" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
abi_decode_tuple_(4, calldatasize())
|
||||
fun_f_6()
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple__to__fromStack(memPos )
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -58,8 +58,16 @@ object \"C_7\" {
|
||||
|
||||
}
|
||||
|
||||
function allocateMemory(size) -> memPtr {
|
||||
function allocate_memory(size) -> memPtr {
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
|
||||
function allocate_unbounded() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
}
|
||||
|
||||
function finalize_allocation(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
|
@ -89,7 +89,7 @@ object \"D_16\" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
abi_decode_tuple_(4, calldatasize())
|
||||
fun_f_15()
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple__to__fromStack(memPos )
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -109,21 +109,25 @@ object \"D_16\" {
|
||||
|
||||
}
|
||||
|
||||
function allocateMemory(size) -> memPtr {
|
||||
function allocate_memory(size) -> memPtr {
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
|
||||
function allocate_unbounded() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
}
|
||||
|
||||
function finalize_allocation(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function allocateTemporaryMemory() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
}
|
||||
|
||||
function fun_f_15() {
|
||||
|
||||
let _1 := allocateTemporaryMemory()
|
||||
let _1 := allocate_unbounded()
|
||||
let _2 := add(_1, datasize(\"C_3\"))
|
||||
if or(gt(_2, 0xffffffffffffffff), lt(_2, _1)) { panic_error_0x41() }
|
||||
datacopy(_1, dataoffset(\"C_3\"), datasize(\"C_3\"))
|
||||
@ -133,7 +137,6 @@ object \"D_16\" {
|
||||
|
||||
if iszero(expr_12_address) { revert_forward_1() }
|
||||
|
||||
releaseTemporaryMemory()
|
||||
let vloc_c_8_address := expr_12_address
|
||||
|
||||
}
|
||||
@ -144,9 +147,6 @@ object \"D_16\" {
|
||||
revert(0, 0x24)
|
||||
}
|
||||
|
||||
function releaseTemporaryMemory() {
|
||||
}
|
||||
|
||||
function revert_forward_1() {
|
||||
returndatacopy(0, 0, returndatasize())
|
||||
revert(0, returndatasize())
|
||||
|
@ -39,7 +39,7 @@ object "test_11" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
abi_decode_tuple_(4, calldatasize())
|
||||
let ret_0 := fun_f_10()
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple_t_bool__to_t_bool__fromStack(memPos , ret_0)
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -65,18 +65,26 @@ object "test_11" {
|
||||
|
||||
}
|
||||
|
||||
function allocateMemory(size) -> memPtr {
|
||||
function allocate_memory(size) -> memPtr {
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
|
||||
function allocate_unbounded() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function cleanup_t_bool(value) -> cleaned {
|
||||
cleaned := iszero(iszero(value))
|
||||
}
|
||||
|
||||
function finalize_allocation(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function fun_f_10() -> vloc__5 {
|
||||
let zero_value_for_type_t_bool_1 := zero_value_for_split_t_bool()
|
||||
vloc__5 := zero_value_for_type_t_bool_1
|
||||
|
@ -76,12 +76,12 @@ object "D_16" {
|
||||
returndatacopy(_1, _1, returndatasize())
|
||||
revert(_1, returndatasize())
|
||||
}
|
||||
return(allocateMemory(_1), _1)
|
||||
return(allocate_memory(_1), _1)
|
||||
}
|
||||
}
|
||||
revert(0, 0)
|
||||
}
|
||||
function allocateMemory(size) -> memPtr
|
||||
function allocate_memory(size) -> memPtr
|
||||
{
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, and(add(size, 31), not(31)))
|
||||
|
@ -38,7 +38,7 @@ object \"C_11\" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
abi_decode_tuple_(4, calldatasize())
|
||||
let ret_0 := fun_f_10()
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple_t_string_memory_ptr__to_t_string_memory_ptr__fromStack(memPos , ret_0)
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -68,22 +68,23 @@ object \"C_11\" {
|
||||
|
||||
}
|
||||
|
||||
function allocateMemory(size) -> memPtr {
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
function allocate_memory(size) -> memPtr {
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
|
||||
function allocate_memory_array_t_string_memory_ptr(length) -> memPtr {
|
||||
let allocSize := array_allocation_size_t_string_memory_ptr(length)
|
||||
memPtr := allocateMemory(allocSize)
|
||||
memPtr := allocate_memory(allocSize)
|
||||
|
||||
mstore(memPtr, length)
|
||||
|
||||
}
|
||||
|
||||
function allocate_unbounded() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
}
|
||||
|
||||
function array_allocation_size_t_string_memory_ptr(length) -> size {
|
||||
// Make sure we can allocate memory without overflow
|
||||
if gt(length, 0xffffffffffffffff) { panic_error_0x41() }
|
||||
@ -128,6 +129,13 @@ object \"C_11\" {
|
||||
}
|
||||
}
|
||||
|
||||
function finalize_allocation(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function fun_f_10() -> vloc__5_mpos {
|
||||
let zero_value_for_type_t_string_memory_ptr_1_mpos := zero_value_for_split_t_string_memory_ptr()
|
||||
vloc__5_mpos := zero_value_for_type_t_string_memory_ptr_1_mpos
|
||||
|
@ -38,7 +38,7 @@ object \"C_11\" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
abi_decode_tuple_(4, calldatasize())
|
||||
let ret_0 := fun_f_10()
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple_t_bytes32__to_t_bytes32__fromStack(memPos , ret_0)
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -64,12 +64,13 @@ object \"C_11\" {
|
||||
|
||||
}
|
||||
|
||||
function allocateMemory(size) -> memPtr {
|
||||
function allocate_memory(size) -> memPtr {
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
|
||||
function allocate_unbounded() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function cleanup_t_bytes32(value) -> cleaned {
|
||||
@ -80,6 +81,13 @@ object \"C_11\" {
|
||||
converted := 0x6162636162630000000000000000000000000000000000000000000000000000
|
||||
}
|
||||
|
||||
function finalize_allocation(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function fun_f_10() -> vloc__5 {
|
||||
let zero_value_for_type_t_bytes32_1 := zero_value_for_split_t_bytes32()
|
||||
vloc__5 := zero_value_for_type_t_bytes32_1
|
||||
|
@ -38,7 +38,7 @@ object \"C_11\" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
abi_decode_tuple_(4, calldatasize())
|
||||
let ret_0 := fun_f_10()
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple_t_bytes4__to_t_bytes4__fromStack(memPos , ret_0)
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -64,12 +64,13 @@ object \"C_11\" {
|
||||
|
||||
}
|
||||
|
||||
function allocateMemory(size) -> memPtr {
|
||||
function allocate_memory(size) -> memPtr {
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
|
||||
function allocate_unbounded() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function cleanup_t_bytes4(value) -> cleaned {
|
||||
@ -84,6 +85,13 @@ object \"C_11\" {
|
||||
converted := shift_left_224(cleanup_t_rational_1633837924_by_1(value))
|
||||
}
|
||||
|
||||
function finalize_allocation(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function fun_f_10() -> vloc__5 {
|
||||
let zero_value_for_type_t_bytes4_1 := zero_value_for_split_t_bytes4()
|
||||
vloc__5 := zero_value_for_type_t_bytes4_1
|
||||
|
@ -38,7 +38,7 @@ object \"C_11\" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
abi_decode_tuple_(4, calldatasize())
|
||||
let ret_0 := fun_f_10()
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple_t_string_memory_ptr__to_t_string_memory_ptr__fromStack(memPos , ret_0)
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -68,22 +68,23 @@ object \"C_11\" {
|
||||
|
||||
}
|
||||
|
||||
function allocateMemory(size) -> memPtr {
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
function allocate_memory(size) -> memPtr {
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
|
||||
function allocate_memory_array_t_string_memory_ptr(length) -> memPtr {
|
||||
let allocSize := array_allocation_size_t_string_memory_ptr(length)
|
||||
memPtr := allocateMemory(allocSize)
|
||||
memPtr := allocate_memory(allocSize)
|
||||
|
||||
mstore(memPtr, length)
|
||||
|
||||
}
|
||||
|
||||
function allocate_unbounded() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
}
|
||||
|
||||
function array_allocation_size_t_string_memory_ptr(length) -> size {
|
||||
// Make sure we can allocate memory without overflow
|
||||
if gt(length, 0xffffffffffffffff) { panic_error_0x41() }
|
||||
@ -128,6 +129,13 @@ object \"C_11\" {
|
||||
}
|
||||
}
|
||||
|
||||
function finalize_allocation(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function fun_f_10() -> vloc__5_mpos {
|
||||
let zero_value_for_type_t_string_memory_ptr_1_mpos := zero_value_for_split_t_string_memory_ptr()
|
||||
vloc__5_mpos := zero_value_for_type_t_string_memory_ptr_1_mpos
|
||||
|
@ -38,7 +38,7 @@ object \"C_11\" {
|
||||
if callvalue() { revert(0, 0) }
|
||||
abi_decode_tuple_(4, calldatasize())
|
||||
let ret_0 := fun_f_10()
|
||||
let memPos := allocateMemory(0)
|
||||
let memPos := allocate_memory(0)
|
||||
let memEnd := abi_encode_tuple_t_bytes4__to_t_bytes4__fromStack(memPos , ret_0)
|
||||
return(memPos, sub(memEnd, memPos))
|
||||
}
|
||||
@ -64,12 +64,13 @@ object \"C_11\" {
|
||||
|
||||
}
|
||||
|
||||
function allocateMemory(size) -> memPtr {
|
||||
function allocate_memory(size) -> memPtr {
|
||||
memPtr := allocate_unbounded()
|
||||
finalize_allocation(memPtr, size)
|
||||
}
|
||||
|
||||
function allocate_unbounded() -> memPtr {
|
||||
memPtr := mload(64)
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function cleanup_t_bytes4(value) -> cleaned {
|
||||
@ -84,6 +85,13 @@ object \"C_11\" {
|
||||
converted := shift_left_224(cleanup_t_rational_2864434397_by_1(value))
|
||||
}
|
||||
|
||||
function finalize_allocation(memPtr, size) {
|
||||
let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
|
||||
// protect against overflow
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
|
||||
function fun_f_10() -> vloc__5 {
|
||||
let zero_value_for_type_t_bytes4_1 := zero_value_for_split_t_bytes4()
|
||||
vloc__5 := zero_value_for_type_t_bytes4_1
|
||||
|
@ -14,9 +14,9 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// creation:
|
||||
// codeDepositCost: 1175600
|
||||
// executionCost: 1221
|
||||
// totalCost: 1176821
|
||||
// codeDepositCost: 1181400
|
||||
// executionCost: 1227
|
||||
// totalCost: 1182627
|
||||
// external:
|
||||
// a(): 1130
|
||||
// b(uint256): infinite
|
||||
|
@ -14,7 +14,6 @@ contract C {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
|
Loading…
Reference in New Issue
Block a user