dcc.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. extern LivenessSet duReg[30]; /* def/use bits for registers */
  56. //extern uint32_t duReg[30]; /* def/use bits for registers */
  57. extern LivenessSet maskDuReg[30]; /* masks off du bits for regs */
  58. /* Registers used by icode instructions */
  59. /* Memory map states */
  60. enum eAreaType
  61. {
  62. BM_UNKNOWN = 0, /* Unscanned memory */
  63. BM_DATA = 1, /* Data */
  64. BM_CODE = 2, /* Code */
  65. BM_IMPURE = 3 /* Used as Data and Code*/
  66. };
  67. /* Intermediate instructions statistics */
  68. struct STATS
  69. {
  70. int numBBbef; /* number of basic blocks initially */
  71. int numBBaft; /* number of basic blocks at the end */
  72. int nOrder; /* n-th order */
  73. int numLLIcode; /* number of low-level Icode instructions */
  74. int numHLIcode; /* number of high-level Icode instructions */
  75. int totalLL; /* total number of low-level Icode insts */
  76. int totalHL; /* total number of high-level Icod insts */
  77. };
  78. extern STATS stats; /* Icode statistics */
  79. /**** Global function prototypes ****/
  80. class DccFrontend
  81. {
  82. void LoadImage(Project &proj);
  83. void parse(Project &proj);
  84. std::string m_fname;
  85. public:
  86. DccFrontend(const std::string &fname) : m_fname(fname)
  87. {
  88. }
  89. bool FrontEnd(); /* frontend.c */
  90. };
  91. void udm(void); /* udm.c */
  92. void freeCFG(BB * cfg); /* graph.c */
  93. BB * newBB(BB *, int, int, uint8_t, int, Function *); /* graph.c */
  94. void BackEnd(char *filename, CALL_GRAPH *); /* backend.c */
  95. extern char *cChar(uint8_t c); /* backend.c */
  96. eErrorId scan(uint32_t ip, ICODE &p); /* scanner.c */
  97. void parse (CALL_GRAPH * *); /* parser.c */
  98. extern int strSize (const uint8_t *, char); /* parser.c */
  99. //void disassem(int pass, Function * pProc); /* disassem.c */
  100. void interactDis(Function *, int initIC); /* disassem.c */
  101. bool JmpInst(llIcode opcode); /* idioms.c */
  102. queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */
  103. void SetupLibCheck(void); /* chklib.c */
  104. void CleanupLibCheck(void); /* chklib.c */
  105. bool LibCheck(Function &p); /* chklib.c */
  106. /* Exported functions from procs.c */
  107. boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
  108. /* Exported functions from hlicode.c */
  109. char *writeJcond (const HLTYPE &, Function *, int *);
  110. char *writeJcondInv (HLTYPE, Function *, int *);
  111. /* Exported funcions from locident.c */
  112. boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &atOffset);
  113. boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &);
  114. eReg otherLongRegi(eReg, int, LOCAL_ID *);
  115. extern const char *indentStr(int level);