mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allocate for returning runtime code.
This commit is contained in:
parent
1814cad4f2
commit
79acebe46f
@ -802,29 +802,24 @@ void IRGenerator::generateImplicitConstructors(ContractDefinition const& _contra
|
|||||||
string IRGenerator::deployCode(ContractDefinition const& _contract)
|
string IRGenerator::deployCode(ContractDefinition const& _contract)
|
||||||
{
|
{
|
||||||
Whiskers t(R"X(
|
Whiskers t(R"X(
|
||||||
<#loadImmutables>
|
let <codeOffset> := <allocateUnbounded>()
|
||||||
let <var> := mload(<memoryOffset>)
|
codecopy(<codeOffset>, dataoffset("<object>"), datasize("<object>"))
|
||||||
</loadImmutables>
|
<#immutables>
|
||||||
|
setimmutable(<codeOffset>, "<immutableName>", <value>)
|
||||||
codecopy(0, dataoffset("<object>"), datasize("<object>"))
|
</immutables>
|
||||||
|
return(<codeOffset>, datasize("<object>"))
|
||||||
<#storeImmutables>
|
|
||||||
setimmutable(0, "<immutableName>", <var>)
|
|
||||||
</storeImmutables>
|
|
||||||
|
|
||||||
return(0, datasize("<object>"))
|
|
||||||
)X");
|
)X");
|
||||||
|
t("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
||||||
|
t("codeOffset", m_context.newYulVariable());
|
||||||
t("object", IRNames::deployedObject(_contract));
|
t("object", IRNames::deployedObject(_contract));
|
||||||
|
|
||||||
vector<map<string, string>> loadImmutables;
|
vector<map<string, string>> immutables;
|
||||||
vector<map<string, string>> storeImmutables;
|
|
||||||
|
|
||||||
if (_contract.isLibrary())
|
if (_contract.isLibrary())
|
||||||
{
|
{
|
||||||
solAssert(ContractType(_contract).immutableVariables().empty(), "");
|
solAssert(ContractType(_contract).immutableVariables().empty(), "");
|
||||||
storeImmutables.emplace_back(map<string, string>{
|
immutables.emplace_back(map<string, string>{
|
||||||
{"var"s, "address()"},
|
{"immutableName"s, IRNames::libraryAddressImmutable()},
|
||||||
{"immutableName"s, IRNames::libraryAddressImmutable()}
|
{"value"s, "address()"}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -833,20 +828,12 @@ string IRGenerator::deployCode(ContractDefinition const& _contract)
|
|||||||
{
|
{
|
||||||
solUnimplementedAssert(immutable->type()->isValueType(), "");
|
solUnimplementedAssert(immutable->type()->isValueType(), "");
|
||||||
solUnimplementedAssert(immutable->type()->sizeOnStack() == 1, "");
|
solUnimplementedAssert(immutable->type()->sizeOnStack() == 1, "");
|
||||||
string yulVar = m_context.newYulVariable();
|
immutables.emplace_back(map<string, string>{
|
||||||
loadImmutables.emplace_back(map<string, string>{
|
{"immutableName"s, to_string(immutable->id())},
|
||||||
{"var"s, yulVar},
|
{"value"s, "mload(" + to_string(m_context.immutableMemoryOffset(*immutable)) + ")"}
|
||||||
{"memoryOffset"s, to_string(m_context.immutableMemoryOffset(*immutable))}
|
|
||||||
});
|
|
||||||
storeImmutables.emplace_back(map<string, string>{
|
|
||||||
{"var"s, yulVar},
|
|
||||||
{"immutableName"s, to_string(immutable->id())}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
t("loadImmutables", std::move(loadImmutables));
|
t("immutables", std::move(immutables));
|
||||||
// reverse order to ease stack strain
|
|
||||||
reverse(storeImmutables.begin(), storeImmutables.end());
|
|
||||||
t("storeImmutables", std::move(storeImmutables));
|
|
||||||
return t.render();
|
return t.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user