Ignore:
Timestamp:
Mar 10, 2018, 11:44:44 AM (19 months ago)
Author:
cameron
Message:

RE compiler restructuring progress

File:
1 edited

Legend:

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

    r5890 r5897  
    5757        mNonFinal = precompiledStream;
    5858        mFinal = pb.createNot(precompiledStream);
    59     }
    60     if (precompiledName == "UTF8_LB") {
    61         mLineBreak = precompiledStream;
    6259    }
    6360}
     
    154151
    155152inline MarkerType RE_Compiler::compileName(Name * const name, MarkerType marker, PabloBuilder & pb) {
     153    if (name->getType() == Name::Type::Capture) {
     154        return process(name->getDefinition(), marker, pb);
     155    } else if (name->getType() == Name::Type::Reference) {
     156        llvm::report_fatal_error("back references not supported in icgrep.");
     157    }
    156158    const auto & nameString = name->getName();
    157     if (nameString == ".") {
    158         return compileAny(marker, pb);
    159     } else if (nameString == "^"){
    160         return compileStart(marker, pb);
    161     } else if (nameString == "$"){
    162         return compileEnd(marker, pb);
    163     } else if (isUnicodeUnitLength(name)) {
    164         MarkerType nameMarker = compileName(name, pb);
     159    MarkerType nameMarker = compileName(name, pb);
     160    if (isUnicodeUnitLength(name)) {
    165161        MarkerType nextPos = AdvanceMarker(marker, FinalPostPositionUnit, pb);
    166162        nameMarker.stream = pb.createAnd(markerVar(nextPos), markerVar(nameMarker), name->getName());
    167163        return nameMarker;
    168164    } else if (name->getType() == Name::Type::ZeroWidth) {
    169         auto f = mExternalNameMap.find(nameString);
    170         if (f != mExternalNameMap.end()) {
    171             MarkerType z = makeMarker(FinalPostPositionUnit, f->second);
    172             AlignMarkers(marker, z, pb);
    173             PabloAST * ze = markerVar(z);
    174             return makeMarker(markerPos(marker), pb.createAnd(markerVar(marker), ze, "zerowidth"));
    175         }
    176         RE * zerowidth = name->getDefinition();
    177         MarkerType zero = compile(zerowidth, pb);
    178         AlignMarkers(marker, zero, pb);
    179         PabloAST * ze = markerVar(zero);
     165        AlignMarkers(marker, nameMarker, pb);
     166        PabloAST * ze = markerVar(nameMarker);
    180167        return makeMarker(markerPos(marker), pb.createAnd(markerVar(marker), ze, "zerowidth"));
    181168    } else {
    182         return process(name->getDefinition(), marker, pb);
     169        llvm::report_fatal_error(nameString + " is neither Unicode unit length nor ZeroWidth.");
    183170    }
    184171}
    185172
    186173inline MarkerType RE_Compiler::compileName(Name * const name, PabloBuilder & pb) {
     174    const auto & nameString = name->getName();
    187175    MarkerType m;
    188176    if (LLVM_LIKELY(mCompiledName->get(name, m))) {
    189177        return m;
    190     } else if (LLVM_LIKELY(name->getDefinition() != nullptr)) {
     178    }
     179    auto f = mExternalNameMap.find(nameString);
     180    if (f != mExternalNameMap.end()) {
     181        if (name->getType() == Name::Type::ZeroWidth) return makeMarker(FinalPostPositionUnit, f->second);
     182        else return makeMarker(FinalMatchUnit, f->second);
     183    }
     184    if (LLVM_LIKELY(name->getDefinition() != nullptr)) {
    191185        m = compile(name->getDefinition(), pb);
    192186        mCompiledName->add(name, m);
     
    569563    PabloAST * const nextPos = markerVar(AdvanceMarker(marker, FinalPostPositionUnit, pb));
    570564    PabloAST * const atEOL = pb.createAnd(mLineBreak, nextPos, "eol");
    571     //PabloAST * const atEOL = pb.createOr(pb.createAnd(mLineBreak, nextPos), pb.createAdvance(pb.createAnd(nextPos, mCRLF), 1), "eol");
    572565    return makeMarker(FinalPostPositionUnit, atEOL);
    573566}
Note: See TracChangeset for help on using the changeset viewer.