Ejemplo n.º 1
0
Base*
Ran::mutating_canonicalize()
{
    Base* ret = this;
    switch (m_subs.size()) {
    case 2: {
        auto it = begin(m_subs);
        Lit* subA = dynamic_cast<Lit*>(*it); it++;
        Lit* subB = dynamic_cast<Lit*>(*it);
        // TODO: Generalize to n bytes and reuse auto_set_detected_pmatch()
        if (subA and subB) {    // if both literals
            const auto nbytes = subA->bitsize().get() / 8;
            if ((subA->bitsize() == 8 and
                 subB->bitsize() == 8 and
                 subA->get_byte() == 0 and
                 (~subB->get_byte()) == 0)
                or
                (subA->bitsize() == 16 and
                 subB->bitsize() == 16 and
                 subA->get_i16ne() == 0 and
                 (~subB->get_i16ne()) == 0)
                or
                (subA->bitsize() == 32 and
                 subB->bitsize() == 32 and
                 subA->get_i32ne() == 0 and
                 (~subB->get_i32ne()) == 0)
                or
                (subA->bitsize() == 64 and
                 subB->bitsize() == 64 and
                 subA->get_i64ne() == 0 and
                 (~subB->get_i64ne()) == 0))
            {
                ret = mutate_to(anybytes(nbytes)); // mutate \p this to \c Any
            }
        }
        break;
    }
    default: {
        break;
    }
    }
    return ret;
}