From 22f5a82edcd3641443abe85e8eb980ccc145f75b Mon Sep 17 00:00:00 2001 From: Bhargava Shastry Date: Mon, 18 Mar 2019 17:12:03 +0100 Subject: [PATCH] yul proto: Add support for generating for and switch statements. --- test/tools/ossfuzz/protoToYul.cpp | 31 +++++++++++++++++++++++++++++++ test/tools/ossfuzz/protoToYul.h | 3 +++ test/tools/ossfuzz/yulProto.proto | 17 +++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/test/tools/ossfuzz/protoToYul.cpp b/test/tools/ossfuzz/protoToYul.cpp index ec0dfdeb1..742b62d39 100644 --- a/test/tools/ossfuzz/protoToYul.cpp +++ b/test/tools/ossfuzz/protoToYul.cpp @@ -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()) @@ -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; } diff --git a/test/tools/ossfuzz/protoToYul.h b/test/tools/ossfuzz/protoToYul.h index f586d97ca..3a427931f 100644 --- a/test/tools/ossfuzz/protoToYul.h +++ b/test/tools/ossfuzz/protoToYul.h @@ -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); } } } diff --git a/test/tools/ossfuzz/yulProto.proto b/test/tools/ossfuzz/yulProto.proto index 60f9b2f1f..33fd51e13 100644 --- a/test/tools/ossfuzz/yulProto.proto +++ b/test/tools/ossfuzz/yulProto.proto @@ -139,6 +139,21 @@ 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; @@ -146,6 +161,8 @@ message Statement { IfStmt ifstmt = 3; StoreFunc storage_func = 4; Block blockstmt = 5; + ForStmt forstmt = 6; + SwitchStmt switchstmt = 7; } }