| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  |  * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-08 19:23:00 -05:00
										 |  |  | #include <AK/DeprecatedFlyString.h>
 | 
					
						
							| 
									
										
										
										
											2023-10-19 23:18:54 +02:00
										 |  |  | #include <AK/HashMap.h>
 | 
					
						
							| 
									
										
										
										
											2023-03-06 17:39:59 +01:00
										 |  |  | #include <AK/NonnullOwnPtr.h>
 | 
					
						
							| 
									
										
										
										
											2023-10-20 12:21:30 +02:00
										 |  |  | #include <AK/OwnPtr.h>
 | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  | #include <AK/WeakPtr.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-24 15:34:30 +02:00
										 |  |  | #include <LibJS/Bytecode/IdentifierTable.h>
 | 
					
						
							| 
									
										
										
										
											2023-10-19 23:18:54 +02:00
										 |  |  | #include <LibJS/Bytecode/Label.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | #include <LibJS/Bytecode/StringTable.h>
 | 
					
						
							| 
									
										
										
										
											2023-10-08 12:25:58 +02:00
										 |  |  | #include <LibJS/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-27 13:23:59 +01:00
										 |  |  | #include <LibJS/Heap/Cell.h>
 | 
					
						
							|  |  |  | #include <LibJS/Heap/CellAllocator.h>
 | 
					
						
							| 
									
										
										
										
											2023-10-26 10:39:40 +02:00
										 |  |  | #include <LibJS/Runtime/EnvironmentCoordinate.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS::Bytecode { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  | struct PropertyLookupCache { | 
					
						
							| 
									
										
										
										
											2023-11-09 09:28:04 +01:00
										 |  |  |     static FlatPtr shape_offset() { return OFFSET_OF(PropertyLookupCache, shape); } | 
					
						
							|  |  |  |     static FlatPtr property_offset_offset() { return OFFSET_OF(PropertyLookupCache, property_offset); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  |     WeakPtr<Shape> shape; | 
					
						
							|  |  |  |     Optional<u32> property_offset; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-12 04:06:59 +02:00
										 |  |  | struct GlobalVariableCache : public PropertyLookupCache { | 
					
						
							| 
									
										
										
										
											2023-11-13 01:44:39 +00:00
										 |  |  |     static FlatPtr environment_serial_number_offset() { return OFFSET_OF(GlobalVariableCache, environment_serial_number); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-12 04:06:59 +02:00
										 |  |  |     u64 environment_serial_number { 0 }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 15:14:54 +01:00
										 |  |  | using EnvironmentVariableCache = Optional<EnvironmentCoordinate>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 16:53:55 +02:00
										 |  |  | struct SourceRecord { | 
					
						
							|  |  |  |     u32 source_start_offset {}; | 
					
						
							|  |  |  |     u32 source_end_offset {}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-27 13:23:59 +01:00
										 |  |  | class Executable final : public Cell { | 
					
						
							|  |  |  |     JS_CELL(Executable, Cell); | 
					
						
							|  |  |  |     JS_DECLARE_ALLOCATOR(Executable); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-03 08:18:10 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     Executable( | 
					
						
							|  |  |  |         NonnullOwnPtr<IdentifierTable>, | 
					
						
							|  |  |  |         NonnullOwnPtr<StringTable>, | 
					
						
							|  |  |  |         NonnullOwnPtr<RegexTable>, | 
					
						
							| 
									
										
										
										
											2024-02-02 09:52:25 +01:00
										 |  |  |         Vector<Value> constants, | 
					
						
							| 
									
										
										
										
											2023-10-03 08:18:10 +02:00
										 |  |  |         NonnullRefPtr<SourceCode const>, | 
					
						
							|  |  |  |         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>>, | 
					
						
							|  |  |  |         bool is_strict_mode); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-27 13:23:59 +01:00
										 |  |  |     virtual ~Executable() override; | 
					
						
							| 
									
										
										
										
											2023-10-03 08:18:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-08 19:23:00 -05:00
										 |  |  |     DeprecatedFlyString name; | 
					
						
							| 
									
										
										
										
											2023-07-08 17:43:26 +02:00
										 |  |  |     Vector<PropertyLookupCache> property_lookup_caches; | 
					
						
							| 
									
										
										
										
											2023-07-12 04:06:59 +02:00
										 |  |  |     Vector<GlobalVariableCache> global_variable_caches; | 
					
						
							| 
									
										
										
										
											2023-11-05 15:14:54 +01:00
										 |  |  |     Vector<EnvironmentVariableCache> environment_variable_caches; | 
					
						
							| 
									
										
										
										
											2023-03-06 17:16:25 +01:00
										 |  |  |     Vector<NonnullOwnPtr<BasicBlock>> basic_blocks; | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  |     NonnullOwnPtr<StringTable> string_table; | 
					
						
							| 
									
										
										
										
											2021-10-24 15:34:30 +02:00
										 |  |  |     NonnullOwnPtr<IdentifierTable> identifier_table; | 
					
						
							| 
									
										
										
										
											2023-07-13 10:49:07 +02:00
										 |  |  |     NonnullOwnPtr<RegexTable> regex_table; | 
					
						
							| 
									
										
										
										
											2024-02-02 09:52:25 +01:00
										 |  |  |     Vector<Value> constants; | 
					
						
							| 
									
										
										
										
											2023-10-19 23:18:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 16:53:55 +02:00
										 |  |  |     NonnullRefPtr<SourceCode const> source_code; | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  |     size_t number_of_registers { 0 }; | 
					
						
							| 
									
										
										
										
											2022-07-17 18:56:36 +01:00
										 |  |  |     bool is_strict_mode { false }; | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-16 17:49:34 +03:30
										 |  |  |     ByteString const& get_string(StringTableIndex index) const { return string_table->get(index); } | 
					
						
							| 
									
										
										
										
											2023-01-08 19:23:00 -05:00
										 |  |  |     DeprecatedFlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); } | 
					
						
							| 
									
										
										
										
											2021-10-24 13:30:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void dump() const; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |