Instruction.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. void Instruction::destroy(Instruction& instruction)
  11. {
  12. #define __BYTECODE_OP(op) \
  13. case Type::op: \
  14. static_cast<Op::op&>(instruction).~op(); \
  15. return;
  16. switch (instruction.type()) {
  17. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  18. default:
  19. VERIFY_NOT_REACHED();
  20. }
  21. #undef __BYTECODE_OP
  22. }
  23. UnrealizedSourceRange InstructionStreamIterator::source_range() const
  24. {
  25. VERIFY(m_executable);
  26. auto record = dereference().source_record();
  27. return {
  28. .source_code = m_executable->source_code,
  29. .start_offset = record.source_start_offset,
  30. .end_offset = record.source_end_offset,
  31. };
  32. }
  33. RefPtr<SourceCode> InstructionStreamIterator::source_code() const
  34. {
  35. return m_executable ? m_executable->source_code.ptr() : nullptr;
  36. }
  37. }