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

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

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

File size: 2.1 KB
RevLine 
[4324]1#ifndef DO_GREP_H
2#define DO_GREP_H
3/*
[4659]4 *  Copyright (c) 2015 International Characters.
[4324]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"
[4325]14#include "include/simd-lib/bitblock_iterator.hpp"
[4324]15
16struct Output {
17    BitBlock matches;
18    BitBlock LF;
19};
20
[4325]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
[4726]40typedef void (*process_block_fcn)(const Basis_bits & basis_bits, Output & output);
[4324]41
[4788]42namespace llvm { class raw_ostream; }
43
[4659]44class GrepExecutor {
45public:
[4324]46
[4726]47    GrepExecutor(void * process_block)
[4659]48    : mCountOnlyOption(false)
49    , mShowFileNameOption(false)
50    , mShowLineNumberingOption(false)
51    , mProcessBlockFcn(reinterpret_cast<process_block_fcn>(process_block)) {
[4324]52
[4659]53    }
[4327]54         
[4324]55    void setCountOnlyOption(bool doCount = true) {mCountOnlyOption = doCount;}
56    void setShowFileNameOption(bool showF = true) {mShowFileNameOption = showF;}
57    void setShowLineNumberOption(bool showN = true) {mShowLineNumberingOption = showN;}
[4460]58    void setNormalizeLineBreaksOption(bool normLB = true) {mNormalizeLineBreaksOption = normLB;}
[4324]59   
[4788]60    void doGrep(const std::string & fileName);
[4324]61private:
[4788]62    ssize_t write_matches(llvm::raw_ostream & out, const char *buffer, ssize_t first_line_start);
63    bool finalLineIsUnterminated() const;
[4325]64
[4324]65    bool mCountOnlyOption;
66    bool mShowFileNameOption;
67    bool mShowLineNumberingOption;
[4460]68    bool mNormalizeLineBreaksOption;
[4478]69
[4324]70    process_block_fcn mProcessBlockFcn;
71   
[4477]72    std::string mFileName;
73    size_t mFileSize;
[4478]74    char * mFileBuffer;
75    ScannerT mLineBreak_scanner;
76    ScannerT mMatch_scanner;
[4788]77    size_t mLineNum;
[4324]78};
79
80
81#endif
Note: See TracBrowser for help on using the repository browser.