| 982 | } |
| 983 | |
| 984 | std::string IRGenerator::deployCode(ContractDefinition const& _contract) |
| 985 | { |
| 986 | Whiskers t(R"X( |
| 987 | <?eof> |
| 988 | <?library> |
| 989 | mstore(<libraryAddressImmutableOffset>, address()) |
| 990 | </library> |
| 991 | returncontract("<object>", <auxDataStart>, <auxDataSize>) |
| 992 | <!eof> |
| 993 | let <codeOffset> := <allocateUnbounded>() |
| 994 | codecopy(<codeOffset>, dataoffset("<object>"), datasize("<object>")) |
| 995 | <#immutables> |
| 996 | setimmutable(<codeOffset>, "<immutableName>", <value>) |
| 997 | </immutables> |
| 998 | return(<codeOffset>, datasize("<object>")) |
| 999 | </eof> |
| 1000 | )X"); |
| 1001 | auto const eof = m_context.eofVersion().has_value(); |
| 1002 | t("eof", eof); |
| 1003 | t("allocateUnbounded", m_utils.allocateUnboundedFunction()); |
| 1004 | t("codeOffset", m_context.newYulVariable()); |
| 1005 | t("object", IRNames::deployedObject(_contract)); |
| 1006 | |
| 1007 | std::vector<std::map<std::string, std::string>> immutables; |
| 1008 | if (_contract.isLibrary()) |
| 1009 | { |
| 1010 | solAssert(ContractType(_contract).immutableVariables().empty(), ""); |
| 1011 | if (!eof) |
| 1012 | immutables.emplace_back(std::map<std::string, std::string>{ |
| 1013 | {"immutableName"s, IRNames::libraryAddressImmutable()}, |
| 1014 | {"value"s, "address()"} |
| 1015 | }); |
| 1016 | else |
| 1017 | t("libraryAddressImmutableOffset", std::to_string(m_context.libraryAddressImmutableOffset())); |
| 1018 | } |
| 1019 | else |
| 1020 | { |
| 1021 | for (VariableDeclaration const* immutable: ContractType(_contract).immutableVariables()) |
| 1022 | { |
| 1023 | solUnimplementedAssert(immutable->type()->isValueType()); |
| 1024 | solUnimplementedAssert(immutable->type()->sizeOnStack() == 1); |
| 1025 | if (!eof) |
| 1026 | immutables.emplace_back(std::map<std::string, std::string>{ |
| 1027 | {"immutableName"s, std::to_string(immutable->id())}, |
| 1028 | {"value"s, "mload(" + std::to_string(m_context.immutableMemoryOffset(*immutable)) + ")"} |
| 1029 | }); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | if (eof) |
| 1034 | { |
| 1035 | t("library", _contract.isLibrary()); |
| 1036 | t("auxDataStart", std::to_string(CompilerUtils::generalPurposeMemoryStart)); |
| 1037 | solAssert(m_context.reservedMemorySize() <= 0xFFFF, "Reserved memory size exceeded maximum allowed EOF data section size."); |
| 1038 | t("auxDataSize", std::to_string(m_context.reservedMemorySize())); |
| 1039 | } |
| 1040 | else |
| 1041 | t("immutables", std::move(immutables)); |
nothing calls this directly
no test coverage detected