Add upto 32 function I/O parameters.

This commit is contained in:
Bhargava Shastry 2021-04-13 16:00:58 +02:00
parent 1df304b92d
commit d81a43e671
3 changed files with 151 additions and 2 deletions

View File

@ -875,6 +875,118 @@ void ProtoConverter::visitFunctionInputParams(FunctionCall const& _x, unsigned _
// We reverse the order of function input visits since it helps keep this switch case concise. // We reverse the order of function input visits since it helps keep this switch case concise.
switch (_numInputParams) switch (_numInputParams)
{ {
case 32:
visit(_x.in_param32());
m_output << ", ";
[[fallthrough]];
case 31:
visit(_x.in_param31());
m_output << ", ";
[[fallthrough]];
case 30:
visit(_x.in_param30());
m_output << ", ";
[[fallthrough]];
case 29:
visit(_x.in_param29());
m_output << ", ";
[[fallthrough]];
case 28:
visit(_x.in_param28());
m_output << ", ";
[[fallthrough]];
case 27:
visit(_x.in_param27());
m_output << ", ";
[[fallthrough]];
case 26:
visit(_x.in_param26());
m_output << ", ";
[[fallthrough]];
case 25:
visit(_x.in_param25());
m_output << ", ";
[[fallthrough]];
case 24:
visit(_x.in_param24());
m_output << ", ";
[[fallthrough]];
case 23:
visit(_x.in_param23());
m_output << ", ";
[[fallthrough]];
case 22:
visit(_x.in_param22());
m_output << ", ";
[[fallthrough]];
case 21:
visit(_x.in_param21());
m_output << ", ";
[[fallthrough]];
case 20:
visit(_x.in_param20());
m_output << ", ";
[[fallthrough]];
case 19:
visit(_x.in_param19());
m_output << ", ";
[[fallthrough]];
case 18:
visit(_x.in_param18());
m_output << ", ";
[[fallthrough]];
case 17:
visit(_x.in_param17());
m_output << ", ";
[[fallthrough]];
case 16:
visit(_x.in_param16());
m_output << ", ";
[[fallthrough]];
case 15:
visit(_x.in_param15());
m_output << ", ";
[[fallthrough]];
case 14:
visit(_x.in_param14());
m_output << ", ";
[[fallthrough]];
case 13:
visit(_x.in_param13());
m_output << ", ";
[[fallthrough]];
case 12:
visit(_x.in_param12());
m_output << ", ";
[[fallthrough]];
case 11:
visit(_x.in_param11());
m_output << ", ";
[[fallthrough]];
case 10:
visit(_x.in_param10());
m_output << ", ";
[[fallthrough]];
case 9:
visit(_x.in_param9());
m_output << ", ";
[[fallthrough]];
case 8:
visit(_x.in_param8());
m_output << ", ";
[[fallthrough]];
case 7:
visit(_x.in_param7());
m_output << ", ";
[[fallthrough]];
case 6:
visit(_x.in_param6());
m_output << ", ";
[[fallthrough]];
case 5:
visit(_x.in_param5());
m_output << ", ";
[[fallthrough]];
case 4: case 4:
visit(_x.in_param4()); visit(_x.in_param4());
m_output << ", "; m_output << ", ";
@ -941,6 +1053,9 @@ optional<string> ProtoConverter::functionExists(NumFunctionReturns _numReturns)
void ProtoConverter::visit(FunctionCall const& _x, string const& _functionName, bool _expression) void ProtoConverter::visit(FunctionCall const& _x, string const& _functionName, bool _expression)
{ {
// Disable recursive calls.
if (_functionName == m_currentFunctionName)
return;
yulAssert(m_functionSigMap.count(_functionName), "Proto fuzzer: Invalid function."); yulAssert(m_functionSigMap.count(_functionName), "Proto fuzzer: Invalid function.");
auto ret = m_functionSigMap.at(_functionName); auto ret = m_functionSigMap.at(_functionName);
unsigned numInParams = ret.first; unsigned numInParams = ret.first;
@ -1686,6 +1801,8 @@ void ProtoConverter::createFunctionDefAndCall(
// Obtain function name // Obtain function name
yulAssert(m_functionDefMap.count(&_x), "Proto fuzzer: Unregistered function"); yulAssert(m_functionDefMap.count(&_x), "Proto fuzzer: Unregistered function");
string funcName = m_functionDefMap.at(&_x); string funcName = m_functionDefMap.at(&_x);
string wasFuncName = m_currentFunctionName;
m_currentFunctionName = funcName;
vector<string> varsVec = {}; vector<string> varsVec = {};
m_output << "function " << funcName << "("; m_output << "function " << funcName << "(";
@ -1730,6 +1847,7 @@ void ProtoConverter::createFunctionDefAndCall(
m_inForBodyScope = wasInForBody; m_inForBodyScope = wasInForBody;
m_inFunctionDef = wasInFunctionDef; m_inFunctionDef = wasInFunctionDef;
m_currentFunctionName = wasFuncName;
yulAssert( yulAssert(
!m_inForInitScope, !m_inForInitScope,

View File

@ -63,6 +63,7 @@ public:
m_filterUnboundedLoops = _filterUnboundedLoops; m_filterUnboundedLoops = _filterUnboundedLoops;
m_filterMemoryWrites = _filterMemoryWrites; m_filterMemoryWrites = _filterMemoryWrites;
m_filterLogs = _filterLogs; m_filterLogs = _filterLogs;
m_currentFunctionName = {};
} }
ProtoConverter(ProtoConverter const&) = delete; ProtoConverter(ProtoConverter const&) = delete;
ProtoConverter(ProtoConverter&&) = delete; ProtoConverter(ProtoConverter&&) = delete;
@ -344,8 +345,8 @@ private:
/// Map of object name to list of sub-object namespace(s) in scope /// Map of object name to list of sub-object namespace(s) in scope
std::map<std::string, std::vector<std::string>> m_objectScope; std::map<std::string, std::vector<std::string>> m_objectScope;
// mod input/output parameters impose an upper bound on the number of input/output parameters a function may have. // mod input/output parameters impose an upper bound on the number of input/output parameters a function may have.
static unsigned constexpr s_modInputParams = 5; static unsigned constexpr s_modInputParams = 33;
static unsigned constexpr s_modOutputParams = 5; static unsigned constexpr s_modOutputParams = 33;
/// Hard-coded identifier for a Yul object's data block /// Hard-coded identifier for a Yul object's data block
static auto constexpr s_dataIdentifier = "datablock"; static auto constexpr s_dataIdentifier = "datablock";
/// Predicate to keep track of for body scope. If false, break/continue /// Predicate to keep track of for body scope. If false, break/continue
@ -391,5 +392,7 @@ private:
/// Flag that, if set, stops the converter from generating log /// Flag that, if set, stops the converter from generating log
/// records. /// records.
bool m_filterLogs; bool m_filterLogs;
/// Name of current function definition
std::string m_currentFunctionName;
}; };
} }

View File

@ -62,6 +62,34 @@ message FunctionCall {
required Expression in_param2 = 2; required Expression in_param2 = 2;
required Expression in_param3 = 3; required Expression in_param3 = 3;
required Expression in_param4 = 4; required Expression in_param4 = 4;
required Expression in_param5 = 5;
required Expression in_param6 = 6;
required Expression in_param7 = 7;
required Expression in_param8 = 8;
required Expression in_param9 = 9;
required Expression in_param10 = 10;
required Expression in_param11 = 11;
required Expression in_param12 = 12;
required Expression in_param13 = 13;
required Expression in_param14 = 14;
required Expression in_param15 = 15;
required Expression in_param16 = 16;
required Expression in_param17 = 17;
required Expression in_param18 = 18;
required Expression in_param19 = 19;
required Expression in_param20 = 20;
required Expression in_param21 = 21;
required Expression in_param22 = 22;
required Expression in_param23 = 23;
required Expression in_param24 = 24;
required Expression in_param25 = 25;
required Expression in_param26 = 26;
required Expression in_param27 = 27;
required Expression in_param28 = 28;
required Expression in_param29 = 29;
required Expression in_param30 = 30;
required Expression in_param31 = 31;
required Expression in_param32 = 32;
} }
message TypedVarDecl { message TypedVarDecl {