Ignore:
Timestamp:
Sep 28, 2016, 7:20:54 AM (3 years ago)
Author:
cameron
Message:

If insertion for bounded repetitions

File:
1 edited

Legend:

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

    r5166 r5168  
    460460
    461461MarkerType RE_Compiler::processLowerBound(RE * repeated, int lb, MarkerType marker, PabloBuilder & pb) {
     462    if (lb == 0) return marker;
    462463    if (!mGraphemeBoundaryRule && isByteLength(repeated) && !AlgorithmOptionIsSet(DisableLog2BoundedRepetition)) {
    463464        PabloAST * cc = markerVar(compile(repeated, pb));
     
    466467        return makeMarker(MarkerPosition::FinalMatchUnit, pb.createAnd(marker_fwd, cc_lb, "lowerbound"));
    467468    }
    468     // Fall through to general case.
    469     for (int i = 1; i <= lb; ++i) {
    470         marker = process(repeated, marker, pb);
    471         if (mGraphemeBoundaryRule) {
    472             marker = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
    473         }
    474     }
    475     return marker;
    476 }
    477 
     469    // Fall through to general case.  Process the first item and insert the rest into an if-structure.   
     470    marker = process(repeated, marker, pb);
     471    if (mGraphemeBoundaryRule) {
     472        marker = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
     473    }
     474    if (lb == 1) return marker;
     475    PabloBuilder nested = PabloBuilder::Create(pb);
     476    MarkerType m1 = processLowerBound(repeated, lb - 1, marker, nested);
     477    Assign * m1a = nested.createAssign("m", markerVar(m1));
     478    pb.createIf(markerVar(marker), {m1a}, nested);
     479    return makeMarker(m1.pos, m1a);
     480}
     481   
    478482MarkerType RE_Compiler::processBoundedRep(RE * repeated, int ub, MarkerType marker, PabloBuilder & pb) {
     483    if (ub == 0) return marker;
    479484    if (!mGraphemeBoundaryRule && isByteLength(repeated) && ub > 1 && !AlgorithmOptionIsSet(DisableLog2BoundedRepetition)) {
    480485        // log2 upper bound for fixed length (=1) class
     
    487492        return makeMarker(MarkerPosition::InitialPostPositionUnit, pb.createAnd(pb.createMatchStar(cursor, rep_class_var), upperLimitMask, "bounded"));
    488493    }
    489     // Fall through to general case.
    490     for (int i = 1; i <= ub; ++i) {
    491         MarkerType a = process(repeated, marker, pb);
    492         MarkerType m = marker;
    493         AlignMarkers(a, m, pb);
    494         marker = makeMarker(markerPos(a), pb.createOr(markerVar(a), markerVar(m), "upper" + std::to_string(i)));
    495         if (mGraphemeBoundaryRule) {
    496             marker = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
    497         }
    498     }
    499     return marker;
     494    // Fall through to general case.  Process the first item and insert the rest into an if-structure.   
     495    MarkerType a = process(repeated, marker, pb);
     496    MarkerType m = marker;
     497    AlignMarkers(a, m, pb);
     498    marker = makeMarker(markerPos(a), pb.createOr(markerVar(a), markerVar(m)));
     499    if (mGraphemeBoundaryRule) {
     500        marker = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
     501    }
     502    if (ub == 1) return marker;
     503    PabloBuilder nested = PabloBuilder::Create(pb);
     504    MarkerType m1 = processBoundedRep(repeated, ub - 1, marker, nested);
     505    Assign * m1a = nested.createAssign("m", markerVar(m1));
     506    pb.createIf(markerVar(marker), {m1a}, nested);
     507    return makeMarker(m1.pos, m1a);
    500508}
    501509
Note: See TracChangeset for help on using the changeset viewer.