source: icGREP/icgrep-devel/icgrep/UCD/ucd_compiler.hpp @ 5276

Last change on this file since 5276 was 5160, checked in by nmedfort, 3 years ago

Initial work for incorporating Types into Pablo AST.

File size: 3.0 KB
Line 
1#ifndef UCDCOMPILER_HPP
2#define UCDCOMPILER_HPP
3
4#include <re/re_cc.h>
5#include <vector>
6#include <boost/container/flat_map.hpp>
7
8namespace cc {
9    class CC_Compiler;
10}
11
12namespace re {
13    class Name;
14}
15
16namespace pablo {
17    class PabloBuilder;
18    class PabloAST;
19}
20
21namespace UCD {
22
23class UnicodeSet;
24
25class UCDCompiler {
26
27    using CC = re::CC;
28    using PabloBuilder = pablo::PabloBuilder;
29    using PabloAST = pablo::PabloAST;
30    using codepoint_t = re::codepoint_t;
31    using RangeList = std::vector<re::interval_t>;
32    using TargetMap = boost::container::flat_map<const UnicodeSet *, PabloAST *>;
33    using Target = std::pair<const UnicodeSet *, PabloAST *>;
34    using TargetVector = std::vector<Target>;
35
36    static const RangeList defaultIfHierachy;
37    static const RangeList noIfHierachy;
38
39public:
40
41    using NameMap = boost::container::flat_map<re::Name *, PabloAST *>;
42
43    UCDCompiler(cc::CC_Compiler & ccCompiler);
44
45    void generateWithDefaultIfHierarchy(NameMap & names, PabloBuilder & entry);
46
47    void generateWithoutIfHierarchy(NameMap & names, PabloBuilder & entry);
48
49    PabloAST * generateWithDefaultIfHierarchy(const UnicodeSet * set, PabloBuilder & entry);
50
51    PabloAST * generateWithoutIfHierarchy(const UnicodeSet * set, PabloBuilder & entry);
52
53protected:
54
55    void generateRange(const RangeList & ifRanges, PabloBuilder & entry);
56
57    void generateRange(const RangeList & ifRanges, const codepoint_t lo, const codepoint_t hi, PabloBuilder & builder);
58
59    void generateSubRanges(const codepoint_t lo, const codepoint_t hi, PabloBuilder & builder);
60
61    PabloAST * sequenceGenerator(const RangeList && ranges, const unsigned byte_no, PabloBuilder & builder, PabloAST * target, PabloAST * prefix);
62
63    PabloAST * sequenceGenerator(const codepoint_t lo, const codepoint_t hi, const unsigned byte_no, PabloBuilder & builder, PabloAST * target, PabloAST * prefix);
64
65    PabloAST * ifTestCompiler(const codepoint_t lo, const codepoint_t hi, PabloBuilder & builder);
66
67    PabloAST * ifTestCompiler(const codepoint_t lo, const codepoint_t hi, const unsigned byte_no, PabloBuilder & builder, PabloAST * target);
68
69    PabloAST * makePrefix(const codepoint_t cp, const unsigned byte_no, PabloBuilder & builder, PabloAST * prefix);
70
71    static RangeList byteDefinitions(const RangeList & list, const unsigned byte_no, bool isUTF_16);
72
73    template <typename RangeListOrUnicodeSet>
74    static RangeList rangeIntersect(const RangeListOrUnicodeSet & list, const codepoint_t lo, const codepoint_t hi);
75
76    static RangeList rangeGaps(const RangeList & list, const codepoint_t lo, const codepoint_t hi);
77
78    static RangeList outerRanges(const RangeList & list);
79
80    static RangeList innerRanges(const RangeList & list);
81
82    void addTargets(PabloBuilder & entry, const NameMap & names);
83
84    void updateNames(NameMap & names, PabloBuilder & entry);
85
86private:
87    cc::CC_Compiler &       mCharacterClassCompiler;
88    PabloAST *              mSuffixVar;
89    TargetMap               mTargetMap;
90};
91
92}
93
94#endif // UCDCOMPILER_HPP
Note: See TracBrowser for help on using the repository browser.