Operand.h 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2024, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Types.h>
  8. #include <LibJS/Forward.h>
  9. namespace JS::Bytecode {
  10. class Operand {
  11. public:
  12. enum class Type {
  13. Register,
  14. Local,
  15. Constant,
  16. };
  17. [[nodiscard]] bool operator==(Operand const&) const = default;
  18. explicit Operand(Type type, u32 index)
  19. : m_type(type)
  20. , m_index(index)
  21. {
  22. }
  23. explicit Operand(Register);
  24. [[nodiscard]] bool is_register() const { return m_type == Type::Register; }
  25. [[nodiscard]] bool is_local() const { return m_type == Type::Local; }
  26. [[nodiscard]] bool is_constant() const { return m_type == Type::Constant; }
  27. [[nodiscard]] Type type() const { return m_type; }
  28. [[nodiscard]] u32 index() const { return m_index; }
  29. [[nodiscard]] Register as_register() const;
  30. private:
  31. Type m_type {};
  32. u32 m_index { 0 };
  33. };
  34. }