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

Last change on this file since 4904 was 4904, checked in by cameron, 3 years ago

Refactoring progress towards layered kernels

File size: 3.6 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>
[4803]11#include "basis_bits.h"
[4324]12#include "include/simd-lib/bitblock.hpp"
13#include "include/simd-lib/transpose.hpp"
[4325]14#include "include/simd-lib/bitblock_iterator.hpp"
[4802]15#include <re/re_cc.h>
[4324]16
17struct Output {
18    BitBlock matches;
19    BitBlock LF;
20};
21
[4325]22#if (BLOCK_SIZE == 128)
23#define SEGMENT_BLOCKS 7
24#endif
25
26#if (BLOCK_SIZE == 256)
27#define SEGMENT_BLOCKS 15
28#endif
29
30#define SEGMENT_SIZE (BLOCK_SIZE * SEGMENT_BLOCKS)
31
32
33#if (BLOCK_SIZE == 256)
34typedef BitStreamScanner<BitBlock, uint64_t, uint64_t, SEGMENT_BLOCKS> ScannerT;
35#endif
36
37#if (BLOCK_SIZE == 128)
38typedef BitStreamScanner<BitBlock, uint32_t, uint32_t, SEGMENT_BLOCKS> ScannerT;
39#endif
40
[4900]41typedef void (*transpose_fcn_T)(BytePack * byte_data, Basis_bits & basis_bits);
[4826]42typedef void (*process_block_initialize_carries_fcn)();
[4726]43typedef void (*process_block_fcn)(const Basis_bits & basis_bits, Output & output);
[4324]44
[4788]45namespace llvm { class raw_ostream; }
46
[4659]47class GrepExecutor {
48public:
[4324]49
[4826]50    GrepExecutor(void * process_block_initialize_carries, void * process_block)
[4659]51    : mCountOnlyOption(false)
[4802]52    , mGetCodePointsOption(false)
[4659]53    , mShowFileNameOption(false)
54    , mShowLineNumberingOption(false)
[4802]55    , mParsedCodePointSet(nullptr)
[4900]56    , mTransposeFcn(reinterpret_cast<transpose_fcn_T>(&s2p_do_block))
[4826]57    , mInitializeCarriesFcn(reinterpret_cast<process_block_initialize_carries_fcn>(process_block_initialize_carries))
[4659]58    , mProcessBlockFcn(reinterpret_cast<process_block_fcn>(process_block)) {
[4900]59       
[4659]60    }
[4900]61    GrepExecutor(void * s2p_fnptr, void * process_block_initialize_carries, void * process_block)
62    : mCountOnlyOption(false)
63    , mGetCodePointsOption(false)
64    , mShowFileNameOption(false)
65    , mShowLineNumberingOption(false)
66    , mParsedCodePointSet(nullptr)
67    , mTransposeFcn(reinterpret_cast<transpose_fcn_T>(s2p_fnptr))
68    , mInitializeCarriesFcn(reinterpret_cast<process_block_initialize_carries_fcn>(process_block_initialize_carries))
69    , mProcessBlockFcn(reinterpret_cast<process_block_fcn>(process_block)) {
70       
71    }
72   
[4324]73    void setCountOnlyOption(bool doCount = true) {mCountOnlyOption = doCount;}
[4803]74    void setParseCodepointsOption() {
75        mGetCodePointsOption = true;
[4802]76        mParsedCodePointSet = re::makeCC();
77    }
[4324]78    void setShowFileNameOption(bool showF = true) {mShowFileNameOption = showF;}
79    void setShowLineNumberOption(bool showN = true) {mShowLineNumberingOption = showN;}
[4460]80    void setNormalizeLineBreaksOption(bool normLB = true) {mNormalizeLineBreaksOption = normLB;}
[4324]81   
[4788]82    void doGrep(const std::string & fileName);
[4802]83    re::CC * getParsedCodepoints() { return mParsedCodePointSet;}
[4324]84private:
[4904]85    void write_matched_line(llvm::raw_ostream & out, const char * buffer, ssize_t line_start, ssize_t line_end);
86
[4788]87    ssize_t write_matches(llvm::raw_ostream & out, const char *buffer, ssize_t first_line_start);
[4802]88   
[4788]89    bool finalLineIsUnterminated() const;
[4802]90    ssize_t extract_codepoints(char * buffer, ssize_t first_line_start);
[4325]91
[4324]92    bool mCountOnlyOption;
[4802]93    bool mGetCodePointsOption;
[4324]94    bool mShowFileNameOption;
95    bool mShowLineNumberingOption;
[4460]96    bool mNormalizeLineBreaksOption;
[4802]97   
98    re::CC * mParsedCodePointSet;
[4478]99
[4900]100    transpose_fcn_T mTransposeFcn;
[4826]101    process_block_initialize_carries_fcn mInitializeCarriesFcn;
[4324]102    process_block_fcn mProcessBlockFcn;
103   
[4477]104    std::string mFileName;
105    size_t mFileSize;
[4478]106    char * mFileBuffer;
107    ScannerT mLineBreak_scanner;
108    ScannerT mMatch_scanner;
[4788]109    size_t mLineNum;
[4324]110};
111
112
113#endif
Note: See TracBrowser for help on using the repository browser.