Add leave mutation

This commit is contained in:
Bhargava Shastry 2019-12-23 21:12:16 +01:00
parent e2efcf222c
commit 194fbeb5c2
2 changed files with 29 additions and 1 deletions

View File

@ -213,9 +213,37 @@ static YulProtoMutator identityFunction(
}
);
/// Add leave statement to an existing function.
static YulProtoMutator addLeave(
FunctionDef::descriptor(),
[](google::protobuf::Message* _message, unsigned int _seed)
{
if (_seed % YulProtoMutator::s_lowIP == 0) {
#ifdef DEBUG
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
std::cout << "YULMUTATOR: Leave in function" << std::endl;
#endif
FunctionDef *funcDef = static_cast<FunctionDef*>(_message);
Statement *newStmt = funcDef->mutable_block()->add_statements();
LeaveStmt *leaveStmt = new LeaveStmt();
newStmt->set_allocated_leave(leaveStmt);
#ifdef DEBUG
std::cout << protobuf_mutator::SaveMessageAsText(*_message) << std::endl;
#endif
}
}
);
Literal* YulProtoMutator::intLiteral(unsigned _value)
{
Literal *lit = new Literal();
lit->set_intval(_value);
return lit;
}
VarRef* YulProtoMutator::varRef(unsigned _index)
{
VarRef *varref = new VarRef();
varref->set_varnum(_index);
return varref;
}

View File

@ -27,7 +27,7 @@ struct YulProtoMutator
/// Return a variable reference
/// @param _index: Index of a variable in scope, 0 being the first
/// variable in scope.
static VarRef* varref(unsigned _index);
static VarRef* varRef(unsigned _index);
static constexpr unsigned s_lowIP = 41;
static constexpr unsigned s_mediumIP = 29;