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

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

Refactoring progress towards layered kernels

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