| 101 | } |
| 102 | |
| 103 | std::string YulUtilFunctions::copyToMemoryFunction(bool _fromCalldata, bool _cleanup) |
| 104 | { |
| 105 | std::string functionName = |
| 106 | "copy_"s + |
| 107 | (_fromCalldata ? "calldata"s : "memory"s) + |
| 108 | "_to_memory"s + |
| 109 | (_cleanup ? "_with_cleanup"s : ""s); |
| 110 | |
| 111 | return m_functionCollector.createFunction(functionName, [&](std::vector<std::string>& _args, std::vector<std::string>&) { |
| 112 | _args = {"src", "dst", "length"}; |
| 113 | |
| 114 | if (_fromCalldata) |
| 115 | return Whiskers(R"( |
| 116 | calldatacopy(dst, src, length) |
| 117 | <?cleanup>mstore(add(dst, length), 0)</cleanup> |
| 118 | )") |
| 119 | ("cleanup", _cleanup) |
| 120 | .render(); |
| 121 | else |
| 122 | { |
| 123 | if (m_evmVersion.hasMcopy()) |
| 124 | return Whiskers(R"( |
| 125 | mcopy(dst, src, length) |
| 126 | <?cleanup>mstore(add(dst, length), 0)</cleanup> |
| 127 | )") |
| 128 | ("cleanup", _cleanup) |
| 129 | .render(); |
| 130 | else |
| 131 | return Whiskers(R"( |
| 132 | let i := 0 |
| 133 | for { } lt(i, length) { i := add(i, 32) } |
| 134 | { |
| 135 | mstore(add(dst, i), mload(add(src, i))) |
| 136 | } |
| 137 | <?cleanup>mstore(add(dst, length), 0)</cleanup> |
| 138 | )") |
| 139 | ("cleanup", _cleanup) |
| 140 | .render(); |
| 141 | } |
| 142 | }); |
| 143 | } |
| 144 | |
| 145 | std::string YulUtilFunctions::copyLiteralToMemoryFunction(std::string const& _literal) |
| 146 | { |
no test coverage detected