Ignore:
Timestamp:
Dec 15, 2017, 12:44:01 PM (14 months ago)
Author:
nmedfort
Message:

Initial check-in of LookAhead? support; modified LineBreakKernel? to compute CR+LF using LookAhead?(1) + misc. fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r5780 r5782  
    3737namespace re { class Alt; }
    3838namespace re { class RE; }
    39 
    40 
    41 #define UNICODE_LINE_BREAK (!AlgorithmOptionIsSet(DisableUnicodeLineBreak))
    4239
    4340using namespace pablo;
     
    9996
    10097inline MarkerType RE_Compiler::compileAny(const MarkerType m, PabloBuilder & pb) {
    101     PabloAST * nextFinalByte = markerVar(AdvanceMarker(m, MarkerPosition::FinalPostPositionUnit, pb));
     98    PabloAST * const nextFinalByte = markerVar(AdvanceMarker(m, MarkerPosition::FinalPostPositionUnit, pb));
    10299    return makeMarker(MarkerPosition::FinalMatchUnit, nextFinalByte);
    103100}
    104101
    105102MarkerType RE_Compiler::compileCC(CC * cc, MarkerType marker, PabloBuilder & pb) {
    106     MarkerType nextPos;
    107     if (markerPos(marker) == MarkerPosition::FinalPostPositionUnit) {
    108         nextPos = marker;
    109     } else {
    110         nextPos = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
    111     }
    112     return makeMarker(MarkerPosition::FinalMatchUnit, pb.createAnd(markerVar(nextPos), mCCCompiler.compileCC(cc, pb)));
     103    PabloAST * const nextPos = markerVar(AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb));
     104    return makeMarker(MarkerPosition::FinalMatchUnit, pb.createAnd(nextPos, mCCCompiler.compileCC(cc, pb)));
    113105}
    114106
     
    123115    } else if (isUnicodeUnitLength(name)) {
    124116        MarkerType nameMarker = compileName(name, pb);
    125         MarkerType nextPos;
    126         if (markerPos(marker) == MarkerPosition::FinalPostPositionUnit) {
    127             nextPos = marker;
    128         } else {
    129             nextPos = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
    130         }
     117        MarkerType nextPos = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
    131118        nameMarker.stream = pb.createAnd(markerVar(nextPos), markerVar(nameMarker), name->getName());
    132119        return nameMarker;
     
    560547}
    561548
    562 inline MarkerType RE_Compiler::compileStart(const MarkerType marker, pablo::PabloBuilder & pb) {
     549inline MarkerType RE_Compiler::compileStart(MarkerType marker, pablo::PabloBuilder & pb) {
     550    PabloAST * sol = pb.createNot(pb.createAdvance(pb.createNot(mLineBreak), 1));
     551    if (!AlgorithmOptionIsSet(DisableUnicodeLineBreak)) {
     552        sol = pb.createScanThru(pb.createAnd(mInitial, sol), mNonFinal);
     553    }
    563554    MarkerType m = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
    564     if (UNICODE_LINE_BREAK) {
    565         PabloAST * line_end = mPB.createOr(mLineBreak, mCRLF);
    566         PabloAST * sol_init = pb.createNot(pb.createOr(pb.createAdvance(pb.createNot(line_end), 1), mCRLF));
    567         PabloAST * sol = pb.createScanThru(pb.createAnd(mInitial, sol_init), mNonFinal);
    568         return makeMarker(MarkerPosition::FinalPostPositionUnit, pb.createAnd(markerVar(m), sol, "sol"));
    569     } else {
    570         PabloAST * sol = pb.createNot(pb.createAdvance(pb.createNot(mLineBreak), 1));
    571         return makeMarker(MarkerPosition::FinalPostPositionUnit, pb.createAnd(markerVar(m), sol, "sol"));
    572     }
    573 }
    574 
    575 inline MarkerType RE_Compiler::compileEnd(const MarkerType marker, pablo::PabloBuilder & pb) {
    576     PabloAST * nextPos = markerVar(AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb));
    577     return makeMarker(MarkerPosition::FinalPostPositionUnit, pb.createAnd(nextPos, mLineBreak, "eol"));
     555    return makeMarker(MarkerPosition::FinalPostPositionUnit, pb.createAnd(markerVar(m), sol, "sol"));
     556}
     557
     558inline MarkerType RE_Compiler::compileEnd(MarkerType marker, pablo::PabloBuilder & pb) {
     559    PabloAST * const nextPos = markerVar(AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb));
     560    return makeMarker(MarkerPosition::FinalPostPositionUnit, pb.createAnd(pb.createScanThru(nextPos, mCRLF), mLineBreak, "eol"));
    578561}
    579562
     
    605588    llvm::report_fatal_error(errmsg);
    606589}
    607    
    608    
    609590
    610591RE_Compiler::RE_Compiler(PabloKernel * kernel, cc::CC_Compiler & ccCompiler)
     
    623604    Var * const linebreak = mKernel->getInputStreamVar("linebreak");
    624605    mLineBreak = mPB.createExtract(linebreak, mPB.getInteger(0));
     606    Var * const crlf = mKernel->getInputStreamVar("cr+lf");
     607    mCRLF = mPB.createExtract(crlf, mPB.getInteger(0));
    625608    Var * const required = mKernel->getInputStreamVar("required");
    626609    mInitial = mPB.createExtract(required, mPB.getInteger(0));
    627610    mNonFinal = mPB.createExtract(required, mPB.getInteger(1));
    628611    mFinal = mPB.createExtract(required, mPB.getInteger(2));
    629     mCRLF = mPB.createExtract(required, mPB.getInteger(3));
     612
    630613}
    631614
Note: See TracChangeset for help on using the changeset viewer.