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

Last change on this file since 4667 was 4660, checked in by nmedfort, 4 years ago

Moved 'resolveProperties' into CC_NameMap as a single call for each unique Name.

File size: 2.2 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
12#include "include/simd-lib/bitblock.hpp"
13#include "include/simd-lib/transpose.hpp"
14#include "include/simd-lib/bitblock_iterator.hpp"
15
16struct Output {
17    BitBlock matches;
18    BitBlock LF;
19};
20
21#if (BLOCK_SIZE == 128)
22#define SEGMENT_BLOCKS 7
23#endif
24
25#if (BLOCK_SIZE == 256)
26#define SEGMENT_BLOCKS 15
27#endif
28
29#define SEGMENT_SIZE (BLOCK_SIZE * SEGMENT_BLOCKS)
30
31
32#if (BLOCK_SIZE == 256)
33typedef BitStreamScanner<BitBlock, uint64_t, uint64_t, SEGMENT_BLOCKS> ScannerT;
34#endif
35
36#if (BLOCK_SIZE == 128)
37typedef BitStreamScanner<BitBlock, uint32_t, uint32_t, SEGMENT_BLOCKS> ScannerT;
38#endif
39
40
41typedef void (*process_block_fcn)(const Basis_bits & basis_bits, BitBlock process_block_state_data[], Output & output);
42
43class GrepExecutor {
44public:
45
46    GrepExecutor(size_t process_block_state_size, void * process_block)
47    : mCountOnlyOption(false)
48    , mShowFileNameOption(false)
49    , mShowLineNumberingOption(false)
50    , mProcessBlockStateSize(process_block_state_size)
51    , mProcessBlockFcn(reinterpret_cast<process_block_fcn>(process_block)) {
52
53    }
54         
55    void setCountOnlyOption(bool doCount = true) {mCountOnlyOption = doCount;}
56    void setShowFileNameOption(bool showF = true) {mShowFileNameOption = showF;}
57    void setShowLineNumberOption(bool showN = true) {mShowLineNumberingOption = showN;}
58    void setNormalizeLineBreaksOption(bool normLB = true) {mNormalizeLineBreaksOption = normLB;}
59   
60    void doGrep(std::string fileName);
61private:
62    ssize_t write_matches(char * buffer, ssize_t first_line_start);
63    bool finalLineIsUnterminated();
64
65    bool mCountOnlyOption;
66    bool mShowFileNameOption;
67    bool mShowLineNumberingOption;
68    bool mNormalizeLineBreaksOption;
69
70    size_t mProcessBlockStateSize;
71    process_block_fcn mProcessBlockFcn;
72   
73    std::string mFileName;
74    size_t mFileSize;
75    char * mFileBuffer;
76    ScannerT mLineBreak_scanner;
77    ScannerT mMatch_scanner;
78    size_t line_no;
79};
80
81
82#endif
Note: See TracBrowser for help on using the repository browser.