MCPcopy Create free account
hub / github.com/argotorg/solidity / storeLiteralInMemoryFunction

Method storeLiteralInMemoryFunction

libsolidity/codegen/YulUtilFunctions.cpp:164–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164std::string YulUtilFunctions::storeLiteralInMemoryFunction(std::string const& _literal)
165{
166 std::string functionName = "store_literal_in_memory_" + util::toHex(util::keccak256(_literal).asBytes());
167
168 return m_functionCollector.createFunction(functionName, [&]() {
169 size_t words = (_literal.length() + 31) / 32;
170 std::vector<std::map<std::string, std::string>> wordParams(words);
171 for (size_t i = 0; i < words; ++i)
172 {
173 wordParams[i]["offset"] = std::to_string(i * 32);
174 wordParams[i]["wordValue"] = formatAsStringOrNumber(_literal.substr(32 * i, 32));
175 }
176
177 return Whiskers(R"(
178 function <functionName>(memPtr) {
179 <#word>
180 mstore(add(memPtr, <offset>), <wordValue>)
181 </word>
182 }
183 )")
184 ("functionName", functionName)
185 ("word", wordParams)
186 .render();
187 });
188}
189
190std::string YulUtilFunctions::copyLiteralToStorageFunction(std::string const& _literal)
191{

Callers 1

Calls 8

toHexFunction · 0.85
WhiskersClass · 0.85
asBytesMethod · 0.80
renderMethod · 0.80
keccak256Function · 0.50
to_stringFunction · 0.50
createFunctionMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected