source: icGREP/icgrep-devel/icgrep/grep/grep_engine.h @ 5941

Last change on this file since 5941 was 5941, checked in by xwa163, 17 months ago
  1. Add attributes to disable some features of multiblock kernel
  2. Fix bug for lz4d new approach in large data, pass all test cases
  3. Disable lz4d related test cases for old approach
File size: 3.7 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6#ifndef GREP_ENGINE_H
7#define GREP_ENGINE_H
8#include <grep_interface.h>
9#include <kernels/streamset.h>
10#include <cc/multiplex_CCs.h>
11#include <string>
12#include <vector>
13#include <sstream>
14#include <atomic>
15
16namespace re { class CC; }
17namespace re { class RE; }
18namespace llvm { namespace cl { class OptionCategory; } }
19class Driver;
20
21
22namespace grep {
23   
24enum class GrepRecordBreakKind {Null, LF, Unicode};
25
26class MatchAccumulator {
27public:
28    MatchAccumulator() {}
29    virtual void accumulate_match(const size_t lineNum, char * line_start, char * line_end) = 0;
30    virtual void finalize_match(char * buffer_end) {}  // default: no op
31};
32
33extern "C" void accumulate_match_wrapper(intptr_t accum_addr, const size_t lineNum, char * line_start, char * line_end);
34
35extern "C" void finalize_match_wrapper(intptr_t accum_addr, char * buffer_end);
36
37void grepBuffer(re::RE * pattern, const char * buffer, size_t bufferLength, MatchAccumulator * accum);
38
39class GrepEngine {
40    enum class FileStatus {Pending, GrepComplete, PrintComplete};
41public:
42
43    GrepEngine();
44    virtual ~GrepEngine();
45   
46    void setRecordBreak(GrepRecordBreakKind b);
47    void initFileResult(std::vector<std::string> & filenames);
48    void initREs(std::vector<re::RE *> & REs);
49    virtual void grepCodeGen();
50    bool searchAllFiles();
51    void * DoGrepThreadMethod();
52
53protected:
54    std::pair<parabix::StreamSetBuffer *, parabix::StreamSetBuffer *> grepPipeline(parabix::StreamSetBuffer * ByteStream);
55
56    virtual uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
57    std::string linePrefix(std::string fileName);
58    int32_t openFile(const std::string & fileName, std::ostringstream & msgstrm);
59
60    Driver * mGrepDriver;
61
62    std::atomic<unsigned> mNextFileToGrep;
63    std::atomic<unsigned> mNextFileToPrint;
64    std::vector<std::string> inputFiles;
65    std::vector<std::ostringstream> mResultStrs;
66    std::vector<FileStatus> mFileStatus;
67    bool grepMatchFound;
68    GrepRecordBreakKind mGrepRecordBreak;
69   
70    std::vector<re:: RE *> mREs;
71    std::set<re::Name *> mUnicodeProperties;
72    re::CC * mBreakCC;
73    std::unique_ptr<cc::MultiplexedAlphabet> mpx;
74    std::string mFileSuffix;
75    bool mMoveMatchesToEOL;
76    pthread_t mEngineThread;
77};
78
79
80//
81// The EmitMatches engine uses an EmitMatchesAccumulator object to concatenate together
82// matched lines.
83
84class EmitMatch : public MatchAccumulator {
85    friend class EmitMatchesEngine;
86public:
87    EmitMatch(std::string linePrefix, std::ostringstream & strm) : mLinePrefix(linePrefix), mLineCount(0), mTerminated(true), mResultStr(strm) {}
88    void accumulate_match(const size_t lineNum, char * line_start, char * line_end) override;
89    void finalize_match(char * buffer_end) override;
90protected:
91    std::string mLinePrefix;
92    size_t mLineCount;
93    bool mTerminated;
94    std::ostringstream & mResultStr;
95};
96
97class EmitMatchesEngine : public GrepEngine {
98public:
99    EmitMatchesEngine();
100    void grepCodeGen() override;
101private:
102    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
103};
104
105class CountOnlyEngine : public GrepEngine {
106public:
107    CountOnlyEngine();
108private:
109    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
110};
111
112class MatchOnlyEngine : public GrepEngine {
113public:
114    MatchOnlyEngine(bool showFilesWithoutMatch);
115private:
116    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
117    unsigned mRequiredCount;
118};
119
120class QuietModeEngine : public GrepEngine {
121public:
122    QuietModeEngine();
123};
124
125}
126
127#endif
Note: See TracBrowser for help on using the repository browser.