Changeset 4212


Ignore:
Timestamp:
Oct 5, 2014, 12:13:27 PM (5 years ago)
Author:
nmedfort
Message:

Removed some unnecessary makeAssign/makeVar calls. Had mystery bus error until I ran make clean.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r4210 r4212  
    5151set(Boost_USE_MULTITHREADED OFF)
    5252set(Boost_USE_STATIC_RUNTIME OFF)
    53 find_package(Boost 1.21 COMPONENTS system)
    54 include_directories("${Boost_INCLUDE_DIRS}")
    55 link_directories(${Boost_LIBRARY_DIR})
     53#find_package(Boost 1.21 COMPONENTS system)
     54
    5655add_library(PabloADT pablo/pe_advance.cpp pablo/pe_all.cpp pablo/pe_and.cpp pablo/pe_call.cpp pablo/pe_charclass.cpp  pablo/pe_matchstar.cpp pablo/pe_scanthru.cpp pablo/pe_not.cpp  pablo/pe_or.cpp  pablo/pe_pabloe.cpp  pablo/pe_sel.cpp  pablo/pe_var.cpp  pablo/pe_xor.cpp pablo/ps_assign.cpp  pablo/ps_if.cpp  pablo/codegenstate.cpp  pablo/symbol_generator.cpp pablo/ps_while.cpp pablo/printer_pablos.cpp)
    5756add_library(RegExpADT re/re_alt.cpp re/re_cc.cpp re/re_end.cpp re/re_name.cpp re/re_parser.cpp re/re_re.cpp re/re_rep.cpp re/re_seq.cpp re/re_start.cpp re/parsefailure.cpp re/re_reducer.cpp re/re_nullable.cpp re/re_simplifier.cpp re/re_compiler.cpp re/printer_re.cpp)
     
    7170target_link_libraries (CCADT PabloADT)
    7271target_link_libraries (icgrep PabloADT RegExpADT CCADT ${REQ_LLVM_LIBRARIES})
    73 IF (Boost_FOUND)
     72# If Boost is on the system, include the headers and libraries
     73IF(Boost_FOUND)
     74    include_directories("${Boost_INCLUDE_DIRS}")
     75    link_directories(${Boost_LIBRARY_DIR})
    7476    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST")
    7577    target_link_libraries (CCADT ${Boost_LIBRARIES})
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4211 r4212  
    5555        if (Seq * seq = dyn_cast<Seq>(i->second)) {
    5656            if (seq->getType() == Seq::Type::Byte) {
    57                 Assign * assignment = nullptr;
     57                PabloE * marker = nullptr;
    5858                auto j = seq->begin();
    5959                while (true) {
     
    6161                    assert (name);
    6262                    CharClass * cc = makeCharClass(name->getName());
    63                     PabloE * sym = assignment ? makeAnd(makeVar(assignment->getName()), cc) : cc;
     63                    PabloE * sym = marker ? makeAnd(marker, cc) : cc;
    6464                    if (++j != seq->end()) {
    65                         assignment = makeAssign(mCG.symgen("marker"), makeAdvance(sym));
    66                         mCG.push_back(assignment);
     65                        marker = makeAdvance(sym);
     66                        mCG.push_back(marker);
    6767                        continue;
    6868                    }
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4211 r4212  
    4949}
    5050
     51inline PabloE * makeVarIfAssign(PabloE * const input) {
     52    return isa<Assign>(input) ? makeVar(cast<Assign>(input)) : input;
     53}
     54
    5155void RE_Compiler::compile(RE * re) {
    5256
    5357    if (hasUnicode(re)) {
    5458        //Set the 'internal.initial' bit stream for the utf-8 multi-byte encoding.
    55         std::string gs_initial = mBaseCG.symgen("internal.initial");
    56         m_name_map.insert(make_pair("internal.initial", gs_initial));
     59        std::string gs_initial = mBaseCG.symgen("initial");
     60        m_name_map.insert(make_pair("initial", gs_initial));
    5761        PabloE * u8single = makeVar(m_name_map.find("UTF8-SingleByte")->second);
    5862        PabloE * u8pfx2 = makeVar(m_name_map.find("UTF8-Prefix2")->second);
     
    6367
    6468        //Set the 'internal.nonfinal' bit stream for the utf-8 multi-byte encoding.
    65         std::string gs_nonfinal = mBaseCG.symgen("internal.nonfinal");
    66         m_name_map.insert(make_pair("internal.nonfinal", gs_nonfinal));
     69        std::string gs_nonfinal = mBaseCG.symgen("nonfinal");
     70        m_name_map.insert(make_pair("nonfinal", gs_nonfinal));
    6771        //#define USE_IF_FOR_NONFINAL
    6872        #ifdef USE_IF_FOR_NONFINAL
     
    7680        std::list<PabloE *> * if_body = new std::list<PabloE *> ();
    7781        if_body->push_back(assign_non_final);
    78         cg.push_back(new If(u8pfx, *if_body));
     82        cg.push_back(makeIf(u8pfx, *if_body));
    7983        #else
    8084        mBaseCG.push_back(assign_non_final);
     
    8286    }
    8387
    84     Assign * start_marker = makeAssign(mBaseCG.symgen("start_marker"), mBaseCG.createAll(1));
     88    PabloE * start_marker = mBaseCG.createAll(1);
    8589    mBaseCG.push_back(start_marker);
    86     Assign * result = process(re, start_marker, mBaseCG);
     90    PabloE * result = process(re, start_marker, mBaseCG);
    8791
    8892    //These three lines are specifically for grep.
    89     Assign * final = makeAssign(mBaseCG.symgen("marker"), makeAnd(makeMatchStar(makeVar(result),
     93    Assign * final = makeAssign(mBaseCG.symgen("marker"), makeAnd(makeMatchStar(makeVarIfAssign(result),
    9094        makeNot(makeVar(m_name_map.find("LineFeed")->second))), makeVar(m_name_map.find("LineFeed")->second)));
    9195    mBaseCG.push_back(final);
    9296}
    9397
    94 Assign * RE_Compiler::process(RE * re, Assign * target, CodeGenState & cg) {
     98PabloE * RE_Compiler::process(RE * re, PabloE * target, CodeGenState & cg) {
    9599    if (Name * name = dyn_cast<Name>(re)) {
    96100        target = process(name, target, cg);
     
    106110    }
    107111    else if (isa<Start>(re)) {
    108         target = makeAssign(cg.symgen("sol"), makeAnd(makeVar(target), makeNot(makeAdvance(makeNot(makeCharClass(m_name_map.find("LineFeed")->second))))));
     112        target = makeAnd(makeVarIfAssign(target), makeNot(makeAdvance(makeNot(makeCharClass(m_name_map.find("LineFeed")->second)))));
    109113        cg.push_back(target);
    110114    }
    111115    else if (isa<End>(re)) {
    112         target = makeAssign(cg.symgen("eol"), makeAnd(makeVar(target), makeCharClass(m_name_map.find("LineFeed")->second)));
     116        target = makeAnd(makeVarIfAssign(target), makeCharClass(m_name_map.find("LineFeed")->second));
    113117        cg.push_back(target);
    114118    }
     
    117121}
    118122
    119 inline Assign * RE_Compiler::process(Name * name, Assign * target, CodeGenState & cg) {
    120     PabloE * markerExpr = makeVar(target);
     123inline PabloE * RE_Compiler::process(Name * name, PabloE * target, CodeGenState & cg) {
     124    PabloE * markerExpr = makeVarIfAssign(target);
    121125    if (name->getType() != Name::Type::FixedLength) {
    122126        // Move the markers forward through any nonfinal UTF-8 bytes to the final position of each character.
    123         markerExpr = makeAnd(markerExpr, makeCharClass(m_name_map.find("internal.initial")->second));
    124         markerExpr = makeScanThru(markerExpr, makeCharClass(m_name_map.find("internal.nonfinal")->second));
    125     }
    126     PabloE * ccExpr;
     127        markerExpr = makeAnd(markerExpr, makeCharClass(m_name_map.find("initial")->second));
     128        markerExpr = makeScanThru(markerExpr, makeCharClass(m_name_map.find("nonfinal")->second));
     129    }
     130    PabloE * cc = nullptr;
    127131    if (name->getType() == Name::Type::UnicodeCategory) {
    128         ccExpr = makeCall(name->getName());
     132        cc = makeCall(name->getName());
    129133    }
    130134    else {
    131         ccExpr = makeCharClass(name->getName());
     135        cc = makeCharClass(name->getName());
    132136    }
    133137    if (name->isNegated()) {
    134         ccExpr = makeNot(makeOr(makeOr(ccExpr, makeCharClass(m_name_map.find("LineFeed")->second)),
    135                                 makeCharClass(m_name_map.find("internal.nonfinal")->second)));
    136     }
    137     target = makeAssign(cg.symgen("marker"), makeAdvance(makeAnd(ccExpr, markerExpr)));
     138        cc = makeNot(makeOr(makeOr(cc, makeCharClass(m_name_map.find("LineFeed")->second)),
     139                                makeCharClass(m_name_map.find("nonfinal")->second)));
     140    }
     141    target = makeAssign(cg.symgen("marker"), makeAdvance(makeAnd(cc, markerExpr)));
    138142    cg.push_back(target);
    139143    return target;
    140144}
    141145
    142 inline Assign * RE_Compiler::process(Seq * seq, Assign * target, CodeGenState & cg) {
     146inline PabloE * RE_Compiler::process(Seq * seq, PabloE * target, CodeGenState & cg) {
    143147    for (RE * re : *seq) {
    144148        target = process(re, target, cg);
     
    148152}
    149153
    150 inline Assign * RE_Compiler::process(Alt * alt, Assign * target, CodeGenState & cg) {
     154inline PabloE * RE_Compiler::process(Alt * alt, PabloE * target, CodeGenState & cg) {
    151155    if (alt->empty()) {
    152         target = makeAssign(cg.symgen("always_fail"), cg.createAll(0));
    153         cg.push_back(target);
     156        target = cg.createAll(0); // always fail (note: I'm not sure this ever occurs. How do I create a 0-element alternation?)
    154157    }
    155158    else {
    156159        auto i = alt->begin();
    157         Assign * const base = target;
    158         target = process(*i, target, cg);
     160        PabloE * const base = target;
     161        target = makeVarIfAssign(process(*i, target, cg));
    159162        while (++i != alt->end()) {
    160             Var * alt1 = makeVar(process(*i, base, cg));
    161             Var * alt2 = makeVar(target);
    162             target = makeAssign(cg.symgen("alt"), makeOr(alt2, alt1));
    163             cg.push_back(target);
    164         }
    165     }
    166     return target;
    167 }
    168 
    169 inline Assign * RE_Compiler::process(Rep * rep, Assign * target, CodeGenState & cg) {
     163            PabloE * other = makeVarIfAssign(process(*i, base, cg));
     164            target = makeOr(target, other);
     165        }
     166        cg.push_back(target);
     167    }   
     168    return target;
     169}
     170
     171inline PabloE * RE_Compiler::process(Rep * rep, PabloE * target, CodeGenState & cg) {
    170172    if (rep->getUB() == Rep::UNBOUNDED_REP) {
    171173        target = processUnboundedRep(rep->getRE(), rep->getLB(), target, cg);
     
    173175    else { // if (rep->getUB() != Rep::UNBOUNDED_REP)
    174176        target = processBoundedRep(rep->getRE(), rep->getLB(), rep->getUB(), target, cg);
    175     }
    176     cg.push_back(target);
    177     return target;
    178 }
    179 
    180 inline Assign * RE_Compiler::processUnboundedRep(RE * repeated, int lb, Assign * target, CodeGenState & cg) {
     177    }   
     178    return target;
     179}
     180
     181inline PabloE * RE_Compiler::processUnboundedRep(RE * repeated, int lb, PabloE * target, CodeGenState & cg) {
    181182    while (lb-- != 0) {
    182183        target = process(repeated, target, cg);
     
    194195
    195196        if (rep_name->isNegated()) {
    196             ccExpr = makeNot(makeOr(makeOr(ccExpr, makeCharClass(m_name_map.find("LineFeed")->second)), makeCharClass(m_name_map.find("internal.nonfinal")->second)));
    197         }
    198 
    199 
    200         std::string marker = cg.symgen("marker");
     197            ccExpr = makeNot(makeOr(makeOr(ccExpr, makeCharClass(m_name_map.find("LineFeed")->second)), makeCharClass(m_name_map.find("nonfinal")->second)));
     198        }
     199
    201200        if (rep_name->getType() == Name::Type::FixedLength) {
    202             target = makeAssign(marker, makeMatchStar(makeVar(target), ccExpr));
     201            target = makeMatchStar(makeVarIfAssign(target), ccExpr);
    203202        }
    204203        else { // Name::Unicode and Name::UnicodeCategory
    205             target = makeAssign(marker,
    206                 makeAnd(makeMatchStar(makeVar(target),
    207                         makeOr(makeCharClass(m_name_map.find("internal.nonfinal")->second), ccExpr)),
    208                                makeCharClass(m_name_map.find("internal.initial")->second)));
     204            target = makeAnd(makeMatchStar(makeVarIfAssign(target), makeOr(makeCharClass(m_name_map.find("nonfinal")->second), ccExpr)), makeCharClass(m_name_map.find("initial")->second));
    209205        }
    210206    }
    211207    else {
    212208
    213         Assign * while_test = makeAssign(cg.symgen("while_test"), makeVar(target));
    214         Assign * while_accum = makeAssign(cg.symgen("while_accum"), makeVar(target));
     209        Assign * while_test = makeAssign(cg.symgen("while_test"), makeVarIfAssign(target));
     210        Assign * while_accum = makeAssign(cg.symgen("while_accum"), makeVarIfAssign(target));
    215211
    216212        CodeGenState wt(cg);
    217213
    218         Var * accum = makeVar(process(repeated, while_test, wt));
     214        PabloE * accum = makeVarIfAssign(process(repeated, while_test, wt));
    219215
    220216        cg.push_back(while_test);
     
    233229}
    234230
    235 inline Assign * RE_Compiler::processBoundedRep(RE * repeated, int lb, int ub, Assign * target, CodeGenState & cg) {
     231inline PabloE * RE_Compiler::processBoundedRep(RE * repeated, int lb, int ub, PabloE * target, CodeGenState & cg) {
    236232    ub -= lb;
    237233    while(lb-- != 0) {
     
    239235    }
    240236    while (ub-- != 0) {
    241         Assign * alt = process(repeated, target, cg);
    242         target = makeAssign(cg.symgen("alt"), makeOr(makeVar(target), makeVar(alt)));
    243         cg.push_back(target);
    244     }
     237        PabloE * alt = process(repeated, target, cg);
     238        target = makeOr(makeVarIfAssign(target), makeVarIfAssign(alt));
     239    }
     240    cg.push_back(target);
    245241    return target;
    246242}
  • icGREP/icgrep-devel/icgrep/re/re_compiler.h

    r4211 r4212  
    2424
    2525private:
    26     pablo::Assign * process(RE * re, pablo::Assign * target, pablo::CodeGenState & cg_state);
    27     pablo::Assign * process(Alt * alt, pablo::Assign * target, pablo::CodeGenState & cg_state);
    28     pablo::Assign * process(Seq * seq, pablo::Assign * target, pablo::CodeGenState & cg_state);
    29     pablo::Assign * process(Rep * rep, pablo::Assign * target, pablo::CodeGenState & cg_state);
    30     pablo::Assign * processUnboundedRep(RE * repeated, int lb, pablo::Assign * target, pablo::CodeGenState & cg_state);
    31     pablo::Assign * processBoundedRep(RE * repeated, int lb, int ub, pablo::Assign * target, pablo::CodeGenState & cg_state);
    32     pablo::Assign * process(Name * name, pablo::Assign * target, pablo::CodeGenState & cg_state);
     26    pablo::PabloE * process(RE * re, pablo::PabloE * target, pablo::CodeGenState & cg_state);
     27    pablo::PabloE * process(Alt * alt, pablo::PabloE * target, pablo::CodeGenState & cg_state);
     28    pablo::PabloE * process(Seq * seq, pablo::PabloE * target, pablo::CodeGenState & cg_state);
     29    pablo::PabloE * process(Rep * rep, pablo::PabloE * target, pablo::CodeGenState & cg_state);
     30    pablo::PabloE * processUnboundedRep(RE * repeated, int lb, pablo::PabloE * target, pablo::CodeGenState & cg_state);
     31    pablo::PabloE * processBoundedRep(RE * repeated, int lb, int ub, pablo::PabloE * target, pablo::CodeGenState & cg_state);
     32    pablo::PabloE * process(Name * name, pablo::PabloE * target, pablo::CodeGenState & cg_state);
    3333
    3434    static bool hasUnicode(const RE *re);
Note: See TracChangeset for help on using the changeset viewer.