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

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

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

File size: 1.7 KB
RevLine 
[5565]1#include "re_collect_unicodesets.h"
2#include <re/re_name.h>
[5631]3#include <re/re_any.h>
[5565]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
[5748]13
[5565]14using namespace llvm;
15
16namespace re {
[5631]17   
[5748]18struct SetCollector {
19    void collect(RE * const re);
[5631]20public:
[5748]21    std::vector<const CC *> UnicodeSets;
22    boost::container::flat_set<const RE *>  Visited;
[5631]23};
[5565]24
[5748]25void SetCollector::collect(RE * const re) {
[5565]26    assert ("RE object cannot be null!" && re);
[5748]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));
[5565]52        }
53    }
54}
[5748]55
56std::vector<const CC *> collectUnicodeSets(RE * const re) {
[5631]57    SetCollector collector;
[5748]58    collector.collect(re);
59    return collector.UnicodeSets;
[5631]60}
[5565]61
[5748]62
63
[5565]64}
Note: See TracBrowser for help on using the repository browser.