dcc.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. struct 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. //#define NUM_PROCS_DELTA 5 /* delta # procs a proc invokes */
  39. //extern std::list<Function> pProcList;
  40. //extern FunctionListType pProcList;
  41. //extern CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
  42. extern bundle cCode; /* Output C procedure's declaration and code */
  43. /**** Global variables ****/
  44. extern char *asm1_name, *asm2_name; /* Assembler output filenames */
  45. typedef struct { /* Command line option flags */
  46. unsigned verbose : 1;
  47. unsigned VeryVerbose : 1;
  48. unsigned asm1 : 1; /* Early disassembly listing */
  49. unsigned asm2 : 1; /* Disassembly listing after restruct */
  50. unsigned Map : 1;
  51. unsigned Stats : 1;
  52. unsigned Interact : 1; /* Interactive mode */
  53. unsigned Calls : 1; /* Follow register indirect calls */
  54. char filename[80]; /* The input filename */
  55. } OPTION;
  56. extern OPTION option; /* Command line options */
  57. struct PROG /* Loaded program image parameters */
  58. {
  59. int16_t initCS;
  60. int16_t initIP; /* These are initial load values */
  61. int16_t initSS; /* Probably not of great interest */
  62. uint16_t initSP;
  63. bool fCOM; /* Flag set if COM program (else EXE)*/
  64. int cReloc; /* No. of relocation table entries */
  65. uint32_t * relocTable; /* Ptr. to relocation table */
  66. uint8_t * map; /* Memory bitmap ptr */
  67. int cProcs; /* Number of procedures so far */
  68. int offMain; /* The offset of the main() proc */
  69. uint16_t segMain; /* The segment of the main() proc */
  70. bool bSigs; /* True if signatures loaded */
  71. int cbImage; /* Length of image in bytes */
  72. uint8_t * Image; /* Allocated by loader to hold entire
  73. * program image */
  74. };
  75. extern PROG prog; /* Loaded program image parameters */
  76. extern std::bitset<32> duReg[30]; /* def/use bits for registers */
  77. //extern uint32_t duReg[30]; /* def/use bits for registers */
  78. extern std::bitset<32> maskDuReg[30]; /* masks off du bits for regs */
  79. /* Registers used by icode instructions */
  80. /* Memory map states */
  81. enum eAreaType
  82. {
  83. BM_UNKNOWN = 0, /* Unscanned memory */
  84. BM_DATA = 1, /* Data */
  85. BM_CODE = 2, /* Code */
  86. BM_IMPURE = 3 /* Used as Data and Code*/
  87. };
  88. /* Intermediate instructions statistics */
  89. struct STATS
  90. {
  91. int numBBbef; /* number of basic blocks initially */
  92. int numBBaft; /* number of basic blocks at the end */
  93. int nOrder; /* n-th order */
  94. int numLLIcode; /* number of low-level Icode instructions */
  95. int numHLIcode; /* number of high-level Icode instructions */
  96. int totalLL; /* total number of low-level Icode insts */
  97. int totalHL; /* total number of high-level Icod insts */
  98. };
  99. extern STATS stats; /* Icode statistics */
  100. /**** Global function prototypes ****/
  101. class DccFrontend
  102. {
  103. void LoadImage(Project &proj);
  104. void parse(Project &proj);
  105. std::string m_fname;
  106. public:
  107. DccFrontend(const std::string &fname) : m_fname(fname)
  108. {
  109. }
  110. bool FrontEnd(); /* frontend.c */
  111. };
  112. void udm(void); /* udm.c */
  113. void freeCFG(BB * cfg); /* graph.c */
  114. BB * newBB(BB *, int, int, uint8_t, int, Function *); /* graph.c */
  115. void BackEnd(char *filename, CALL_GRAPH *); /* backend.c */
  116. char *cChar(uint8_t c); /* backend.c */
  117. eErrorId scan(uint32_t ip, ICODE &p); /* scanner.c */
  118. void parse (CALL_GRAPH * *); /* parser.c */
  119. int strSize (uint8_t *, char); /* parser.c */
  120. //void disassem(int pass, Function * pProc); /* disassem.c */
  121. void interactDis(Function * initProc, int initIC); /* disassem.c */
  122. bool JmpInst(llIcode opcode); /* idioms.c */
  123. queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */
  124. void SetupLibCheck(void); /* chklib.c */
  125. void CleanupLibCheck(void); /* chklib.c */
  126. bool LibCheck(Function &p); /* chklib.c */
  127. /* Exported functions from procs.c */
  128. boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
  129. void adjustActArgType (COND_EXPR *, hlType, Function *);
  130. /* Exported functions from ast.c */
  131. std::string walkCondExpr (const COND_EXPR *exp, Function * pProc, int *);
  132. int hlTypeSize (const COND_EXPR *, Function *);
  133. //hlType expType (const COND_EXPR *, Function *);
  134. /* Exported functions from hlicode.c */
  135. std::string writeCall (Function *, STKFRAME &, Function *, int *);
  136. char *writeJcond (const HLTYPE &, Function *, int *);
  137. char *writeJcondInv (HLTYPE, Function *, int *);
  138. /* Exported funcions from locident.c */
  139. boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
  140. boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE);
  141. eReg otherLongRegi(eReg, int, LOCAL_ID *);
  142. extern const char *indentStr(int level);