dcc.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. /* CALL GRAPH NODE */
  22. struct CALL_GRAPH
  23. {
  24. ilFunction proc; /* Pointer to procedure in pProcList */
  25. std::vector<CALL_GRAPH *> outEdges; /* array of out edges */
  26. public:
  27. void write();
  28. CALL_GRAPH() : outEdges(0)
  29. {
  30. }
  31. public:
  32. void writeNodeCallGraph(int indIdx);
  33. bool insertCallGraph(ilFunction caller, ilFunction callee);
  34. bool insertCallGraph(Function *caller, ilFunction callee);
  35. void insertArc(ilFunction newProc);
  36. };
  37. //#define NUM_PROCS_DELTA 5 /* delta # procs a proc invokes */
  38. //extern std::list<Function> pProcList;
  39. extern FunctionListType pProcList;
  40. extern CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
  41. extern bundle cCode; /* Output C procedure's declaration and code */
  42. /**** Global variables ****/
  43. extern char *asm1_name, *asm2_name; /* Assembler output filenames */
  44. typedef struct { /* Command line option flags */
  45. unsigned verbose : 1;
  46. unsigned VeryVerbose : 1;
  47. unsigned asm1 : 1; /* Early disassembly listing */
  48. unsigned asm2 : 1; /* Disassembly listing after restruct */
  49. unsigned Map : 1;
  50. unsigned Stats : 1;
  51. unsigned Interact : 1; /* Interactive mode */
  52. unsigned Calls : 1; /* Follow register indirect calls */
  53. char filename[80]; /* The input filename */
  54. } OPTION;
  55. extern OPTION option; /* Command line options */
  56. extern SYMTAB symtab; /* Global symbol table */
  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. #define BM_UNKNOWN 0 /* Unscanned memory */
  82. #define BM_DATA 1 /* Data */
  83. #define BM_CODE 2 /* Code */
  84. #define BM_IMPURE 3 /* Used as Data and Code*/
  85. /* Intermediate instructions statistics */
  86. struct STATS
  87. {
  88. int numBBbef; /* number of basic blocks initially */
  89. int numBBaft; /* number of basic blocks at the end */
  90. int nOrder; /* n-th order */
  91. int numLLIcode; /* number of low-level Icode instructions */
  92. int numHLIcode; /* number of high-level Icode instructions */
  93. int totalLL; /* total number of low-level Icode insts */
  94. int totalHL; /* total number of high-level Icod insts */
  95. };
  96. extern STATS stats; /* Icode statistics */
  97. /**** Global function prototypes ****/
  98. void FrontEnd(char *filename, CALL_GRAPH * *); /* frontend.c */
  99. void udm(void); /* udm.c */
  100. void freeCFG(BB * cfg); /* graph.c */
  101. BB * newBB(BB *, int, int, uint8_t, int, Function *); /* graph.c */
  102. void BackEnd(char *filename, CALL_GRAPH *); /* backend.c */
  103. char *cChar(uint8_t c); /* backend.c */
  104. eErrorId scan(uint32_t ip, ICODE &p); /* scanner.c */
  105. void parse (CALL_GRAPH * *); /* parser.c */
  106. int strSize (uint8_t *, char); /* parser.c */
  107. //void disassem(int pass, Function * pProc); /* disassem.c */
  108. void interactDis(Function * initProc, int initIC); /* disassem.c */
  109. bool JmpInst(llIcode opcode); /* idioms.c */
  110. queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */
  111. void SetupLibCheck(void); /* chklib.c */
  112. void CleanupLibCheck(void); /* chklib.c */
  113. bool LibCheck(Function &p); /* chklib.c */
  114. /* Exported functions from procs.c */
  115. boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
  116. void allocStkArgs (ICODE *, int);
  117. void placeStkArg (ICODE *, COND_EXPR *, int);
  118. void adjustActArgType (COND_EXPR *, hlType, Function *);
  119. /* Exported functions from ast.c */
  120. std::string walkCondExpr (const COND_EXPR *exp, Function * pProc, int *);
  121. int hlTypeSize (const COND_EXPR *, Function *);
  122. hlType expType (const COND_EXPR *, Function *);
  123. /* Exported functions from hlicode.c */
  124. std::string writeCall (Function *, STKFRAME &, Function *, int *);
  125. char *writeJcond (const HLTYPE &, Function *, int *);
  126. char *writeJcondInv (HLTYPE, Function *, int *);
  127. /* Exported funcions from locident.c */
  128. boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
  129. boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE);
  130. eReg otherLongRegi(eReg, int, LOCAL_ID *);
  131. extern eReg subRegH(eReg reg); //TODO: move these into machine_x86
  132. extern eReg subRegL(eReg reg);
  133. extern const char *indentStr(int level);