BasicBlock.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. warn("{}", m_name);
  32. if (m_handler || m_finalizer) {
  33. warn(" [");
  34. if (m_handler)
  35. warn(" Handler: {}", Label { *m_handler });
  36. if (m_finalizer)
  37. warn(" Finalizer: {}", Label { *m_finalizer });
  38. warn(" ]");
  39. }
  40. warnln(":");
  41. while (!it.at_end()) {
  42. warnln("[{:4x}] {}", it.offset(), (*it).to_deprecated_string(executable));
  43. ++it;
  44. }
  45. }
  46. void BasicBlock::grow(size_t additional_size)
  47. {
  48. m_buffer.grow_capacity(m_buffer.size() + additional_size);
  49. m_buffer.resize(m_buffer.size() + additional_size);
  50. }
  51. }