source: icGREP/icgrep-devel/icgrep/grep/grep_engine.h @ 5913

Last change on this file since 5913 was 5913, checked in by cameron, 17 months ago

Restructuring step

File size: 3.1 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 <cc/multiplex_CCs.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   
24enum class GrepRecordBreakKind {Null, LF, Unicode};
25
26class MatchAccumulator {
27public:
28    MatchAccumulator() {}
29    virtual void accumulate_match(const size_t lineNum, char * line_start, char * line_end) = 0;
30    virtual void finalize_match(char * buffer_end) {}  // default: no op
31};
32
33extern "C" void accumulate_match_wrapper(intptr_t accum_addr, const size_t lineNum, char * line_start, char * line_end);
34
35extern "C" void finalize_match_wrapper(intptr_t accum_addr, char * buffer_end);
36
37void grepBuffer(re::RE * pattern, const char * buffer, size_t bufferLength, MatchAccumulator * accum);
38
39class GrepEngine {
40    enum class FileStatus {Pending, GrepComplete, PrintComplete};
41public:
42
43    GrepEngine();
44    virtual ~GrepEngine();
45   
46    void setRecordBreak(GrepRecordBreakKind b);
47    void initFileResult(std::vector<std::string> & filenames);
48    void initREs(std::vector<re::RE *> & REs);
49    virtual void grepCodeGen();
50    bool searchAllFiles();
51    void * DoGrepThreadMethod();
52
53protected:
54    std::pair<parabix::StreamSetBuffer *, parabix::StreamSetBuffer *> grepPipeline(parabix::StreamSetBuffer * ByteStream);
55
56    virtual uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
57    std::string linePrefix(std::string fileName);
58    int32_t openFile(const std::string & fileName, std::ostringstream & msgstrm);
59
60    Driver * mGrepDriver;
61
62    std::atomic<unsigned> mNextFileToGrep;
63    std::atomic<unsigned> mNextFileToPrint;
64    std::vector<std::string> inputFiles;
65    std::vector<std::ostringstream> mResultStrs;
66    std::vector<FileStatus> mFileStatus;
67    bool grepMatchFound;
68    GrepRecordBreakKind mGrepRecordBreak;
69   
70    std::vector<re:: RE *> mREs;
71    std::set<re::Name *> mUnicodeProperties;
72    re::CC * mBreakCC;
73    std::unique_ptr<cc::MultiplexedAlphabet> mpx;
74    std::string mFileSuffix;
75    bool mMoveMatchesToEOL;
76    pthread_t mEngineThread;
77};
78
79class EmitMatchesEngine : public GrepEngine {
80public:
81    EmitMatchesEngine();
82    void grepCodeGen() override;
83private:
84    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
85};
86
87class CountOnlyEngine : public GrepEngine {
88public:
89    CountOnlyEngine();
90private:
91    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
92};
93
94class MatchOnlyEngine : public GrepEngine {
95public:
96    MatchOnlyEngine(bool showFilesWithoutMatch);
97private:
98    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
99    unsigned mRequiredCount;
100};
101
102class QuietModeEngine : public GrepEngine {
103public:
104    QuietModeEngine();
105};
106
107}
108
109#endif
Note: See TracBrowser for help on using the repository browser.