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

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

Minor changes to function compilation preceeding any modification of the pablo Call class.

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