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