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

Last change on this file since 5700 was 5700, checked in by cameron, 20 months ago

Refactoring of grep_engine based on mode

File size: 1.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 <toolchain/grep_pipeline.h>
10#include <string>       // for string
11#include <vector>
12#include <sstream>
13#include <mutex>
14
15namespace re { class CC; }
16namespace re { class RE; }
17namespace llvm { namespace cl { class OptionCategory; } }
18class Driver;
19
20
21namespace grep {
22
23class GrepEngine {
24public:
25
26    GrepEngine() : mGrepDriver(nullptr), mFileSuffix(InitialTabFlag ? "\t:" : ":"), grepMatchFound(false), fileCount(0) {}
27
28    virtual ~GrepEngine();
29   
30    void initFileResult(std::vector<std::string> filenames);
31   
32    virtual void grepCodeGen(std::vector<re::RE *> REs);
33
34    void run();
35   
36    void PrintResults();
37   
38   
39   
40protected:
41    static void * DoGrepThreadFunction(void *args);
42    virtual uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
43    std::string linePrefix(std::string fileName);
44   
45    Driver * mGrepDriver;
46
47    std::vector<std::string> inputFiles;
48    std::vector<std::stringstream> mResultStrs;
49   
50    std::string mFileSuffix;
51   
52    bool grepMatchFound;
53    std::mutex count_mutex;
54    size_t fileCount;
55};
56
57class CountOnlyGrepEngine : public GrepEngine {
58public:
59   
60    CountOnlyGrepEngine() : GrepEngine() {mFileSuffix = ":";}
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};
66
67class MatchOnlyGrepEngine : public CountOnlyGrepEngine {
68public:
69   
70    MatchOnlyGrepEngine() : CountOnlyGrepEngine(), mRequiredCount(Mode != FilesWithoutMatch) {mFileSuffix = NullFlag ? std::string("\0", 1) : "\n";}
71private:
72    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
73    unsigned mRequiredCount;       
74};
75   
76}
77
78#endif
Note: See TracBrowser for help on using the repository browser.