Ignore:
Timestamp:
Sep 30, 2014, 2:44:40 PM (5 years ago)
Author:
nmedfort
Message:

Replaced dynamic_cast with llvm::dyn_cast in pablo code; implemented make functions for pablo constructors. Disabled RTTI.

File:
1 edited

Legend:

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

    r4199 r4200  
    1717
    1818//Pablo Expressions
    19 #include <pablo/pablo_routines.h>
    2019#include <pablo/ps_pablos.h>
    2120#include <pablo/pe_advance.h>
     
    5958            if (seq->getType() == Seq::Type::Byte) {
    6059                std::string gs_retVal = symgen.get("start_marker");
    61                 cg_state.stmtsl.push_back(new Assign(gs_retVal, new All(1)));
     60                cg_state.stmtsl.push_back(make_assign(gs_retVal, make_all(1)));
    6261                for (auto j = seq->begin();; ) {
    6362                    Name * name = dyn_cast<Name>(*j);
    6463                    assert (name);
    65                     And * cc_mask = new And(new Var(gs_retVal), new CharClass(name->getName()));
     64                    auto * cc_mask = make_and(make_var(gs_retVal), make_charclass(name->getName()));
    6665                    if (++j != seq->end()) {
    6766                        gs_retVal = symgen.get("marker");
    68                         cg_state.stmtsl.push_back(new Assign(gs_retVal, new Advance(cc_mask)));
     67                        cg_state.stmtsl.push_back(make_assign(gs_retVal, make_advance(cc_mask)));
    6968                    }
    7069                    else {
    71                         cg_state.stmtsl.push_back(new Assign(seq->getName(), cc_mask));
     70                        cg_state.stmtsl.push_back(make_assign(seq->getName(), cc_mask));
    7271                        break;
    7372                    }
     
    8584
    8685    std::string gs_m0 = symgen.get("start_marker");
    87     cg_state.stmtsl.push_back(new Assign(gs_m0, new All(1)));
     86    cg_state.stmtsl.push_back(make_assign(gs_m0, make_all(1)));
    8887
    8988    if (hasUnicode(re)) {
     
    9291        std::string gs_initial = symgen.get("internal.initial");
    9392        m_name_map.insert(make_pair("internal.initial", gs_initial));
    94         PabloE * u8single = new Var(m_name_map.find("UTF8-SingleByte")->second);
    95         PabloE * u8pfx2 = new Var(m_name_map.find("UTF8-Prefix2")->second);
    96         PabloE * u8pfx3 = new Var(m_name_map.find("UTF8-Prefix3")->second);
    97         PabloE * u8pfx4 = new Var(m_name_map.find("UTF8-Prefix4")->second);
    98         PabloE * u8pfx = new Or(new Or(u8pfx2, u8pfx3), u8pfx4);
    99         cg_state.stmtsl.push_back(new Assign(gs_initial, new Or(u8pfx, u8single)));
     93        PabloE * u8single = make_var(m_name_map.find("UTF8-SingleByte")->second);
     94        PabloE * u8pfx2 = make_var(m_name_map.find("UTF8-Prefix2")->second);
     95        PabloE * u8pfx3 = make_var(m_name_map.find("UTF8-Prefix3")->second);
     96        PabloE * u8pfx4 = make_var(m_name_map.find("UTF8-Prefix4")->second);
     97        PabloE * u8pfx = make_or(make_or(u8pfx2, u8pfx3), u8pfx4);
     98        cg_state.stmtsl.push_back(make_assign(gs_initial, make_or(u8pfx, u8single)));
    10099        cg_state.newsym = gs_initial;
    101100
     
    106105        //#define USE_IF_FOR_NONFINAL
    107106        #ifdef USE_IF_FOR_NONFINAL
    108         cg_state.stmtsl.push_back(new Assign(gs_nonfinal, new All(0)));
     107        cg_state.stmtsl.push_back(make_assign(gs_nonfinal, make_all(0)));
    109108        #endif
    110         PabloE * u8scope32 = new Advance(u8pfx3);
    111         PabloE * u8scope42 = new Advance(u8pfx4);
    112         PabloE * u8scope43 = new Advance(u8scope42);
    113         PabloE * assign_non_final = new Assign(gs_nonfinal, new Or(new Or(u8pfx, u8scope32), new Or(u8scope42, u8scope43)));
     109        PabloE * u8scope32 = make_advance(u8pfx3);
     110        PabloE * u8scope42 = make_advance(u8pfx4);
     111        PabloE * u8scope43 = make_advance(u8scope42);
     112        PabloE * assign_non_final = make_assign(gs_nonfinal, make_or(make_or(u8pfx, u8scope32), make_or(u8scope42, u8scope43)));
    114113        #ifdef USE_IF_FOR_NONFINAL
    115114        std::list<PabloE *> * if_body = new std::list<PabloE *> ();
     
    127126    //These three lines are specifically for grep.
    128127    std::string gs_retVal = symgen.get("marker");
    129     cg_state.stmtsl.push_back(new Assign(gs_retVal, new And(new MatchStar(new Var(cg_state.newsym),
    130         new Not(new Var(m_name_map.find("LineFeed")->second))), new Var(m_name_map.find("LineFeed")->second))));
     128    cg_state.stmtsl.push_back(make_assign(gs_retVal, make_and(new MatchStar(make_var(cg_state.newsym),
     129        make_not(make_var(m_name_map.find("LineFeed")->second))), make_var(m_name_map.find("LineFeed")->second))));
    131130    cg_state.newsym = gs_retVal;
    132131
     
    149148    else if (isa<Start>(re)) {
    150149        std::string gs_retVal = symgen.get("sol");
    151         cg_state.stmtsl.push_back(new Assign(gs_retVal, new And(new Var(cg_state.newsym), new Not(new Advance(new Not(new CharClass(m_name_map.find("LineFeed")->second)))))));
     150        cg_state.stmtsl.push_back(make_assign(gs_retVal, make_and(make_var(cg_state.newsym), make_not(make_advance(make_not(make_charclass(m_name_map.find("LineFeed")->second)))))));
    152151        cg_state.newsym = gs_retVal;
    153152    }
    154153    else if (isa<End>(re)) {
    155154        std::string gs_retVal = symgen.get("eol");
    156         cg_state.stmtsl.push_back(new Assign(gs_retVal, new And(new Var(cg_state.newsym), new CharClass(m_name_map.find("LineFeed")->second))));
     155        cg_state.stmtsl.push_back(make_assign(gs_retVal, make_and(make_var(cg_state.newsym), make_charclass(m_name_map.find("LineFeed")->second))));
    157156        cg_state.newsym = gs_retVal;
    158157    }
     
    161160inline void RE_Compiler::compile(Name * name, CodeGenState & cg_state) {
    162161    std::string gs_retVal = symgen.get("marker");
    163     PabloE * markerExpr = new Var(cg_state.newsym);
     162    PabloE * markerExpr = make_var(cg_state.newsym);
    164163    if (name->getType() != Name::Type::FixedLength) {
    165164        // Move the markers forward through any nonfinal UTF-8 bytes to the final position of each character.
    166         markerExpr = new And(markerExpr, new CharClass(m_name_map.find("internal.initial")->second));
    167         markerExpr = new ScanThru(markerExpr, new CharClass(m_name_map.find("internal.nonfinal")->second));
     165        markerExpr = make_and(markerExpr, make_charclass(m_name_map.find("internal.initial")->second));
     166        markerExpr = new ScanThru(markerExpr, make_charclass(m_name_map.find("internal.nonfinal")->second));
    168167    }
    169168    PabloE * ccExpr;
    170169    if (name->getType() == Name::Type::UnicodeCategory) {
    171         ccExpr = new Call(name->getName());
     170        ccExpr = make_call(name->getName());
    172171    }
    173172    else {
    174         ccExpr = new CharClass(name->getName());
     173        ccExpr = make_charclass(name->getName());
    175174    }
    176175    if (name->isNegated()) {
    177         ccExpr = new Not(new Or(new Or(ccExpr, new CharClass(m_name_map.find("LineFeed")->second)),
    178                                 new CharClass(m_name_map.find("internal.nonfinal")->second)));
    179     }
    180     cg_state.stmtsl.push_back(new Assign(gs_retVal, new Advance(new And(ccExpr, markerExpr))));
     176        ccExpr = make_not(make_or(make_or(ccExpr, make_charclass(m_name_map.find("LineFeed")->second)),
     177                                make_charclass(m_name_map.find("internal.nonfinal")->second)));
     178    }
     179    cg_state.stmtsl.push_back(make_assign(gs_retVal, make_advance(make_and(ccExpr, markerExpr))));
    181180    cg_state.newsym = gs_retVal;
    182181}
     
    191190    if (alt->empty()) {
    192191        std::string gs_retVal = symgen.get("always_fail_marker");
    193         cg_state.stmtsl.push_back(new Assign(gs_retVal, new All(0)));
     192        cg_state.stmtsl.push_back(make_assign(gs_retVal, make_all(0)));
    194193        cg_state.newsym = gs_retVal;
    195194    }
     
    203202            compile(*i, cg_state);
    204203            std::string altsym = symgen.get("alt");
    205             cg_state.stmtsl.push_back(new Assign(altsym, new Or(new Var(oldsym), new Var(cg_state.newsym))));
     204            cg_state.stmtsl.push_back(make_assign(altsym, make_or(make_var(oldsym), make_var(cg_state.newsym))));
    206205            cg_state.newsym = altsym;
    207206        }
     
    216215        PabloE* ccExpr;
    217216        if (rep_name->getType() == Name::Type::UnicodeCategory) {
    218             ccExpr = new Call(rep_name->getName());
     217            ccExpr = make_call(rep_name->getName());
    219218        }
    220219        else {
    221             ccExpr = new CharClass(rep_name->getName());
     220            ccExpr = make_charclass(rep_name->getName());
    222221        }
    223222
    224223        if (rep_name->isNegated()) {
    225             ccExpr = new Not(new Or(new Or(ccExpr, new CharClass(m_name_map.find("LineFeed")->second)), new CharClass(m_name_map.find("internal.nonfinal")->second)));
     224            ccExpr = make_not(make_or(make_or(ccExpr, make_charclass(m_name_map.find("LineFeed")->second)), make_charclass(m_name_map.find("internal.nonfinal")->second)));
    226225        }
    227226        if (rep_name->getType() == Name::Type::FixedLength) {
    228             cg_state.stmtsl.push_back(new Assign(gs_retVal, new MatchStar(new Var(cg_state.newsym), ccExpr)));
     227            cg_state.stmtsl.push_back(make_assign(gs_retVal, new MatchStar(make_var(cg_state.newsym), ccExpr)));
    229228        }
    230229        else { // Name::Unicode and Name::UnicodeCategory
    231             cg_state.stmtsl.push_back(new Assign(gs_retVal,
    232                 new And(new MatchStar(new Var(cg_state.newsym),
    233                         new Or(new CharClass(m_name_map.find("internal.nonfinal")->second), ccExpr)),
    234                                new CharClass(m_name_map.find("internal.initial")->second))));
     230            cg_state.stmtsl.push_back(make_assign(gs_retVal,
     231                make_and(new MatchStar(make_var(cg_state.newsym),
     232                        make_or(make_charclass(m_name_map.find("internal.nonfinal")->second), ccExpr)),
     233                               make_charclass(m_name_map.find("internal.initial")->second))));
    235234        }
    236235        cg_state.newsym = gs_retVal;
     
    253252    while_test_state.newsym = while_test;
    254253    compile(repeated, while_test_state);
    255     cg_state.stmtsl.push_back(new Assign(while_test, new Var(cg_state.newsym)));
    256     cg_state.stmtsl.push_back(new Assign(while_accum, new Var(cg_state.newsym)));
    257     while_test_state.stmtsl.push_back(new Assign(while_test, new And(new Var(while_test_state.newsym), new Not(new Var(while_accum)))));
    258     while_test_state.stmtsl.push_back(new Assign(while_accum, new Or(new Var(while_accum), new Var(while_test_state.newsym))));
    259     cg_state.stmtsl.push_back(new While(new Var(while_test), while_test_state.stmtsl));
     254    cg_state.stmtsl.push_back(make_assign(while_test, make_var(cg_state.newsym)));
     255    cg_state.stmtsl.push_back(make_assign(while_accum, make_var(cg_state.newsym)));
     256    while_test_state.stmtsl.push_back(make_assign(while_test, make_and(make_var(while_test_state.newsym), make_not(make_var(while_accum)))));
     257    while_test_state.stmtsl.push_back(make_assign(while_accum, make_or(make_var(while_accum), make_var(while_test_state.newsym))));
     258    cg_state.stmtsl.push_back(new While(make_var(while_test), while_test_state.stmtsl));
    260259    cg_state.newsym = while_accum;
    261260}
     
    271270         compileBoundedRep(repeated, 0, ub - 1, cg_state);
    272271         std::string altsym = symgen.get("alt");
    273          cg_state.stmtsl.push_back(new Assign(altsym, new Or(new Var(oldsym), new Var(cg_state.newsym))));
     272         cg_state.stmtsl.push_back(make_assign(altsym, make_or(make_var(oldsym), make_var(cg_state.newsym))));
    274273         cg_state.newsym = altsym;
    275274    }
Note: See TracChangeset for help on using the changeset viewer.