mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-31 13:20:59 +00:00 
			
		
		
		
	 3a73eb99ac
			
		
	
	
		3a73eb99ac
		
	
	
	
	
		
			
			Instead of storing a BasicBlock* and forcing the size of Label to be sizeof(BasicBlock*), we now store the basic block index as a u32. This means the final version of the bytecode is able to keep labels at sizeof(u32), shrinking the size of many instructions. :^)
		
			
				
	
	
		
			44 lines
		
	
	
	
		
			1,000 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
	
		
			1,000 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/Format.h>
 | |
| 
 | |
| namespace JS::Bytecode {
 | |
| 
 | |
| class BasicBlock;
 | |
| 
 | |
| class Label {
 | |
| public:
 | |
|     explicit Label(BasicBlock const&);
 | |
| 
 | |
|     explicit Label(u32 basic_block_index)
 | |
|         : m_address_or_basic_block_index(basic_block_index)
 | |
|     {
 | |
|     }
 | |
| 
 | |
|     // Used while compiling.
 | |
|     size_t basic_block_index() const { return m_address_or_basic_block_index; }
 | |
| 
 | |
|     // Used after compiling.
 | |
|     size_t address() const { return m_address_or_basic_block_index; }
 | |
| 
 | |
|     void set_address(size_t address) { m_address_or_basic_block_index = address; }
 | |
| 
 | |
| private:
 | |
|     u32 m_address_or_basic_block_index { 0 };
 | |
| };
 | |
| 
 | |
| }
 | |
| 
 | |
| template<>
 | |
| struct AK::Formatter<JS::Bytecode::Label> : AK::Formatter<FormatString> {
 | |
|     ErrorOr<void> format(FormatBuilder& builder, JS::Bytecode::Label const& label)
 | |
|     {
 | |
|         return AK::Formatter<FormatString>::format(builder, "@{:x}"sv, label.address());
 | |
|     }
 | |
| };
 |