dcc.h 5.5 KB

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