Skip to content

Proto support for "for" and "switch" statements #6333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions test/tools/ossfuzz/protoToYul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,31 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, StoreFunc const& _x)
return _os;
}

ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, ForStmt const& _x)
{
_os << "for { let i := 0 } lt(i, 0x100) { i := add(i, 0x20) } ";
return _os << _x.for_body();
}

ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, CaseStmt const& _x)
{
_os << "case " << _x.case_lit() << " ";
return _os << _x.case_block();
}

ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, SwitchStmt const& _x)
{
if (_x.case_stmt_size() > 0 || _x.has_default_block())
{
_os << "switch " << _x.switch_expr() << "\n";
for (auto const& caseStmt: _x.case_stmt())
_os << caseStmt;
if (_x.has_default_block())
_os << "default " << _x.default_block();
}
return _os;
}

ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Statement const& _x)
{
switch (_x.stmt_oneof_case())
Expand All @@ -254,6 +279,12 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Statement const& _x)
case Statement::kBlockstmt:
_os << _x.blockstmt();
break;
case Statement::kForstmt:
_os << _x.forstmt();
break;
case Statement::kSwitchstmt:
_os << _x.switchstmt();
break;
case Statement::STMT_ONEOF_NOT_SET:
break;
}
Expand Down
3 changes: 3 additions & 0 deletions test/tools/ossfuzz/protoToYul.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ std::ostream& operator<<(std::ostream& _os, StoreFunc const& _x);
std::ostream& operator<<(std::ostream& _os, Statement const& _x);
std::ostream& operator<<(std::ostream& _os, Block const& _x);
std::ostream& operator<<(std::ostream& _os, Function const& _x);
std::ostream& operator<<(std::ostream& _os, ForStmt const& _x);
std::ostream& operator<<(std::ostream& _os, CaseStmt const& _x);
std::ostream& operator<<(std::ostream& _os, SwitchStmt const& _x);
}
}
}
17 changes: 17 additions & 0 deletions test/tools/ossfuzz/yulProto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,30 @@ message IfStmt {
required Block if_body = 2;
}

message ForStmt {
required Block for_body = 2;
}

message CaseStmt {
required Literal case_lit = 1;
required Block case_block = 2;
}

message SwitchStmt {
required Expression switch_expr = 1;
repeated CaseStmt case_stmt = 2;
optional Block default_block = 3;
}

message Statement {
oneof stmt_oneof {
VarDecl decl = 1;
AssignmentStatement assignment = 2;
IfStmt ifstmt = 3;
StoreFunc storage_func = 4;
Block blockstmt = 5;
ForStmt forstmt = 6;
SwitchStmt switchstmt = 7;
}
}

Expand Down