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

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

Misc changes + potential SIGBUS fix for issue reported by Hongpu.

File size: 2.1 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
40typedef void (*process_block_fcn)(const Basis_bits & basis_bits, Output & output);
41
42namespace llvm { class raw_ostream; }
43
44class GrepExecutor {
45public:
46
47    GrepExecutor(void * process_block)
48    : mCountOnlyOption(false)
49    , mShowFileNameOption(false)
50    , mShowLineNumberingOption(false)
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(const std::string & fileName);
61private:
62    ssize_t write_matches(llvm::raw_ostream & out, const char *buffer, ssize_t first_line_start);
63    bool finalLineIsUnterminated() const;
64
65    bool mCountOnlyOption;
66    bool mShowFileNameOption;
67    bool mShowLineNumberingOption;
68    bool mNormalizeLineBreaksOption;
69
70    process_block_fcn mProcessBlockFcn;
71   
72    std::string mFileName;
73    size_t mFileSize;
74    char * mFileBuffer;
75    ScannerT mLineBreak_scanner;
76    ScannerT mMatch_scanner;
77    size_t mLineNum;
78};
79
80
81#endif
Note: See TracBrowser for help on using the repository browser.