| 2360 | } |
| 2361 | |
| 2362 | std::string YulUtilFunctions::arrayAllocationSizeFunction(ArrayType const& _type) |
| 2363 | { |
| 2364 | solAssert(_type.dataStoredIn(DataLocation::Memory), ""); |
| 2365 | std::string functionName = "array_allocation_size_" + _type.identifier(); |
| 2366 | return m_functionCollector.createFunction(functionName, [&]() { |
| 2367 | Whiskers w(R"( |
| 2368 | function <functionName>(length) -> size { |
| 2369 | // Make sure we can allocate memory without overflow |
| 2370 | if gt(length, 0xffffffffffffffff) { <panic>() } |
| 2371 | <?byteArray> |
| 2372 | size := <roundUp>(length) |
| 2373 | <!byteArray> |
| 2374 | size := mul(length, 0x20) |
| 2375 | </byteArray> |
| 2376 | <?dynamic> |
| 2377 | // add length slot |
| 2378 | size := add(size, 0x20) |
| 2379 | </dynamic> |
| 2380 | } |
| 2381 | )"); |
| 2382 | w("functionName", functionName); |
| 2383 | w("panic", panicFunction(PanicCode::ResourceError)); |
| 2384 | w("byteArray", _type.isByteArrayOrString()); |
| 2385 | w("roundUp", roundUpFunction()); |
| 2386 | w("dynamic", _type.isDynamicallySized()); |
| 2387 | return w.render(); |
| 2388 | }); |
| 2389 | } |
| 2390 | |
| 2391 | std::string YulUtilFunctions::arrayDataAreaFunction(ArrayType const& _type) |
| 2392 | { |
no test coverage detected