source: icGREP/icgrep-devel/icgrep/re/re_toolchain.h @ 6184

Last change on this file since 6184 was 6178, checked in by cameron, 9 months ago

RE Validation

File size: 3.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#ifndef RE_TOOLCHAIN_H
8#define RE_TOOLCHAIN_H
9
10#include <map>
11#include <set>
12#include <string>
13#include <llvm/Support/Compiler.h>
14
15namespace llvm { namespace cl { class OptionCategory; } }
16namespace pablo { class PabloKernel; class PabloAST; }
17namespace re { class RE; class CC;}
18namespace re { class Name; class Start; class End; class CC; class Seq; class Alt;
19    class Rep; class Intersect; class Diff; class Range; class Group;
20    class Assertion;
21}
22
23namespace re {
24
25enum RE_PrintFlags {
26    ShowREs, ShowAllREs, ShowStrippedREs, ShowSimplifiedREs
27};
28   
29enum RE_AlgorithmFlags {
30    DisableLog2BoundedRepetition, DisableIfHierarchy, DisableMatchStar, DisableUnicodeMatchStar, 
31    DisableUnicodeLineBreak, UsePregeneratedUnicode
32};
33   
34bool LLVM_READONLY PrintOptionIsSet(RE_PrintFlags flag);
35bool LLVM_READONLY AlgorithmOptionIsSet(RE_AlgorithmFlags flag);
36   
37extern int IfInsertionGap;
38
39const llvm::cl::OptionCategory * LLVM_READONLY re_toolchain_flags();
40   
41   
42void UndefinedNameError (const Name * n);
43
44enum class NameTransformationMode {None, TransformDefinition};
45
46class RE_Transformer {
47    struct MemoizerComparator {
48        bool operator() (const RE * lh, const RE * rh) const;
49    };
50public:
51    RE * transformRE(RE * r);
52protected:
53    RE_Transformer(std::string transformationName, NameTransformationMode m = NameTransformationMode::None)
54    : mTransformationName(std::move(transformationName)), mNameTransform(m) {}
55
56    RE * transform(RE * r);
57    virtual RE * transformName(Name * n);
58    virtual RE * transformStart(Start * s);
59    virtual RE * transformEnd(End * e);
60    virtual RE * transformCC(CC * cc);
61    virtual RE * transformSeq(Seq * s);
62    virtual RE * transformAlt(Alt * a);
63    virtual RE * transformRep(Rep * rep);
64    virtual RE * transformIntersect(Intersect * e);
65    virtual RE * transformDiff(Diff * d);
66    virtual RE * transformRange(Range * rg);
67    virtual RE * transformGroup(Group * g);
68    virtual RE * transformAssertion(Assertion * a);
69private:
70    const std::string mTransformationName;
71    const NameTransformationMode mNameTransform;
72    std::map<RE *, RE *, MemoizerComparator> mMap;
73};
74
75enum class InspectionMode {TraverseNonUnique, IgnoreNonUnique};
76
77class RE_Inspector {
78    struct MemoizerComparator {
79        bool operator() (const RE * lh, const RE * rh) const;
80    };
81public:
82    void inspectRE(RE * r);
83protected:
84    RE_Inspector(const InspectionMode ignoreNonUnique = InspectionMode::IgnoreNonUnique) : mIgnoreNonUnique(ignoreNonUnique) {}
85    void inspect(RE * r);
86    virtual void inspectName(Name * n);
87    virtual void inspectStart(Start * s);
88    virtual void inspectEnd(End * e);
89    virtual void inspectCC(CC * cc);
90    virtual void inspectSeq(Seq * s);
91    virtual void inspectAlt(Alt * a);
92    virtual void inspectRep(Rep * rep);
93    virtual void inspectIntersect(Intersect * e);
94    virtual void inspectDiff(Diff * d);
95    virtual void inspectRange(Range * rg);
96    virtual void inspectGroup(Group * g);
97    virtual void inspectAssertion(Assertion * a);
98private:
99    const InspectionMode mIgnoreNonUnique;
100    std::set<RE *, MemoizerComparator> mMap;
101};
102
103RE * resolveModesAndExternalSymbols(RE * r, bool globallyCaseInsensitive = false);
104
105RE * excludeUnicodeLineBreak(RE * r);
106
107RE * regular_expression_passes(RE * r);
108   
109}
110#endif
Note: See TracBrowser for help on using the repository browser.