source: icGREP/icgrep-devel/icgrep/re/re_diff.cpp

Last change on this file was 6264, checked in by cameron, 9 months ago

Restructured contextual assertion simplifier

File size: 1.4 KB
Line 
1/*
2 *  Copyright (c) 2018 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include "re_diff.h"
8#include <re/re_cc.h>
9#include <re/re_seq.h>
10#include <re/re_name.h>
11#include <re/re_empty_set.h>
12#include <re/re_nullable.h>
13#include <re/validation.h>
14#include <re/re_toolchain.h>
15#include <llvm/Support/Casting.h>
16
17using namespace llvm;
18
19namespace re {
20
21#include <re/re_empty_set.h>
22   
23RE * makeDiff(RE * lh, RE * rh) {
24    if (isEmptySeq(lh)) {
25        if (isNullable(rh)) return makeEmptySet();
26        if (validateAssertionFree(rh)) return lh; // EmptySeq()
27    } else if (LLVM_UNLIKELY(isEmptySet(rh))) {
28        return lh;
29    } else if (LLVM_UNLIKELY(isEmptySet(lh))) {
30        return lh;
31    }
32    return Diff::Create(lh, rh);
33}
34
35class DiffResolver : public RE_Transformer {
36public:
37    DiffResolver() : RE_Transformer("DiffResolver") {}
38    RE * transformDiff(Diff * d) override {
39        RE * lh = d->getLH();
40        RE * rh = d->getRH();
41        if (defined<CC>(lh) && defined<CC>(rh)) {
42            CC * lh_cc = defCast<CC>(lh);
43            CC * rh_cc = defCast<CC>(rh);
44            if (lh_cc->getAlphabet() == rh_cc->getAlphabet()) {
45                return subtractCC(lh_cc, rh_cc);
46            }
47        }
48        return d;
49    }
50};
51
52RE * resolveDiffs(RE * r) {
53    return DiffResolver().transformRE(r);
54}
55}
Note: See TracBrowser for help on using the repository browser.