Use YulArity in IR generator

This commit is contained in:
Kamil Śliwak 2020-04-28 13:15:26 +02:00
parent 16e58449ab
commit 1a521cc7ac
3 changed files with 13 additions and 15 deletions

View File

@ -121,9 +121,9 @@ string IRGenerationContext::newYulVariable()
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, [&]() {
Whiskers templ(R"(
function <functionName>(fun <comma> <in>) <arrow> <out> {
@ -138,12 +138,12 @@ string IRGenerationContext::internalDispatch(size_t _in, size_t _out)
}
)");
templ("functionName", funName);
templ("comma", _in > 0 ? "," : "");
templ("comma", _arity.in > 0 ? "," : "");
YulUtilFunctions utils(m_evmVersion, m_revertStrings, m_functions);
templ("in", suffixedVariableNameList("in_", 0, _in));
templ("arrow", _out > 0 ? "->" : "");
templ("assignment_op", _out > 0 ? ":=" : "");
templ("out", suffixedVariableNameList("out_", 0, _out));
templ("in", suffixedVariableNameList("in_", 0, _arity.in));
templ("arrow", _arity.out > 0 ? "->" : "");
templ("assignment_op", _arity.out > 0 ? ":=" : "");
templ("out", suffixedVariableNameList("out_", 0, _arity.out));
// 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
@ -153,10 +153,8 @@ string IRGenerationContext::internalDispatch(size_t _in, size_t _out)
for (auto const& contract: mostDerivedContract().annotation().linearizedBaseContracts)
for (FunctionDefinition const* function: contract->definedFunctions())
if (
FunctionType const* functionType = TypeProvider::function(*function, FunctionType::Kind::Internal);
!function->isConstructor() &&
TupleType(functionType->parameterTypes()).sizeOnStack() == _in &&
TupleType(functionType->returnParameterTypes()).sizeOnStack() == _out
YulArity::fromType(*TypeProvider::function(*function, FunctionType::Kind::Internal)) == _arity
)
{
// 0 is reserved for uninitialized function pointers

View File

@ -102,7 +102,7 @@ public:
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).
YulUtilFunctions utils();

View File

@ -692,16 +692,16 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
joinHumanReadable(args) <<
")\n";
else
{
YulArity arity = YulArity::fromType(*functionType);
define(_functionCall) <<
// NOTE: internalDispatch() takes care of adding the function to function generation queue
m_context.internalDispatch(
TupleType(functionType->parameterTypes()).sizeOnStack(),
TupleType(functionType->returnParameterTypes()).sizeOnStack()
) <<
m_context.internalDispatch(arity) <<
"(" <<
IRVariable(_functionCall.expression()).part("functionIdentifier").name() <<
joinHumanReadablePrefixed(args) <<
")\n";
}
break;
}
case FunctionType::Kind::External: