SymbolTable.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef SYMBOLTABLE_H
  2. #define SYMBOLTABLE_H
  3. #include <QString>
  4. #include <QList>
  5. #include <QMultiMap>
  6. #include <QMultiHash>
  7. #include <QDateTime>
  8. #include <QXmlStreamReader>
  9. #include <QXmlStreamWriter>
  10. #include <QFileSystemWatcher>
  11. struct MemoryLayout;
  12. class SymbolTable;
  13. class Symbol
  14. {
  15. public:
  16. Symbol(const QString& str, int addr, int val = 0xFFFF);
  17. Symbol(const Symbol& symbol);
  18. // ACTIVE status is for regular symbols. HIDDEN is for symbols
  19. // that are in the list but not shown anywhere. LOST is a special
  20. // status for symbols that were once loaded from a symbol file, but
  21. // weren't found later. These aren't deleted immediately because
  22. // the possible custom settings would be lost even if the reload
  23. // was of a bad file (after a failed assembler run for instance).
  24. enum SymbolStatus { ACTIVE, HIDDEN, LOST };
  25. enum SymbolType { JUMPLABEL, VARIABLELABEL, VALUE };
  26. enum Register { REG_A = 1, REG_B = 2, REG_C = 4, REG_D = 8, REG_E = 16,
  27. REG_H = 32, REG_L = 64, REG_BC = 128, REG_DE = 256,
  28. REG_HL = 512, REG_IX = 1024, REG_IY = 2048, REG_IXL = 4096,
  29. REG_IXH = 8192, REG_IYL = 16384, REG_IYH = 32768,
  30. REG_OFFSET = 65536, REG_I = 131072,
  31. REG_ALL8 = 1+2+4+8+16+32+64+4096+8192+16384+32768+65536+131072,
  32. REG_ALL16 = 128+256+512+1024+2048,
  33. REG_ALL = 0x3FFFF };
  34. const QString& text() const;
  35. void setText(const QString& str);
  36. int value() const;
  37. void setValue(int addr);
  38. int validSlots() const;
  39. void setValidSlots(int val);
  40. int validRegisters() const;
  41. void setValidRegisters(int regs);
  42. const QString* source() const;
  43. void setSource(const QString* name);
  44. SymbolStatus status() const;
  45. void setStatus(SymbolStatus s);
  46. SymbolType type() const;
  47. void setType(SymbolType t);
  48. bool isSlotValid(const MemoryLayout* ml = 0) const;
  49. private:
  50. SymbolTable* table;
  51. QString symText;
  52. int symValue;
  53. int symSlots;
  54. QList<unsigned char> symSegments;
  55. int symRegisters;
  56. const QString* symSource;
  57. SymbolStatus symStatus;
  58. SymbolType symType;
  59. friend class SymbolTable;
  60. };
  61. class SymbolTable : public QObject
  62. {
  63. Q_OBJECT
  64. public:
  65. enum FileType {
  66. DETECT_FILE,
  67. TNIASM0_FILE,
  68. TNIASM1_FILE,
  69. SJASM_FILE,
  70. ASMSX_FILE,
  71. LINKMAP_FILE,
  72. HTC_FILE,
  73. PASMO_FILE
  74. };
  75. SymbolTable();
  76. ~SymbolTable();
  77. void add(Symbol* symbol);
  78. void removeAt(int index);
  79. void remove(Symbol *symbol);
  80. void clear();
  81. int size() const;
  82. /* xml session file functions */
  83. void saveSymbols(QXmlStreamWriter& xml);
  84. void loadSymbols(QXmlStreamReader& xml);
  85. /* Symbol access functions */
  86. Symbol* findFirstAddressSymbol(int addr, MemoryLayout* ml = 0);
  87. Symbol* getCurrentAddressSymbol();
  88. Symbol* findNextAddressSymbol(MemoryLayout* ml = 0);
  89. Symbol* getValueSymbol(int val, Symbol::Register reg, MemoryLayout* ml = 0);
  90. Symbol* getAddressSymbol(int val, MemoryLayout* ml = 0);
  91. Symbol* getAddressSymbol(const QString& label, bool case_sensitive = false);
  92. QStringList labelList(bool include_vars = false, const MemoryLayout* ml = 0) const;
  93. void symbolTypeChanged(Symbol* symbol);
  94. void symbolValueChanged(Symbol* symbol);
  95. int symbolFilesSize() const;
  96. const QString& symbolFile(int index) const;
  97. const QDateTime& symbolFileRefresh(int index) const;
  98. bool readFile(const QString& filename, FileType type = DETECT_FILE);
  99. void reloadFiles();
  100. void unloadFile(const QString& file, bool keepSymbols = false);
  101. private:
  102. void appendFile(const QString& file, FileType type);
  103. bool readSymbolFile(
  104. const QString& filename, FileType type, const QString& equ);
  105. bool readTNIASM0File(const QString& filename);
  106. bool readTNIASM1File(const QString& filename);
  107. bool readASMSXFile(const QString& filename);
  108. bool readSJASMFile(const QString& filename);
  109. bool readHTCFile(const QString& filename);
  110. bool readLinkMapFile(const QString& filename);
  111. bool readPASMOFile(const QString& filename);
  112. void mapSymbol(Symbol* symbol);
  113. void unmapSymbol(Symbol* symbol);
  114. QList<Symbol*> symbols;
  115. QMultiMap<int, Symbol*> addressSymbols;
  116. QMultiHash<int, Symbol*> valueSymbols;
  117. QMultiMap<int, Symbol*>::iterator currentAddress;
  118. struct SymbolFileRecord {
  119. QString fileName;
  120. QDateTime refreshTime;
  121. FileType fileType;
  122. };
  123. QList<SymbolFileRecord> symbolFiles;
  124. QFileSystemWatcher fileWatcher;
  125. private slots:
  126. void fileChanged(const QString & path);
  127. signals:
  128. void symbolFileChanged();
  129. };
  130. #endif // SYMBOLTABLE_H