SymTable.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. class SymTable
  7. {
  8. typedef JsUtil::Pair<SymID, Js::PropertyId> SymIdPropIdPair;
  9. typedef JsUtil::BaseDictionary<SymIdPropIdPair, PropertySym *, JitArenaAllocator, PrimeSizePolicy> PropertyMap;
  10. typedef JsUtil::BaseDictionary<Js::PropertyId, BVSparse<JitArenaAllocator> *, JitArenaAllocator, PowerOf2SizePolicy> PropertyEquivBvMap;
  11. public:
  12. static const int k_symTableSize = 8192;
  13. Sym * m_table[k_symTableSize];
  14. PropertyMap * m_propertyMap;
  15. PropertyEquivBvMap *m_propertyEquivBvMap;
  16. private:
  17. Func * m_func;
  18. SymID m_currentID;
  19. SymID m_IDAdjustment;
  20. public:
  21. SymTable() : m_currentID(0), m_func(nullptr), m_IDAdjustment(0)
  22. {
  23. memset(m_table, 0, sizeof(m_table));
  24. }
  25. void Init(Func* func);
  26. void Add(Sym * newSym);
  27. Sym * Find(SymID id) const;
  28. StackSym * FindStackSym(SymID id) const;
  29. PropertySym * FindPropertySym(SymID id) const;
  30. PropertySym * FindPropertySym(SymID stackSymID, Js::PropertyId propertyId) const;
  31. void SetStartingID(SymID startingID);
  32. void IncreaseStartingID(SymID IDIncrease);
  33. SymID NewID();
  34. StackSym * GetArgSlotSym(Js::ArgSlot argSlotNum);
  35. SymID GetMaxSymID() const;
  36. void ClearStackSymScratch();
  37. void SetIDAdjustment() { m_IDAdjustment = m_currentID;}
  38. void ClearIDAdjustment() { m_IDAdjustment = 0; }
  39. SymID MapSymID(SymID id) { return id + m_IDAdjustment; }
  40. private:
  41. int Hash(SymID id) const;
  42. };
  43. #define FOREACH_SYM_IN_TABLE(sym, table) \
  44. for (uint i = 0; i < table->k_symTableSize; i++) \
  45. { \
  46. for (Sym *sym = table->m_table[i]; sym != nullptr; sym = sym->m_next) \
  47. {
  48. #define NEXT_SYM_IN_TABLE } }