Ignore:
Timestamp:
Oct 16, 2018, 2:29:44 PM (7 months ago)
Author:
nmedfort
Message:

Added RE_Inspector.

Migrated RE passes to RE_Transformer.

Incorporated Memoizer functionality into RE_Transformer/Inspector.

Removed Memoizer.

Bug fix for unicode_set.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/collect_ccs.cpp

    r5935 r6173  
    1212#include <re/re_assertion.h>
    1313#include <cc/alphabet.h>
    14 #include <re/re_memoizer.hpp>
     14#include <re/re_toolchain.h>
    1515
    1616#include <boost/container/flat_set.hpp>
     
    2121namespace re {
    2222   
    23 struct SetCollector : private Memoizer {
    24     void collect(RE * const re);
    25 public:
    26     const cc::Alphabet * alphabet;
    27     std::vector<CC *> theSets;
    28     std::set<Name *> ignoredExternals;
     23struct SetCollector final : public RE_Inspector {
     24
     25    SetCollector(const cc::Alphabet * alphabet, const std::set<Name *> & ignoredExternals, std::vector<CC *> & ccs)
     26    : RE_Inspector(InspectionMode::IgnoreNonUnique)
     27    , alphabet(alphabet)
     28    , ignoredExternals(ignoredExternals)
     29    , ccs(ccs) {
     30
     31    }
     32
     33    void inspectName(Name * n) final {
     34        if (ignoredExternals.count(n) == 0) {
     35            RE_Inspector::inspectName(n);
     36        }
     37    }
     38
     39    void inspectCC(CC * cc) final {
     40        if (LLVM_LIKELY(cc->getAlphabet() == alphabet)) {
     41            ccs.push_back(cc);
     42        }
     43    }
     44
     45private:
     46    const cc::Alphabet * const alphabet;
     47    const std::set<Name *> & ignoredExternals;
     48    std::vector<CC *> & ccs;
    2949};
    3050
    31 void SetCollector::collect(RE * const re) {
    32     assert ("RE object cannot be null!" && re);
    33     if (CC * cc = dyn_cast<CC>(re)) {
    34         if (cc->getAlphabet() == alphabet) {
    35             if (find(cc) == end()) {
    36                 cc = memoize(cc);
    37                 theSets.push_back(cc);
    38             }
    39         }
    40     } else if (isa<Name>(re)) {
    41         if (ignoredExternals.find(cast<Name>(re)) != ignoredExternals.end()) return;
    42         auto def = cast<Name>(re)->getDefinition();
    43         if (def != nullptr)
    44             collect(def);
    45     } else if (isa<Seq>(re)) {
    46         for (auto item : *cast<Seq>(re)) {
    47             collect(item);
    48         }
    49     } else if (isa<Alt>(re)) {
    50         for (auto item : *cast<Alt>(re)) {
    51             collect(item);
    52         }
    53     } else if (isa<Rep>(re)) {
    54         collect(cast<Rep>(re)->getRE());
    55     } else if (isa<Assertion>(re)) {
    56         collect(cast<Assertion>(re)->getAsserted());
    57     } else if (isa<Diff>(re)) {
    58         collect(cast<Diff>(re)->getLH());
    59         collect(cast<Diff>(re)->getRH());
    60     } else if (isa<Intersect>(re)) {
    61         collect(cast<Intersect>(re)->getLH());
    62         collect(cast<Intersect>(re)->getRH());
    63     }
    64 }
    6551
    6652std::vector<CC *> collectCCs(RE * const re, const cc::Alphabet * a, std::set<Name *> external) {
    67     SetCollector collector;
    68     collector.alphabet = a;
    69     collector.ignoredExternals = external;
    70     collector.collect(re);
    71     return collector.theSets;
     53    std::vector<CC *> ccs;
     54    SetCollector collector(a, external, ccs);
     55    collector.inspectRE(re);
     56    return ccs;
    7257}
    7358
Note: See TracChangeset for help on using the changeset viewer.