| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-08 12:25:58 +02:00
										 |  |  | #include <LibJS/Bytecode/BasicBlock.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | #include <LibJS/Bytecode/Executable.h>
 | 
					
						
							| 
									
										
										
										
											2023-10-08 12:25:58 +02:00
										 |  |  | #include <LibJS/Bytecode/RegexTable.h>
 | 
					
						
							| 
									
										
										
										
											2023-10-20 12:21:30 +02:00
										 |  |  | #include <LibJS/JIT/Compiler.h>
 | 
					
						
							| 
									
										
										
										
											2023-10-30 22:06:27 +01:00
										 |  |  | #include <LibJS/JIT/NativeExecutable.h>
 | 
					
						
							| 
									
										
										
										
											2023-10-03 08:18:10 +02:00
										 |  |  | #include <LibJS/SourceCode.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS::Bytecode { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-27 13:23:59 +01:00
										 |  |  | JS_DEFINE_ALLOCATOR(Executable); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-03 08:18:10 +02:00
										 |  |  | Executable::Executable( | 
					
						
							|  |  |  |     NonnullOwnPtr<IdentifierTable> identifier_table, | 
					
						
							|  |  |  |     NonnullOwnPtr<StringTable> string_table, | 
					
						
							|  |  |  |     NonnullOwnPtr<RegexTable> regex_table, | 
					
						
							|  |  |  |     NonnullRefPtr<SourceCode const> source_code, | 
					
						
							|  |  |  |     size_t number_of_property_lookup_caches, | 
					
						
							|  |  |  |     size_t number_of_global_variable_caches, | 
					
						
							| 
									
										
										
										
											2023-10-26 10:39:40 +02:00
										 |  |  |     size_t number_of_environment_variable_caches, | 
					
						
							| 
									
										
										
										
											2023-10-03 08:18:10 +02:00
										 |  |  |     size_t number_of_registers, | 
					
						
							|  |  |  |     Vector<NonnullOwnPtr<BasicBlock>> basic_blocks, | 
					
						
							|  |  |  |     bool is_strict_mode) | 
					
						
							|  |  |  |     : basic_blocks(move(basic_blocks)) | 
					
						
							|  |  |  |     , string_table(move(string_table)) | 
					
						
							|  |  |  |     , identifier_table(move(identifier_table)) | 
					
						
							|  |  |  |     , regex_table(move(regex_table)) | 
					
						
							|  |  |  |     , source_code(move(source_code)) | 
					
						
							|  |  |  |     , number_of_registers(number_of_registers) | 
					
						
							|  |  |  |     , is_strict_mode(is_strict_mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     property_lookup_caches.resize(number_of_property_lookup_caches); | 
					
						
							|  |  |  |     global_variable_caches.resize(number_of_global_variable_caches); | 
					
						
							| 
									
										
										
										
											2023-10-26 10:39:40 +02:00
										 |  |  |     environment_variable_caches.resize(number_of_environment_variable_caches); | 
					
						
							| 
									
										
										
										
											2023-10-03 08:18:10 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Executable::~Executable() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | void Executable::dump() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-10-24 14:33:56 +02:00
										 |  |  |     dbgln("\033[33;1mJS::Bytecode::Executable\033[0m ({})", name); | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  |     for (auto& block : basic_blocks) | 
					
						
							| 
									
										
										
										
											2023-03-06 17:16:25 +01:00
										 |  |  |         block->dump(*this); | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  |     if (!string_table->is_empty()) { | 
					
						
							|  |  |  |         outln(); | 
					
						
							|  |  |  |         string_table->dump(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-24 15:34:30 +02:00
										 |  |  |     if (!identifier_table->is_empty()) { | 
					
						
							|  |  |  |         outln(); | 
					
						
							|  |  |  |         identifier_table->dump(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-20 12:21:30 +02:00
										 |  |  | JIT::NativeExecutable const* Executable::get_or_create_native_executable() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!m_did_try_jitting) { | 
					
						
							|  |  |  |         m_did_try_jitting = true; | 
					
						
							|  |  |  |         m_native_executable = JIT::Compiler::compile(*this); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return m_native_executable; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | } |