project.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include <string>
  3. #include <stdint.h>
  4. #include <cassert>
  5. #include <list>
  6. #include <llvm/ADT/ilist.h>
  7. #include "symtab.h"
  8. #include "BinaryImage.h"
  9. struct Function;
  10. struct SourceMachine;
  11. struct CALL_GRAPH;
  12. typedef llvm::iplist<Function> FunctionListType;
  13. typedef FunctionListType lFunction;
  14. typedef lFunction::iterator ilFunction;
  15. struct Project
  16. {
  17. SYMTAB symtab; /* Global symbol table */
  18. std::string m_fname;
  19. FunctionListType pProcList;
  20. CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
  21. PROG prog; /* Loaded program image parameters */
  22. Project() {}
  23. // no copies
  24. Project(const Project&) = delete;
  25. const Project &operator=(const Project & l) =delete;
  26. // only moves
  27. Project(Project && l)
  28. {
  29. m_fname =l.m_fname;
  30. size_t before=l.pProcList.size();
  31. pProcList.splice(pProcList.end(),l.pProcList);
  32. callGraph=l.callGraph;
  33. l.m_fname.clear();
  34. l.pProcList.clear();
  35. l.callGraph=0;
  36. assert(before==pProcList.size());
  37. }
  38. Project &operator=(Project && l)
  39. {
  40. if(this == &l)
  41. return *this;
  42. m_fname =l.m_fname;
  43. size_t before=l.pProcList.size();
  44. pProcList.splice(pProcList.end(),l.pProcList);
  45. callGraph=l.callGraph;
  46. l.m_fname.clear();
  47. l.pProcList.clear();
  48. l.callGraph=0;
  49. assert(before==pProcList.size());
  50. return *this;
  51. }
  52. public:
  53. ilFunction funcIter(Function *to_find);
  54. ilFunction findByEntry(uint32_t entry);
  55. ilFunction createFunction();
  56. bool valid(ilFunction iter);
  57. int getSymIdxByAdd(uint32_t adr);
  58. bool validSymIdx(size_t idx);
  59. size_t symbolSize(size_t idx);
  60. hlType symbolType(size_t idx);
  61. const std::string &symbolName(size_t idx);
  62. const SYM &getSymByIdx(size_t idx) const;
  63. static Project *get();
  64. PROG * binary() {return &prog;}
  65. SourceMachine *machine();
  66. protected:
  67. void writeGlobSymTable();
  68. };
  69. //extern Project g_proj;