| 143 | } |
| 144 | |
| 145 | std::string YulUtilFunctions::copyLiteralToMemoryFunction(std::string const& _literal) |
| 146 | { |
| 147 | std::string functionName = "copy_literal_to_memory_" + util::toHex(util::keccak256(_literal).asBytes()); |
| 148 | |
| 149 | return m_functionCollector.createFunction(functionName, [&]() { |
| 150 | return Whiskers(R"( |
| 151 | function <functionName>() -> memPtr { |
| 152 | memPtr := <arrayAllocationFunction>(<size>) |
| 153 | <storeLiteralInMem>(add(memPtr, 32)) |
| 154 | } |
| 155 | )") |
| 156 | ("functionName", functionName) |
| 157 | ("arrayAllocationFunction", allocateMemoryArrayFunction(*TypeProvider::array(DataLocation::Memory, true))) |
| 158 | ("size", std::to_string(_literal.size())) |
| 159 | ("storeLiteralInMem", storeLiteralInMemoryFunction(_literal)) |
| 160 | .render(); |
| 161 | }); |
| 162 | } |
| 163 | |
| 164 | std::string YulUtilFunctions::storeLiteralInMemoryFunction(std::string const& _literal) |
| 165 | { |