PageRenderTime 33ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/symbolicAnalysisFramework/tests/liveDeadVarAnalysisSelfTest.C.bak

https://github.com/GoblinInventor/edg4x-rose
Unknown | 150 lines | 134 code | 16 blank | 0 comment | 0 complexity | f10fe94ae8f12acfc7d795b8d13a98d9 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, Apache-2.0
  1. #include "rose.h"
  2. #include <list>
  3. #include <sstream>
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string.h>
  7. using namespace std;
  8. #include "common.h"
  9. #include "variables.h"
  10. #include "cfgUtils.h"
  11. #include "analysisCommon.h"
  12. #include "functionState.h"
  13. #include "latticeFull.h"
  14. #include "analysis.h"
  15. #include "dataflow.h"
  16. #include "liveDeadVarAnalysis.h"
  17. #include "saveDotAnalysis.h"
  18. int numFails=0;
  19. class evaluateAnalysisStates : public UnstructuredPassIntraAnalysis
  20. {
  21. public:
  22. LiveDeadVarsAnalysis* ldva;
  23. string indent;
  24. evaluateAnalysisStates(LiveDeadVarsAnalysis* ldva, string indent) : ldva(ldva), indent(indent)
  25. {}
  26. void visit(const Function& func, const DataflowNode& n, NodeState& state)
  27. {
  28. if(isSgFunctionCallExp(n.getNode()) && isSgFunctionCallExp(n.getNode())->getAssociatedFunctionSymbol()) {
  29. string funcName = isSgFunctionCallExp(n.getNode())->getAssociatedFunctionSymbol()->get_name().getString();
  30. if(funcName.find("testFunc")!=string::npos) {
  31. set<varID> liveVars = getAllLiveVarsAt(ldva, n, state, " ");
  32. cout << funcName<<"(): liveVars=";
  33. for(set<varID>::iterator v=liveVars.begin(); v!=liveVars.end(); v++)
  34. cout << *v <<", ";
  35. cout << "\n";
  36. varID funcCallVar = SgExpr2Var(isSgFunctionCallExp(n.getNode()));
  37. if(funcName == "testFunc0") {
  38. set<varID>::iterator v = liveVars.begin();
  39. int i=0;
  40. if(funcCallVar!=*v) { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \""<<funcCallVar<<"\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  41. if(v!=liveVars.end()) { numFails++; cout << indent << "ERROR at "<<funcName<<"(): Too many live variables : #"<<i<<"!"; }
  42. } else if(funcName == "testFunc1") {
  43. set<varID>::iterator v = liveVars.begin();
  44. int i=0;
  45. if(funcCallVar!=*v) { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \""<<funcCallVar<<"\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  46. if((*v).str()!="a") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"a\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  47. if((*v).str()!="b") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"b\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  48. if((*v).str()!="c") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"c\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  49. if(v!=liveVars.end()) { numFails++; cout << indent << "ERROR at "<<funcName<<"(): Too many live variables : #"<<i<<"!"; }
  50. } else if(funcName == "testFunc2") {
  51. set<varID>::iterator v = liveVars.begin();
  52. int i=0;
  53. if(funcCallVar!=*v) { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \""<<funcCallVar<<"\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  54. if((*v).str()!="a") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"a\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  55. if((*v).str()!="b") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"b\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  56. if((*v).str()!="c") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"c\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  57. if((*v).str()!="d") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"d\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  58. if((*v).str()!="e") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"e\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  59. if(v!=liveVars.end()) { numFails++; cout << indent << "ERROR at "<<funcName<<"(): Too many live variables : #"<<i<<"!"; }
  60. } else if(funcName == "testFunc3") {
  61. set<varID>::iterator v = liveVars.begin();
  62. int i=0;
  63. if(funcCallVar!=*v) { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \""<<funcCallVar<<"\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  64. if((*v).str()!="c") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"c\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  65. if((*v).str()!="d") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"d\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  66. if(v!=liveVars.end()) { numFails++; cout << indent << "ERROR at "<<funcName<<"(): Too many live variables : #"<<i<<"!"; }
  67. } else if(funcName == "testFunc4") {
  68. set<varID>::iterator v = liveVars.begin();
  69. int i=0;
  70. if(funcCallVar!=*v) { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \""<<funcCallVar<<"\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  71. if((*v).str()!="c") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"c\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  72. if((*v).str()!="d") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"d\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  73. if(v!=liveVars.end()) { numFails++; cout << indent << "ERROR at "<<funcName<<"(): Too many live variables : #"<<i<<"!"; }
  74. } else if(funcName == "testFunc5") {
  75. set<varID>::iterator v = liveVars.begin();
  76. int i=0;
  77. if(funcCallVar!=*v) { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \""<<funcCallVar<<"\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  78. if((*v).str()!="c") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"c\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  79. if((*v).str()!="d") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"d\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  80. if((*v).str()!="arr") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"arr\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  81. if(v!=liveVars.end()) { numFails++; cout << indent << "ERROR at "<<funcName<<"(): Too many live variables : #"<<i<<"!"; }
  82. } else if(funcName == "testFunc6") {
  83. set<varID>::iterator v = liveVars.begin();
  84. int i=0;
  85. if(funcCallVar!=*v) { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \""<<funcCallVar<<"\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  86. if((*v).str()!="c") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"c\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  87. if((*v).str()!="d") { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \"d\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  88. if(v!=liveVars.end()) { numFails++; cout << indent << "ERROR at "<<funcName<<"(): Too many live variables : #"<<i<<"!"; }
  89. } else if(funcName == "testFunc7") {
  90. set<varID>::iterator v = liveVars.begin();
  91. int i=0;
  92. if(funcCallVar!=*v) { cout << indent << "ERROR at "<<funcName<<"(): Live Var "<<i<<" should be \""<<funcCallVar<<"\"!\n"; numFails++; cout.flush(); return; } v++; i++;
  93. if(v!=liveVars.end()) { numFails++; cout << indent << "ERROR at "<<funcName<<"(): Too many live variables : #"<<i<<"!"; }
  94. }
  95. }
  96. }
  97. }
  98. };
  99. int main( int argc, char * argv[] )
  100. {
  101. printf("========== S T A R T ==========\n");
  102. // Build the AST used by ROSE
  103. SgProject* project = frontend(argc,argv);
  104. initAnalysis(project);
  105. /*analysisDebugLevel = 0;
  106. SaveDotAnalysis sda;
  107. UnstructuredPassInterAnalysis upia_sda(sda);
  108. upia_sda.runAnalysis();*/
  109. liveDeadAnalysisDebugLevel = 0;
  110. analysisDebugLevel = 0;
  111. if(liveDeadAnalysisDebugLevel) {
  112. printf("*************************************************************\n");
  113. printf("***************** Live/Dead Variable Analysis *****************\n");
  114. printf("*************************************************************\n");
  115. }
  116. LiveDeadVarsAnalysis ldva(project);
  117. //CallGraphBuilder cgb(project);
  118. //cgb.buildCallGraph();
  119. //SgIncidenceDirectedGraph* graph = cgb.getGraph();
  120. //ContextInsensitiveInterProceduralDataflow ciipd_da(&ldva, graph);
  121. UnstructuredPassInterDataflow ciipd_ldva(&ldva);
  122. ciipd_ldva.runAnalysis();
  123. // printLiveDeadVarsAnalysisStates(&ldva, "[");
  124. evaluateAnalysisStates eas(&ldva, " ");
  125. UnstructuredPassInterAnalysis upia_eas(eas);
  126. upia_eas.runAnalysis();
  127. if(numFails==0)
  128. printf("PASS\n");
  129. else
  130. printf("FAIL!\n");
  131. printf("========== E N D ==========\n");
  132. // Unparse and compile the project (so this can be used for testing)
  133. return backend(project);
  134. }