Ignore:
Timestamp:
Apr 5, 2018, 9:18:57 PM (18 months ago)
Author:
cameron
Message:

Decouple GrepEngine? and re utilities from command line flags

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep/grep_engine.h

    r5941 r5945  
    3535extern "C" void finalize_match_wrapper(intptr_t accum_addr, char * buffer_end);
    3636
     37   
     38#define MAX_SIMD_WIDTH_SUPPORTED 512
     39#define INITIAL_CAPACITY 1024
     40   
     41class SearchableBuffer  {
     42    SearchableBuffer();
     43    void addSearchCandidate(char * string_ptr, size_t length);
     44    ~SearchableBuffer();
     45private:
     46    static const unsigned BUFFER_ALIGNMENT = MAX_SIMD_WIDTH_SUPPORTED/8;
     47    size_t allocated_capacity;
     48    char * buffer_base;
     49    alignas(BUFFER_ALIGNMENT) char initial_buffer[INITIAL_CAPACITY];
     50    size_t space_used;
     51    size_t entries;
     52};
     53
    3754void grepBuffer(re::RE * pattern, const char * buffer, size_t bufferLength, MatchAccumulator * accum);
    3855
     
    4461    virtual ~GrepEngine();
    4562   
     63    void setPreferMMap() {mPreferMMap = true;}
     64   
     65    void showFileNames() {mShowFileNames = true;}
     66    void setStdinLabel(std::string lbl) {mStdinLabel = lbl;}
     67    void showLineNumbers() {mShowLineNumbers = true;}
     68    void setInitialTab() {mInitialTab = true;}
     69
     70    void setMaxCount(int m) {mMaxCount = m;}
     71    void setInvertMatches() {mInvertMatches = true;}
     72    void setCaseInsensitive()  {mCaseInsensitive = true;}
     73
     74    void suppressFileMessages() {mSuppressFileMessages = true;}
     75
    4676    void setRecordBreak(GrepRecordBreakKind b);
    4777    void initFileResult(std::vector<std::string> & filenames);
     
    5585
    5686    virtual uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx);
    57     std::string linePrefix(std::string fileName);
    5887    int32_t openFile(const std::string & fileName, std::ostringstream & msgstrm);
    5988
     89    enum class EngineKind {QuietMode, MatchOnly, CountOnly, EmitMatches};
     90    EngineKind mEngineKind;
     91   
     92    std::string linePrefix(std::string fileName);
     93
     94    bool mSuppressFileMessages;
     95    bool mPreferMMap;
     96    bool mShowFileNames;
     97    std::string mStdinLabel;
     98    bool mShowLineNumbers;
     99    bool mInitialTab;
     100    bool mCaseInsensitive;
     101    bool mInvertMatches;
     102    int mMaxCount;
     103   
    60104    Driver * mGrepDriver;
    61105
     
    85129    friend class EmitMatchesEngine;
    86130public:
    87     EmitMatch(std::string linePrefix, std::ostringstream & strm) : mLinePrefix(linePrefix), mLineCount(0), mTerminated(true), mResultStr(strm) {}
     131    EmitMatch(std::string linePrefix, bool showLineNumbers, bool initialTab, std::ostringstream & strm) : mLinePrefix(linePrefix),
     132        mShowLineNumbers(showLineNumbers),
     133        mInitialTab(initialTab),
     134        mLineCount(0),
     135        mTerminated(true),
     136        mResultStr(strm) {}
    88137    void accumulate_match(const size_t lineNum, char * line_start, char * line_end) override;
    89138    void finalize_match(char * buffer_end) override;
    90139protected:
    91140    std::string mLinePrefix;
     141    bool mShowLineNumbers;
     142    bool mInitialTab;
    92143    size_t mLineCount;
    93144    bool mTerminated;
     
    112163class MatchOnlyEngine : public GrepEngine {
    113164public:
    114     MatchOnlyEngine(bool showFilesWithoutMatch);
     165    MatchOnlyEngine(bool showFilesWithoutMatch, bool useNullSeparators);
    115166private:
    116167    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) override;
Note: See TracChangeset for help on using the changeset viewer.