project.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <string>
  3. #include <stdint.h>
  4. #include <cassert>
  5. #include <list>
  6. #include <llvm/ADT/ilist.h>
  7. #include <boost/icl/interval.hpp>
  8. #include <boost/icl/interval_map.hpp>
  9. #include <boost/icl/split_interval_map.hpp>
  10. #include <unordered_set>
  11. #include "symtab.h"
  12. #include "BinaryImage.h"
  13. #include "Procedure.h"
  14. class SourceMachine;
  15. struct CALL_GRAPH;
  16. class IProject
  17. {
  18. virtual PROG *binary()=0;
  19. virtual const std::string & project_name() const =0;
  20. virtual const std::string & binary_path() const =0;
  21. };
  22. class Project : public IProject
  23. {
  24. static Project *s_instance;
  25. std::string m_fname;
  26. std::string m_project_name;
  27. public:
  28. typedef llvm::iplist<Function> FunctionListType;
  29. typedef FunctionListType lFunction;
  30. typedef FunctionListType::iterator ilFunction;
  31. SYMTAB symtab; /* Global symbol table */
  32. FunctionListType pProcList;
  33. CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
  34. PROG prog; /* Loaded program image parameters */
  35. // no copies
  36. Project(const Project&) = delete;
  37. const Project &operator=(const Project & l) =delete;
  38. // only moves
  39. Project(); // default constructor,
  40. public:
  41. void create(const std::string & a);
  42. const std::string &project_name() const {return m_project_name;}
  43. const std::string &binary_path() const {return m_fname;}
  44. ilFunction funcIter(Function *to_find);
  45. ilFunction findByEntry(uint32_t entry);
  46. ilFunction createFunction(FunctionType *f,const std::string &name);
  47. bool valid(ilFunction iter);
  48. int getSymIdxByAdd(uint32_t adr);
  49. bool validSymIdx(size_t idx);
  50. size_t symbolSize(size_t idx);
  51. hlType symbolType(size_t idx);
  52. const std::string &symbolName(size_t idx);
  53. const SYM &getSymByIdx(size_t idx) const;
  54. static Project *get();
  55. PROG * binary() {return &prog;}
  56. SourceMachine *machine();
  57. protected:
  58. void initialize();
  59. void writeGlobSymTable();
  60. };
  61. //extern Project g_proj;