project.cpp 2.6 KB

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