yul proto fuzzer: Generate at most 2 for loops per program

This commit is contained in:
Bhargava Shastry 2019-12-03 11:50:41 +01:00
parent bd73bfbe05
commit b7a9fe2203
2 changed files with 10 additions and 0 deletions

View File

@ -979,6 +979,8 @@ void ProtoConverter::visit(StoreFunc const& _x)
void ProtoConverter::visit(ForStmt const& _x)
{
if (++m_numForLoops > s_maxForLoops)
return;
bool wasInGenericForBodyScope = m_inGenericForBodyScope;
bool wasInForInit = m_inForInitScope;
bool wasInBoundedForBodyScope = m_inBoundedForBodyScope;
@ -1020,6 +1022,9 @@ void ProtoConverter::visit(ForStmt const& _x)
void ProtoConverter::visit(BoundedForStmt const& _x)
{
if (++m_numForLoops > s_maxForLoops)
return;
// Boilerplate for loop that limits the number of iterations to a maximum of 4.
std::string loopVarName("i_" + std::to_string(m_numNestedForLoops++));
m_output << "for { let " << loopVarName << " := 0 } "

View File

@ -45,6 +45,7 @@ public:
m_inForInitScope = false;
m_inForCond = false;
m_numNestedForLoops = 0;
m_numForLoops = 0;
m_counter = 0;
m_inputSize = 0;
m_inFunctionDef = false;
@ -338,12 +339,16 @@ private:
static unsigned constexpr s_modOutputParams = 5;
/// Hard-coded identifier for a Yul object's data block
static auto constexpr s_dataIdentifier = "datablock";
/// Maximum number of for loops that a test case may contain
static auto constexpr s_maxForLoops = 2;
/// Predicate to keep track of of the body of a generic for stmt.
bool m_inGenericForBodyScope;
/// Predicate to keep track of scope of the body of a bounded for stmt.
bool m_inBoundedForBodyScope;
// Index used for naming loop variable of bounded for loops
unsigned m_numNestedForLoops;
/// Counter for number of for loops
unsigned m_numForLoops;
/// Predicate to keep track of for loop init scope. If true, variable
/// or function declarations can not be created.
bool m_inForInitScope;