mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:42:45 +00:00 
			
		
		
		
	JSSpecCompiler: Store arguments in declaration instead of definition
And create a struct encapsulating argument name in the preparation for argument types and optional arguments.
This commit is contained in:
		
							parent
							
								
									0806ccaeec
								
							
						
					
					
						commit
						483e195e48
					
				
					 8 changed files with 57 additions and 40 deletions
				
			
		|  | @ -14,8 +14,8 @@ namespace JSSpecCompiler { | |||
| 
 | ||||
| void ReferenceResolvingPass::process_function() | ||||
| { | ||||
|     for (auto name : m_function->m_argument_names) | ||||
|         m_function->m_local_variables.set(name, make_ref_counted<NamedVariableDeclaration>(name)); | ||||
|     for (auto argument : m_function->m_arguments) | ||||
|         m_function->m_local_variables.set(argument.name, make_ref_counted<NamedVariableDeclaration>(argument.name)); | ||||
|     GenericASTPass::process_function(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -430,16 +430,16 @@ void SSABuildingPass::rename_variables(Vertex u, Vertex from) | |||
| void SSABuildingPass::rename_variables() | ||||
| { | ||||
|     HashMap<StringView, size_t> argument_index_by_name; | ||||
|     for (size_t i = 0; i < m_function->m_argument_names.size(); ++i) | ||||
|         argument_index_by_name.set(m_function->m_argument_names[i], i); | ||||
|     m_function->m_arguments.resize(m_function->m_argument_names.size()); | ||||
|     for (size_t i = 0; i < m_function->m_arguments.size(); ++i) | ||||
|         argument_index_by_name.set(m_function->m_arguments[i].name, i); | ||||
|     m_function->m_ssa_arguments.resize(m_function->m_arguments.size()); | ||||
| 
 | ||||
|     for (auto const& [name, var_decl] : m_function->m_local_variables) { | ||||
|         make_new_ssa_variable_for(var_decl); | ||||
| 
 | ||||
|         if (auto maybe_index = argument_index_by_name.get(name); maybe_index.has_value()) { | ||||
|             size_t index = maybe_index.value(); | ||||
|             m_function->m_arguments[index] = m_def_stack.get(var_decl).value()[0]; | ||||
|             m_function->m_ssa_arguments[index] = m_def_stack.get(var_decl).value()[0]; | ||||
|         } | ||||
|     } | ||||
|     make_new_ssa_variable_for(m_function->m_named_return_value); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Klishch
						Dan Klishch