Instruction.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Bytecode/Executable.h>
  7. #include <LibJS/Bytecode/Instruction.h>
  8. #include <LibJS/Bytecode/Op.h>
  9. namespace JS::Bytecode {
  10. bool Instruction::is_terminator() const
  11. {
  12. #define __BYTECODE_OP(op) \
  13. case Type::op: \
  14. return Op::op::IsTerminator;
  15. switch (type()) {
  16. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  17. default:
  18. VERIFY_NOT_REACHED();
  19. }
  20. #undef __BYTECODE_OP
  21. }
  22. void Instruction::replace_references(BasicBlock const& from, BasicBlock const& to)
  23. {
  24. #define __BYTECODE_OP(op) \
  25. case Instruction::Type::op: \
  26. return static_cast<Bytecode::Op::op&>(*this).replace_references_impl(from, to);
  27. switch (type()) {
  28. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  29. default:
  30. VERIFY_NOT_REACHED();
  31. }
  32. #undef __BYTECODE_OP
  33. }
  34. void Instruction::destroy(Instruction& instruction)
  35. {
  36. #define __BYTECODE_OP(op) \
  37. case Type::op: \
  38. static_cast<Op::op&>(instruction).~op(); \
  39. return;
  40. switch (instruction.type()) {
  41. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  42. default:
  43. VERIFY_NOT_REACHED();
  44. }
  45. #undef __BYTECODE_OP
  46. }
  47. UnrealizedSourceRange InstructionStreamIterator::source_range() const
  48. {
  49. VERIFY(m_executable);
  50. auto record = dereference().source_record();
  51. return {
  52. .source_code = m_executable->source_code,
  53. .start_offset = record.source_start_offset,
  54. .end_offset = record.source_end_offset,
  55. };
  56. }
  57. RefPtr<SourceCode> InstructionStreamIterator::source_code() const
  58. {
  59. return m_executable ? m_executable->source_code.ptr() : nullptr;
  60. }
  61. Operand::Operand(Register reg)
  62. : m_type(Type::Register)
  63. , m_index(reg.index())
  64. {
  65. }
  66. }