dcc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. extern bundle cCode; /* Output C procedure's declaration and code */
  24. /**** Global variables ****/
  25. extern std::string asm1_name, asm2_name; /* Assembler output filenames */
  26. typedef struct { /* Command line option flags */
  27. unsigned verbose : 1;
  28. unsigned VeryVerbose : 1;
  29. unsigned asm1 : 1; /* Early disassembly listing */
  30. unsigned asm2 : 1; /* Disassembly listing after restruct */
  31. unsigned Map : 1;
  32. unsigned Stats : 1;
  33. unsigned Interact : 1; /* Interactive mode */
  34. unsigned Calls : 1; /* Follow register indirect calls */
  35. std::string filename; /* The input filename */
  36. } OPTION;
  37. extern OPTION option; /* Command line options */
  38. #include "BinaryImage.h"
  39. /* Memory map states */
  40. enum eAreaType
  41. {
  42. BM_UNKNOWN = 0, /* Unscanned memory */
  43. BM_DATA = 1, /* Data */
  44. BM_CODE = 2, /* Code */
  45. BM_IMPURE = 3 /* Used as Data and Code*/
  46. };
  47. /* Intermediate instructions statistics */
  48. struct STATS
  49. {
  50. int numBBbef; /* number of basic blocks initially */
  51. int numBBaft; /* number of basic blocks at the end */
  52. int nOrder; /* n-th order */
  53. int numLLIcode; /* number of low-level Icode instructions */
  54. int numHLIcode; /* number of high-level Icode instructions */
  55. int totalLL; /* total number of low-level Icode insts */
  56. int totalHL; /* total number of high-level Icod insts */
  57. };
  58. extern STATS stats; /* Icode statistics */
  59. /**** Global function prototypes ****/
  60. class DccFrontend
  61. {
  62. void LoadImage(Project &proj);
  63. void parse(Project &proj);
  64. std::string m_fname;
  65. public:
  66. DccFrontend(const std::string &fname) : m_fname(fname)
  67. {
  68. }
  69. bool FrontEnd(); /* frontend.c */
  70. };
  71. void udm(void); /* udm.c */
  72. void freeCFG(BB * cfg); /* graph.c */
  73. BB * newBB(BB *, int, int, uint8_t, int, Function *); /* graph.c */
  74. void BackEnd(const std::string &filename, CALL_GRAPH *); /* backend.c */
  75. extern char *cChar(uint8_t c); /* backend.c */
  76. eErrorId scan(uint32_t ip, ICODE &p); /* scanner.c */
  77. void parse (CALL_GRAPH * *); /* parser.c */
  78. extern int strSize (const uint8_t *, char); /* parser.c */
  79. //void disassem(int pass, Function * pProc); /* disassem.c */
  80. void interactDis(Function *, int initIC); /* disassem.c */
  81. bool JmpInst(llIcode opcode); /* idioms.c */
  82. queue::iterator appendQueue(queue &Q, BB *node); /* reducible.c */
  83. void SetupLibCheck(void); /* chklib.c */
  84. void CleanupLibCheck(void); /* chklib.c */
  85. bool LibCheck(Function &p); /* chklib.c */
  86. /* Exported functions from hlicode.c */
  87. const char *writeJcond(const HLTYPE &, Function *, int *);
  88. const char *writeJcondInv (HLTYPE, Function *, int *);
  89. /* Exported funcions from locident.c */
  90. bool checkLongEq(LONG_STKID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &atOffset);
  91. bool checkLongRegEq(LONGID_TYPE, iICODE, int, Function *, Assignment &asgn, LLInst &);
  92. eReg otherLongRegi(eReg, int, LOCAL_ID *);
  93. extern const char *indentStr(int level);