Ignore:
Timestamp:
Oct 7, 2017, 4:59:20 PM (23 months ago)
Author:
cameron
Message:

MatchAccumulator? objects to collect match results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5646 r5676  
    546546}
    547547
     548class CodepointAccumulator : public kernel::MatchAccumulator {
     549public:
     550   
     551    CodepointAccumulator(const char * searchBuffer) : mSearchBuffer(searchBuffer), mParsedCodePointSet(re::makeCC()) {}
     552   
     553    void accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) override;
     554    re::CC * getCodePoints() {return mParsedCodePointSet;}
     555private:
     556    const char * mSearchBuffer;
     557    re::CC * mParsedCodePointSet;
     558};
     559   
     560void CodepointAccumulator::accumulate_match(const size_t lineNum, size_t line_start, size_t line_end) {
     561    assert (line_start <= line_end);
     562    re::codepoint_t c = 0;
     563    size_t line_pos = line_start;
     564    while (isxdigit(mSearchBuffer[line_pos])) {
     565        assert (line_pos < line_end);
     566        if (isdigit(mSearchBuffer[line_pos])) {
     567            c = (c << 4) | (mSearchBuffer[line_pos] - '0');
     568        }
     569        else {
     570            c = (c << 4) | (tolower(mSearchBuffer[line_pos]) - 'a' + 10);
     571        }
     572        line_pos++;
     573    }
     574    assert(((line_pos - line_start) >= 4) && ((line_pos - line_start) <= 6)); // UCD format 4 to 6 hex digits.
     575    mParsedCodePointSet->insert(c);   
     576}
     577
     578
     579   
    548580re::CC * grepCodepoints(re::RE * pattern, char * UnicodeDataBuffer, size_t bufferLength) {
    549     parsedCodePointSet = re::makeCC();       
     581    //parsedCodePointSet = re::makeCC();       
    550582    const unsigned segmentSize = 8;
    551583
     
    590622    pxDriver.makeKernelCall(matchedLinesK, {MatchResults, LineBreakStream}, {MatchedLines});
    591623   
    592     kernel::Kernel * scanMatchK = pxDriver.addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, GrepType::NameExpression, 8));
    593     scanMatchK->setInitialArguments({idb->getInt32(0)});
     624    kernel::Kernel * scanMatchK = pxDriver.addKernelInstance(make_unique<kernel::ScanMatchKernel>(idb, GrepType::CallBack, 8));
     625    CodepointAccumulator accum(UnicodeDataBuffer);
     626    intptr_t accum_addr = (intptr_t) &accum;
     627    scanMatchK->setInitialArguments({ConstantInt::get(idb->getIntAddrTy(), accum_addr)});
    594628    pxDriver.makeKernelCall(scanMatchK, {MatchedLines, LineBreakStream, ByteStream}, {});
    595     pxDriver.LinkFunction(*scanMatchK, "matcher", &insert_codepoints);
    596629    pxDriver.generatePipelineIR();
    597630    pxDriver.deallocateBuffers();
     
    603636    f(UnicodeDataBuffer, bufferLength);
    604637   
    605     return parsedCodePointSet;   
     638    //return parsedCodePointSet;
     639    return accum.getCodePoints();
    606640}
    607641
     
    614648}
    615649
     650   
    616651
    617652const std::vector<std::string> & grepPropertyValues(const std::string& propertyName, re::RE * propertyValuePattern) {
Note: See TracChangeset for help on using the changeset viewer.