udm.cpp 3.0 KB

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