Ignore:
Timestamp:
Jul 8, 2017, 1:09:56 PM (21 months ago)
Author:
cameron
Message:

Flattening if-hierarchy for bounded repetitions, allowing CCs to pass through to re_compiler

File:
1 edited

Legend:

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

    r5548 r5555  
    229229    } else if (isa<End>(re)) {
    230230        return compileEnd(marker, pb);
     231    } else if (isa<CC>(re)) {
     232        // CCs may be passed through the toolchain directly to the compiler.
     233        return compileCC(cast<CC>(re), marker, pb);
    231234    }
    232235    UnsupportedRE("RE Compiler failed to process " + Printer_RE::PrintRE(re));
     
    240243    }
    241244    return makeMarker(MarkerPosition::FinalMatchUnit, pb.createAnd(nextFinalByte, pb.createNot(lb), "dot"));
     245}
     246
     247MarkerType RE_Compiler::compileCC(CC * cc, MarkerType marker, PabloBuilder & pb) {
     248    MarkerType nextPos;
     249    if (markerPos(marker) == MarkerPosition::FinalPostPositionUnit) {
     250        nextPos = marker;
     251    } else {
     252        nextPos = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
     253    }
     254    return makeMarker(MarkerPosition::FinalMatchUnit, pb.createAnd(markerVar(marker), mCCCompiler.compileCC(cc)));
    242255}
    243256
     
    401414    int ub = rep->getUB();
    402415    if (lb > 0) {
    403         marker = processLowerBound(rep->getRE(), lb, marker, pb);
     416        marker = processLowerBound(rep->getRE(), lb, marker, IfInsertionGap, pb);
    404417    }
    405418    if (ub == Rep::UNBOUNDED_REP) {
    406419        marker = processUnboundedRep(rep->getRE(), marker, pb);
    407420    } else if (lb < ub) {
    408         marker = processBoundedRep(rep->getRE(), ub - lb, marker, pb);
     421        marker = processBoundedRep(rep->getRE(), ub - lb, marker, IfInsertionGap, pb);
    409422    }
    410423    return marker;
     
    454467}
    455468
    456 MarkerType RE_Compiler::processLowerBound(RE * repeated, int lb, MarkerType marker, PabloBuilder & pb) {
     469MarkerType RE_Compiler::processLowerBound(RE * repeated, int lb, MarkerType marker, int ifGroupSize, PabloBuilder & pb) {
    457470    if (lb == 0) {
    458471        return marker;
     
    463476        return makeMarker(MarkerPosition::FinalMatchUnit, pb.createAnd(marker_fwd, cc_lb, "lowerbound"));
    464477    }
    465     // Fall through to general case.  Process the first item and insert the rest into an if-structure.   
    466     marker = process(repeated, marker, pb);
    467     if (mGraphemeBoundaryRule) {
    468         marker = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
    469     }
    470     if (lb == 1) {
     478    // Fall through to general case.  Process the first item and insert the rest into an if-structure.
     479    auto group = ifGroupSize < lb ? ifGroupSize : lb;
     480    for (auto i = 0; i < group; i++) {
     481        marker = process(repeated, marker, pb);
     482        if (mGraphemeBoundaryRule) {
     483            marker = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
     484        }
     485    }
     486    if (lb == group) {
    471487        return marker;
    472488    }
    473489    Var * m = pb.createVar("m", pb.createZeroes());
    474490    PabloBuilder nested = PabloBuilder::Create(pb);
    475     MarkerType m1 = processLowerBound(repeated, lb - 1, marker, nested);
     491    MarkerType m1 = processLowerBound(repeated, lb - group, marker, ifGroupSize * 2, nested);
    476492    nested.createAssign(m, markerVar(m1));
    477493    pb.createIf(markerVar(marker), nested);
     
    479495}
    480496   
    481 MarkerType RE_Compiler::processBoundedRep(RE * repeated, int ub, MarkerType marker, PabloBuilder & pb) {
     497MarkerType RE_Compiler::processBoundedRep(RE * repeated, int ub, MarkerType marker, int ifGroupSize,  PabloBuilder & pb) {
    482498    if (ub == 0) {
    483499        return marker;
     
    493509    }
    494510    // 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) {
     511    auto group = ifGroupSize < ub ? ifGroupSize : ub;
     512    for (auto i = 0; i < group; i++) {
     513        MarkerType a = process(repeated, marker, pb);
     514        MarkerType m = marker;
     515        AlignMarkers(a, m, pb);
     516        marker = makeMarker(markerPos(a), pb.createOr(markerVar(a), markerVar(m)));
     517        if (mGraphemeBoundaryRule) {
     518            marker = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
     519        }
     520    }
     521    if (ub == group) {
    503522        return marker;
    504523    }
    505524    Var * m1a = pb.createVar("m", pb.createZeroes());
    506525    PabloBuilder nested = PabloBuilder::Create(pb);
    507     MarkerType m1 = processBoundedRep(repeated, ub - 1, marker, nested);
     526    MarkerType m1 = processBoundedRep(repeated, ub - group, marker, ifGroupSize * 2, nested);
    508527    nested.createAssign(m1a, markerVar(m1));
    509528    pb.createIf(markerVar(marker), nested);
Note: See TracChangeset for help on using the changeset viewer.