source: icGREP/icgrep-devel/icgrep/printer_pablos.cpp @ 3935

Last change on this file since 3935 was 3914, checked in by cameron, 5 years ago

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

File size: 3.3 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include "printer_pablos.h"
8
9
10std::string StatementPrinter::PrintStmts(CodeGenState cg_state)
11{
12    std::string strOut = "[";
13
14    strOut = strOut.substr(0, strOut.length() - 1);
15    strOut += "],[";
16
17    strOut = Print_PB_PabloStmts(cg_state.stmtsl, strOut);
18
19    strOut = strOut.substr(0, strOut.length() - 1);
20    strOut += "],";
21
22    //Print the name of the variable that holds the match result for the overall expression so far.
23    strOut += "'" + cg_state.newsym + "'";
24
25    return strOut;
26}
27
28std::string StatementPrinter::Print_PB_PabloStmts(std::list<PabloS*> stmts, std::string strOut)
29{
30    std::list<PabloS*>::iterator it;
31    //std::cout << "Total Statements: " + INT2STRING(stmts.size()) << std::endl;
32    for (it = stmts.begin(); it != stmts.end(); ++it)
33    {
34        strOut += ShowPabloS(*it);
35    }
36
37    return strOut;
38}
39
40std::string StatementPrinter::Print_CC_PabloStmts(std::list<PabloS*> stmts)
41{
42    std::string strOut;
43
44    std::cout << "Total Statements: " + INT2STRING(stmts.size()) << std::endl;
45    std::list<PabloS*>::iterator it;
46    for (it = stmts.begin(); it != stmts.end(); ++it)
47    {
48        strOut += ShowPabloS(*it) + "\n";
49    }
50
51    return strOut;
52}
53
54std::string StatementPrinter::ShowPabloS(PabloS* stmt)
55{
56    std::string retVal = "";
57
58    if (Assign* an = dynamic_cast<Assign*>(stmt))
59    {
60        retVal = "Assign('" + an->getM() + "', " + ShowPabloE(an->getExpr()) + "),";
61    }
62    if (While* whl = dynamic_cast<While*>(stmt))
63    {
64        retVal = "While(" + ShowPabloE(whl->getExpr()) + ", " + Print_PB_PabloStmts(whl->getPSList(), retVal) + ")";
65    }
66
67    return retVal;
68}
69
70std::string StatementPrinter::ShowPabloE(PabloE* expr)
71{
72    std::string retVal = "";
73
74    if (All* all = dynamic_cast<All*>(expr))
75    {
76        retVal = "All " + INT2STRING(all->getNum()) + " ";
77    }
78    else if (Var* pablo_var = dynamic_cast<Var*>(expr))
79    {
80        retVal = "Var '" + pablo_var->getVar() + "' ";
81    }
82    else if (And* pablo_and = dynamic_cast<And*>(expr))
83    {
84        retVal = "And(" + ShowPabloE(pablo_and->getExpr1()) +", " + ShowPabloE(pablo_and->getExpr2()) + ")";
85    }
86    else if (Or* pablo_or = dynamic_cast<Or*>(expr))
87    {
88        retVal = "Or(" + ShowPabloE(pablo_or->getExpr1()) + ", " + ShowPabloE(pablo_or->getExpr2()) + ")";
89    }
90    else if (Sel* pablo_sel = dynamic_cast<Sel*>(expr))
91    {
92        retVal = "((" + ShowPabloE(pablo_sel->getIf_expr()) + "And " + ShowPabloE(pablo_sel->getT_expr()) +
93                ")|(Not(" + ShowPabloE(pablo_sel->getIf_expr()) + ") And " + ShowPabloE(pablo_sel->getF_expr()) + ")";
94    }
95    else if (Not* pablo_not = dynamic_cast<Not*>(expr))
96    {
97        retVal = "Not (" + ShowPabloE(pablo_not->getExpr()) + ")";
98    }
99    else if (CharClass* cc = dynamic_cast<CharClass*>(expr))
100    {
101        retVal = "CharClass '" + cc->getCharClass() + "'";
102    }
103    else if (Advance* adv = dynamic_cast<Advance*>(expr))
104    {
105        retVal = "Advance(" + ShowPabloE(adv->getExpr()) + ")";
106    }
107    else if (MatchStar* mstar = dynamic_cast<MatchStar*>(expr))
108    {
109        retVal = "MatchStar (" + ShowPabloE(mstar->getExpr1()) + ", " + ShowPabloE(mstar->getExpr2()) + ")";
110    }
111
112    return retVal;
113}
114
115
Note: See TracBrowser for help on using the repository browser.