SymTable.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. private:
  12. static const int k_symTableSize = 8192;
  13. static const int k_maxImplicitParamSlot = 4;
  14. Sym * m_table[k_symTableSize];
  15. StackSym * m_implicitParams[k_maxImplicitParamSlot];
  16. PropertyMap * m_propertyMap;
  17. Func * m_func;
  18. SymID m_currentID;
  19. SymID m_IDAdjustment;
  20. public:
  21. PropertyEquivBvMap *m_propertyEquivBvMap;
  22. public:
  23. SymTable() :
  24. m_table{ nullptr },
  25. m_implicitParams{ nullptr },
  26. m_propertyMap(nullptr),
  27. m_func(nullptr),
  28. m_currentID(0),
  29. m_IDAdjustment(0)
  30. {
  31. }
  32. void Init(Func* func);
  33. void Add(Sym * newSym);
  34. Sym * Find(SymID id) const;
  35. StackSym * FindStackSym(SymID id) const;
  36. PropertySym * FindPropertySym(SymID id) const;
  37. PropertySym * FindPropertySym(SymID stackSymID, Js::PropertyId propertyId) const;
  38. void SetStartingID(SymID startingID);
  39. void IncreaseStartingID(SymID IDIncrease);
  40. SymID NewID();
  41. StackSym * GetArgSlotSym(Js::ArgSlot argSlotNum);
  42. StackSym * GetImplicitParam(Js::ArgSlot paramSlotNum);
  43. SymID GetMaxSymID() const;
  44. void ClearStackSymScratch();
  45. void SetIDAdjustment() { m_IDAdjustment = m_currentID;}
  46. void ClearIDAdjustment() { m_IDAdjustment = 0; }
  47. SymID MapSymID(SymID id) { return id + m_IDAdjustment; }
  48. private:
  49. int Hash(SymID id) const;
  50. };
  51. #define FOREACH_SYM_IN_TABLE(sym, table) \
  52. for (uint i = 0; i < table->k_symTableSize; i++) \
  53. { \
  54. for (Sym *sym = table->m_table[i]; sym != nullptr; sym = sym->m_next) \
  55. {
  56. #define NEXT_SYM_IN_TABLE } }