Changeset 4486 for icGREP/icgrep-devel


Ignore:
Timestamp:
Feb 9, 2015, 12:32:19 PM (5 years ago)
Author:
nmedfort
Message:

Minor code clean-up

Location:
icGREP/icgrep-devel/icgrep
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4433 r4486  
    7474        strm << "if ";
    7575        print(ifstmt->getCondition(), strm);
    76         strm << ":\n";
     76        strm << ":" << std::endl;
    7777        print(ifstmt->getBody(), indent + "  ", strm);
    7878    }
    7979    else if (const While * whl = dyn_cast<const While>(stmt)) {
    80         strm << "while";
     80        strm << "while ";
    8181        print(whl->getCondition(), strm);
    82         strm << ":\n";
     82        strm << ":" << std::endl;
    8383        print(whl->getBody(), indent + "  ", strm);
    8484    }
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4485 r4486  
    7878    }
    7979}
    80    
    81    
    8280
    8381#define USE_IF_FOR_NONFINAL 1
     
    8785
    8886void RE_Compiler::initializeRequiredStreams(cc::CC_Compiler & ccc) {
    89 
    90     const std::string nonfinal = "nonfinal";
    9187
    9288    Assign * LF = mPB.createAssign("LF", ccc.compileCC(makeCC(0x0A)));
     
    119115    PabloAST * LS_PS = mPB.createAnd(mPB.createAdvance(E2_80, 1), ccc.compileCC(makeCC(0xA8,0xA9)));
    120116    PabloAST * LB_chars = mPB.createOr(LF_VT_FF_CR, mPB.createOr(NEL, LS_PS));
    121     mNonFinal = mPB.createAssign(nonfinal, mPB.createOr(mPB.createOr(u8pfx, u8scope32), mPB.createOr(u8scope42, u8scope43)));
     117    mNonFinal = mPB.createAssign("nonfinal", mPB.createOr(mPB.createOr(u8pfx, u8scope32), mPB.createOr(u8scope42, u8scope43)));
    122118    mUnicodeLineBreak = mPB.createAnd(LB_chars, mPB.createNot(mCRLF));  // count the CR, but not CRLF
    123119#endif
     
    133129    PabloAST * u8scope42 = it.createAdvance(u8pfx4, 1, "u8scope42");
    134130    PabloAST * u8scope43 = it.createAdvance(u8scope42, 1);
    135     mNonFinal = it.createAssign(nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));
     131    mNonFinal = it.createAssign("nonfinal", it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));
    136132    PabloAST * NEL = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xC2), it), 1), ccc.compileCC(makeCC(0x85), it));
    137133    PabloAST * E2_80 = it.createAnd(it.createAdvance(ccc.compileCC(makeCC(0xE2), it), 1), ccc.compileCC(makeCC(0x80), it));
     
    159155}
    160156
    161 PabloAST * RE_Compiler::character_class_strm(Name * name, PabloBlock & pb) {
    162     PabloAST * var = name->getCompiled();
    163     if (var) {
    164         return var;
    165     }
    166     else {
    167         RE * def = name->getDefinition();
    168         if (def != nullptr) {
    169             MarkerType m = compile(def, mPB);
    170             assert(markerPos(m) == FinalMatchByte);
    171             PabloAST * v = markerVar(m);
    172             v = mPB.createAnd(v, mPB.createNot(UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed));
    173             name->setCompiled(v);
    174             return v;
    175         }
    176         else if (name->getType() == Name::Type::UnicodeProperty) {
    177             PabloAST * v = mPB.createCall(name->getName());
    178             v = mPB.createAnd(v, mPB.createNot(UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed));
    179             name->setCompiled(v);
    180             return v;
    181         }
    182         else {
    183             throw std::runtime_error("Unresolved name " + name->getName());
    184         }
    185     }
    186 }
    187 
    188157PabloAST * RE_Compiler::nextUnicodePosition(MarkerType m, PabloBlock & pb) {
    189158    if (markerPos(m) == FinalPostPositionByte) {
     
    257226        nextPos = AdvanceMarker(marker, FinalPostPositionByte, pb);
    258227    }
    259     return makeMarker(FinalMatchByte, pb.createAnd(markerVar(nextPos), character_class_strm(name, pb), "m"));
    260 }
     228    return makeMarker(FinalMatchByte, pb.createAnd(markerVar(nextPos), getNamedCharacterClassStream(name), "m"));
     229}
     230
     231PabloAST * RE_Compiler::getNamedCharacterClassStream(Name * name) {
     232    PabloAST * var = name->getCompiled();
     233    if (LLVM_LIKELY(var != nullptr)) {
     234        return var;
     235    }
     236    else if (name->getDefinition() != nullptr) {
     237        MarkerType m = compile(name->getDefinition(), mPB);
     238        assert(markerPos(m) == FinalMatchByte);
     239        var = markerVar(m);
     240    }
     241    else if (name->getType() == Name::Type::UnicodeProperty) {
     242        var = mPB.createCall(name->getName());
     243    }
     244    else {
     245        throw std::runtime_error("Unresolved name " + name->getName());
     246    }
     247
     248    var = mPB.createAnd(var, mPB.createNot(UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed));
     249    name->setCompiled(var);
     250    return var;
     251}
     252
    261253
    262254MarkerType RE_Compiler::process(Seq * seq, MarkerType marker, PabloBlock & pb) {
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4442 r4486  
    7272    void AlignMarkers(MarkerType & m1, MarkerType & m2, pablo::PabloBlock & pb);
    7373   
    74     pablo::PabloAST * character_class_strm(Name * name, pablo::PabloBlock & pb);
     74    pablo::PabloAST * getNamedCharacterClassStream(Name * name);
    7575    pablo::PabloAST * nextUnicodePosition(MarkerType m, pablo::PabloBlock & pb);
    7676    MarkerType process(RE * re, MarkerType marker, pablo::PabloBlock & pb);
Note: See TracChangeset for help on using the changeset viewer.