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

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

icgrep-0.8 distribution

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