source: icGREP/icgrep-devel/icgrep/re/re_collect_unicodesets.cpp @ 5748

Last change on this file since 5748 was 5748, checked in by nmedfort, 17 months ago

Bug fix for segment pipeline parallel mode + memory management improvements.

File size: 1.7 KB
Line 
1#include "re_collect_unicodesets.h"
2#include <re/re_name.h>
3#include <re/re_any.h>
4#include <re/re_alt.h>
5#include <re/re_cc.h>
6#include <re/re_seq.h>
7#include <re/re_rep.h>
8#include <re/re_diff.h>
9#include <re/re_intersect.h>
10#include <re/re_assertion.h>
11#include <boost/container/flat_set.hpp>
12
13
14using namespace llvm;
15
16namespace re {
17   
18struct SetCollector {
19    void collect(RE * const re);
20public:
21    std::vector<const CC *> UnicodeSets;
22    boost::container::flat_set<const RE *>  Visited;
23};
24
25void SetCollector::collect(RE * const re) {
26    assert ("RE object cannot be null!" && re);
27    if (Visited.insert(re).second) {
28        if (CC * cc = dyn_cast<CC>(re)) {
29            UnicodeSets.push_back(cc);
30        } else if (isa<Name>(re)) {
31            collect(cast<Name>(re)->getDefinition());
32        } else if (isa<Seq>(re)) {
33            for (auto item : *cast<Seq>(re)) {
34                collect(item);
35            }
36        } else if (isa<Alt>(re)) {
37            for (auto item : *cast<Alt>(re)) {
38                collect(item);
39            }
40        } else if (isa<Rep>(re)) {
41            collect(cast<Rep>(re)->getRE());
42        } else if (isa<Assertion>(re)) {
43            collect(cast<Assertion>(re)->getAsserted());
44        } else if (isa<Diff>(re)) {
45            collect(cast<Diff>(re)->getLH());
46            collect(cast<Diff>(re)->getRH());
47        } else if (isa<Intersect>(re)) {
48            collect(cast<Intersect>(re)->getLH());
49            collect(cast<Intersect>(re)->getRH());
50        } else if (isa<Any>(re)) {
51            UnicodeSets.push_back(makeCC(0x00, 0x10FFFF));
52        }
53    }
54}
55
56std::vector<const CC *> collectUnicodeSets(RE * const re) {
57    SetCollector collector;
58    collector.collect(re);
59    return collector.UnicodeSets;
60}
61
62
63
64}
Note: See TracBrowser for help on using the repository browser.