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

Last change on this file since 5795 was 5771, checked in by nmedfort, 16 months ago

Minor changes and hopefully a fix for bug exposed by base64 test

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