mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use YulArity in IR generator
This commit is contained in:
parent
16e58449ab
commit
1a521cc7ac
@ -121,9 +121,9 @@ string IRGenerationContext::newYulVariable()
|
|||||||
return "_" + to_string(++m_varCounter);
|
return "_" + to_string(++m_varCounter);
|
||||||
}
|
}
|
||||||
|
|
||||||
string IRGenerationContext::internalDispatch(size_t _in, size_t _out)
|
string IRGenerationContext::internalDispatch(YulArity const& _arity)
|
||||||
{
|
{
|
||||||
string funName = "dispatch_internal_in_" + to_string(_in) + "_out_" + to_string(_out);
|
string funName = "dispatch_internal_in_" + to_string(_arity.in) + "_out_" + to_string(_arity.out);
|
||||||
return m_functions.createFunction(funName, [&]() {
|
return m_functions.createFunction(funName, [&]() {
|
||||||
Whiskers templ(R"(
|
Whiskers templ(R"(
|
||||||
function <functionName>(fun <comma> <in>) <arrow> <out> {
|
function <functionName>(fun <comma> <in>) <arrow> <out> {
|
||||||
@ -138,12 +138,12 @@ string IRGenerationContext::internalDispatch(size_t _in, size_t _out)
|
|||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
templ("functionName", funName);
|
templ("functionName", funName);
|
||||||
templ("comma", _in > 0 ? "," : "");
|
templ("comma", _arity.in > 0 ? "," : "");
|
||||||
YulUtilFunctions utils(m_evmVersion, m_revertStrings, m_functions);
|
YulUtilFunctions utils(m_evmVersion, m_revertStrings, m_functions);
|
||||||
templ("in", suffixedVariableNameList("in_", 0, _in));
|
templ("in", suffixedVariableNameList("in_", 0, _arity.in));
|
||||||
templ("arrow", _out > 0 ? "->" : "");
|
templ("arrow", _arity.out > 0 ? "->" : "");
|
||||||
templ("assignment_op", _out > 0 ? ":=" : "");
|
templ("assignment_op", _arity.out > 0 ? ":=" : "");
|
||||||
templ("out", suffixedVariableNameList("out_", 0, _out));
|
templ("out", suffixedVariableNameList("out_", 0, _arity.out));
|
||||||
|
|
||||||
// UNIMPLEMENTED: Internal library calls via pointers are not implemented yet.
|
// UNIMPLEMENTED: Internal library calls via pointers are not implemented yet.
|
||||||
// We're not generating code for internal library functions here even though it's possible
|
// We're not generating code for internal library functions here even though it's possible
|
||||||
@ -153,10 +153,8 @@ string IRGenerationContext::internalDispatch(size_t _in, size_t _out)
|
|||||||
for (auto const& contract: mostDerivedContract().annotation().linearizedBaseContracts)
|
for (auto const& contract: mostDerivedContract().annotation().linearizedBaseContracts)
|
||||||
for (FunctionDefinition const* function: contract->definedFunctions())
|
for (FunctionDefinition const* function: contract->definedFunctions())
|
||||||
if (
|
if (
|
||||||
FunctionType const* functionType = TypeProvider::function(*function, FunctionType::Kind::Internal);
|
|
||||||
!function->isConstructor() &&
|
!function->isConstructor() &&
|
||||||
TupleType(functionType->parameterTypes()).sizeOnStack() == _in &&
|
YulArity::fromType(*TypeProvider::function(*function, FunctionType::Kind::Internal)) == _arity
|
||||||
TupleType(functionType->returnParameterTypes()).sizeOnStack() == _out
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// 0 is reserved for uninitialized function pointers
|
// 0 is reserved for uninitialized function pointers
|
||||||
|
@ -102,7 +102,7 @@ public:
|
|||||||
|
|
||||||
std::string newYulVariable();
|
std::string newYulVariable();
|
||||||
|
|
||||||
std::string internalDispatch(size_t _in, size_t _out);
|
std::string internalDispatch(YulArity const& _arity);
|
||||||
|
|
||||||
/// @returns a new copy of the utility function generator (but using the same function set).
|
/// @returns a new copy of the utility function generator (but using the same function set).
|
||||||
YulUtilFunctions utils();
|
YulUtilFunctions utils();
|
||||||
|
@ -692,16 +692,16 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
|||||||
joinHumanReadable(args) <<
|
joinHumanReadable(args) <<
|
||||||
")\n";
|
")\n";
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
YulArity arity = YulArity::fromType(*functionType);
|
||||||
define(_functionCall) <<
|
define(_functionCall) <<
|
||||||
// NOTE: internalDispatch() takes care of adding the function to function generation queue
|
// NOTE: internalDispatch() takes care of adding the function to function generation queue
|
||||||
m_context.internalDispatch(
|
m_context.internalDispatch(arity) <<
|
||||||
TupleType(functionType->parameterTypes()).sizeOnStack(),
|
|
||||||
TupleType(functionType->returnParameterTypes()).sizeOnStack()
|
|
||||||
) <<
|
|
||||||
"(" <<
|
"(" <<
|
||||||
IRVariable(_functionCall.expression()).part("functionIdentifier").name() <<
|
IRVariable(_functionCall.expression()).part("functionIdentifier").name() <<
|
||||||
joinHumanReadablePrefixed(args) <<
|
joinHumanReadablePrefixed(args) <<
|
||||||
")\n";
|
")\n";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FunctionType::Kind::External:
|
case FunctionType::Kind::External:
|
||||||
|
Loading…
Reference in New Issue
Block a user