source: icGREP/icgrep-0.8/icgrep/printer_pablos.cpp @ 3850

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

icgrep-0.8 distribution

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