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/re_toolchain.h

    r6170 r6173  
    77#ifndef RE_TOOLCHAIN_H
    88#define RE_TOOLCHAIN_H
     9
     10#include <map>
     11#include <set>
    912#include <string>
    1013#include <llvm/Support/Compiler.h>
     14
    1115namespace llvm { namespace cl { class OptionCategory; } }
    1216namespace pablo { class PabloKernel; class PabloAST; }
     
    4044
    4145class RE_Transformer {
     46    struct MemoizerComparator {
     47        bool operator() (const RE * lh, const RE * rh) const;
     48    };
    4249public:
    43     RE_Transformer(std::string transformationName = "",
    44                    NameTransformationMode m = NameTransformationMode::None) :
    45     mTransformationName(transformationName), mNameTransform(m) {}
    4650    RE * transformRE(RE * r);
    4751protected:
     52    RE_Transformer(std::string transformationName, NameTransformationMode m = NameTransformationMode::None)
     53    : mTransformationName(std::move(transformationName)), mNameTransform(m) {}
     54
    4855    RE * transform(RE * r);
    4956    virtual RE * transformName(Name * n);
     
    5966    virtual RE * transformGroup(Group * g);
    6067    virtual RE * transformAssertion(Assertion * a);
    61    
    62     std::string mTransformationName;
    63     NameTransformationMode mNameTransform;
     68private:
     69    const std::string mTransformationName;
     70    const NameTransformationMode mNameTransform;
     71    std::map<RE *, RE *, MemoizerComparator> mMap;
     72};
     73
     74enum class InspectionMode {TraverseNonUnique, IgnoreNonUnique};
     75
     76class RE_Inspector {
     77    struct MemoizerComparator {
     78        bool operator() (const RE * lh, const RE * rh) const;
     79    };
     80public:
     81    void inspectRE(RE * r);
     82protected:
     83    RE_Inspector(const InspectionMode ignoreNonUnique = InspectionMode::IgnoreNonUnique) : mIgnoreNonUnique(ignoreNonUnique) {}
     84    void inspect(RE * r);
     85    virtual void inspectName(Name * n);
     86    virtual void inspectStart(Start * s);
     87    virtual void inspectEnd(End * e);
     88    virtual void inspectCC(CC * cc);
     89    virtual void inspectSeq(Seq * s);
     90    virtual void inspectAlt(Alt * a);
     91    virtual void inspectRep(Rep * rep);
     92    virtual void inspectIntersect(Intersect * e);
     93    virtual void inspectDiff(Diff * d);
     94    virtual void inspectRange(Range * rg);
     95    virtual void inspectGroup(Group * g);
     96    virtual void inspectAssertion(Assertion * a);
     97private:
     98    const InspectionMode mIgnoreNonUnique;
     99    std::set<RE *, MemoizerComparator> mMap;
    64100};
    65101
Note: See TracChangeset for help on using the changeset viewer.