BasicBlock.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/DeprecatedString.h>
  7. #include <LibJS/Bytecode/BasicBlock.h>
  8. #include <LibJS/Bytecode/Op.h>
  9. namespace JS::Bytecode {
  10. NonnullOwnPtr<BasicBlock> BasicBlock::create(DeprecatedString name)
  11. {
  12. return adopt_own(*new BasicBlock(move(name)));
  13. }
  14. BasicBlock::BasicBlock(DeprecatedString name)
  15. : m_name(move(name))
  16. {
  17. }
  18. BasicBlock::~BasicBlock()
  19. {
  20. Bytecode::InstructionStreamIterator it(instruction_stream());
  21. while (!it.at_end()) {
  22. auto& to_destroy = (*it);
  23. ++it;
  24. Instruction::destroy(const_cast<Instruction&>(to_destroy));
  25. }
  26. }
  27. void BasicBlock::dump(Bytecode::Executable const& executable) const
  28. {
  29. Bytecode::InstructionStreamIterator it(instruction_stream());
  30. if (!m_name.is_empty())
  31. warnln("{}:", m_name);
  32. while (!it.at_end()) {
  33. warnln("[{:4x}] {}", it.offset(), (*it).to_deprecated_string(executable));
  34. ++it;
  35. }
  36. }
  37. void BasicBlock::grow(size_t additional_size)
  38. {
  39. m_buffer.grow_capacity(m_buffer.size() + additional_size);
  40. m_buffer.resize(m_buffer.size() + additional_size);
  41. }
  42. }