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

Last change on this file since 5698 was 5698, checked in by cameron, 2 years ago

Modularization progress

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
23// Thread function only.
24void *DoGrepThreadFunction(void *args);
25   
26
27class NonNormalizingReportMatch : public MatchAccumulator {
28public:
29    NonNormalizingReportMatch(std::string linePrefix) : mLinePrefix(linePrefix), mLineCount(0), mPrevious_line_end(nullptr) {}
30    void accumulate_match(const size_t lineNum, char * line_start, char * line_end) override;
31    void finalize_match(char * buffer_end) override;
32    std::string mLinePrefix;
33    size_t mLineCount;
34    char * mPrevious_line_end;
35    std::stringstream mResultStr;
36   
37};
38
39
40class GrepEngine {
41public:
42
43    GrepEngine() : mGrepDriver(nullptr), grepMatchFound(false), fileCount(0) {}
44
45
46    virtual ~GrepEngine();
47   
48    void initFileResult(std::vector<std::string> filenames);
49   
50    virtual void grepCodeGen(std::vector<re::RE *> REs);
51
52    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
53
54    uint64_t doGrep(const int32_t fileDescriptor, const uint32_t fileIdx);
55   
56    void PrintResults();
57   
58   
59
60    Driver * mGrepDriver;
61    bool grepMatchFound;
62
63    std::vector<std::unique_ptr<NonNormalizingReportMatch>> resultAccums;
64    std::vector<std::string> inputFiles;
65   
66    std::mutex count_mutex;
67    size_t fileCount;
68   
69};
70
71class CountOnlyGrepEngine : public GrepEngine {
72public:
73   
74    CountOnlyGrepEngine() : GrepEngine() {}
75    void grepCodeGen(std::vector<re::RE *> REs) override;
76   
77};
78
79}
80
81#endif
Note: See TracBrowser for help on using the repository browser.