Ignore:
Timestamp:
Oct 30, 2014, 1:19:34 PM (5 years ago)
Author:
nmedfort
Message:

Created an "insertion friendly" Pablo AST structure similar to LLVM; fixed engine builder bug when creating a unicode class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/printer_pablos.cpp

    r4268 r4276  
    3838using namespace pablo;
    3939
    40 std::string StatementPrinter::PrintStmts(const PabloBlock & cg_state)
     40std::string PabloPrinter::print(const PabloBlock & block)
    4141{
    4242    std::string strOut = "[";
     
    4545    strOut += "],[";
    4646
    47     strOut += Print_PB_PabloStmts(cg_state.statements());
     47    strOut += print(block.statements());
    4848
    4949    strOut = strOut.substr(0, strOut.length() - 1);
     
    5353}
    5454
    55 std::string StatementPrinter::Print_PB_PabloStmts(const StatementList & stmts) {
     55std::string PabloPrinter::print(const StatementList & stmts) {
    5656    std::string strOut = "";
    57     for (const auto stmt : stmts) {
    58         strOut += ShowPabloS(stmt);
     57    for (const Statement * stmt : stmts) {
     58        strOut += print(stmt) + "\n";
    5959    }
    6060    return strOut;
    6161}
    6262
    63 std::string StatementPrinter::Print_CC_PabloStmts(const pablo::StatementList &stmts) {
    64     std::string strOut = "Total Statements: " + std::to_string(stmts.size()) + "\n";
    65     for (const auto stmt : stmts) {
    66         strOut += ShowPabloS(stmt) + "\n";
    67     }
    68     return strOut;
    69 }
    70 
    71 std::string StatementPrinter::ShowPabloS(const PabloAST * stmt)
     63std::string PabloPrinter::print(const Statement * stmt)
    7264{
    7365    if (const Assign * an = dyn_cast<const Assign>(stmt)) {
    74         std::string result = "Assign('" + an->getName()->str() + "', " + ShowPabloAST(an->getExpr());
     66        std::string result = "Assign('" + an->getName()->str() + "'," + print(an->getExpr());
    7567        if (an->isOutputAssignment()) {
    76             result += ", Output=" + std::to_string(an->getOutputIndex());
     68            result += ",Output=" + std::to_string(an->getOutputIndex());
    7769        }
    78         return result + "),";
     70        return result + ")";
    7971    }
    8072    else if (const Next * next = dyn_cast<const Next>(stmt)) {
    81         return "Next(" + next->getName()->str() + ", " + ShowPabloAST(next->getExpr()) + ")";
     73        return "Next(" + next->getName()->str() + "," + print(next->getExpr()) + ")";
    8274    }
    8375    else if (const If * ifstmt = dyn_cast<const If>(stmt)) {
    84         return "If(" + ShowPabloAST(ifstmt->getCondition()) + ", " + Print_PB_PabloStmts(ifstmt->getBody()) + ")";
     76        return "If(" + print(ifstmt->getCondition()) + "," + print(ifstmt->getBody()) + ")";
    8577    }
    8678    else if (const While * whl = dyn_cast<const While>(stmt)) {
    87         return "While(" + ShowPabloAST(whl->getCondition()) + ", " + Print_PB_PabloStmts(whl->getBody()) + ")";
     79        return "While(" + print(whl->getCondition()) + "," + print(whl->getBody()) + ")";
    8880    }
    8981    return "???";
    9082}
    9183
    92 std::string StatementPrinter::ShowPabloAST(const PabloAST *expr) {
     84std::string PabloPrinter::print(const PabloAST *expr) {
    9385    if (isa<const Zeroes>(expr)) {
    9486        return "Zeroes";
     
    10496    }
    10597    else if (const And * pablo_and = dyn_cast<const And>(expr)) {
    106         return "And(" + ShowPabloAST(pablo_and->getExpr1()) +", " + ShowPabloAST(pablo_and->getExpr2()) + ")";
     98        return "And(" + print(pablo_and->getExpr1()) +"," + print(pablo_and->getExpr2()) + ")";
    10799    }
    108100    else if (const Or * pablo_or = dyn_cast<const Or>(expr)) {
    109         return "Or(" + ShowPabloAST(pablo_or->getExpr1()) + ", " + ShowPabloAST(pablo_or->getExpr2()) + ")";
     101        return "Or(" + print(pablo_or->getExpr1()) + "," + print(pablo_or->getExpr2()) + ")";
    110102    }
    111103    else if (const Sel * pablo_sel = dyn_cast<const Sel>(expr)) {
    112         return "((" + ShowPabloAST(pablo_sel->getCondition()) + "And " + ShowPabloAST(pablo_sel->getTrueExpr()) +
    113                 ")|(Not(" + ShowPabloAST(pablo_sel->getCondition()) + ") And " + ShowPabloAST(pablo_sel->getFalseExpr()) + ")";
     104        return "(" + print(pablo_sel->getCondition()) + " ? " + print(pablo_sel->getTrueExpr()) + " : " + print(pablo_sel->getFalseExpr()) + ")";
    114105    }
    115106    else if (const Not * pablo_not = dyn_cast<const Not>(expr)) {
    116         return "Not (" + ShowPabloAST(pablo_not->getExpr()) + ")";
     107        return "Not (" + print(pablo_not->getExpr()) + ")";
    117108    }
    118109    else if (const Advance * adv = dyn_cast<const Advance>(expr)) {
    119         return "Advance(" + ShowPabloAST(adv->getExpr()) + ", " + std::to_string(adv->getAdvanceAmount()) + ")";
     110        return "Advance(" + print(adv->getExpr()) + ", " + std::to_string(adv->getAdvanceAmount()) + ")";
    120111    }
    121112    else if (const MatchStar * mstar = dyn_cast<const MatchStar>(expr)) {
    122         return "MatchStar (" + ShowPabloAST(mstar->getMarker()) + ", " + ShowPabloAST(mstar->getCharClass()) + ")";
     113        return "MatchStar(" + print(mstar->getMarker()) + ", " + print(mstar->getCharClass()) + ")";
    123114    }
    124115    else if (const ScanThru * sthru = dyn_cast<const ScanThru>(expr)) {
    125         return "ScanThru (" + ShowPabloAST(sthru->getScanFrom()) + ", " + ShowPabloAST(sthru->getScanThru()) + ")";
     116        return "ScanThru(" + print(sthru->getScanFrom()) + ", " + print(sthru->getScanThru()) + ")";
    126117    }
    127118    return "???";
Note: See TracChangeset for help on using the changeset viewer.