Changeset 4266 for icGREP


Ignore:
Timestamp:
Oct 24, 2014, 11:42:57 AM (5 years ago)
Author:
nmedfort
Message:

Temporary check-in for Pablo Use Analysis.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4264 r4266  
    7575    Call * createCall(const std::string name);
    7676
    77     inline Assign * createAssign(const std::string prefix, PabloAST * expr) {
     77    inline Assign * createAssign(const std::string prefix, PabloAST * expr, const bool isOutput = false) {
    7878        // TODO: should this test whether we've somehow created a var for this prior to
    7979        // making the assignment?
    80         Assign * assign = new Assign(mSymbolGenerator.get_ssa(prefix), expr);
     80        Assign * assign = new Assign(mSymbolGenerator.get_ssa(prefix), expr, isOutput);
    8181        mStatements.push_back(assign);
    8282        return assign;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4264 r4266  
    178178    Value * result = compileStatements(pb.expressions());
    179179    SetReturnMarker(result, 0); // matches
    180     const String * lf = pb.createVar(mNameMap["LineFeed"]->getName())->getName();
     180    const String * lf = mNameMap["LineFeed"]->getVar()->getName();
    181181    SetReturnMarker(mMarkerMap.find(lf)->second, 1); // line feeds
    182182
  • icGREP/icgrep-devel/icgrep/pablo/ps_assign.h

    r4257 r4266  
    3030        return mExpr;
    3131    }
     32    inline bool isOutput() const {
     33        return mIsOutput;
     34    }
    3235protected:
    33     Assign(PabloAST * name, PabloAST * expr)
     36    Assign(PabloAST * name, PabloAST * expr, const bool isOutput)
    3437    : PabloAST(ClassTypeId::Assign)
    3538    , mName(cast<String>(name))
    3639    , mExpr(expr)
     40    , mIsOutput(isOutput)
    3741    {
    3842
     
    4145    String * const          mName;
    4246    PabloAST * const        mExpr;
     47    const bool              mIsOutput;
    4348};
    4449
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4265 r4266  
    7373    }
    7474
    75     Assign * start_marker = pb.createAssign("start", pb.createOnes());
    76     PabloAST * result = process(re, start_marker, pb);
     75    PabloAST * result = process(re, pb.createAssign("start", pb.createOnes()), pb);
    7776
    7877    //These three lines are specifically for grep.
    79     pb.createAssign("matches", pb.createAnd(pb.createMatchStar(pb.createVar(result), pb.createNot(mLineFeed)), mLineFeed));
    80 }
    81 
    82 
    83 Assign * RE_Compiler::process(RE * re, Assign * target, PabloBlock & pb) {
     78    pb.createAssign("matches", pb.createAnd(pb.createMatchStar(pb.createVar(result), pb.createNot(mLineFeed)), mLineFeed), true);
     79}
     80
     81
     82Assign * RE_Compiler::process(RE * re, Assign * marker, PabloBlock & pb) {
    8483    if (Name * name = dyn_cast<Name>(re)) {
    85         target = process(name, target, pb);
     84        marker = process(name, marker, pb);
    8685    }
    8786    else if (Seq* seq = dyn_cast<Seq>(re)) {
    88         target = process(seq, target, pb);
     87        marker = process(seq, marker, pb);
    8988    }
    9089    else if (Alt * alt = dyn_cast<Alt>(re)) {
    91         target = process(alt, target, pb);
     90        marker = process(alt, marker, pb);
    9291    }
    9392    else if (Rep * rep = dyn_cast<Rep>(re)) {
    94         target = process(rep, target, pb);
     93        marker = process(rep, marker, pb);
    9594    }
    9695    else if (isa<Any>(re)) {
    9796        // Move the markers forward through any nonfinal UTF-8 bytes to the final position of each character.
    98         PabloAST * marker = pb.createVar(target);
    99         marker = pb.createAnd(marker, mInitial);
    100         marker = pb.createScanThru(marker, mNonFinal);
     97        PabloAST * markerVar = pb.createVar(marker);
     98        markerVar = pb.createAnd(markerVar, mInitial);
     99        markerVar = pb.createScanThru(markerVar, mNonFinal);
    101100        PabloAST * dot = pb.createNot(mLineFeed);
    102         target = pb.createAssign("dot", pb.createAdvance(pb.createAnd(marker, dot), 1));
     101        marker = pb.createAssign("dot", pb.createAdvance(pb.createAnd(markerVar, dot), 1));
    103102    }
    104103    else if (Diff * diff = dyn_cast<Diff>(re)) {
    105         target = process(diff, target, pb);
     104        marker = process(diff, marker, pb);
    106105    }
    107106    else if (isa<Start>(re)) {
    108107        PabloAST * const sol = pb.createNot(pb.createAdvance(pb.createNot(mLineFeed), 1));
    109         target = pb.createAssign("sol", pb.createAnd(pb.createVar(target), sol));
     108        marker = pb.createAssign("sol", pb.createAnd(pb.createVar(marker), sol));
    110109    }
    111110    else if (isa<End>(re)) {
    112         target = pb.createAssign("eol", pb.createAnd(pb.createVar(target), mLineFeed));
    113     }
    114     return target;
    115 }
    116 
    117 inline Assign * RE_Compiler::process(Name * name, Assign * target, PabloBlock & pb) {
    118     PabloAST * marker = pb.createVar(target);
     111        marker = pb.createAssign("eol", pb.createAnd(pb.createVar(marker), mLineFeed));
     112    }
     113    return marker;
     114}
     115
     116inline Assign * RE_Compiler::process(Name * name, Assign * marker, PabloBlock & pb) {
     117    PabloAST * markerVar = pb.createVar(marker);
    119118    if (name->getType() != Name::Type::FixedLength) {
    120119        // Move the markers forward through any nonfinal UTF-8 bytes to the final position of each character.
    121         marker = pb.createAnd(marker, mInitial);
    122         marker = pb.createScanThru(marker, mNonFinal);
     120        markerVar = pb.createAnd(markerVar, mInitial);
     121        markerVar = pb.createScanThru(markerVar, mNonFinal);
    123122    }
    124123    PabloAST * cc = nullptr;
     
    129128        cc = pb.createVar(name->getName());
    130129    }
    131     return pb.createAssign("m", pb.createAdvance(pb.createAnd(cc, marker), 1));
    132 }
    133 
    134 inline Assign * RE_Compiler::process(Seq * seq, Assign *target, PabloBlock & pb) {
     130    return pb.createAssign("m", pb.createAdvance(pb.createAnd(cc, markerVar), 1));
     131}
     132
     133inline Assign * RE_Compiler::process(Seq * seq, Assign * marker, PabloBlock & pb) {
    135134    for (RE * re : *seq) {
    136         target = process(re, target, pb);
    137     }
    138     return target;
    139 }
    140 
    141 inline Assign * RE_Compiler::process(Alt * alt, Assign * target, PabloBlock & pb) {
     135        marker = process(re, marker, pb);
     136    }
     137    return marker;
     138}
     139
     140inline Assign * RE_Compiler::process(Alt * alt, Assign * marker, PabloBlock & pb) {
    142141    if (alt->empty()) {
    143         target = pb.createAssign("fail", pb.createZeroes()); // always fail (note: I'm not sure this ever occurs. How do I create a 0-element alternation?)
     142        marker = pb.createAssign("fail", pb.createZeroes()); // always fail (note: I'm not sure this ever occurs. How do I create a 0-element alternation?)
    144143    }
    145144    else {
    146145        auto i = alt->begin();
    147         Assign * const base = target;
    148         target = process(*i, base, pb);
     146        Assign * const base = marker;
     147        marker = process(*i, base, pb);
    149148        while (++i != alt->end()) {
    150149            Assign * other = process(*i, base, pb);
    151             target = pb.createAssign("alt", pb.createOr(pb.createVar(target), pb.createVar(other)));
     150            marker = pb.createAssign("alt", pb.createOr(pb.createVar(marker), pb.createVar(other)));
    152151        }
    153152    }   
    154     return target;
    155 }
    156 
    157 inline Assign * RE_Compiler::process(Diff * diff, Assign * target, PabloBlock & pb) {
     153    return marker;
     154}
     155
     156inline Assign * RE_Compiler::process(Diff * diff, Assign * marker, PabloBlock & pb) {
    158157    RE * lh = diff->getLH();
    159158    RE * rh = diff->getRH();
    160159    if ((isa<Any>(lh) || isa<Name>(lh)) && (isa<Any>(rh) || isa<Name>(rh))) {
    161         Assign * t1 = process(lh, target, pb);
    162         Assign * t2 = process(rh, target, pb);
     160        Assign * t1 = process(lh, marker, pb);
     161        Assign * t2 = process(rh, marker, pb);
    163162        return pb.createAssign("diff", pb.createAnd(pb.createVar(t1), pb.createNot(pb.createVar(t2))));
    164163    }
     
    166165}
    167166
    168 inline Assign * RE_Compiler::process(Rep * rep, Assign * target, PabloBlock & pb) {
     167inline Assign * RE_Compiler::process(Rep * rep, Assign * marker, PabloBlock & pb) {
    169168    int lb = rep->getLB();
    170169    int ub = rep->getUB();
    171170    if (lb > 0) {
    172         target = processLowerBound(rep->getRE(), lb, target, pb);
     171        marker = processLowerBound(rep->getRE(), lb, marker, pb);
    173172    }
    174173    if (ub == Rep::UNBOUNDED_REP) {
    175         target = processUnboundedRep(rep->getRE(), target, pb);
     174        marker = processUnboundedRep(rep->getRE(), marker, pb);
    176175    }
    177176    else { // if (rep->getUB() != Rep::UNBOUNDED_REP)
    178         target = processBoundedRep(rep->getRE(), ub - lb, target, pb);
     177        marker = processBoundedRep(rep->getRE(), ub - lb, marker, pb);
    179178    }   
    180     return target;
     179    return marker;
    181180}
    182181
     
    205204               
    206205inline bool RE_Compiler::isFixedLength(RE * regexp) {
    207         return isa<Name>(regexp) && ((cast<Name>(regexp) -> getType()) == Name::Type::FixedLength);
    208 }
     206    return isa<Name>(regexp) && ((cast<Name>(regexp) -> getType()) == Name::Type::FixedLength);
     207}
     208
    209209inline Assign * RE_Compiler::processLowerBound(RE * repeated, int lb, Assign * marker, PabloBlock & pb) {
    210210#ifndef VARIABLE_ADVANCE
     
    231231}
    232232
    233 inline Assign * RE_Compiler::processUnboundedRep(RE * repeated, Assign * target, PabloBlock & pb) {
     233inline Assign * RE_Compiler::processUnboundedRep(RE * repeated, Assign * marker, PabloBlock & pb) {
    234234
    235235    PabloAST * unbounded = nullptr;
     
    246246        }
    247247
    248         unbounded = pb.createVar(target);
     248        unbounded = pb.createVar(marker);
    249249        if (rep_name->getType() == Name::Type::FixedLength) {
    250250            unbounded = pb.createMatchStar(unbounded, cc);
     
    256256    else if (isa<Any>(repeated)) {
    257257        PabloAST * dot = pb.createNot(mLineFeed);
    258         unbounded = pb.createVar(target);
     258        unbounded = pb.createVar(marker);
    259259        unbounded = pb.createAnd(pb.createMatchStar(unbounded, pb.createOr(mNonFinal, dot)), mInitial);
    260260    }
    261261    else {
    262         Var * targetVar = pb.createVar(target);
    263         Assign * whileTest = pb.createAssign("test", targetVar);
    264         Assign * whileAccum = pb.createAssign("accum", targetVar);
     262        Var * markerVar = pb.createVar(marker);
     263        Assign * whileTest = pb.createAssign("test", markerVar);
     264        Assign * whileAccum = pb.createAssign("accum", markerVar);
    265265
    266266        PabloBlock wb(pb);
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4261 r4266  
    3939    void compile(RE * re, pablo::PabloBlock & cg);
    4040
    41     pablo::Assign * process(RE * re, pablo::Assign *target, pablo::PabloBlock & pb);
    42     pablo::Assign * process(Name * name, pablo::Assign * target, pablo::PabloBlock & pb);
    43     pablo::Assign * process(Seq * seq, pablo::Assign * target, pablo::PabloBlock & pb);
    44     pablo::Assign * process(Alt * alt, pablo::Assign * target, pablo::PabloBlock & pb);
    45     pablo::Assign * process(Rep * rep, pablo::Assign *target, pablo::PabloBlock & pb);
    46     pablo::Assign * process(Diff * diff, pablo::Assign * target, pablo::PabloBlock & cg);
     41    pablo::Assign * process(RE * re, pablo::Assign *marker, pablo::PabloBlock & pb);
     42    pablo::Assign * process(Name * name, pablo::Assign * marker, pablo::PabloBlock & pb);
     43    pablo::Assign * process(Seq * seq, pablo::Assign * marker, pablo::PabloBlock & pb);
     44    pablo::Assign * process(Alt * alt, pablo::Assign * marker, pablo::PabloBlock & pb);
     45    pablo::Assign * process(Rep * rep, pablo::Assign *marker, pablo::PabloBlock & pb);
     46    pablo::Assign * process(Diff * diff, pablo::Assign * marker, pablo::PabloBlock & cg);
    4747    pablo::Assign * consecutive(pablo::Assign * repeated,  int repeated_lgth, int repeat_count, pablo::PabloBlock & pb);
    4848    bool isFixedLength(RE * regexp);
    49     pablo::Assign * processLowerBound(RE * repeated,  int lb, pablo::Assign * target, pablo::PabloBlock & pb);
    50     pablo::Assign * processUnboundedRep(RE * repeated, pablo::Assign * target, pablo::PabloBlock & pb);
    51     pablo::Assign * processBoundedRep(RE * repeated, int ub, pablo::Assign * target, pablo::PabloBlock & pb);
     49    pablo::Assign * processLowerBound(RE * repeated,  int lb, pablo::Assign * marker, pablo::PabloBlock & pb);
     50    pablo::Assign * processUnboundedRep(RE * repeated, pablo::Assign * marker, pablo::PabloBlock & pb);
     51    pablo::Assign * processBoundedRep(RE * repeated, int ub, pablo::Assign * marker, pablo::PabloBlock & pb);
    5252
    5353
Note: See TracChangeset for help on using the changeset viewer.