SymTable.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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() : m_currentID(0), m_func(nullptr), m_IDAdjustment(0)
  24. {
  25. memset(m_table, 0, sizeof(m_table));
  26. memset(m_implicitParams, 0, sizeof(m_implicitParams));
  27. }
  28. void Init(Func* func);
  29. void Add(Sym * newSym);
  30. Sym * Find(SymID id) const;
  31. StackSym * FindStackSym(SymID id) const;
  32. PropertySym * FindPropertySym(SymID id) const;
  33. PropertySym * FindPropertySym(SymID stackSymID, Js::PropertyId propertyId) const;
  34. void SetStartingID(SymID startingID);
  35. void IncreaseStartingID(SymID IDIncrease);
  36. SymID NewID();
  37. StackSym * GetArgSlotSym(Js::ArgSlot argSlotNum);
  38. StackSym * GetImplicitParam(Js::ArgSlot paramSlotNum);
  39. SymID GetMaxSymID() const;
  40. void ClearStackSymScratch();
  41. void SetIDAdjustment() { m_IDAdjustment = m_currentID;}
  42. void ClearIDAdjustment() { m_IDAdjustment = 0; }
  43. SymID MapSymID(SymID id) { return id + m_IDAdjustment; }
  44. private:
  45. int Hash(SymID id) const;
  46. };
  47. #define FOREACH_SYM_IN_TABLE(sym, table) \
  48. for (uint i = 0; i < table->k_symTableSize; i++) \
  49. { \
  50. for (Sym *sym = table->m_table[i]; sym != nullptr; sym = sym->m_next) \
  51. {
  52. #define NEXT_SYM_IN_TABLE } }