/* * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include namespace JS::Bytecode { template concept HasVariableLength = Op::IsVariableLength; template concept HasFixedLength = !Op::IsVariableLength; template size_t get_length_impl(Op const& op) { return op.length_impl(); } // Function template for types without a length_impl method template size_t get_length_impl(Op const&) { return sizeof(Op); } size_t Instruction::length() const { #define __BYTECODE_OP(op) \ case Type::op: { \ auto& typed_op = static_cast(*this); \ return get_length_impl(typed_op); \ } switch (type()) { ENUMERATE_BYTECODE_OPS(__BYTECODE_OP) default: VERIFY_NOT_REACHED(); } #undef __BYTECODE_OP } }