Commit bd24f471 authored by charlie's avatar charlie
Browse files

Use custom distance function

parent 6e94e607
......@@ -74,14 +74,29 @@ bool operator==(const instruction& i, instruction_ref ref)
return std::addressof(i) == std::addressof(*ref);
}
static void debug_name(std::ostream& os, const instruction& ins);
bool instruction::valid(instruction_ref start, bool check_order) const
{
// Need this lambda because std::distance has undefined behavior when comparing iterators of
// from different ranges
auto ins_dist = [](instruction_ref s, instruction_ref e) {
int dist = 0;
while((*s) != (*e))
{
++s;
++dist;
}
return dist;
};
return valid() && std::all_of(arguments.begin(), arguments.end(), [&](instruction_ref i) {
auto self = std::find(i->outputs().begin(), i->outputs().end(), *this);
bool ret = self != i->outputs().end();
if(check_order)
{
ret = ret and (std::distance(start, i) < std::distance(start, *self));
// arguments for this instruction before this instruction
ret = ret and (ins_dist(start, i) < ins_dist(start, *self));
}
return ret;
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment