| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-26 23:57:51 -04:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  | #include <LibJS/Bytecode/BasicBlock.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  | #include <LibJS/Bytecode/Op.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS::Bytecode { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-06 08:06:56 +02:00
										 |  |  | NonnullOwnPtr<BasicBlock> BasicBlock::create(u32 index, String name) | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-05-06 08:06:56 +02:00
										 |  |  |     return adopt_own(*new BasicBlock(index, move(name))); | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-06 08:06:56 +02:00
										 |  |  | BasicBlock::BasicBlock(u32 index, String name) | 
					
						
							|  |  |  |     : m_index(index) | 
					
						
							|  |  |  |     , m_name(move(name)) | 
					
						
							| 
									
										
										
										
											2021-06-09 00:50:42 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  | BasicBlock::~BasicBlock() | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-06-07 15:12:43 +02:00
										 |  |  |     Bytecode::InstructionStreamIterator it(instruction_stream()); | 
					
						
							|  |  |  |     while (!it.at_end()) { | 
					
						
							|  |  |  |         auto& to_destroy = (*it); | 
					
						
							|  |  |  |         ++it; | 
					
						
							|  |  |  |         Instruction::destroy(const_cast<Instruction&>(to_destroy)); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-06-07 15:24:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  | void BasicBlock::grow(size_t additional_size) | 
					
						
							| 
									
										
										
										
											2021-06-09 00:50:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-09-30 09:33:11 +02:00
										 |  |  |     m_buffer.grow_capacity(m_buffer.size() + additional_size); | 
					
						
							| 
									
										
										
										
											2023-09-28 09:29:42 +02:00
										 |  |  |     m_buffer.resize(m_buffer.size() + additional_size); | 
					
						
							| 
									
										
										
										
											2021-06-09 00:50:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | } |