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

Last change on this file since 5761 was 5761, checked in by nmedfort, 15 months ago

Cache signature is now written into .kernel bitcode file. Minor bug fix and revision of GrepEngine::DoGrepThreadMethod?

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