project.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <QtCore/QString>
  12. #include "symtab.h"
  13. #include "BinaryImage.h"
  14. #include "Procedure.h"
  15. class QString;
  16. class SourceMachine;
  17. struct CALL_GRAPH;
  18. class IProject
  19. {
  20. virtual PROG *binary()=0;
  21. virtual const QString & project_name() const =0;
  22. virtual const QString & binary_path() const =0;
  23. };
  24. class Project : public IProject
  25. {
  26. static Project *s_instance;
  27. QString m_fname;
  28. QString m_project_name;
  29. QString m_output_path;
  30. public:
  31. typedef llvm::iplist<Function> FunctionListType;
  32. typedef FunctionListType lFunction;
  33. typedef FunctionListType::iterator ilFunction;
  34. SYMTAB symtab; /* Global symbol table */
  35. FunctionListType pProcList;
  36. CALL_GRAPH * callGraph; /* Pointer to the head of the call graph */
  37. PROG prog; /* Loaded program image parameters */
  38. // no copies
  39. Project(const Project&) = delete;
  40. const Project &operator=(const Project & l) =delete;
  41. // only moves
  42. Project(); // default constructor,
  43. public:
  44. void create(const QString &a);
  45. bool load();
  46. const QString &output_path() const {return m_output_path;}
  47. const QString &project_name() const {return m_project_name;}
  48. const QString &binary_path() const {return m_fname;}
  49. QString output_name(const char *ext);
  50. ilFunction funcIter(Function *to_find);
  51. ilFunction findByEntry(uint32_t entry);
  52. ilFunction createFunction(FunctionType *f,const std::string &name);
  53. bool valid(ilFunction iter);
  54. int getSymIdxByAdd(uint32_t adr);
  55. bool validSymIdx(size_t idx);
  56. size_t symbolSize(size_t idx);
  57. hlType symbolType(size_t idx);
  58. const std::string &symbolName(size_t idx);
  59. const SYM &getSymByIdx(size_t idx) const;
  60. static Project *get();
  61. PROG * binary() {return &prog;}
  62. SourceMachine *machine();
  63. const FunctionListType &functions() const { return pProcList; }
  64. protected:
  65. void initialize();
  66. void writeGlobSymTable();
  67. };
  68. //extern Project g_proj;