| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 18:29:30 +02:00
										 |  |  | #include <AK/Format.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS::Bytecode { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Register { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     constexpr static u32 accumulator_index = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static Register accumulator() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         static Register accumulator(accumulator_index); | 
					
						
							|  |  |  |         return accumulator; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  |     explicit Register(u32 index) | 
					
						
							|  |  |  |         : m_index(index) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     u32 index() const { return m_index; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |     u32 m_index; | 
					
						
							| 
									
										
										
										
											2021-06-03 10:46:30 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-06-03 18:29:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | struct AK::Formatter<JS::Bytecode::Register> : AK::Formatter<FormatString> { | 
					
						
							|  |  |  |     void format(FormatBuilder& builder, JS::Bytecode::Register const& value) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-06-07 20:58:36 -07:00
										 |  |  |         if (value.index() == JS::Bytecode::Register::accumulator_index) | 
					
						
							|  |  |  |             return AK::Formatter<FormatString>::format(builder, "acc"); | 
					
						
							| 
									
										
										
										
											2021-06-04 12:02:31 +02:00
										 |  |  |         return AK::Formatter<FormatString>::format(builder, "${}", value.index()); | 
					
						
							| 
									
										
										
										
											2021-06-03 18:29:30 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | }; |