Ignore:
Timestamp:
Jul 21, 2014, 11:49:25 AM (5 years ago)
Author:
cameron
Message:

Updates for icgrep-0.9: re simplifications, re names, replimit mods, debugged while loops

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pbix_compiler.cpp

    r3850 r3914  
    77#include "pbix_compiler.h"
    88
    9 Pbix_Compiler::Pbix_Compiler(){
    10   symgen = SymbolGenerator();
     9Pbix_Compiler::Pbix_Compiler(std::string lf_ccname)
     10{
     11    m_lf_ccname = lf_ccname;
     12    symgen = SymbolGenerator();
    1113}
    1214
    1315CodeGenState Pbix_Compiler::compile(RE *re)
    14 {
     16{   
    1517    std::string gs_retVal;
    1618    gs_retVal = symgen.gensym("start_marker");
     
    2426    //These three lines are specifically for grep.
    2527    gs_retVal = symgen.gensym("marker");
    26     cg_state.stmtsl.push_back(new Assign(gs_retVal, new And(new MatchStar(new Var(cg_state.newsym), new Not(new Var("lex.cclf"))), new Var("lex.cclf"))));
     28    cg_state.stmtsl.push_back(new Assign(gs_retVal, new And(new MatchStar(new Var(cg_state.newsym), new Not(new Var(m_lf_ccname))), new Var(m_lf_ccname))));
    2729    cg_state.newsym = gs_retVal;
    2830
     
    3234CodeGenState Pbix_Compiler::re2pablo_helper(RE *re, CodeGenState cg_state)
    3335{
    34     if (CC* cc = dynamic_cast<CC*>(re))
     36    if (Name* name = dynamic_cast<Name*>(re))
    3537    {
    3638        std::string gs_retVal = symgen.gensym("marker");
    37         cg_state.stmtsl.push_back(new Assign(gs_retVal, new Advance(new And(new Var(cg_state.newsym), new CharClass(cc->getName())))));
     39        cg_state.stmtsl.push_back(new Assign(gs_retVal, new Advance(new And(new Var(cg_state.newsym), new CharClass(name->getName())))));
    3840        cg_state.newsym = gs_retVal;
    3941
     
    4345    {
    4446        std::string gs_retVal = symgen.gensym("start_of_line_marker");
    45         cg_state.stmtsl.push_back(new Assign(gs_retVal, new And(new Var(cg_state.newsym), new Not(new Advance(new Not(new CharClass("lex.cclf")))))));
     47        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_lf_ccname)))))));
    4648        cg_state.newsym = gs_retVal;
    4749    }
     
    4951    {
    5052        std::string gs_retVal = symgen.gensym("end_of_line_marker");
    51         cg_state.stmtsl.push_back(new Assign(gs_retVal, new And(new Var(cg_state.newsym), new CharClass("lex.cclf"))));
     53        cg_state.stmtsl.push_back(new Assign(gs_retVal, new And(new Var(cg_state.newsym), new CharClass(m_lf_ccname))));
    5254        cg_state.newsym = gs_retVal;
    5355    }
     
    8688    else if (Rep* rep = dynamic_cast<Rep*>(re))
    8789    {
    88         if ((dynamic_cast<CC*>(rep->getRE()) != 0) && (rep->getLB() == 0) && (dynamic_cast<Unbounded*>(rep->getUB())!= 0))
     90        if ((dynamic_cast<Name*>(rep->getRE()) != 0) && (rep->getLB() == 0) && (rep->getUB()== unboundedRep))
    8991        {
    9092            //std::cout << "Matchstar!" << std::endl;
    91             CC* rep_cc = dynamic_cast<CC*>(rep->getRE());
     93
     94            Name* rep_name = dynamic_cast<Name*>(rep->getRE());
    9295            std::string gs_retVal = symgen.gensym("marker");
    93             cg_state.stmtsl.push_back(new Assign(gs_retVal, new MatchStar(new Var(cg_state.newsym), new CharClass(rep_cc->getName()))));
     96            cg_state.stmtsl.push_back(new Assign(gs_retVal, new MatchStar(new Var(cg_state.newsym), new CharClass(rep_name->getName()))));
    9497            cg_state.newsym = gs_retVal;
    9598        }
    96         else if (dynamic_cast<Unbounded*>(rep->getUB()) != 0)
     99        else if (rep->getUB() == unboundedRep)
    97100        {
    98101            if (rep->getLB() == 0)
    99102            {
    100                 //std::cout << "While, no lb." << std::endl; //THIS IS THE ONE THAT ISN'T WORKING.
     103                //std::cout << "While, no lb." << std::endl;
    101104
    102105                std::string while_test_gs_retVal = symgen.gensym("while_test");
     
    121124            }
    122125        }
    123         else if (dynamic_cast<UpperBound*>(rep->getUB()) != 0)
     126        else if (rep->getUB() != unboundedRep)
    124127        {
    125             UpperBound* ub = dynamic_cast<UpperBound*>(rep->getUB());
    126             if ((rep->getLB() == 0) && (ub->getUB() == 0))
     128            if ((rep->getLB() == 0) && (rep->getUB() == 0))
    127129            {
    128130                //Just fall through...do nothing.
    129131            }
    130             else if ((rep->getLB() == 0) && (ub->getUB() > 0))
     132            else if ((rep->getLB() == 0) && (rep->getUB() > 0))
    131133            {
    132134                CodeGenState t1_cg_state = re2pablo_helper(rep->getRE(), cg_state);
    133                 ub->setUB(ub->getUB() - 1);
     135                rep->setUB(rep->getUB() - 1);
    134136                CodeGenState t2_cg_state = re2pablo_helper(re, t1_cg_state);
    135137                std::string gs_retVal = symgen.gensym("alt_marker");
     
    138140                cg_state.newsym = gs_retVal;
    139141            }
    140             else //if ((rep->getLB() > 0) && (ub->getUB() > 0))
     142            else //if ((rep->getLB() > 0) && (rep->getUB() > 0))
    141143            {
    142144                CodeGenState t1_cg_state = re2pablo_helper(rep->getRE(), cg_state);
    143145                rep->setLB(rep->getLB() - 1);
    144                 ub->setUB(ub->getUB() - 1);
     146                rep->setUB(rep->getUB() - 1);
    145147                cg_state = re2pablo_helper(rep, t1_cg_state);
    146148            }
Note: See TracChangeset for help on using the changeset viewer.