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

Last change on this file since 5839 was 5804, checked in by cameron, 19 months ago

Fixes

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 <cc/multiplex_CCs.h>
12#include <string>
13#include <vector>
14#include <sstream>
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::ostringstream & 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::ostringstream> mResultStrs;
50    std::vector<FileStatus> mFileStatus;
51    bool grepMatchFound;
52
53    std::unique_ptr<cc::MultiplexedAlphabet> mpx;
54    std::string mFileSuffix;
55    bool mMoveMatchesToEOL;
56    pthread_t mEngineThread;
57};
58
59class EmitMatchesEngine : public GrepEngine {
60public:
61    EmitMatchesEngine();
62    void grepCodeGen(std::vector<re::RE *> REs) override;
63private:
64    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
65};
66
67class CountOnlyEngine : public GrepEngine {
68public:
69    CountOnlyEngine();
70private:
71    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
72};
73
74class MatchOnlyEngine : public GrepEngine {
75public:
76    MatchOnlyEngine(bool showFilesWithoutMatch);
77private:
78    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
79    unsigned mRequiredCount;
80};
81
82class QuietModeEngine : public GrepEngine {
83public:
84    QuietModeEngine();
85};
86
87}
88
89#endif
Note: See TracBrowser for help on using the repository browser.