Changeset 4208


Ignore:
Timestamp:
Oct 3, 2014, 1:23:15 PM (5 years ago)
Author:
cameron
Message:

Ensure MatchStar? used for unbounded repetitions, after lb reduced to 0

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/llvm_gen.h

    r4207 r4208  
    1111
    1212//define this indicates that we use llvm.uadd.with.overflow for genAddWithCarry
    13 #define USE_UADD_OVERFLOW
     13//#define USE_UADD_OVERFLOW
    1414
    1515//Pablo Expressions
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4207 r4208  
    208208
    209209inline void RE_Compiler::compile(Rep * rep, CodeGenState & cg_state) {
    210     if (isa<Name>(rep->getRE()) && (rep->getLB() == 0) && (rep->getUB()== Rep::UNBOUNDED_REP)) {
    211         Name * rep_name = dyn_cast<Name>(rep->getRE());
     210    if (rep->getUB() == Rep::UNBOUNDED_REP) {
     211        compileUnboundedRep(rep->getRE(), rep->getLB(), cg_state);
     212    }
     213    else { // if (rep->getUB() != Rep::UNBOUNDED_REP)
     214        compileBoundedRep(rep->getRE(), rep->getLB(), rep->getUB(), cg_state);
     215    }
     216}
     217
     218inline void RE_Compiler::compileUnboundedRep(RE * repeated, int lb, CodeGenState & cg_state) {
     219    while (lb > 0) {
     220        compile(repeated, cg_state);
     221        lb--;
     222    }
     223    if (isa<Name>(repeated)) {
     224        Name * rep_name = dyn_cast<Name>(repeated);
    212225        std::string gs_retVal = symgen.get("marker");
    213226
     
    233246        }
    234247        cg_state.newsym = gs_retVal;
    235     }
    236     else if (rep->getUB() == Rep::UNBOUNDED_REP) {
    237         compileUnboundedRep(rep->getRE(), rep->getLB(), cg_state);
    238     }
    239     else { // if (rep->getUB() != Rep::UNBOUNDED_REP)
    240         compileBoundedRep(rep->getRE(), rep->getLB(), rep->getUB(), cg_state);
    241     }
    242 }
    243 
    244 inline void RE_Compiler::compileUnboundedRep(RE * repeated, int lb, CodeGenState & cg_state) {
    245     for (; lb; --lb) {
    246         compile(repeated, cg_state);
    247     }
    248     std::string while_test = symgen.get("while_test");
    249     std::string while_accum = symgen.get("while_accum");
    250     CodeGenState while_test_state;
    251     while_test_state.newsym = while_test;
    252     compile(repeated, while_test_state);
    253     cg_state.stmtsl.push_back(make_assign(while_test, make_var(cg_state.newsym)));
    254     cg_state.stmtsl.push_back(make_assign(while_accum, make_var(cg_state.newsym)));
    255     while_test_state.stmtsl.push_back(make_assign(while_test, make_and(make_var(while_test_state.newsym), make_not(make_var(while_accum)))));
    256     while_test_state.stmtsl.push_back(make_assign(while_accum, make_or(make_var(while_accum), make_var(while_test_state.newsym))));
    257     cg_state.stmtsl.push_back(new While(make_var(while_test), while_test_state.stmtsl));
    258     cg_state.newsym = while_accum;
     248     
     249    }
     250    else {
     251      std::string while_test = symgen.get("while_test");
     252      std::string while_accum = symgen.get("while_accum");
     253      CodeGenState while_test_state;
     254      while_test_state.newsym = while_test;
     255      compile(repeated, while_test_state);
     256      cg_state.stmtsl.push_back(make_assign(while_test, make_var(cg_state.newsym)));
     257      cg_state.stmtsl.push_back(make_assign(while_accum, make_var(cg_state.newsym)));
     258      while_test_state.stmtsl.push_back(make_assign(while_test, make_and(make_var(while_test_state.newsym), make_not(make_var(while_accum)))));
     259      while_test_state.stmtsl.push_back(make_assign(while_accum, make_or(make_var(while_accum), make_var(while_test_state.newsym))));
     260      cg_state.stmtsl.push_back(new While(make_var(while_test), while_test_state.stmtsl));
     261      cg_state.newsym = while_accum;
     262    }
    259263}
    260264
Note: See TracChangeset for help on using the changeset viewer.