dcc.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /****************************************************************************
  2. * dcc project general header
  3. * (C) Cristina Cifuentes, Mike van Emmerik
  4. ****************************************************************************/
  5. #pragma once
  6. #include <llvm/ADT/ilist.h>
  7. #include <bitset>
  8. #include "Enums.h"
  9. #include "types.h"
  10. #include "ast.h"
  11. #include "icode.h"
  12. #include "locident.h"
  13. #include "error.h"
  14. #include "graph.h"
  15. #include "bundle.h"
  16. #include "Procedure.h"
  17. #include "BasicBlock.h"
  18. typedef llvm::iplist<Function> FunctionListType;
  19. typedef FunctionListType lFunction;
  20. typedef lFunction::iterator ilFunction;
  21. /* SYMBOL TABLE */
  22. struct SYM
  23. {
  24. SYM() : label(0),size(0),flg(0),type(TYPE_UNKNOWN)
  25. {
  26. }
  27. char name[10]; /* New name for this variable */
  28. uint32_t label; /* physical address (20 bit) */
  29. int size; /* maximum size */
  30. uint32_t flg; /* SEG_IMMED, IMPURE, WORD_OFF */
  31. hlType type; /* probable type */
  32. eDuVal duVal; /* DEF, USE, VAL */
  33. };
  34. typedef std::vector<SYM> SYMTAB;
  35. /* CALL GRAPH NODE */
  36. struct CALL_GRAPH
  37. {
  38. ilFunction proc; /* Pointer to procedure in pProcList */
  39. std::vector<CALL_GRAPH *> outEdges; /* array of out edges */
  40. public:
  41. void write();
  42. CALL_GRAPH() : outEdges(0)
  43. {
  44. }
  45. public:
  46. void writeNodeCallGraph(int indIdx);
  47. boolT insertCallGraph(ilFunction caller, ilFunction callee);
  48. boolT insertCallGraph(Function *caller, ilFunction callee);
  49. void insertArc(ilFunction newProc);
  50. };
  51. //#define NUM_PROCS_DELTA 5 /* delta # procs a proc invokes */
  52. //extern std::list<Function> pProcList;
  53. extern FunctionListType pProcList;
  54. extern CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
  55. extern bundle cCode; /* Output C procedure's declaration and code */
  56. /**** Global variables ****/
  57. extern char *asm1_name, *asm2_name; /* Assembler output filenames */
  58. typedef struct { /* Command line option flags */
  59. unsigned verbose : 1;
  60. unsigned VeryVerbose : 1;
  61. unsigned asm1 : 1; /* Early disassembly listing */
  62. unsigned asm2 : 1; /* Disassembly listing after restruct */
  63. unsigned Map : 1;
  64. unsigned Stats : 1;
  65. unsigned Interact : 1; /* Interactive mode */
  66. unsigned Calls : 1; /* Follow register indirect calls */
  67. char filename[80]; /* The input filename */
  68. } OPTION;
  69. extern OPTION option; /* Command line options */
  70. extern SYMTAB symtab; /* Global symbol table */
  71. struct PROG /* Loaded program image parameters */
  72. {
  73. int16_t initCS;
  74. int16_t initIP; /* These are initial load values */
  75. int16_t initSS; /* Probably not of great interest */
  76. uint16_t initSP;
  77. bool fCOM; /* Flag set if COM program (else EXE)*/
  78. int cReloc; /* No. of relocation table entries */
  79. uint32_t * relocTable; /* Ptr. to relocation table */
  80. uint8_t * map; /* Memory bitmap ptr */
  81. int cProcs; /* Number of procedures so far */
  82. int offMain; /* The offset of the main() proc */
  83. uint16_t segMain; /* The segment of the main() proc */
  84. bool bSigs; /* True if signatures loaded */
  85. int cbImage; /* Length of image in bytes */
  86. uint8_t * Image; /* Allocated by loader to hold entire
  87. * program image */
  88. };
  89. extern PROG prog; /* Loaded program image parameters */
  90. extern std::bitset<32> duReg[30]; /* def/use bits for registers */
  91. //extern uint32_t duReg[30]; /* def/use bits for registers */
  92. extern std::bitset<32> maskDuReg[30]; /* masks off du bits for regs */
  93. /* Registers used by icode instructions */
  94. /* Memory map states */
  95. #define BM_UNKNOWN 0 /* Unscanned memory */
  96. #define BM_DATA 1 /* Data */
  97. #define BM_CODE 2 /* Code */
  98. #define BM_IMPURE 3 /* Used as Data and Code*/
  99. /* Intermediate instructions statistics */
  100. struct STATS
  101. {
  102. int numBBbef; /* number of basic blocks initially */
  103. int numBBaft; /* number of basic blocks at the end */
  104. int nOrder; /* n-th order */
  105. int numLLIcode; /* number of low-level Icode instructions */
  106. int numHLIcode; /* number of high-level Icode instructions */
  107. int totalLL; /* total number of low-level Icode insts */
  108. int totalHL; /* total number of high-level Icod insts */
  109. };
  110. extern STATS stats; /* Icode statistics */
  111. /**** Global function prototypes ****/
  112. void FrontEnd(char *filename, CALL_GRAPH * *); /* frontend.c */
  113. void *allocMem(int cb); /* frontend.c */
  114. void udm(void); /* udm.c */
  115. void freeCFG(BB * cfg); /* graph.c */
  116. BB * newBB(BB *, int, int, uint8_t, int, Function *); /* graph.c */
  117. void BackEnd(char *filename, CALL_GRAPH *); /* backend.c */
  118. char *cChar(uint8_t c); /* backend.c */
  119. eErrorId scan(uint32_t ip, ICODE &p); /* scanner.c */
  120. void parse (CALL_GRAPH * *); /* parser.c */
  121. int strSize (uint8_t *, char); /* parser.c */
  122. //void disassem(int pass, Function * pProc); /* disassem.c */
  123. void interactDis(Function * initProc, int initIC); /* disassem.c */
  124. bool JmpInst(llIcode opcode); /* idioms.c */
  125. queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */
  126. void SetupLibCheck(void); /* chklib.c */
  127. void CleanupLibCheck(void); /* chklib.c */
  128. bool LibCheck(Function &p); /* chklib.c */
  129. /* Exported functions from procs.c */
  130. boolT insertCallGraph (CALL_GRAPH *, ilFunction, ilFunction);
  131. void allocStkArgs (ICODE *, int);
  132. void placeStkArg (ICODE *, COND_EXPR *, int);
  133. void adjustActArgType (COND_EXPR *, hlType, Function *);
  134. /* Exported functions from ast.c */
  135. std::string walkCondExpr (const COND_EXPR *exp, Function * pProc, int *);
  136. int hlTypeSize (const COND_EXPR *, Function *);
  137. hlType expType (const COND_EXPR *, Function *);
  138. /* Exported functions from hlicode.c */
  139. std::string writeCall (Function *, STKFRAME *, Function *, int *);
  140. char *writeJcond (const HLTYPE &, Function *, int *);
  141. char *writeJcondInv (HLTYPE, Function *, int *);
  142. /* Exported funcions from locident.c */
  143. boolT checkLongEq (LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE atOffset);
  144. boolT checkLongRegEq (LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, iICODE);
  145. eReg otherLongRegi(eReg, int, LOCAL_ID *);
  146. extern eReg subRegH(eReg reg); //TODO: move these into machine_x86
  147. extern eReg subRegL(eReg reg);
  148. extern const char *indentStr(int level);