mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
IRGenerationContext: Extract code for enumerating dispatchable functions from generateInternalDispatch() into a separate function
This commit is contained in:
parent
bd75543900
commit
6c6a8a74e8
@ -144,29 +144,27 @@ string IRGenerationContext::generateInternalDispatchFunction(YulArity const& _ar
|
|||||||
templ("assignment_op", _arity.out > 0 ? ":=" : "");
|
templ("assignment_op", _arity.out > 0 ? ":=" : "");
|
||||||
templ("out", suffixedVariableNameList("out_", 0, _arity.out));
|
templ("out", suffixedVariableNameList("out_", 0, _arity.out));
|
||||||
|
|
||||||
// UNIMPLEMENTED: Internal library calls via pointers are not implemented yet.
|
vector<map<string, string>> cases;
|
||||||
// We're not generating code for internal library functions here even though it's possible
|
for (FunctionDefinition const* function: collectFunctionsOfArity(_arity))
|
||||||
// to call them via pointers. Right now such calls end up triggering the `default` case in
|
|
||||||
// the switch above.
|
|
||||||
vector<map<string, string>> functions;
|
|
||||||
for (auto const& contract: mostDerivedContract().annotation().linearizedBaseContracts)
|
|
||||||
for (FunctionDefinition const* function: contract->definedFunctions())
|
|
||||||
if (
|
|
||||||
!function->isConstructor() &&
|
|
||||||
YulArity::fromType(*TypeProvider::function(*function, FunctionType::Kind::Internal)) == _arity
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
|
solAssert(function, "");
|
||||||
|
solAssert(
|
||||||
|
YulArity::fromType(*TypeProvider::function(*function, FunctionType::Kind::Internal)) == _arity,
|
||||||
|
"A single dispatch function can only handle functions of one arity"
|
||||||
|
);
|
||||||
|
solAssert(!function->isConstructor(), "");
|
||||||
// 0 is reserved for uninitialized function pointers
|
// 0 is reserved for uninitialized function pointers
|
||||||
solAssert(function->id() != 0, "Unexpected function ID: 0");
|
solAssert(function->id() != 0, "Unexpected function ID: 0");
|
||||||
|
|
||||||
functions.emplace_back(map<string, string> {
|
cases.emplace_back(map<string, string>{
|
||||||
{"funID", to_string(function->id())},
|
{"funID", to_string(function->id())},
|
||||||
{"name", IRNames::function(*function)}
|
{"name", IRNames::function(*function)}
|
||||||
});
|
});
|
||||||
|
|
||||||
enqueueFunctionForCodeGeneration(*function);
|
enqueueFunctionForCodeGeneration(*function);
|
||||||
}
|
}
|
||||||
templ("cases", move(functions));
|
|
||||||
|
templ("cases", move(cases));
|
||||||
return templ.render();
|
return templ.render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -186,3 +184,20 @@ std::string IRGenerationContext::revertReasonIfDebug(std::string const& _message
|
|||||||
return YulUtilFunctions::revertReasonIfDebug(m_revertStrings, _message);
|
return YulUtilFunctions::revertReasonIfDebug(m_revertStrings, _message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set<FunctionDefinition const*> IRGenerationContext::collectFunctionsOfArity(YulArity const& _arity)
|
||||||
|
{
|
||||||
|
// UNIMPLEMENTED: Internal library calls via pointers are not implemented yet.
|
||||||
|
// We're not returning any internal library functions here even though it's possible
|
||||||
|
// to call them via pointers. Right now such calls end will up triggering the `default` case in
|
||||||
|
// the switch in the generated dispatch function.
|
||||||
|
set<FunctionDefinition const*> functions;
|
||||||
|
for (auto const& contract: mostDerivedContract().annotation().linearizedBaseContracts)
|
||||||
|
for (FunctionDefinition const* function: contract->definedFunctions())
|
||||||
|
if (
|
||||||
|
!function->isConstructor() &&
|
||||||
|
YulArity::fromType(*TypeProvider::function(*function, FunctionType::Kind::Internal)) == _arity
|
||||||
|
)
|
||||||
|
functions.insert(function);
|
||||||
|
|
||||||
|
return functions;
|
||||||
|
}
|
||||||
|
@ -120,6 +120,8 @@ public:
|
|||||||
std::set<ContractDefinition const*, ASTNode::CompareByID>& subObjectsCreated() { return m_subObjects; }
|
std::set<ContractDefinition const*, ASTNode::CompareByID>& subObjectsCreated() { return m_subObjects; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::set<FunctionDefinition const*> collectFunctionsOfArity(YulArity const& _arity);
|
||||||
|
|
||||||
langutil::EVMVersion m_evmVersion;
|
langutil::EVMVersion m_evmVersion;
|
||||||
RevertStrings m_revertStrings;
|
RevertStrings m_revertStrings;
|
||||||
OptimiserSettings m_optimiserSettings;
|
OptimiserSettings m_optimiserSettings;
|
||||||
|
Loading…
Reference in New Issue
Block a user