Add/remove assignment mutation

This commit is contained in:
Bhargava Shastry 2019-12-28 20:03:44 +01:00
parent 60930ca119
commit b6f9a2d380
2 changed files with 53 additions and 3 deletions

View File

@ -369,6 +369,56 @@ static YulProtoMutator removeLeave(
}
);
/// Add assignment to block
static YulProtoMutator addAssignment(
Block::descriptor(),
[](google::protobuf::Message* _message, unsigned int _seed)
{
if (_seed % YulProtoMutator::s_mediumIP == 0) {
#ifdef DEBUG
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
std::cout << "YULMUTATOR: Add assignment" << std::endl;
#endif
Block *block = static_cast<Block*>(_message);
AssignmentStatement *assignmentStatement = new AssignmentStatement();
VarRef *varRef = new VarRef();
varRef->set_varnum(0);
assignmentStatement->set_allocated_ref_id(varRef);
VarRef *rhs = new VarRef();
rhs->set_varnum(1);
Expression *rhsExpr = new Expression();
rhsExpr->set_allocated_varref(rhs);
assignmentStatement->set_allocated_expr(rhsExpr);
Statement *newStmt = block->add_statements();
newStmt->set_allocated_assignment(assignmentStatement);
#ifdef DEBUG
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
#endif
}
}
);
/// Remove assignment from block
static YulProtoMutator removeAssignment(
Block::descriptor(),
[](google::protobuf::Message* _message, unsigned int _seed)
{
if (_seed % YulProtoMutator::s_mediumIP == 1) {
#ifdef DEBUG
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
std::cout << "YULMUTATOR: Remove assignment" << std::endl;
#endif
Block *block = static_cast<Block*>(_message);
for (auto &stmt: *block->mutable_statements())
if (stmt.has_assignment())
stmt.clear_assignment();
#ifdef DEBUG
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
#endif
}
}
);
Literal* YulProtoMutator::intLiteral(unsigned _value)
{
Literal *lit = new Literal();

View File

@ -29,9 +29,9 @@ struct YulProtoMutator
/// variable in scope.
static VarRef* varRef(unsigned _index);
static constexpr unsigned s_lowIP = 41;
static constexpr unsigned s_mediumIP = 29;
static constexpr unsigned s_highIP = 17;
static constexpr unsigned s_lowIP = 827;
static constexpr unsigned s_mediumIP = 569;
static constexpr unsigned s_highIP = 251;
};