udm.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*****************************************************************************
  2. * dcc project Universal Decompilation Module
  3. * This is supposedly a machine independant and language independant module
  4. * that just plays with abstract cfg's and intervals and such like.
  5. * (C) Cristina Cifuentes
  6. ****************************************************************************/
  7. #include <list>
  8. #include <cassert>
  9. #include <stdio.h>
  10. #include "dcc.h"
  11. static void displayCFG(Function * pProc);
  12. static void displayDfs(BB * pBB);
  13. /****************************************************************************
  14. * udm
  15. ****************************************************************************/
  16. void Function::buildCFG()
  17. {
  18. if(flg & PROC_ISLIB)
  19. return; // Ignore library functions
  20. createCFG();
  21. if (option.VeryVerbose)
  22. displayCFG();
  23. compressCFG(); // Remove redundancies and add in-edge information
  24. if (option.asm2)
  25. disassem(2, this); // Print 2nd pass assembler listing
  26. /* Idiom analysis and propagation of long type */
  27. lowLevelAnalysis();
  28. /* Generate HIGH_LEVEL icodes whenever possible */
  29. highLevelGen();
  30. }
  31. void Function::controlFlowAnalysis()
  32. {
  33. if (flg & PROC_ISLIB)
  34. return; /* Ignore library functions */
  35. derSeq *derivedG=0;
  36. /* Make cfg reducible and build derived sequences */
  37. derivedG=checkReducibility();
  38. if (option.VeryVerbose)
  39. derivedG->display();
  40. /* Structure the graph */
  41. structure(derivedG);
  42. /* Check for compound conditions */
  43. compoundCond ();
  44. if (option.verbose)
  45. {
  46. printf("\nDepth first traversal - Proc %s\n", name.c_str());
  47. m_cfg.front()->displayDfs();
  48. }
  49. /* Free storage occupied by this procedure */
  50. freeDerivedSeq(*derivedG);
  51. }
  52. void udm(void)
  53. {
  54. /* Build the control flow graph, find idioms, and convert low-level
  55. * icodes to high-level ones */
  56. for (auto iter = pProcList.rbegin(); iter!=pProcList.rend(); ++iter)
  57. {
  58. iter->buildCFG();
  59. }
  60. /* Data flow analysis - eliminate condition codes, extraneous registers
  61. * and intermediate instructions. Find expressions by forward
  62. * substitution algorithm */
  63. std::bitset<32> live_regs;
  64. pProcList.front().dataFlow (live_regs);
  65. /* Control flow analysis - structuring algorithm */
  66. for (auto iter = pProcList.rbegin(); iter!=pProcList.rend(); ++iter)
  67. {
  68. iter->controlFlowAnalysis();
  69. }
  70. }
  71. /****************************************************************************
  72. * displayCFG - Displays the Basic Block list
  73. ***************************************************************************/
  74. void Function::displayCFG()
  75. {
  76. printf("\nBasic Block List - Proc %s", name.c_str());
  77. #ifdef _lint
  78. for (auto ik=m_cfg.begin(); ik!=m_cfg.end(); ++ik)
  79. {
  80. BB *pBB(*ik);
  81. #else
  82. for (BB *pBB : m_cfg)
  83. {
  84. #endif
  85. pBB->display();
  86. }
  87. }