Changeset 4347


Ignore:
Timestamp:
Dec 18, 2014, 12:42:34 PM (4 years ago)
Author:
cameron
Message:

Wrap code initializating some multibyte streams in ifs - not enabled yet.

File:
1 edited

Legend:

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

    r4342 r4347  
    6868
    6969//#define USE_IF_FOR_NONFINAL 1
     70//#define USE_IF_FOR_CRLF
    7071#define UNICODE_LINE_BREAK true
    7172
     
    7374void RE_Compiler::initializeRequiredStreams(cc::CC_Compiler & ccc) {
    7475
    75     mLineFeed = ccc.compileCC(makeCC(0x0A));
     76    Assign * LF = mCG.createAssign("LF", ccc.compileCC(makeCC(0x0A)));
     77    mLineFeed = mCG.createVar(LF);
    7678    PabloAST * CR = ccc.compileCC(makeCC(0x0D));
    7779    PabloAST * LF_VT_FF_CR = ccc.compileCC(makeCC(0x0A, 0x0D));
     
    8082    PabloAST * LS_PS = mCG.createAnd(mCG.createAdvance(E2_80, 1), ccc.compileCC(makeCC(0xA8,0xA9)));
    8183    PabloAST * LB_chars = mCG.createOr(LF_VT_FF_CR, mCG.createOr(NEL, LS_PS));
     84#ifndef USE_IF_FOR_CRLF
    8285    mCRLF = mCG.createAnd(mCG.createAdvance(CR, 1), mLineFeed);
     86#else
     87    PabloBlock crb(mCG);
     88    Assign * cr1 = crb.createAssign("cr1", crb.createAdvance(CR, 1));
     89    Assign * acrlf = crb.createAssign("crlf", crb.createAnd(crb.createVar(cr1), crb.createVar(LF)));
     90    mCG.createIf(CR, std::move(std::vector<Assign *>{acrlf}), std::move(crb));
     91    mCRLF = mCG.createVar(acrlf);
     92#endif
    8393    mUnicodeLineBreak = mCG.createAnd(LB_chars, mCG.createNot(mCRLF));  // count the CR, but not CRLF
    8494    PabloAST * u8single = ccc.compileCC(makeCC(0x00, 0x7F));
     
    92102    PabloAST * u8pfx = mCG.createOr(mCG.createOr(u8pfx2, u8pfx3), u8pfx4);
    93103    mInitial = mCG.createVar(mCG.createAssign(initial, mCG.createOr(u8pfx, u8single)));
    94     #ifdef USE_IF_FOR_NONFINAL
    95     mNonFinal = mCG.createVar(pb.createAssign(nonfinal, mCG.createZeroes()));
    96     #endif
     104   
     105    #ifndef USE_IF_FOR_NONFINAL
    97106    PabloAST * u8scope32 = mCG.createAdvance(u8pfx3, 1);
    98107    PabloAST * u8scope42 = mCG.createAdvance(u8pfx4, 1);
    99108    PabloAST * u8scope43 = mCG.createAdvance(u8scope42, 1);
     109    mNonFinal = mCG.createVar(mCG.createAssign(nonfinal, mCG.createOr(mCG.createOr(u8pfx, u8scope32), mCG.createOr(u8scope42, u8scope43))));
     110    #endif
    100111    #ifdef USE_IF_FOR_NONFINAL
    101112    PabloBlock it(mCG);
    102     it.createAssign(nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));
    103     mCG.createIf(u8pfx, std::move(it));
    104     #else
    105     mNonFinal = mCG.createVar(mCG.createAssign(nonfinal, mCG.createOr(mCG.createOr(u8pfx, u8scope32), mCG.createOr(u8scope42, u8scope43))));
     113    PabloAST * u8scope32 = it.createAdvance(u8pfx3, 1);
     114    PabloAST * u8scope42 = it.createVar(it.createAssign("u8scope42", it.createAdvance(u8pfx4, 1)));
     115    PabloAST * u8scope43 = it.createAdvance(u8scope42, 1);
     116    Assign * a = it.createAssign(nonfinal, it.createOr(it.createOr(u8pfx, u8scope32), it.createOr(u8scope42, u8scope43)));
     117    mCG.createIf(u8pfx, std::move(std::vector<Assign *>{a}), std::move(it));
     118    mNonFinal = mCG.createVar(a);   
    106119    #endif
    107120}
     
    110123    //These three lines are specifically for grep.
    111124    PabloAST * lb = UNICODE_LINE_BREAK ? mUnicodeLineBreak : mLineFeed;
    112     mCG.createAssign("matches", mCG.createAnd(mCG.createMatchStar(markerVar(match_result, mCG), mCG.createNot(lb)), lb), 0);
    113     mCG.createAssign("lf", lb, 1);//mCG.createAnd(lb, mCG.createNot(mCRLF)), 1);
     125    Var * v = markerVar(match_result, mCG);
     126    mCG.createAssign("matches", mCG.createAnd(mCG.createMatchStar(v, mCG.createNot(lb)), lb), 0);
     127    mCG.createAssign("lf", mCG.createAnd(lb, mCG.createNot(mCRLF)), 1);
    114128}
    115129   
    116130MarkerType RE_Compiler::compile(RE * re, PabloBlock & pb) {
    117         return process(re, makePostPositionMarker("start", pb.createOnes(), pb), pb);
     131    return process(re, makePostPositionMarker("start", pb.createOnes(), pb), pb);
    118132}
    119133       
     
    126140        if (var == nullptr) {
    127141            RE * def = name->getDefinition();
    128                 assert(!isa<CC>(def));  //  Names mapping to CCs should have been compiled.
    129                 assert(name->getType == Name::Type::Unicode);  //
    130                 // compile in top-level block
    131                 MarkerType m = compile(def, mCG);
    132                 assert(isFinalPositionMarker(m));
    133                 name -> setCompiled(pb.createVar(markerStream(m, mCG)));
    134         }
    135         return name->getCompiled();
     142            assert(!isa<CC>(def));  //  Names mapping to CCs should have been compiled.
     143            assert(name->getType == Name::Type::Unicode);  //
     144            // compile in top-level block
     145            MarkerType m = compile(def, mCG);
     146            assert(isFinalPositionMarker(m));
     147            Var * v = pb.createVar(markerStream(m, mCG));
     148            name -> setCompiled(v);
     149            return v;
     150        }
     151        else return var;
    136152    }
    137153}
     
    147163    }
    148164}
    149     
     165   
    150166
    151167MarkerType RE_Compiler::process(RE * re, MarkerType marker, PabloBlock & pb) {
Note: See TracChangeset for help on using the changeset viewer.