Proto spec and translator bug fixes.

This commit is contained in:
Bhargava Shastry 2019-03-14 15:40:54 +01:00
parent 94cd81de8c
commit 5681086d2c
3 changed files with 81 additions and 58 deletions

View File

@ -25,7 +25,16 @@ using namespace yul::test::yul_fuzzer;
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Literal const& _x) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Literal const& _x)
{ {
return _os << "(" << _x.val() << ")"; switch (_x.literal_oneof_case())
{
case Literal::kIntval:
_os << _x.intval();
break;
case Literal::LITERAL_ONEOF_NOT_SET:
_os << "1";
break;
}
return _os;
} }
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, VarRef const& _x) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, VarRef const& _x)
@ -35,15 +44,25 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, VarRef const& _x)
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Expression const& _x) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Expression const& _x)
{ {
if (_x.has_varref()) switch (_x.expr_oneof_case())
return _os << _x.varref(); {
else if (_x.has_cons()) case Expression::kVarref:
return _os << _x.cons(); _os << _x.varref();
else if (_x.has_binop()) break;
return _os << _x.binop(); case Expression::kCons:
else if (_x.has_unop()) _os << _x.cons();
return _os << _x.unop(); break;
return _os << ""; case Expression::kBinop:
_os << _x.binop();
break;
case Expression::kUnop:
_os << _x.unop();
break;
case Expression::EXPR_ONEOF_NOT_SET:
_os << "1";
break;
}
return _os;
} }
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, BinaryOp const& _x) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, BinaryOp const& _x)
@ -51,47 +70,46 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, BinaryOp const& _x)
switch (_x.op()) switch (_x.op())
{ {
case BinaryOp::ADD: case BinaryOp::ADD:
_os << "add("; _os << "add";
break; break;
case BinaryOp::SUB: case BinaryOp::SUB:
_os << "sub("; _os << "sub";
break; break;
case BinaryOp::MUL: case BinaryOp::MUL:
_os << "mul("; _os << "mul";
break; break;
case BinaryOp::DIV: case BinaryOp::DIV:
_os << "div("; _os << "div";
break; break;
case BinaryOp::MOD: case BinaryOp::MOD:
_os << "mod("; _os << "mod";
break; break;
case BinaryOp::XOR: case BinaryOp::XOR:
_os << "xor("; _os << "xor";
break; break;
case BinaryOp::AND: case BinaryOp::AND:
_os << "and("; _os << "and";
break; break;
case BinaryOp::OR: case BinaryOp::OR:
_os << "or("; _os << "or";
break; break;
case BinaryOp::EQ: case BinaryOp::EQ:
_os << "eq("; _os << "eq";
break; break;
case BinaryOp::LT: case BinaryOp::LT:
_os << "lt("; _os << "lt";
break; break;
case BinaryOp::GT: case BinaryOp::GT:
_os << "gt("; _os << "gt";
break; break;
} }
return _os << _x.left() << "," << _x.right() << ")"; return _os << "(" << _x.left() << "," << _x.right() << ")";
} }
// New var numbering starts from x_10 until x_16 // New var numbering starts from x_10 until x_16
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, VarDecl const& _x) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, VarDecl const& _x)
{ {
_os << "let x_" << ((_x.id() % 7) + 10) << " := " << _x.expr() << "\n"; return _os << "let x_" << ((_x.id() % 7) + 10) << " := " << _x.expr() << "\n";
return _os;
} }
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, TypedVarDecl const& _x) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, TypedVarDecl const& _x)
@ -141,20 +159,19 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, UnaryOp const& _x)
switch (_x.op()) switch (_x.op())
{ {
case UnaryOp::NOT: case UnaryOp::NOT:
_os << "not("; _os << "not";
break; break;
case UnaryOp::MLOAD: case UnaryOp::MLOAD:
_os << "mload("; _os << "mload";
break; break;
case UnaryOp::SLOAD: case UnaryOp::SLOAD:
_os << "sload("; _os << "sload";
break; break;
case UnaryOp::ISZERO: case UnaryOp::ISZERO:
_os << "iszero("; _os << "iszero";
break; break;
} }
_os << _x.operand() << ")"; return _os << "(" << _x.operand() << ")";
return _os;
} }
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, AssignmentStatement const& _x) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, AssignmentStatement const& _x)
@ -187,17 +204,27 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, StoreFunc const& _x)
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Statement const& _x) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Statement const& _x)
{ {
if (_x.has_decl()) switch (_x.stmt_oneof_case())
return _os << _x.decl(); {
else if (_x.has_assignment()) case Statement::kDecl:
return _os << _x.assignment(); _os << _x.decl();
else if (_x.has_ifstmt()) break;
return _os << _x.ifstmt(); case Statement::kAssignment:
else if (_x.has_storage_func()) _os << _x.assignment();
return _os << _x.storage_func(); break;
else if (_x.has_blockstmt()) case Statement::kIfstmt:
return _os << _x.blockstmt(); _os << _x.ifstmt();
return _os << ""; break;
case Statement::kStorageFunc:
_os << _x.storage_func();
break;
case Statement::kBlockstmt:
_os << _x.blockstmt();
break;
case Statement::STMT_ONEOF_NOT_SET:
break;
}
return _os;
} }
ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Block const& _x) ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Block const& _x)
@ -208,7 +235,10 @@ ostream& yul::test::yul_fuzzer::operator<<(ostream& _os, Block const& _x)
for (auto const& st: _x.statements()) for (auto const& st: _x.statements())
_os << st; _os << st;
_os << "}\n"; _os << "}\n";
}
else
{
_os << "{}\n";
} }
return _os; return _os;
} }

View File

@ -17,16 +17,9 @@
syntax = "proto2"; syntax = "proto2";
// VariableDeclaration =
// 'let' TypedIdentifierList ( ':=' Expression )?
// TypedIdentifierList = Identifier ':' TypeName ( ',' Identifier ':' TypeName )*
// Identifier = [a-zA-Z_$] [a-zA-Z_$0-9]*
// IdentifierList = Identifier ( ',' Identifier)*
// TypeName = Identifier | BuiltinTypeName
// BuiltinTypeName = 'bool' | [us] ( '8' | '32' | '64' | '128' | '256' )
message VarDecl { message VarDecl {
required int32 id = 1; required int32 id = 1;
required Expression expr = 3; required Expression expr = 2;
} }
message TypedVarDecl { message TypedVarDecl {
@ -53,7 +46,9 @@ message VarRef {
} }
message Literal { message Literal {
required int32 val = 1; oneof literal_oneof {
uint64 intval = 1;
}
} }
message TypedLiteral { message TypedLiteral {
@ -133,8 +128,6 @@ message IfStmt {
required Block if_body = 2; required Block if_body = 2;
} }
// add for loop
// TODO: add block and scope for if
message Statement { message Statement {
oneof stmt_oneof { oneof stmt_oneof {
VarDecl decl = 1; VarDecl decl = 1;