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

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

Fix missing filename as line output prefix

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 <grep_type.h>  // for GrepType, GrepType::Normal
10#include <toolchain/grep_pipeline.h>
11#include <string>       // for string
12#include <vector>
13#include <re/re_parser.h>
14#include <re/re_multiplex.h>
15#include <sstream>
16#include <mutex>
17
18namespace re { class CC; }
19namespace re { class RE; }
20namespace llvm { namespace cl { class OptionCategory; } }
21class Driver;
22
23
24namespace grep {
25
26// Thread function only.
27void *DoGrepThreadFunction(void *args);
28   
29
30class NonNormalizingReportMatch : public MatchAccumulator {
31public:
32    NonNormalizingReportMatch(std::string linePrefix) : mLinePrefix(linePrefix), mLineCount(0), mPrevious_line_end(nullptr) {}
33    void accumulate_match(const size_t lineNum, char * line_start, char * line_end) override;
34    void finalize_match(char * buffer_end) override;
35    std::string mLinePrefix;
36    size_t mLineCount;
37    char * mPrevious_line_end;
38    std::stringstream mResultStr;
39   
40};
41
42
43class GrepEngine {
44public:
45
46    GrepEngine() : mGrepDriver(nullptr), grepMatchFound(false), fileCount(0) {}
47
48
49    ~GrepEngine();
50   
51    void initFileResult(std::vector<std::string> filenames);
52   
53    void grepCodeGen(std::vector<re::RE *> REs, GrepModeType grepMode);
54
55    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
56
57    uint64_t doGrep(const int32_t fileDescriptor, const uint32_t fileIdx);
58   
59    void PrintResults();
60   
61   
62
63    Driver * mGrepDriver;
64    bool grepMatchFound;
65
66    std::vector<std::unique_ptr<NonNormalizingReportMatch>> resultAccums;
67    std::vector<std::string> inputFiles;
68   
69    std::mutex count_mutex;
70    size_t fileCount;
71   
72};
73
74   
75}
76
77#endif
Note: See TracBrowser for help on using the repository browser.