Block.cpp 813 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/Op.h>
  8. namespace JS::Bytecode {
  9. NonnullOwnPtr<Block> Block::create()
  10. {
  11. return adopt_own(*new Block);
  12. }
  13. Block::~Block()
  14. {
  15. Bytecode::InstructionStreamIterator it(instruction_stream());
  16. while (!it.at_end()) {
  17. auto& to_destroy = (*it);
  18. ++it;
  19. Instruction::destroy(const_cast<Instruction&>(to_destroy));
  20. }
  21. }
  22. void Block::dump() const
  23. {
  24. Bytecode::InstructionStreamIterator it(instruction_stream());
  25. while (!it.at_end()) {
  26. warnln("[{:4x}] {}", it.offset(), (*it).to_string());
  27. ++it;
  28. }
  29. }
  30. void InstructionStreamIterator::operator++()
  31. {
  32. m_offset += dereference().length();
  33. }
  34. }