5#include <SgGraphTemplate.h>
16yices_expr mainParse(vector<SgGraphNode*> expr, yices_context& ctx);
19typedef myGraph CFGforT;
21std::map<SgInitializedName*, yices_var_decl> unknowns;
22std::map<yices_var_decl, SgInitializedName*> IName;
23std::vector<yices_var_decl> unknownvdeclis;
25std::map<SgInitializedName*, std::vector<int> > notMap;
28std::map<std::vector<SgGraphNode*>, std::set<int> > calledMap;
29std::set<SgNode*> unknownFunctions;
36 std::vector<std::vector<SgGraphNode*> > vpaths;
37 void analyzePath(std::vector<VertexID>& pth);
44void visitorTraversalFunc::analyzePath(std::vector<VertexID>& pathR) {
49 std::vector<SgGraphNode*> path;
50 for (
unsigned int j = 0; j < pathR.size(); j++) {
54 ROSE_ASSERT(isSgFunctionDefinition(path[0]->get_SgNode()));
61 if (path.back()->get_SgNode() == path.front()->get_SgNode()) {
62 vpaths.push_back(path);
67std::map<SgNode*, std::vector<std::vector<SgGraphNode*> > > FuncPathMap;
72std::map<SgName, string> nameOf;
74std::map<SgNode*, int> forsts;
76std::map<int, std::vector<SgGraphNode*> > intvecmap;
77std::map<std::vector<SgGraphNode*>,
int> vecintmap;
79typedef myGraph CFGforT;
81std::vector<std::vector<SgGraphNode*> > paths;
95typedef boost::adjacency_list<
98 boost::bidirectionalS,
103typedef newGraph::vertex_descriptor VertexID2;
104typedef newGraph::edge_descriptor EdgeID2;
106 typedef boost::graph_traits<newGraph>::vertex_iterator vertex_iterator;
107 typedef boost::graph_traits<newGraph>::out_edge_iterator out_edge_iterator;
108 typedef boost::graph_traits<newGraph>::in_edge_iterator in_edge_iterator;
109 typedef boost::graph_traits<newGraph>::edge_iterator edge_iterator;
167void propagateFunctionCall(std::vector<SgGraphNode*> path,
int i,
int pathnum) {
169 SgName nam = sgfd->get_qualified_name();
171 ROSE_ASSERT(sgfd != NULL);
173 ROSE_ASSERT(sgfdef != NULL);
176 std::vector<std::vector<SgGraphNode*> > funcPaths = FuncPathMap[sgfdef];
177 ROSE_ASSERT(funcPaths.size() > 0);
178 int funcIndEnd = path[i]->get_SgNode()->cfgIndexForEnd();
179 if (path.size() > 1) {
182 while (indiec < funcIndEnd) {
184 if (path[kk]->get_SgNode() == path[i]->get_SgNode()) {
186 if (indiec == funcIndEnd) {
193 int startingpoint = kk;
198 std::vector<SgGraphNode*> oldpath = path;
199 std::vector<SgGraphNode*> newpath;
201 for (
int qe = 0; qe < startingpoint; qe++) {
202 newpath.push_back(path[qe]);
204 for (
size_t qe2 = 0; qe2 < funcPaths[0].size(); qe2++) {
205 newpath.push_back(funcPaths[0][qe2]);
207 for (
size_t qe3 = startingpoint; qe3 < path.size(); qe3++) {
208 newpath.push_back(path[qe3]);
211 paths[pathnum] = newpath;
212 calledMap[newpath] = calledMap[path];
213 calledMap[newpath].insert(i);
218 if (funcPaths.size() == 1) {
221 for (
size_t qw = 1; qw < funcPaths.size(); qw++) {
223 std::vector<SgGraphNode*> npath;
224 for (
int qe = 0; qe < startingpoint; qe++) {
225 npath.push_back(path[qe]);
227 for (
size_t qe2 = 0; qe2 < funcPaths[qw].size(); qe2++) {
228 npath.push_back(funcPaths[qw][qe2]);
230 for (
size_t qe3 = startingpoint; qe3 < path.size(); qe3++) {
231 npath.push_back(path[qe3]);
233 calledMap[npath] = calledMap[newpath];
239 paths.push_back(npath);
243 std::vector<std::vector<SgGraphNode*> >::iterator tt = paths.begin();
253std::map<SgName, yices_expr> getExpr;
262 std::set<SgNode*> knownNodes;
264 void analyzePath(std::vector<VertexID>& pth);
278 void analyzePath(std::vector<VertexID>& pth);
291 unsigned int i = n->get_index();
301std::set<std::pair<VertexID2, VertexID2> > knownEdges;
302std::map<SgGraphNode*, VertexID2> graphVertex;
304void visitorTraversal2::analyzePath(std::vector<VertexID2>& pathR) {
305 tltnodes += pathR.size();
311std::map<int, EdgeID2> intedgemap;
312std::map<EdgeID2, int> edgeintmap;
313std::map<VertexID2, int> intmap;
316getSource(
int& edge, newGraph*& g)
318 EdgeID2 e = intedgemap[edge];
319 VertexID2 v = boost::source(e, *g);
325int getTarget(
int& edge, newGraph*& g)
327 EdgeID2 e = intedgemap[edge];
328 VertexID2 v = boost::target(e, *g);
332 void printCFGNode2(
int& cf, VertexID2 v, newGraph*& g, std::ofstream& o)
337 str << cf <<
" expr: " << (*g)[v].exprstr;
339 else if ((*g)[v].vardec) {
341 str << cf <<
" vardec: " << (*g)[v].varstr;
346 std::string nodeColor =
"black";
347 o << cf <<
" [label=\"" <<
" num:" << str.str() <<
"\", color=\"" << nodeColor <<
"\", style=\"" <<
"solid" <<
"\"];\n";
350 void printCFGEdge2(
int& cf, newGraph*& cfg, std::ofstream& o)
352 int src = getSource(cf, cfg);
353 int tar = getTarget(cf, cfg);
354 o << src <<
" -> " << tar <<
" [label=\"" << src <<
" " << tar <<
"\", style=\"" <<
"solid" <<
"\"];\n";
357 void printHotness2(newGraph*& g)
363 std::stringstream filenam;
364 filenam <<
"hotness2" << currhot <<
".dot";
365 std::string fn = filenam.str();
368 mf <<
"digraph defaultName { \n";
369 vertex_iterator v, vend;
370 edge_iterator e, eend;
373 for (tie(v, vend) = vertices(*g); v != vend; ++v)
375 intmap[*v] = intcurr;
376 printCFGNode2(intcurr, *v, g, mf);
379 for (tie(e, eend) = edges(*g); e != eend; ++e)
381 edgeintmap[*e] = intcurr2;
382 intedgemap[intcurr2] = *e;
383 printCFGEdge2(intcurr2, g, mf);
390string getType(
SgNode* n) {
391 if (isSgTypeInt(n)) {
394 else if (isSgTypeDouble(n)) {
397 else if (isSgTypeFloat(n)) {
400 else if (isSgTypeShort(n)) {
403 else if (isSgTypeLong(n)) {
406 else if (isSgTypeLongLong(n)) {
407 return "long long int";
409 else if (isSgTypeLongDouble(n)) {
410 return "long double";
412 else if (isSgTypeBool(n)) {
421yices_expr evalFunction(std::vector<SgGraphNode*> path, yices_context& ctx,
bool mainFlag);
423std::vector<VertexID> exprs;
430std::set<std::vector<SgGraphNode*> > globalPaths;
434void visitorTraversal::analyzePath(std::vector<VertexID>& pathR) {
448 stringstream pathstream;
460 inconsistent =
false;
461 std::vector<SgGraphNode*> path;
463 std::vector<SgGraphNode*> exprPath;
464 for (
unsigned int j = 0; j < pathR.size(); j++) {
468 if (path.back()->get_SgNode() != path.front()->get_SgNode()) {
486paths.push_back(path);
487std::vector<SgNode*> called;
488 while (jjf != paths.size()) {
490 std::vector<SgGraphNode*> pathc = paths[jjf];
492 while (jj != pathc.size()) {
493 if (isSgFunctionCallExp(pathc[jj]->get_SgNode()) && calledMap[pathc].find(jj) == calledMap[pathc].end() && opencfg->
toCFGNode(pathc[jj]).
getIndex() == 0) {
495 SgName nam = sgfd->get_qualified_name();
497 ROSE_ASSERT(sgfd != NULL);
501 if (sgfdef != NULL) {
505 propagateFunctionCall(pathc, jj, jjf);
515 unknownFunctions.insert(pathc[jj]->get_SgNode());
535 pathnumber += paths.size();
536 std::vector<SgNode*> ncalled;
538for (
size_t q = 0; q < paths.size(); q++) {
540 y <<
"yices" << qst + q <<
".txt";
542 string fileSaver =
"pathsets";
543 fout.open(fileSaver.c_str(),ios::app);
544 for (
size_t qr = 0; qr < paths[q].size(); qr++) {
545 fout << getGraphNodeType(paths[q][qr]) << std::endl;
547 fout <<
"************************\n";
550 yices_enable_log_file((
char*) y.str().c_str());
561 std::vector<SgGraphNode*> path = paths[q];
564 ROSE_ASSERT(path.front()->get_SgNode() == path.back()->get_SgNode());
565 yices_context ctx = yices_mk_context();
570 switch(yices_check(ctx)) {
573 if (unknownvdeclis.size() != 0) {
575 yices_model m = yices_get_model(ctx);
581 for (
int yy = 0; yy < 4; yy++) {
582 std::cout <<
"unknownvdeclis.size(): " << unknownvdeclis.size() << std::endl;
583 for (
size_t yy2 = 0; yy2 < unknownvdeclis.size(); yy2++) {
584 yices_var_decl vdecli =
new yices_var_decl();
585 vdecli = unknownvdeclis[yy2];
588 ROSE_ASSERT(
sg != NULL);
589 ROSE_ASSERT(IName.find(vdecli) != IName.end());
590 long* val =
new long;
591 yices_get_int_value(m,vdecli,val);
592 SgName sn =
sg->get_qualified_name();
594 std::cout <<
"unknown " << sn.getString() <<
" is: " << *val << std::endl;
595 notMap[
sg].push_back(
int(*val));
603 unknownvdeclis.clear();
606 inconsistent =
false;
607 evalFunction(path, ctx,
true);
609 if (yices_inconsistent(ctx)) {
610 std::cout <<
"********************" << std::endl;
611 std::cout <<
"inconsistent at yy: " << yy << std::endl;
612 std::cout <<
"********************" << std::endl;
619 std::cout <<
"*****************" << std::endl;
620 std::cout <<
"consistent at yy: " << yy << std::endl;
621 std::cout <<
"*****************" << std::endl;
645 unknownvdeclis.clear();
653yices_expr evalFunction(std::vector<SgGraphNode*> path, yices_context& ctx,
bool mainFlag) {
660 std::vector<SgGraphNode*> exprPath;
702 while (i < (
int)path.size()) {
718 if (yices_inconsistent(ctx)) {
732 inconsistent =
false;
734 yices_expr ywrong = yices_mk_fresh_bool_var(ctx);
742 if (isSgReturnStmt(path[i]->get_SgNode())) {
745 std::vector<SgGraphNode*> retpath;
749 while (path[j]->get_SgNode() != path[i]->get_SgNode()) {
750 retpath.push_back(path[j]);
753 if (j == (
int)path.size()) {
758 yices_expr retparse = mainParse(retpath, ctx);
763 i += retpath.size()+2;
766 if (isSgInitializedName(path[i]->get_SgNode()) ) {
769 exprPath.push_back(path[i]);
770 if (path[i]->get_SgNode()->cfgIndexForEnd() == 0) {
772 SgName svs = (isSgInitializedName(exprPath[0]->get_SgNode()))->get_qualified_name();
773 if (nameOf.find(svs) == nameOf.end()) {
774 SgType* typ = (isSgInitializedName(exprPath[0]->get_SgNode()))->get_type();
775 string typ_str = getType(typ);
779 funN << svs.getString() << nvars;
780 char* fun = (
char*) funN.str().c_str();
781 char* valTypeCh = (
char*) typ_str.c_str();
782 yices_type ty = yices_mk_type(ctx, valTypeCh);
783 yices_var_decl vdecl = yices_mk_var_decl(ctx, fun, ty);
784 yices_expr e1 = yices_mk_var_from_decl(ctx, vdecl);
786 nameOf[svs] = funN.str();
791 unsigned int k = i+1;
798 while (check < path[i]->get_SgNode()->cfgIndexForEnd()) {
799 if (path[i]->get_SgNode() == path[k]->get_SgNode()) {
801 if (check == path[i]->get_SgNode()->cfgIndexForEnd()) {
805 exprPath.push_back(path[k]);
808 exprPath.push_back(path[k]);
821 y1 = mainParse(exprPath, ctx);
823 ROSE_ASSERT(y1 != NULL);
824 if (!unknown_flag && unknowns.find(isSgInitializedName(path[i]->get_SgNode())) == unknowns.end()) {
827 yices_assert(ctx, y1);
834 unknown_flag =
false;
836 i += exprPath.size()+1;
841 else if (isSgWhileStmt(path[i]->get_SgNode()) && opencfg->
toCFGNode(path[i]).
getIndex() == 0) {
842 std::vector<SgGraphNode*> internals;
843 std::vector<SgGraphNode*> exitStmt;
849 while (i < (
int)path.size() && path[i]->get_SgNode() != path[iorig]->get_SgNode()) {
850 if (isSgBasicBlock(path[i]->get_SgNode())) {
854 exitStmt.push_back(path[i]);
865 while (i < (
int)path.size() && path[iorig]->get_SgNode() != path[i]->get_SgNode()) {
868 internals.push_back(path[i]);
875 if (internals.size() == 0) {
876 yices_expr wh = mainParse(exitStmt, ctx);
877 yices_expr nwhile = yices_mk_not(ctx,wh);
878 yices_assert(ctx,nwhile);
885 while (path[i]->get_SgNode() != path[iorig]->get_SgNode()) {
890 while (n < FORLOOPS) {
893 yices_expr exityi = mainParse(exitStmt, ctx);
894 yices_assert(ctx, exityi);
895 if (yices_inconsistent(ctx)) {
897 if (!yices_inconsistent(ctx)) {
922 yices_expr mP = mainParse(exitStmt, ctx);
923 yices_expr nmP = yices_mk_not(ctx, mP);
924 yices_assert(ctx, nmP);
928 yices_expr yf = yices_mk_false(ctx);
929 yices_assert(ctx,yf);
936 while (isSgBasicBlock(path[i]->get_SgNode())) {
944 else if (isSgForStatement(path[i]->get_SgNode()) && opencfg->
toCFGNode(path[i]).
getIndex() == 0) {
945 std::vector<SgGraphNode*> internals;
946 std::vector<SgGraphNode*> initStmt;
947 std::vector<SgGraphNode*> exitStmt;
948 std::vector<SgGraphNode*> update;
950 ROSE_ASSERT(isSgForInitStatement(path[i+1]->get_SgNode()));
956 while (path[i+1]->get_SgNode() != path[k]->get_SgNode()) {
957 initStmt.push_back(path[k]);
965 yices_expr yk = mainParse(initStmt, ctx);
968 yices_assert(ctx, yk);
969 ROSE_ASSERT(isSgForStatement(path[k]->get_SgNode()));
971 while (path[j]->get_SgNode() != path[k]->get_SgNode()) {
972 exitStmt.push_back(path[j]);
988 while (isSgBasicBlock(path[j]->get_SgNode())) {
992 if (isSgForStatement(path[j]->get_SgNode()) && opencfg->
toCFGNode(path[j]).
getIndex() == 4) {
999 yices_expr exity = mainParse(exitStmt, ctx);
1002 yices_expr notexp = yices_mk_not(ctx, exity);
1003 yices_assert(ctx, notexp);
1009 while (path[j]->get_SgNode() != path[i]->get_SgNode() && j < (
int)path.size()-1) {
1012 internals.push_back(path[j]);
1030 while (path[j]->get_SgNode() != path[i]->get_SgNode()) {
1031 update.push_back(path[j]);
1037 ROSE_ASSERT(path[j]->get_SgNode() == path[i]->get_SgNode());
1039 while(path[j]->get_SgNode() != path[i]->get_SgNode()) {
1050 while (n < FORLOOPS) {
1053 yices_expr exityi = mainParse(exitStmt, ctx);
1054 yices_assert(ctx, exityi);
1055 if (yices_inconsistent(ctx)) {
1057 if (!yices_inconsistent(ctx)) {
1068 evalFunction(internals, ctx,
false);
1069 yices_expr eupdate = mainParse(update, ctx);
1070 yices_assert(ctx, eupdate);
1083 yices_expr ey = mainParse(exitStmt, ctx);
1084 yices_expr eyn = yices_mk_not(ctx,ey);
1085 yices_assert(ctx,eyn);
1089 yices_expr yf = yices_mk_false(ctx);
1090 yices_assert(ctx,yf);
1102 if (isSgForInitStatement(path[i]->get_SgNode())) {
1144 else if (isSgIfStmt(path[i]->get_SgNode()) && opencfg->
toCFGNode(path[i]).
getIndex() == 0) {
1151 while (isSgBasicBlock(path[i+1]->get_SgNode())) {
1154 if (!isSgExprStatement(path[i+1]->get_SgNode())) {
1158 ROSE_ASSERT(isSgExprStatement(path[i+1]->get_SgNode()));
1160 std::vector<SgGraphNode*> fpath;
1161 while (path[k]->get_SgNode() != path[i+1]->get_SgNode()) {
1162 if (!isSgBasicBlock(path[k]->get_SgNode())) {
1163 fpath.push_back(path[k]);
1168 ROSE_ASSERT(isSgExprStatement(path[k]->get_SgNode()));;
1174 yices_expr y1 = mainParse(fpath, ctx);
1176 ROSE_ASSERT(isSgIfStmt(path[kk]->get_SgNode()));
1177 std::set<SgDirectedGraphEdge*> ifoeds = openg->computeEdgeSetOut(path[kk]);
1178 CFGNode cn = opencfg->
toCFGNode(path[kk+1]);
1179 std::vector<CFGEdge> ed = cn.
inEdges();
1182 EdgeConditionKind kn;
1184 for (
size_t qt = 0; qt < ed.size(); qt++) {
1185 if (ed[qt].source() == opencfg->
toCFGNode(path[kk])) {
1187 kn = needEdge.condition();
1190 while (isSgBasicBlock(path[kk+1]->get_SgNode())) {
1206 unknown_flag =
false;
1214 if (kn == eckTrue) {
1215 yices_assert(ctx, y1);
1218 ROSE_ASSERT(kn == eckFalse);
1219 yices_expr ynot = yices_mk_not(ctx,y1);
1220 yices_assert(ctx,ynot);
1231 std::vector<SgGraphNode*> fpath2;
1232 fpath2.push_back(path[kk2]);
1234 while (path[kk2]->get_SgNode() != path[kk+1]->get_SgNode() || opencfg->
toCFGNode(path[kk2]).
getIndex() != path[kk+1]->get_SgNode()->cfgIndexForEnd()) {
1237 fpath2.push_back(path[kk2]);
1240 if (kk2 == (
int)path.size()) {
1246 if (kk2 < (
int)path.size()) {
1247 fpath2.push_back(path[kk2]);
1249 if (kk2 == (
int)path.size()) {
1256 yices_expr ewe = evalFunction(fpath2,ctx,
false);
1266 if (fpath2.size() != 0) {
1267 evalFunction(fpath2,ctx,
false);
1316 else if (isSgExprStatement(path[i]->get_SgNode()) && opencfg->
toCFGNode(path[i]).
getIndex() == 0 ) {
1318 std::vector<SgGraphNode*> ses;
1319 ses.push_back(path[i]);
1320 while (path[i]->get_SgNode() != path[j]->get_SgNode()) {
1322 ses.push_back(path[j]);
1326 ses.push_back(path[j]);
1327 yices_expr mP = mainParse(ses, ctx);
1328 yices_assert(ctx, mP);
1443std::vector<int> breakTriple(std::vector<SgGraphNode*> expr) {
1444 SgNode* index = expr[0]->get_SgNode();
1445 std::vector<int> bounds(3, 0);
1448 while (expr[i]->get_SgNode() != index) {
1450 ROSE_ASSERT(i < expr.size());
1454 bounds[2] = expr.size()-1;
1463bool isLogicalSplit(
SgNode*);
1464string getLogicalSplit(
SgNode*);
1465string getBinaryLogicOp(
SgNode*);
1466bool isBinaryLogicOp(
SgNode*);
1468string getBinaryOp(
SgNode*);
1471std::vector<SgGraphNode*> getSlice(std::vector<SgGraphNode*> vv,
int i) {
1472 int cfgEnd = vv[i]->get_SgNode()->cfgIndexForEnd();
1474 std::vector<SgGraphNode*> slice;
1477 slice.push_back(vv[i]);
1480 slice.push_back(vv[i]);
1483 ROSE_ASSERT(cfgEnd != ind);
1485 if (vv[i]->get_SgNode() == vv[k]->get_SgNode()) {
1487 if (ind == cfgEnd) {
1488 slice.push_back(vv[k]);
1492 slice.push_back(vv[k]);
1507yices_expr mainParse(vector<SgGraphNode*> expr, yices_context& ctx) {
1509 string typ = getGraphNodeType(expr[0]);
1514 std::stringstream stst;
1517 std::vector<SgGraphNode*> vec1;
1518 std::vector<SgGraphNode*> vec2;
1521 if (expr.size() == 0) {
1522 yices_expr empty =
new yices_expr;
1530 if (isSgReturnStmt(expr[0]->get_SgNode())) {
1531 ROSE_ASSERT(isSgReturnStmt(expr.back()));
1532 std::vector<SgGraphNode*> toSolve;
1533 for (
size_t j = 1; j < expr.size()-1; j++) {
1534 toSolve.push_back(expr[j]);
1536 yices_expr ts = mainParse(toSolve, ctx);
1539 else if (isSgFunctionCallExp(expr[0]->get_SgNode())) {
1542 yices_var_decl ftydecl;
1545 if (unknownFunctions.find(expr[0]->get_SgNode()) != unknownFunctions.end()) {
1549 SgFunctionDeclaration* afd = (isSgFunctionCallExp(expr[0]->get_SgNode()))->getAssociatedFunctionDeclaration();
1551 string ty_str = getType(ty);
1552 const char* ty_const_char = ty_str.c_str();
1553 yices_type rty = yices_mk_type(ctx,(
char*)ty_const_char);
1554 SgInitializedNamePtrList sipl = afd->get_args();
1555 yices_type dom[sipl.size()];
1557 for (SgInitializedNamePtrList::iterator ii = sipl.begin(); ii != sipl.end(); ii++) {
1558 string domY = getType((*ii)->get_type());
1559 yices_type typdom = yices_mk_type(ctx,(
char*)domY.c_str());
1567 nam << afd->get_qualified_name().getString();
1569 fty = yices_mk_function_type(ctx, dom, ds, rty);;
1570 ftydecl = yices_mk_var_decl(ctx, (
char*) nam.str().c_str(),fty);
1571 f = yices_mk_var_from_decl(ctx, ftydecl);
1579 while (!isSgExprListExp(expr[i]->get_SgNode())) {
1581 if (i > (
int)expr.size()) {
1587 std::vector<yices_expr> argsyices;
1588 std::vector<SgGraphNode*> yexp;
1589 while (checks != (
int)expr[i]->get_SgNode()->cfgIndexForEnd()) {
1591 while (expr[j]->get_SgNode() != expr[i]->get_SgNode()) {
1592 yexp.push_back(expr[j]);
1594 if (j >= (
int)expr.size()) {
1606 yices_expr yex = mainParse(yexp,ctx);
1608 ROSE_ASSERT(yex != NULL);
1609 argsyices.push_back(yex);
1615 yices_expr argsaryices[argsyices.size()];
1616 for (
size_t tt = 0; tt < argsyices.size(); tt++) {
1617 argsaryices[tt] = argsyices[tt];
1620 yices_expr app = yices_mk_app(ctx,f,argsaryices,argsyices.size());
1625 SgInitializedNamePtrList sinp = sfpl->
get_args();
1626 SgInitializedNamePtrList::iterator ite = sinp.begin();
1628 for (ite = sinp.begin(); ite != sinp.end(); ite++) {
1629 SgName svs = (isSgInitializedName((*ite)))->get_qualified_name();
1632 funN << svs.getString() << nvars;
1634 nameOf[svs] = funN.str();
1635 string valType = getType(isSgInitializedName(*ite)->get_type());
1636 yices_type ty1 = yices_mk_type(ctx, (
char*) valType.c_str());
1637 yices_var_decl decl1 = yices_mk_var_decl(ctx, (
char*) funN.str().c_str(), ty1);
1638 yices_expr e1 = yices_mk_var_from_decl(ctx, decl1);
1645 ROSE_ASSERT(argsyices[argnum] != NULL);
1646 getExpr[svs] = argsyices[argnum];
1648 yices_expr exp = yices_mk_eq(ctx,e1,argsyices[argnum]);
1649 yices_assert(ctx,exp);
1661 ROSE_ASSERT(isSgFunctionCallExp(expr[j]->get_SgNode()));
1667 std::vector<SgGraphNode*> funcLine;
1677 while (check2 < (
int)expr[k]->get_SgNode()->cfgIndexForEnd()) {
1678 if (expr[k]->get_SgNode() == expr[j]->get_SgNode()) {
1688 funcLine.push_back(expr[j]);
1693 std::vector<SgGraphNode*> funcLine2;
1694 for (
size_t kk = 1; kk < funcLine.size()-1; kk++) {
1695 funcLine2.push_back(funcLine[kk]);
1703 ROSE_ASSERT(!unknown_flag);
1705 yices_expr funcexp = evalFunction(funcLine2, ctx,
false);
1706 ROSE_ASSERT(funcexp != NULL);
1712 else if (isSgNotOp(expr[0]->get_SgNode())) {
1713 ret = yices_mk_fresh_bool_var(ctx);
1716 while (curr->get_SgNode() != expr[0]->get_SgNode()) {
1717 vec1.push_back(curr);
1721 yices_expr e1 = yices_mk_fresh_bool_var(ctx);
1722 e1 = mainParse(vec1, ctx);
1723 ret = yices_mk_not(ctx, e1);
1726 else if (isLogicalSplit(expr[0]->get_SgNode())) {
1727 ret = yices_mk_fresh_bool_var(ctx);
1728 string ls = getLogicalSplit(expr[0]->get_SgNode());
1730 std::map<int, std::vector<SgGraphNode*> > vec;
1731 std::vector<SgGraphNode*> vecX;
1740 if (expr[qt]->get_SgNode() == expr[0]->get_SgNode()) {
1746 vecX.push_back(expr[qt]);
1761 yices_expr e1 = yices_mk_fresh_bool_var(ctx);
1762 yices_expr e2 = yices_mk_fresh_bool_var(ctx);
1772 e1 = mainParse(vec1, ctx);
1773 if (vec2.size() != 0) {
1774 e2 = mainParse(vec2, ctx);
1778 if (vec1.size() == 0 && ls ==
"and") {
1779 e1 = yices_mk_false(ctx);
1781 else if (vec1.size() == 0 && ls ==
"or") {
1782 e1 = yices_mk_true(ctx);
1784 else if (vec2.size() == 0 && ls ==
"and") {
1785 e2 = yices_mk_false(ctx);
1787 else if (vec2.size() == 0 && ls ==
"or") {
1788 e2 = yices_mk_true(ctx);
1796 ret = yices_mk_or(ctx, arr, 2);
1798 else if (ls ==
"and") {
1799 ret = yices_mk_and(ctx, arr, 2);
1813 else if (isBinaryLogicOp(expr[0]->get_SgNode()) || isBinaryOp(expr[0]->get_SgNode())) {
1823 std::vector<SgGraphNode*> vecX;
1824 std::map<int, std::vector<SgGraphNode*> > vec;
1825 while (check < (
int)expr[0]->get_SgNode()->cfgIndexForEnd()) {
1826 if (expr[0]->get_SgNode() == expr[i]->get_SgNode()) {
1830 if (check == (
int)expr[0]->get_SgNode()->cfgIndexForEnd()) {
1834 if (expr[0]->get_SgNode() != expr[i]->get_SgNode()) {
1835 vecX.push_back(expr[i]);
1849 if (isBinaryLogicOp(expr[0]->get_SgNode())) {
1850 parsed = getBinaryLogicOp(expr[0]->get_SgNode());
1853 parsed = getBinaryOp(expr[0]->get_SgNode());
1856 if (isBinaryLogicOp(expr[0]->get_SgNode())) {
1857 ret = yices_mk_fresh_bool_var(ctx);
1858 yices_expr e1 = mainParse(vec1, ctx);
1859 yices_expr e2 = mainParse(vec2, ctx);
1860 if (parsed ==
">") {
1861 ret = yices_mk_gt(ctx,e1, e2);
1863 else if (parsed ==
"<") {
1864 ret = yices_mk_lt(ctx, e1, e2);
1866 else if (parsed ==
"=") {
1867 ret = yices_mk_eq(ctx, e1, e2);
1869 else if (parsed ==
"!=") {
1870 ret = yices_mk_diseq(ctx, e1, e2);
1872 else if (parsed ==
"<=") {
1873 ret = yices_mk_le(ctx, e1, e2);
1875 else if (parsed ==
">=") {
1876 ret = yices_mk_ge(ctx, e1, e2);
1883 ROSE_ASSERT(ret != NULL);
1889 yices_expr e1 = mainParse(vec1, ctx);
1890 yices_expr e2 = mainParse(vec2, ctx);
1891 yices_expr yicesarr[2];
1894 string bop = getBinaryOp(expr[0]->get_SgNode());
1897 ret = yices_mk_sum(ctx, yicesarr, 2);
1899 else if (bop ==
"-") {
1900 ret = yices_mk_sub(ctx, yicesarr, 2);
1902 else if (bop ==
"*") {
1903 ret = yices_mk_mul(ctx, yicesarr, 2);
1917 else if (isSgPlusPlusOp(expr[0]->get_SgNode())) {
1918 for (
size_t i = 1; i < expr.size() - 1; i++) {
1919 vec1.push_back(expr[i]);
1921 yices_expr e1 = mainParse(vec1, ctx);
1924 funN <<
"V" << nvars;
1931 yices_expr en = yices_mk_num(ctx, 1);
1934 ret = yices_mk_sum(ctx, arr, 2);
1937 else if (isAtom(expr[0]->get_SgNode()) !=
"") {
1938 string ty = isAtom(expr[0]->get_SgNode());
1940 int ival = isSgIntVal(expr[0]->get_SgNode())->get_value();
1941 ret = yices_mk_num(ctx, ival);
1946 else if (ty ==
"double") {
1947 double dval = isSgDoubleVal(expr[0]->get_SgNode())->get_value();
1950 ret = yices_mk_num(ctx, dval);
1952 else if (ty ==
"float") {
1953 float fval = isSgFloatVal(expr[0]->get_SgNode())->get_value();
1956 ret = yices_mk_num(ctx, fval);
1958 else if (ty ==
"short") {
1959 short sval = isSgShortVal(expr[0]->get_SgNode())->get_value();
1962 ret = yices_mk_num(ctx, sval);
1964 else if (ty ==
"long") {
1965 long lval = isSgLongIntVal(expr[0]->get_SgNode())->get_value();
1968 ret = yices_mk_num(ctx, lval);
1970 else if (ty ==
"long long int") {
1971 long long llval = isSgLongLongIntVal(expr[0]->get_SgNode())->get_value();
1974 ret = yices_mk_num(ctx, llval);
1976 else if (ty ==
"long double") {
1977 long double lldval = isSgLongDoubleVal(expr[0]->get_SgNode())->get_value();
1980 ret = yices_mk_num(ctx, lldval);
1982 else if (ty ==
"bool") {
1983 bool bval = isSgBoolValExp(expr[0]->get_SgNode())->get_value();
1986 ret = yices_mk_true(ctx);
1990 ret = yices_mk_false(ctx);
1999 else if (isSgVarRefExp((expr[0])->get_SgNode())) {
2002 ROSE_ASSERT(getExpr.find(svs) != getExpr.end());
2003 ROSE_ASSERT(nameOf.find(svs) != nameOf.end());
2014 if (getExpr.find(svs) != getExpr.end()) {
2019 string valType = getType(typ);
2020 char* valTypeCh = (
char*) valType.c_str();
2023 stst << svs.getString() << nvars;
2024 nameOf[svs] = stst.str();
2026 char* fun = (
char*) stst.str().c_str();
2027 yices_type ty = yices_mk_type(ctx, valTypeCh);
2028 yices_var_decl vdecl = yices_mk_var_decl(ctx, fun, ty);
2029 e1 = yices_mk_var_from_decl(ctx, vdecl);
2036 else if (isSgInitializedName(expr[0]->get_SgNode())) {
2038 std::vector<SgGraphNode*> vec1;
2044 SgName svs = (isSgInitializedName(expr[0]->get_SgNode()))->get_qualified_name();
2045 SgType* typ = (isSgInitializedName(expr[0]->get_SgNode()))->get_type();
2046 string valType = getType(typ);
2067 vec1.push_back(expr[2]);
2069 if (!isSgVarRefExp(vec1[0])) {
2071 while ( check < (
int)expr[2]->get_SgNode()->cfgIndexForEnd()) {
2072 if (expr[2]->get_SgNode() == expr[p]->get_SgNode()) {
2074 if (check >= (
int)expr[2]->get_SgNode()->cfgIndexForEnd()) {
2078 vec1.push_back(expr[p]);
2083 vec1.push_back(expr[p]);
2097 funN << svs.getString() << nvars;
2098 nameOf[svs] = funN.str();
2103 char* fun = (
char*) funN.str().c_str();
2108 char* valTypeCh = (
char*) valType.c_str();
2115 yices_type ty = yices_mk_type(ctx, valTypeCh);
2116 yices_var_decl vdecl = yices_mk_var_decl(ctx, fun, ty);
2117 yices_expr e1 = yices_mk_var_from_decl(ctx, vdecl);
2125 mainParse(vec1,ctx);
2126 if (unknown_flag || unknowns.find(isSgInitializedName(expr[0]->get_SgNode())) != unknowns.end()) {
2127 if (unknown_flag || unknowns.find(isSgInitializedName(expr[0]->get_SgNode())) != unknowns.end()) {
2128 unknowns[isSgInitializedName(expr[0]->get_SgNode())] = vdecl;
2130 unknownvdeclis.push_back(vdecl);
2132 IName[vdecl] = isSgInitializedName(expr[0]->get_SgNode());
2136 ROSE_ASSERT(notMap.find(isSgInitializedName(expr[0]->get_SgNode())) != notMap.end());
2137 for (
size_t j = 0; j < notMap[isSgInitializedName(expr[0]->get_SgNode())].size(); j++) {
2138 int jv = notMap[isSgInitializedName(expr[0]->get_SgNode())][j];
2139 yices_expr jvexpr =yices_mk_num(ctx, jv);
2140 yices_expr ei = yices_mk_diseq(ctx, e1, jvexpr);
2141 yices_assert(ctx,ei);
2147 unknown_flag =
false;
2148 ret = yices_mk_eq(ctx, e1, e1);
2151 yices_expr e2 = mainParse(vec1, ctx);
2161 ROSE_ASSERT(e1 != NULL);
2162 ROSE_ASSERT(e2 != NULL);
2163 ret = yices_mk_eq(ctx, e1, e2);
2173 else if (isSgVariableDeclaration(expr[0]->get_SgNode())) {
2175 std::vector<SgGraphNode*> expr2;
2177 ROSE_ASSERT(isSgVariableDeclaration(expr.back()->get_SgNode()));
2178 for (
size_t tt = 1; tt < expr.size()-1; tt++) {
2179 expr2.push_back(expr[tt]);
2181 yices_expr y2 = mainParse(expr2, ctx);
2186 else if (isSgAssignOp(expr[0]->get_SgNode())) {
2188 ROSE_ASSERT(isSgVarRefExp(expr[1]->get_SgNode()));
2191 std::vector<int> bounds = breakTriple(expr);
2196 SgType* typ = isSgVarRefExp((expr[1]->get_SgNode()))->get_symbol()->get_declaration()->get_type();
2197 string valType = getType(typ);
2198 for (
int j = bounds[1]+1; j < bounds[2]; j++) {
2199 vec2.push_back(expr[j]);
2201 if (nameOf.find(svs) != nameOf.end()) {
2204 ss << svs.getString();
2207 yices_type ty1 = yices_mk_type(ctx, (
char*) valType.c_str());
2208 yices_var_decl decl1 = yices_mk_var_decl(ctx, (
char*) ss.str().c_str(), ty1);
2209 yices_expr e1 = yices_mk_var_from_decl(ctx, decl1);
2210 yices_expr e2 = mainParse(vec2, ctx);
2212 unknown_flag =
false;
2213 ret = yices_mk_eq(ctx, e1, e1);
2217 ret = yices_mk_eq(ctx, e1, e2);
2220 nameOf[svs] = ss.str();
2229 ss << svs.getString();
2231 char valTypeCh[valType.size()];
2232 for (
size_t k = 0; k < valType.size(); k++) {
2233 valTypeCh[k] = valType[k];
2235 char nam[ss.str().size()];
2236 for (
size_t q = 0; q < ss.str().size(); q++) {
2237 nam[q] = ss.str()[q];
2239 string fun = valType;
2241 yices_type ty = yices_mk_type(ctx, (
char*) valType.c_str());
2242 yices_var_decl decl1 = yices_mk_var_decl(ctx,(
char*) ss.str().c_str(), ty);
2243 yices_expr e1 = yices_mk_var_from_decl(ctx, decl1);
2244 yices_expr e2 = mainParse(vec2, ctx);
2249 ret = yices_mk_eq(ctx, e1, e2);
2252 nameOf[svs] = ss.str();
2263 else if (isSgExprStatement(expr[0]->get_SgNode())) {
2265 ROSE_ASSERT(isSgExprStatement(expr.back()->get_SgNode()));
2266 std::vector<SgGraphNode*> nexpr;
2267 for (
size_t q = 1; q < expr.size()-1; q++) {
2268 nexpr.push_back(expr[q]);
2270 yices_expr y2 = mainParse(nexpr, ctx);
2278 unknown_flag =
true;
2279 yices_expr y1 = yices_mk_fresh_bool_var(ctx);
2286string isAtom(
SgNode* n) {
2287 if (isSgIntVal(n)) {
2290 else if (isSgDoubleVal(n)) {
2293 else if (isSgFloatVal(n)) {
2296 else if (isSgShortVal(n)) {
2299 else if (isSgLongIntVal(n)) {
2302 else if (isSgLongLongIntVal(n)) {
2303 return "long long int";
2305 else if (isSgLongDoubleVal(n)) {
2306 return "long double";
2308 else if (isSgBoolValExp(n)) {
2314bool isLogicalSplit(
SgNode* n) {
2315 if (isSgAndOp(n) || isSgOrOp(n) || isSgNotOp(n)) {
2321std::string getLogicalSplit(
SgNode* n) {
2325 else if (isSgOrOp(n)) {
2328 else if (isSgNotOp(n)) {
2337std::string getBinaryLogicOp(
SgNode* n) {
2339 if (isSgEqualityOp(n)) {
2342 else if (isSgLessThanOp(n)) {
2345 else if (isSgGreaterThanOp(n)) {
2348 else if (isSgNotEqualOp(n)) {
2358bool isBinaryLogicOp(
SgNode* n) {
2359 if (isSgEqualityOp(n) || isSgLessThanOp(n) || isSgGreaterThanOp(n) || isSgNotEqualOp(n)) {
2367bool isBinaryOp(
SgNode* n) {
2368 if (isSgAddOp(n) || isSgSubtractOp(n) || isSgMultiplyOp(n) || isSgDivideOp(n)) {
2376std::string getBinaryOp(
SgNode* n) {
2381 else if (isSgSubtractOp(n)) {
2384 else if (isSgMultiplyOp(n)) {
2387 else if (isSgDivideOp(n)) {
2439int yicesCheck(
int argc,
char **argv) {
2442 string y =
"yices.txt";
2443 yices_enable_log_file((
char*) y.c_str());
2445 string fileSaver =
"saviorStuff";
2450 ROSE_ASSERT (proj != NULL);
2453 Rose_STL_Container<SgNode*> functionDeclarationList = NodeQuery::querySubTree(proj,V_SgFunctionDeclaration);
2454 Rose_STL_Container<SgNode*> functionDefinitionList = NodeQuery::querySubTree(proj, V_SgFunctionDefinition);
2458 std::vector<SgNode*> funcs;
2459 for (Rose_STL_Container<SgNode*>::iterator i = functionDefinitionList.begin(); i != functionDefinitionList.end(); i++) {
2460 if (isSgFunctionDefinition(*i) != mainDef) {
2462 ROSE_ASSERT(fni != NULL);
2464 funcs.push_back(fni);
2470 for (
unsigned int i = 0; i < funcs.size(); i++) {
2482 string fileName= functionDeclaration->get_name().str();
2483 string dotFileName1;
2484ss << fileName <<
"." << counter <<
".dot";
2486 dotFileName1 = ss.str();
2491 CFGforT* mg =
new CFGforT();
2492 mg = instantiateGraph(g, *cfg, fnc);
2493 visfunc->tltnodes = 0;
2501 std::vector<std::vector<SgGraphNode*> > vp = visfunc->vpaths;
2502 ROSE_ASSERT(sfdd != NULL);
2503 FuncPathMap[sfdd] = vp;
2552 vis->pathnumber = 0;
2555 string dotFileName1=fileName+
"."+ mainDef->get_declaration()->get_name() +
".dot";
2559 myGraph* mg =
new myGraph();
2560 mg = instantiateGraph(g, *cfg);
2573 cout <<
"filename: " << fileName << std::endl;
2574 cout <<
"finished" << std::endl;
2575 cout <<
"paths: " << vis->pathnumber <<
" ipaths: " << ipaths << std::endl;
SgFunctionDeclaration * getAssociatedFunctionDeclaration() const
Returns the associated function declaration, if it can be resolved statically.
This class represents the concept of a function declaration statement.
SgType * get_orig_return_type() const
Support for C++ covariant return types (used in virtual function overloading).
This class represents the concept of a scope in C++ (e.g. global scope, fuction scope,...
This class represents the concept of a declaration list.
const SgInitializedNamePtrList & get_args() const
Access function for p_args.
void constructPathAnalyzer(CFG *g, bool unbounded=false, Vertex end=0, Vertex begin=0, bool ns=true)
This is the function that is used by the user directly to start the algorithm.
This class represents the notion of a declared variable.
SgName get_qualified_name() const
Returns the name with appropriate qualified names representing nested scopes.
virtual Sg_File_Info * get_file_info() const override
Interface function to implement original SAGE interface to SgFile_Info objects.
This class represents strings within the IR nodes.
This class represents the base class for all IR nodes within Sage III.
This class represents a source project, with a list of SgFile objects and global information about th...
This class represents the base class for all types.
SgType * get_type() const override
Get the type associated with this expression.
SgIncidenceDirectedGraph * getGraph() const
Get the pointer pointing to the graph used by static CFG.
CFGNode toCFGNode(SgGraphNode *node)
Turn a graph node into a CFGNode which is defined in VirtualCFG namespace.
std::string toString() const
Pretty string for Dot node labels, etc.
std::vector< CFGEdge > inEdges() const
Incoming control flow edges to this node.
unsigned int getIndex() const
An identifying index within the AST node given by getNode()
Brief Overview of Algorithm:
ROSE_UTIL_API std::string stripPathFromFileName(const std::string &fileNameWithPath)
Returns the last component of a path in a filesystem.
ROSE_DLL_API SgFunctionDeclaration * findMain(SgNode *currentNode)
top-down traversal from current node to find the main() function declaration
This namespace contains template functions that operate on the ROSE AST.