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

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

Refactoring, clean-up, set initial threads to 2

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();
27    virtual ~GrepEngine();
28   
29    void initFileResult(std::vector<std::string> & filenames);
30    virtual void grepCodeGen(std::vector<re::RE *> REs);
31    bool searchAllFiles();
32    void writeMatches();
33   
34protected:
35    static void * DoGrepThreadFunction(void *args);
36    virtual uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) = 0;
37    std::string linePrefix(std::string fileName);
38    int32_t openFile(const std::string & fileName, std::stringstream & msgstrm);
39
40    Driver * mGrepDriver;
41
42    std::vector<std::string> inputFiles;
43    std::vector<std::stringstream> mResultStrs;
44   
45    std::string mFileSuffix;
46   
47    bool grepMatchFound;
48    std::mutex count_mutex;
49    size_t fileCount;
50};
51
52class EmitMatchesEngine : public GrepEngine {
53public:
54    EmitMatchesEngine();
55    void grepCodeGen(std::vector<re::RE *> REs) override;
56private:
57    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
58};
59
60class CountOnlyEngine : public GrepEngine {
61public:
62    CountOnlyEngine();
63private:
64    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
65};
66
67class MatchOnlyEngine : public GrepEngine {
68public:
69    MatchOnlyEngine(bool showFilesWithoutMatch);
70private:
71    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
72    unsigned mRequiredCount;       
73};
74   
75}
76
77#endif
Note: See TracBrowser for help on using the repository browser.