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

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

Progress on multi-target UCD compilation

File size: 2.8 KB
Line 
1#ifndef UCDCOMPILER_HPP
2#define UCDCOMPILER_HPP
3
4#include <re/re_cc.h>
5#include <vector>
6#ifdef USE_BOOST
7#include <boost/container/flat_map.hpp>
8#else
9#include <unordered_map>
10#endif
11
12namespace cc {
13    class CC_Compiler;
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    #ifdef USE_BOOST
33    using TargetMap = boost::container::flat_map<const UnicodeSet *, PabloAST *>;
34    #else
35    using TargetMap = std::unordered_map<const UnicodeSet *, PabloAST *>;
36    #endif
37    using Target = std::pair<const UnicodeSet *, PabloAST *>;
38    using TargetVector = std::vector<Target>;
39
40public:
41    UCDCompiler(cc::CC_Compiler & ccCompiler);
42
43    std::vector<PabloAST *> generateWithDefaultIfHierarchy(const std::vector<UnicodeSet> &sets, PabloBuilder & entry);
44
45    std::vector<PabloAST *> generateWithoutIfHierarchy(const std::vector<UnicodeSet> & sets, PabloBuilder & entry);
46
47protected:
48
49    void generateRange(const RangeList & ifRanges, PabloBuilder & entry);
50
51    void generateRange(const RangeList & ifRanges, const codepoint_t lo, const codepoint_t hi, PabloBuilder & builder);
52
53    void generateSubRanges(const codepoint_t lo, const codepoint_t hi, PabloBuilder & builder);
54
55    PabloAST * sequenceGenerator(const RangeList && ranges, const unsigned byte_no, PabloBuilder & builder, PabloAST * target, PabloAST * prefix);
56
57    PabloAST * sequenceGenerator(const codepoint_t lo, const codepoint_t hi, const unsigned byte_no, PabloBuilder & builder, PabloAST * target, PabloAST * prefix);
58
59    PabloAST * ifTestCompiler(const codepoint_t lo, const codepoint_t hi, PabloBuilder & builder);
60
61    PabloAST * ifTestCompiler(const codepoint_t lo, const codepoint_t hi, const unsigned byte_no, PabloBuilder & builder, PabloAST * target);
62
63    PabloAST * makePrefix(const codepoint_t cp, const unsigned byte_no, PabloBuilder & builder, PabloAST * prefix);
64
65    static RangeList byteDefinitions(const RangeList & list, const unsigned byte_no);
66
67    template <typename RangeListOrUnicodeSet>
68    static RangeList rangeIntersect(const RangeListOrUnicodeSet & list, const codepoint_t lo, const codepoint_t hi);
69
70    static RangeList rangeGaps(const RangeList & list, const codepoint_t lo, const codepoint_t hi);
71
72    static RangeList outerRanges(const RangeList & list);
73
74    static RangeList innerRanges(const RangeList & list);
75
76    void addTargets(const std::vector<UnicodeSet> & sets);
77
78    std::vector<PabloAST *> returnMarkers(const std::vector<UnicodeSet> &sets) const;
79
80private:
81    cc::CC_Compiler &       mCharacterClassCompiler;
82    PabloAST *              mSuffixVar;
83    TargetMap               mTargetMap;
84};
85
86}
87
88#endif // UCDCOMPILER_HPP
Note: See TracBrowser for help on using the repository browser.