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

View File

@ -45,6 +45,7 @@ public:
m_inForInitScope = false; m_inForInitScope = false;
m_inForCond = false; m_inForCond = false;
m_numNestedForLoops = 0; m_numNestedForLoops = 0;
m_numForLoops = 0;
m_counter = 0; m_counter = 0;
m_inputSize = 0; m_inputSize = 0;
m_inFunctionDef = false; m_inFunctionDef = false;
@ -338,12 +339,16 @@ private:
static unsigned constexpr s_modOutputParams = 5; static unsigned constexpr s_modOutputParams = 5;
/// 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";
/// 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. /// Predicate to keep track of of the body of a generic for stmt.
bool m_inGenericForBodyScope; bool m_inGenericForBodyScope;
/// Predicate to keep track of scope of the body of a bounded for stmt. /// Predicate to keep track of scope of the body of a bounded for stmt.
bool m_inBoundedForBodyScope; bool m_inBoundedForBodyScope;
// Index used for naming loop variable of bounded for loops // Index used for naming loop variable of bounded for loops
unsigned m_numNestedForLoops; unsigned m_numNestedForLoops;
/// Counter for number of for loops
unsigned m_numForLoops;
/// Predicate to keep track of for loop init scope. If true, variable /// Predicate to keep track of for loop init scope. If true, variable
/// or function declarations can not be created. /// or function declarations can not be created.
bool m_inForInitScope; bool m_inForInitScope;