Instruction.cpp 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Bytecode/Block.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. size_t Instruction::length() const
  24. {
  25. if (type() == Type::Call)
  26. return static_cast<Op::Call const&>(*this).length();
  27. #define __BYTECODE_OP(op) \
  28. case Type::op: \
  29. return sizeof(Op::op);
  30. switch (type()) {
  31. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  32. default:
  33. VERIFY_NOT_REACHED();
  34. }
  35. }
  36. }