project.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <QtCore/QString>
  2. #include <QtCore/QDir>
  3. #include <utility>
  4. #include "dcc.h"
  5. #include "CallGraph.h"
  6. #include "project.h"
  7. #include "Procedure.h"
  8. using namespace std;
  9. QString asm1_name, asm2_name; /* Assembler output filenames */
  10. STATS stats; /* cfg statistics */
  11. OPTION option; /* Command line options */
  12. Project *Project::s_instance = nullptr;
  13. Project::Project() : callGraph(nullptr)
  14. {
  15. }
  16. void Project::initialize()
  17. {
  18. delete callGraph;
  19. callGraph = nullptr;
  20. }
  21. void Project::create(const QString &a)
  22. {
  23. initialize();
  24. QFileInfo fi(a);
  25. m_fname=a;
  26. m_project_name = fi.completeBaseName();
  27. m_output_path = fi.path();
  28. }
  29. QString Project::output_name(const char *ext) {
  30. return m_output_path+QDir::separator()+m_project_name+"."+ext;
  31. }
  32. bool Project::valid(ilFunction iter)
  33. {
  34. return iter!=pProcList.end();
  35. }
  36. ilFunction Project::funcIter(Function *to_find)
  37. {
  38. auto iter=std::find_if(pProcList.begin(),pProcList.end(),
  39. [to_find](const Function &f)->bool {return to_find==&f;});
  40. assert(iter!=pProcList.end());
  41. return iter;
  42. }
  43. ilFunction Project::findByEntry(uint32_t entry)
  44. {
  45. /* Search procedure list for one with appropriate entry point */
  46. ilFunction iter= std::find_if(pProcList.begin(),pProcList.end(),
  47. [entry](const Function &f) { return f.procEntry==entry; });
  48. return iter;
  49. }
  50. ilFunction Project::createFunction(FunctionType *f,const QString &name)
  51. {
  52. pProcList.push_back(*Function::Create(f,0,name,0));
  53. return (++pProcList.rbegin()).base();
  54. }
  55. int Project::getSymIdxByAddr(uint32_t adr)
  56. {
  57. size_t i;
  58. for (i = 0; i < symtab.size(); i++)
  59. if (symtab[i].label == adr)
  60. break;
  61. return i;
  62. }
  63. bool Project::validSymIdx(size_t idx)
  64. {
  65. return idx<symtab.size();
  66. }
  67. const SYM &Project::getSymByIdx(size_t idx) const
  68. {
  69. return symtab[idx];
  70. }
  71. size_t Project::symbolSize(size_t idx)
  72. {
  73. assert(validSymIdx(idx));
  74. return symtab[idx].size;
  75. }
  76. hlType Project::symbolType(size_t idx)
  77. {
  78. assert(validSymIdx(idx));
  79. return symtab[idx].type;
  80. }
  81. const QString &Project::symbolName(size_t idx)
  82. {
  83. assert(validSymIdx(idx));
  84. return symtab[idx].name;
  85. }
  86. Project *Project::get()
  87. {
  88. //WARNING: poor man's singleton, not thread safe
  89. if(s_instance==nullptr)
  90. s_instance=new Project;
  91. return s_instance;
  92. }
  93. SourceMachine *Project::machine()
  94. {
  95. return nullptr;
  96. }