Ignore:
Timestamp:
Feb 9, 2017, 4:06:24 PM (2 years ago)
Author:
cameron
Message:

Boundary assertions; comment out a bug with RemoveNullableAfterAssertion?

Location:
icGREP/icgrep-devel/icgrep/re
Files:
6 edited

Legend:

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

    r5267 r5308  
    5757    } else if (const Assertion * a = dyn_cast<const Assertion>(re)) {
    5858        retVal = (a->getSense() == Assertion::Sense::Positive) ? "" : "Negative";
    59         retVal += (a->getKind() == Assertion::Kind::Lookahead) ? "Lookahead" : "Lookbehind";
     59        switch (a->getKind()) {
     60            case Assertion::Kind::Lookahead:
     61                retVal += "Lookahead";
     62                break;
     63            case Assertion::Kind::Lookbehind:
     64                retVal += "Lookbehind";
     65                break;
     66            case Assertion::Kind::Boundary:
     67                retVal += "Boundary";
     68                break;
     69        }
    6070        retVal += "Assertion(";
    6171        retVal += PrintRE(a->getAsserted());
  • icGREP/icgrep-devel/icgrep/re/re_assertion.h

    r4829 r5308  
    2020        return false;
    2121    }
    22     enum class Kind {Lookbehind, Lookahead};
     22    enum class Kind {Lookbehind, Lookahead, Boundary};
    2323    enum class Sense {Positive, Negative};
    2424
     
    6060}
    6161
     62inline RE * makeBoundaryAssertion(RE * r) {
     63    return makeAssertion(r, Assertion::Kind::Boundary, Assertion::Sense::Positive);
     64}
     65
     66inline RE * makeNegativeBoundaryAssertion(RE * r) {
     67    return makeAssertion(r, Assertion::Kind::Boundary, Assertion::Sense::Negative);
     68}
     69   
    6270}
    6371
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r5267 r5308  
    266266        return compileEnd(marker, pb);
    267267    }
    268     throw std::runtime_error("RE Compiler failed to process " + Printer_RE::PrintRE(re));
     268    UnsupportedRE("RE Compiler failed to process " + Printer_RE::PrintRE(re));
    269269}
    270270
     
    313313        return m;
    314314    }
    315     throw std::runtime_error("Unresolved name " + name->getName());
     315    UnsupportedRE("Unresolved name " + name->getName());
    316316}
    317317
     
    377377        }
    378378        return makeMarker(markerPos(marker), pb.createAnd(markerVar(marker), lb, "lookback"));
     379    } else if (a->getKind() == Assertion::Kind::Boundary) {
     380        MarkerType cond = compile(asserted, pb);
     381        if (LLVM_LIKELY(markerPos(cond) == MarkerPosition::FinalMatchUnit)) {
     382            MarkerType postCond = AdvanceMarker(cond, MarkerPosition::FinalPostPositionUnit, pb);
     383            PabloAST * boundaryCond = pb.createAnd(mAny, pb.createXor(markerVar(cond), markerVar(postCond)));
     384            if (a->getSense() == Assertion::Sense::Negative) {
     385                boundaryCond = pb.createNot(boundaryCond);
     386            }
     387            MarkerType fbyte = AdvanceMarker(marker, MarkerPosition::FinalPostPositionUnit, pb);
     388            return makeMarker(MarkerPosition::FinalPostPositionUnit, pb.createAnd(markerVar(fbyte), boundaryCond, "boundary"));
     389        }
     390        else UnsupportedRE("Unsupported boundary assertion");
    379391    } else if (isUnicodeUnitLength(asserted)) {
    380392        MarkerType lookahead = compile(asserted, pb);
     
    388400        }
    389401    }
    390     throw std::runtime_error("Unsupported lookahead assertion.");
     402    UnsupportedRE("Unsupported lookahead assertion.");
    391403}
    392404
     
    406418        return makeMarker(markerPos(t1), pb.createAnd(markerVar(t1), pb.createNot(markerVar(t2)), "diff"));
    407419    }
    408     throw std::runtime_error("Unsupported Diff operands: " + Printer_RE::PrintRE(diff));
     420    UnsupportedRE("Unsupported Diff operands: " + Printer_RE::PrintRE(diff));
    409421}
    410422
     
    418430        return makeMarker(markerPos(t1), pb.createAnd(markerVar(t1), markerVar(t2), "intersect"));
    419431    }
    420     throw std::runtime_error("Unsupported Intersect operands: " + Printer_RE::PrintRE(x));
     432    UnsupportedRE("Unsupported Intersect operands: " + Printer_RE::PrintRE(x));
    421433}
    422434
     
    625637    }
    626638}
     639   
     640LLVM_ATTRIBUTE_NORETURN void RE_Compiler::UnsupportedRE(std::string errmsg) {
     641    llvm::report_fatal_error(errmsg);
     642}
     643   
     644   
    627645
    628646RE_Compiler::RE_Compiler(PabloKernel * kernel, cc::CC_Compiler & ccCompiler, bool CountOnly)
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r5267 r5308  
    6767    }
    6868
     69    static LLVM_ATTRIBUTE_NORETURN void UnsupportedRE(std::string errmsg);
     70   
    6971private:
    7072
  • icGREP/icgrep-devel/icgrep/re/re_parser.cpp

    r5267 r5308  
    10811081
    10821082inline RE * RE_Parser::makeReBoundary(RE * re) {
    1083     return makeAlt({makeSeq({makeNegativeLookBehindAssertion(re), makeLookAheadAssertion(re)}),
    1084                     makeSeq({makeLookBehindAssertion(re), makeNegativeLookAheadAssertion(re)})});
     1083    return makeBoundaryAssertion(re);
    10851084}
    10861085inline RE * RE_Parser::makeReNonBoundary(RE * re) {
    1087     return makeAlt({makeSeq({makeNegativeLookBehindAssertion(re), makeNegativeLookAheadAssertion(re)}),
    1088                     makeSeq({makeLookBehindAssertion(re), makeLookAheadAssertion(re)})});
     1086    return makeNegativeBoundaryAssertion(re);
    10891087}
    10901088
  • icGREP/icgrep-devel/icgrep/re/re_toolchain.cpp

    r5295 r5308  
    7272        std::cerr << "RemoveNullableAssertion:" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    7373    }
    74     re_ast = re::RE_Nullable::removeNullableAfterAssertion(re_ast);
    75     if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
    76         std::cerr << "RemoveNullableAfterAssertion" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
    77     }
     74    //re_ast = re::RE_Nullable::removeNullableAfterAssertion(re_ast);
     75    //if (PrintOptions.isSet(ShowAllREs) || PrintOptions.isSet(ShowStrippedREs)) {
     76    //    std::cerr << "RemoveNullableAfterAssertion" << std::endl << Printer_RE::PrintRE(re_ast) << std::endl;
     77    //}
    7878   
    7979    re_ast = re::RE_Simplifier::simplify(re_ast);
Note: See TracChangeset for help on using the changeset viewer.