PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/symbolicAnalysisFramework/tests/liveDeadVarAnalysisSelfTest.C

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