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

Last change on this file since 4639 was 4538, checked in by cameron, 5 years ago

Restructure to use a single process_block_state data area

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