ValueRelativeOffset.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. typedef unsigned int ValueNumber;
  7. class Value;
  8. extern const ValueNumber InvalidValueNumber;
  9. extern const ValueNumber ZeroValueNumber;
  10. extern const ValueNumber FirstNewValueNumber;
  11. class ValueRelativeOffset sealed
  12. {
  13. private:
  14. const Value *baseValue;
  15. int offset;
  16. bool wasEstablishedExplicitly;
  17. public:
  18. ValueRelativeOffset();
  19. ValueRelativeOffset(const Value *const baseValue, const bool wasEstablishedExplicitly);
  20. ValueRelativeOffset(const Value *const baseValue, const int offset, const bool wasEstablishedExplicitly);
  21. #if DBG
  22. private:
  23. bool IsValid() const;
  24. #endif
  25. public:
  26. ValueNumber BaseValueNumber() const;
  27. StackSym *BaseSym() const;
  28. int Offset() const;
  29. void SetOffset(const int offset);
  30. bool WasEstablishedExplicitly() const;
  31. void SetWasEstablishedExplicitly();
  32. public:
  33. bool Add(const int n);
  34. public:
  35. template<bool Lower, bool Aggressive> void Merge(const ValueRelativeOffset &other);
  36. template<bool Lower, bool Aggressive> void MergeConstantValue(const int constantValue);
  37. };
  38. template<>
  39. inline ValueNumber JsUtil::ValueToKey<ValueNumber, ValueRelativeOffset>::ToKey(const ValueRelativeOffset &valueRelativeOffset)
  40. {
  41. return valueRelativeOffset.BaseValueNumber();
  42. }