dcc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /****************************************************************************
  2. * dcc project general header
  3. * (C) Cristina Cifuentes, Mike van Emmerik
  4. ****************************************************************************/
  5. #pragma once
  6. //TODO: Remove boolT
  7. #include <llvm/ADT/ilist.h>
  8. #include <utility>
  9. #include <algorithm>
  10. #include <bitset>
  11. #include "Enums.h"
  12. #include "types.h"
  13. #include "ast.h"
  14. #include "icode.h"
  15. #include "locident.h"
  16. #include "error.h"
  17. #include "graph.h"
  18. #include "bundle.h"
  19. #include "Procedure.h"
  20. #include "BasicBlock.h"
  21. class Project;
  22. /* CALL GRAPH NODE */
  23. struct CALL_GRAPH
  24. {
  25. ilFunction proc; /* Pointer to procedure in pProcList */
  26. std::vector<CALL_GRAPH *> outEdges; /* array of out edges */
  27. public:
  28. void write();
  29. CALL_GRAPH() : outEdges(0)
  30. {
  31. }
  32. public:
  33. void writeNodeCallGraph(int indIdx);
  34. bool insertCallGraph(ilFunction caller, ilFunction callee);
  35. bool insertCallGraph(Function *caller, ilFunction callee);
  36. void insertArc(ilFunction newProc);
  37. };
  38. //extern CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
  39. extern bundle cCode; /* Output C procedure's declaration and code */
  40. /**** Global variables ****/
  41. extern char *asm1_name, *asm2_name; /* Assembler output filenames */
  42. typedef struct { /* Command line option flags */
  43. unsigned verbose : 1;
  44. unsigned VeryVerbose : 1;
  45. unsigned asm1 : 1; /* Early disassembly listing */
  46. unsigned asm2 : 1; /* Disassembly listing after restruct */
  47. unsigned Map : 1;
  48. unsigned Stats : 1;
  49. unsigned Interact : 1; /* Interactive mode */
  50. unsigned Calls : 1; /* Follow register indirect calls */
  51. char filename[80]; /* The input filename */
  52. } OPTION;
  53. extern OPTION option; /* Command line options */
  54. #include "BinaryImage.h"
  55. /* Memory map states */
  56. enum eAreaType
  57. {
  58. BM_UNKNOWN = 0, /* Unscanned memory */
  59. BM_DATA = 1, /* Data */
  60. BM_CODE = 2, /* Code */
  61. BM_IMPURE = 3 /* Used as Data and Code*/
  62. };
  63. /* Intermediate instructions statistics */
  64. struct STATS
  65. {
  66. int numBBbef; /* number of basic blocks initially */
  67. int numBBaft; /* number of basic blocks at the end */
  68. int nOrder; /* n-th order */
  69. int numLLIcode; /* number of low-level Icode instructions */
  70. int numHLIcode; /* number of high-level Icode instructions */
  71. int totalLL; /* total number of low-level Icode insts */
  72. int totalHL; /* total number of high-level Icod insts */
  73. };
  74. extern STATS stats; /* Icode statistics */
  75. /**** Global function prototypes ****/
  76. class DccFrontend
  77. {
  78. void LoadImage(Project &proj);
  79. void parse(Project &proj);
  80. std::string m_fname;
  81. public:
  82. DccFrontend(const std::string &fname) : m_fname(fname)
  83. {
  84. }
  85. bool FrontEnd(); /* frontend.c */
  86. };
  87. void udm(void); /* udm.c */
  88. void freeCFG(BB * cfg); /* graph.c */
  89. BB * newBB(BB *, int, int, uint8_t, int, Function *); /* graph.c */
  90. void BackEnd(char *filename, CALL_GRAPH *); /* backend.c */
  91. extern char *cChar(uint8_t c); /* backend.c */
  92. eErrorId scan(uint32_t ip, ICODE &p); /* scanner.c */
  93. void parse (CALL_GRAPH * *); /* parser.c */
  94. extern int strSize (const uint8_t *, char); /* parser.c */
  95. //void disassem(int pass, Function * pProc); /* disassem.c */
  96. void interactDis(Function *, int initIC); /* disassem.c */
  97. bool JmpInst(llIcode opcode); /* idioms.c */
  98. queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */
  99. void SetupLibCheck(void); /* chklib.c */
  100. void CleanupLibCheck(void); /* chklib.c */
  101. bool LibCheck(Function &p); /* chklib.c */
  102. /* Exported functions from procs.c */
  103. boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
  104. /* Exported functions from hlicode.c */
  105. char *writeJcond (const HLTYPE &, Function *, int *);
  106. char *writeJcondInv (HLTYPE, Function *, int *);
  107. /* Exported funcions from locident.c */
  108. bool checkLongEq(LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &atOffset);
  109. bool checkLongRegEq(LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &);
  110. eReg otherLongRegi(eReg, int, LOCAL_ID *);
  111. extern const char *indentStr(int level);