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

Last change on this file since 5892 was 5892, checked in by cameron, 18 months ago

Restructuring: integrating grep_engine and grep_pipeline

File size: 2.9 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    class MatchAccumulator {
24    public:
25        MatchAccumulator() {}
26        virtual void accumulate_match(const size_t lineNum, char * line_start, char * line_end) = 0;
27        virtual void finalize_match(char * buffer_end) {}  // default: no op
28    };
29   
30    void accumulate_match_wrapper(intptr_t accum_addr, const size_t lineNum, char * line_start, char * line_end);
31   
32    void finalize_match_wrapper(intptr_t accum_addr, char * buffer_end);
33   
34    void grepBuffer(re::RE * pattern, const char * buffer, size_t bufferLength, MatchAccumulator * accum);
35
36class GrepEngine {
37    enum class FileStatus {Pending, GrepComplete, PrintComplete};
38public:
39
40    GrepEngine();
41    virtual ~GrepEngine();
42   
43    void initFileResult(std::vector<std::string> & filenames);
44    virtual void grepCodeGen(std::vector<re::RE *> REs);
45    bool searchAllFiles();
46    void * DoGrepThreadMethod();
47
48protected:
49    std::pair<parabix::StreamSetBuffer *, parabix::StreamSetBuffer *> grepPipeline(std::vector<re::RE *> & REs, parabix::StreamSetBuffer * ByteStream);
50
51    virtual uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
52    std::string linePrefix(std::string fileName);
53    int32_t openFile(const std::string & fileName, std::ostringstream & msgstrm);
54
55    Driver * mGrepDriver;
56
57    std::atomic<unsigned> mNextFileToGrep;
58    std::atomic<unsigned> mNextFileToPrint;
59    std::vector<std::string> inputFiles;
60    std::vector<std::ostringstream> mResultStrs;
61    std::vector<FileStatus> mFileStatus;
62    bool grepMatchFound;
63
64    std::unique_ptr<cc::MultiplexedAlphabet> mpx;
65    std::string mFileSuffix;
66    bool mMoveMatchesToEOL;
67    pthread_t mEngineThread;
68};
69
70class EmitMatchesEngine : public GrepEngine {
71public:
72    EmitMatchesEngine();
73    void grepCodeGen(std::vector<re::RE *> REs) override;
74private:
75    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
76};
77
78class CountOnlyEngine : public GrepEngine {
79public:
80    CountOnlyEngine();
81private:
82    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
83};
84
85class MatchOnlyEngine : public GrepEngine {
86public:
87    MatchOnlyEngine(bool showFilesWithoutMatch);
88private:
89    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
90    unsigned mRequiredCount;
91};
92
93class QuietModeEngine : public GrepEngine {
94public:
95    QuietModeEngine();
96};
97
98}
99
100#endif
Note: See TracBrowser for help on using the repository browser.