source: icGREP/icgrep-devel/icgrep/do_grep.h @ 4808

Last change on this file since 4808 was 4803, checked in by cameron, 4 years ago

Work on character name patterns

File size: 2.5 KB
Line 
1#ifndef DO_GREP_H
2#define DO_GREP_H
3/*
4 *  Copyright (c) 2015 International Characters.
5 *  This software is licensed to the public under the Open Software License 3.0.
6 *  icgrep is a trademark of International Characters.
7 */
8
9#include <string>
10#include <stdint.h>
11#include "basis_bits.h"
12#include "include/simd-lib/bitblock.hpp"
13#include "include/simd-lib/transpose.hpp"
14#include "include/simd-lib/bitblock_iterator.hpp"
15#include <re/re_cc.h>
16
17struct Output {
18    BitBlock matches;
19    BitBlock LF;
20};
21
22#if (BLOCK_SIZE == 128)
23#define SEGMENT_BLOCKS 7
24#endif
25
26#if (BLOCK_SIZE == 256)
27#define SEGMENT_BLOCKS 15
28#endif
29
30#define SEGMENT_SIZE (BLOCK_SIZE * SEGMENT_BLOCKS)
31
32
33#if (BLOCK_SIZE == 256)
34typedef BitStreamScanner<BitBlock, uint64_t, uint64_t, SEGMENT_BLOCKS> ScannerT;
35#endif
36
37#if (BLOCK_SIZE == 128)
38typedef BitStreamScanner<BitBlock, uint32_t, uint32_t, SEGMENT_BLOCKS> ScannerT;
39#endif
40
41typedef void (*process_block_fcn)(const Basis_bits & basis_bits, Output & output);
42
43namespace llvm { class raw_ostream; }
44
45class GrepExecutor {
46public:
47
48    GrepExecutor(void * process_block)
49    : mCountOnlyOption(false)
50    , mGetCodePointsOption(false)
51    , mShowFileNameOption(false)
52    , mShowLineNumberingOption(false)
53    , mParsedCodePointSet(nullptr)
54    , mProcessBlockFcn(reinterpret_cast<process_block_fcn>(process_block)) {
55
56    }
57         
58    void setCountOnlyOption(bool doCount = true) {mCountOnlyOption = doCount;}
59    void setParseCodepointsOption() {
60        mGetCodePointsOption = true;
61        mParsedCodePointSet = re::makeCC();
62    }
63    void setShowFileNameOption(bool showF = true) {mShowFileNameOption = showF;}
64    void setShowLineNumberOption(bool showN = true) {mShowLineNumberingOption = showN;}
65    void setNormalizeLineBreaksOption(bool normLB = true) {mNormalizeLineBreaksOption = normLB;}
66   
67    void doGrep(const std::string & fileName);
68    re::CC * getParsedCodepoints() { return mParsedCodePointSet;}
69private:
70    ssize_t write_matches(llvm::raw_ostream & out, const char *buffer, ssize_t first_line_start);
71   
72    bool finalLineIsUnterminated() const;
73    ssize_t extract_codepoints(char * buffer, ssize_t first_line_start);
74
75    bool mCountOnlyOption;
76    bool mGetCodePointsOption;
77    bool mShowFileNameOption;
78    bool mShowLineNumberingOption;
79    bool mNormalizeLineBreaksOption;
80   
81    re::CC * mParsedCodePointSet;
82
83    process_block_fcn mProcessBlockFcn;
84   
85    std::string mFileName;
86    size_t mFileSize;
87    char * mFileBuffer;
88    ScannerT mLineBreak_scanner;
89    ScannerT mMatch_scanner;
90    size_t mLineNum;
91};
92
93
94#endif
Note: See TracBrowser for help on using the repository browser.