BasicBlock.cpp 880 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/String.h>
  7. #include <LibJS/Bytecode/BasicBlock.h>
  8. #include <LibJS/Bytecode/Op.h>
  9. namespace JS::Bytecode {
  10. NonnullOwnPtr<BasicBlock> BasicBlock::create(u32 index, String name)
  11. {
  12. return adopt_own(*new BasicBlock(index, move(name)));
  13. }
  14. BasicBlock::BasicBlock(u32 index, String name)
  15. : m_index(index)
  16. , m_name(move(name))
  17. {
  18. }
  19. BasicBlock::~BasicBlock()
  20. {
  21. Bytecode::InstructionStreamIterator it(instruction_stream());
  22. while (!it.at_end()) {
  23. auto& to_destroy = (*it);
  24. ++it;
  25. Instruction::destroy(const_cast<Instruction&>(to_destroy));
  26. }
  27. }
  28. void BasicBlock::grow(size_t additional_size)
  29. {
  30. m_buffer.grow_capacity(m_buffer.size() + additional_size);
  31. m_buffer.resize(m_buffer.size() + additional_size);
  32. }
  33. }