udm.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /* Remove redundancies and add in-edge information */
  24. compressCFG();
  25. /* Print 2nd pass assembler listing */
  26. if (option.asm2)
  27. disassem(2, this);
  28. /* Idiom analysis and propagation of long type */
  29. lowLevelAnalysis();
  30. /* Generate HIGH_LEVEL icodes whenever possible */
  31. highLevelGen();
  32. }
  33. void Function::controlFlowAnalysis()
  34. {
  35. if (flg & PROC_ISLIB)
  36. return; /* Ignore library functions */
  37. derSeq *derivedG=0;
  38. /* Make cfg reducible and build derived sequences */
  39. derivedG=checkReducibility();
  40. if (option.VeryVerbose)
  41. derivedG->display();
  42. /* Structure the graph */
  43. structure(derivedG);
  44. /* Check for compound conditions */
  45. compoundCond ();
  46. if (option.verbose)
  47. {
  48. printf("\nDepth first traversal - Proc %s\n", name.c_str());
  49. m_cfg.front()->displayDfs();
  50. }
  51. /* Free storage occupied by this procedure */
  52. freeDerivedSeq(*derivedG);
  53. }
  54. void udm(void)
  55. {
  56. /* Build the control flow graph, find idioms, and convert low-level
  57. * icodes to high-level ones */
  58. for (auto iter = pProcList.rbegin(); iter!=pProcList.rend(); ++iter)
  59. {
  60. iter->buildCFG();
  61. }
  62. /* Data flow analysis - eliminate condition codes, extraneous registers
  63. * and intermediate instructions. Find expressions by forward
  64. * substitution algorithm */
  65. std::bitset<32> live_regs;
  66. pProcList.front().dataFlow (live_regs);
  67. /* Control flow analysis - structuring algorithm */
  68. for (auto iter = pProcList.rbegin(); iter!=pProcList.rend(); ++iter)
  69. {
  70. iter->controlFlowAnalysis();
  71. }
  72. }
  73. /****************************************************************************
  74. * displayCFG - Displays the Basic Block list
  75. ***************************************************************************/
  76. void Function::displayCFG()
  77. {
  78. printf("\nBasic Block List - Proc %s", name.c_str());
  79. for (BB *pBB : m_cfg)
  80. {
  81. pBB->display();
  82. }
  83. }