yul proto: Add support for generating for and switch statements.

This commit is contained in:
Bhargava Shastry 2019-03-18 17:12:03 +01:00 committed by Alex Beregszaszi
parent e3c1dea97c
commit 22f5a82edc
3 changed files with 51 additions and 0 deletions

View File

@ -235,6 +235,31 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, StoreFunc const& _x)
return _os; 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) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Statement const& _x)
{ {
switch (_x.stmt_oneof_case()) switch (_x.stmt_oneof_case())
@ -254,6 +279,12 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Statement const& _x)
case Statement::kBlockstmt: case Statement::kBlockstmt:
_os << _x.blockstmt(); _os << _x.blockstmt();
break; break;
case Statement::kForstmt:
_os << _x.forstmt();
break;
case Statement::kSwitchstmt:
_os << _x.switchstmt();
break;
case Statement::STMT_ONEOF_NOT_SET: case Statement::STMT_ONEOF_NOT_SET:
break; break;
} }

View File

@ -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, Statement const& _x);
std::ostream& operator<<(std::ostream& _os, Block 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, 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);
} }
} }
} }

View File

@ -139,6 +139,21 @@ message IfStmt {
required Block if_body = 2; 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 { message Statement {
oneof stmt_oneof { oneof stmt_oneof {
VarDecl decl = 1; VarDecl decl = 1;
@ -146,6 +161,8 @@ message Statement {
IfStmt ifstmt = 3; IfStmt ifstmt = 3;
StoreFunc storage_func = 4; StoreFunc storage_func = 4;
Block blockstmt = 5; Block blockstmt = 5;
ForStmt forstmt = 6;
SwitchStmt switchstmt = 7;
} }
} }