Operand.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2024, Andreas Kling <andreas@ladybird.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. void offset_index_by(u32 offset) { m_index += offset; }
  31. private:
  32. Type m_type {};
  33. u32 m_index { 0 };
  34. };
  35. }