source: icGREP/icgrep-devel/icgrep/grep_engine.h @ 5751

Last change on this file since 5751 was 5735, checked in by cameron, 21 months ago

Incremental object caching; multithreaded print

File size: 2.3 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 <toolchain/grep_pipeline.h>
11#include <string>       // for string
12#include <vector>
13#include <sstream>
14#include <mutex>
15
16namespace re { class CC; }
17namespace re { class RE; }
18namespace llvm { namespace cl { class OptionCategory; } }
19class Driver;
20
21
22namespace grep {
23
24class GrepEngine {
25public:
26
27    GrepEngine();
28    virtual ~GrepEngine();
29   
30    void initFileResult(std::vector<std::string> & filenames);
31    virtual void grepCodeGen(std::vector<re::RE *> REs);
32    bool searchAllFiles();
33    void * DoGrepThreadMethod();
34
35protected:
36    std::pair<parabix::StreamSetBuffer *, parabix::StreamSetBuffer *> grepPipeline(std::vector<re::RE *> & REs, parabix::StreamSetBuffer * ByteStream);
37
38    virtual uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
39    std::string linePrefix(std::string fileName);
40    int32_t openFile(const std::string & fileName, std::stringstream * msgstrm);
41
42    Driver * mGrepDriver;
43
44    enum class FileStatus {Pending, InGrep, GrepComplete, Printing, PrintComplete};
45    std::mutex count_mutex;
46    size_t mNextFileToGrep;
47    size_t mNextFileToPrint;
48    std::vector<std::string> inputFiles;
49    std::vector<std::unique_ptr<std::stringstream>> mResultStrs;
50    std::vector<FileStatus> mFileStatus;
51    bool grepMatchFound;
52   
53    std::string mFileSuffix;
54    bool mMoveMatchesToEOL;
55    pthread_t mEngineThread;
56};
57
58class EmitMatchesEngine : public GrepEngine {
59public:
60    EmitMatchesEngine();
61    void grepCodeGen(std::vector<re::RE *> REs) override;
62private:
63    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
64};
65
66class CountOnlyEngine : public GrepEngine {
67public:
68    CountOnlyEngine();
69private:
70    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
71};
72
73class MatchOnlyEngine : public GrepEngine {
74public:
75    MatchOnlyEngine(bool showFilesWithoutMatch);
76private:
77    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
78    unsigned mRequiredCount;
79};
80
81class QuietModeEngine : public GrepEngine {
82public:
83    QuietModeEngine();
84};
85
86}
87
88#endif
Note: See TracBrowser for help on using the repository browser.