Instruction.cpp 927 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Bytecode/Instruction.h>
  7. #include <LibJS/Bytecode/Op.h>
  8. namespace JS::Bytecode {
  9. void Instruction::destroy(Instruction& instruction)
  10. {
  11. #define __BYTECODE_OP(op) \
  12. case Type::op: \
  13. static_cast<Op::op&>(instruction).~op(); \
  14. return;
  15. switch (instruction.type()) {
  16. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  17. default:
  18. VERIFY_NOT_REACHED();
  19. }
  20. #undef __BYTECODE_OP
  21. }
  22. size_t Instruction::length() const
  23. {
  24. if (type() == Type::Call)
  25. return static_cast<Op::Call const&>(*this).length();
  26. #define __BYTECODE_OP(op) \
  27. case Type::op: \
  28. return sizeof(Op::op);
  29. switch (type()) {
  30. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  31. default:
  32. VERIFY_NOT_REACHED();
  33. }
  34. }
  35. }