project.cpp 2.6 KB

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