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

Last change on this file since 4826 was 4826, checked in by cameron, 3 years ago

Reset carries for each file

File size: 2.8 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_initialize_carries_fcn)();
42typedef void (*process_block_fcn)(const Basis_bits & basis_bits, Output & output);
43
44namespace llvm { class raw_ostream; }
45
46class GrepExecutor {
47public:
48
49    GrepExecutor(void * process_block_initialize_carries, void * process_block)
50    : mCountOnlyOption(false)
51    , mGetCodePointsOption(false)
52    , mShowFileNameOption(false)
53    , mShowLineNumberingOption(false)
54    , mParsedCodePointSet(nullptr)
55    , mInitializeCarriesFcn(reinterpret_cast<process_block_initialize_carries_fcn>(process_block_initialize_carries))
56    , mProcessBlockFcn(reinterpret_cast<process_block_fcn>(process_block)) {
57
58    }
59         
60    void setCountOnlyOption(bool doCount = true) {mCountOnlyOption = doCount;}
61    void setParseCodepointsOption() {
62        mGetCodePointsOption = true;
63        mParsedCodePointSet = re::makeCC();
64    }
65    void setShowFileNameOption(bool showF = true) {mShowFileNameOption = showF;}
66    void setShowLineNumberOption(bool showN = true) {mShowLineNumberingOption = showN;}
67    void setNormalizeLineBreaksOption(bool normLB = true) {mNormalizeLineBreaksOption = normLB;}
68   
69    void doGrep(const std::string & fileName);
70    re::CC * getParsedCodepoints() { return mParsedCodePointSet;}
71private:
72    ssize_t write_matches(llvm::raw_ostream & out, const char *buffer, ssize_t first_line_start);
73   
74    bool finalLineIsUnterminated() const;
75    ssize_t extract_codepoints(char * buffer, ssize_t first_line_start);
76
77    bool mCountOnlyOption;
78    bool mGetCodePointsOption;
79    bool mShowFileNameOption;
80    bool mShowLineNumberingOption;
81    bool mNormalizeLineBreaksOption;
82   
83    re::CC * mParsedCodePointSet;
84
85    process_block_initialize_carries_fcn mInitializeCarriesFcn;
86    process_block_fcn mProcessBlockFcn;
87   
88    std::string mFileName;
89    size_t mFileSize;
90    char * mFileBuffer;
91    ScannerT mLineBreak_scanner;
92    ScannerT mMatch_scanner;
93    size_t mLineNum;
94};
95
96
97#endif
Note: See TracBrowser for help on using the repository browser.