udm.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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);
  49. 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. pProcList.front().dataFlow (0);
  66. /* Control flow analysis - structuring algorithm */
  67. for (auto iter = pProcList.rbegin(); iter!=pProcList.rend(); ++iter)
  68. {
  69. iter->controlFlowAnalysis();
  70. }
  71. }
  72. /****************************************************************************
  73. * displayCFG - Displays the Basic Block list
  74. ***************************************************************************/
  75. void Function::displayCFG()
  76. {
  77. Int i;
  78. BB * pBB;
  79. printf("\nBasic Block List - Proc %s", name);
  80. for (auto iter = cfg.begin(); iter!=cfg.end(); ++iter)
  81. {
  82. pBB = *iter;
  83. (*iter)->display();
  84. }
  85. }