mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Only provide code generator to CodeTransform.
This commit is contained in:
		
							parent
							
								
									2d5b9036c2
								
							
						
					
					
						commit
						467cbf92bc
					
				| @ -520,7 +520,7 @@ void CompilerContext::appendInlineAssembly( | |||||||
| 		analysisInfo, | 		analysisInfo, | ||||||
| 		*m_asm, | 		*m_asm, | ||||||
| 		m_evmVersion, | 		m_evmVersion, | ||||||
| 		identifierAccess, | 		identifierAccess.generateCode, | ||||||
| 		_system, | 		_system, | ||||||
| 		_optimiserSettings.optimizeStackAllocation | 		_optimiserSettings.optimizeStackAllocation | ||||||
| 	); | 	); | ||||||
|  | |||||||
| @ -702,15 +702,11 @@ bool ContractCompiler::visit(FunctionDefinition const& _function) | |||||||
| bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) | bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) | ||||||
| { | { | ||||||
| 	unsigned startStackHeight = m_context.stackHeight(); | 	unsigned startStackHeight = m_context.stackHeight(); | ||||||
| 	yul::ExternalIdentifierAccess identifierAccess; | 	yul::ExternalIdentifierAccess::CodeGenerator identifierAccessCodeGen = [&]( | ||||||
| 	identifierAccess.resolve = [&](yul::Identifier const& _identifier, yul::IdentifierContext, bool) | 		yul::Identifier const& _identifier, | ||||||
| 	{ | 		yul::IdentifierContext _context, | ||||||
| 		auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier); | 		yul::AbstractAssembly& _assembly | ||||||
| 		if (ref == _inlineAssembly.annotation().externalReferences.end()) | 	) | ||||||
| 			return numeric_limits<size_t>::max(); |  | ||||||
| 		return ref->second.valueSize; |  | ||||||
| 	}; |  | ||||||
| 	identifierAccess.generateCode = [&](yul::Identifier const& _identifier, yul::IdentifierContext _context, yul::AbstractAssembly& _assembly) |  | ||||||
| 	{ | 	{ | ||||||
| 		auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier); | 		auto ref = _inlineAssembly.annotation().externalReferences.find(&_identifier); | ||||||
| 		solAssert(ref != _inlineAssembly.annotation().externalReferences.end(), ""); | 		solAssert(ref != _inlineAssembly.annotation().externalReferences.end(), ""); | ||||||
| @ -918,7 +914,7 @@ bool ContractCompiler::visit(InlineAssembly const& _inlineAssembly) | |||||||
| 		*analysisInfo, | 		*analysisInfo, | ||||||
| 		*m_context.assemblyPtr(), | 		*m_context.assemblyPtr(), | ||||||
| 		m_context.evmVersion(), | 		m_context.evmVersion(), | ||||||
| 		identifierAccess, | 		identifierAccessCodeGen, | ||||||
| 		false, | 		false, | ||||||
| 		m_optimiserSettings.optimizeStackAllocation | 		m_optimiserSettings.optimizeStackAllocation | ||||||
| 	); | 	); | ||||||
|  | |||||||
| @ -37,7 +37,7 @@ void CodeGenerator::assemble( | |||||||
| 	AsmAnalysisInfo& _analysisInfo, | 	AsmAnalysisInfo& _analysisInfo, | ||||||
| 	evmasm::Assembly& _assembly, | 	evmasm::Assembly& _assembly, | ||||||
| 	langutil::EVMVersion _evmVersion, | 	langutil::EVMVersion _evmVersion, | ||||||
| 	ExternalIdentifierAccess const& _identifierAccess, | 	ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen, | ||||||
| 	bool _useNamedLabelsForFunctions, | 	bool _useNamedLabelsForFunctions, | ||||||
| 	bool _optimizeStackAllocation | 	bool _optimizeStackAllocation | ||||||
| ) | ) | ||||||
| @ -51,7 +51,7 @@ void CodeGenerator::assemble( | |||||||
| 		EVMDialect::strictAssemblyForEVM(_evmVersion), | 		EVMDialect::strictAssemblyForEVM(_evmVersion), | ||||||
| 		builtinContext, | 		builtinContext, | ||||||
| 		_optimizeStackAllocation, | 		_optimizeStackAllocation, | ||||||
| 		_identifierAccess, | 		_identifierAccessCodeGen, | ||||||
| 		_useNamedLabelsForFunctions | 		_useNamedLabelsForFunctions | ||||||
| 	); | 	); | ||||||
| 	transform(_parsedData); | 	transform(_parsedData); | ||||||
|  | |||||||
| @ -44,7 +44,7 @@ public: | |||||||
| 		AsmAnalysisInfo& _analysisInfo, | 		AsmAnalysisInfo& _analysisInfo, | ||||||
| 		evmasm::Assembly& _assembly, | 		evmasm::Assembly& _assembly, | ||||||
| 		langutil::EVMVersion _evmVersion, | 		langutil::EVMVersion _evmVersion, | ||||||
| 		ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(), | 		ExternalIdentifierAccess::CodeGenerator _identifierAccess = {}, | ||||||
| 		bool _useNamedLabelsForFunctions = false, | 		bool _useNamedLabelsForFunctions = false, | ||||||
| 		bool _optimizeStackAllocation = false | 		bool _optimizeStackAllocation = false | ||||||
| 	); | 	); | ||||||
|  | |||||||
| @ -61,7 +61,7 @@ CodeTransform::CodeTransform( | |||||||
| 	bool _allowStackOpt, | 	bool _allowStackOpt, | ||||||
| 	EVMDialect const& _dialect, | 	EVMDialect const& _dialect, | ||||||
| 	BuiltinContext& _builtinContext, | 	BuiltinContext& _builtinContext, | ||||||
| 	ExternalIdentifierAccess _identifierAccess, | 	ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen, | ||||||
| 	bool _useNamedLabelsForFunctions, | 	bool _useNamedLabelsForFunctions, | ||||||
| 	shared_ptr<Context> _context, | 	shared_ptr<Context> _context, | ||||||
| 	vector<TypedName> _delayedReturnVariables, | 	vector<TypedName> _delayedReturnVariables, | ||||||
| @ -73,7 +73,7 @@ CodeTransform::CodeTransform( | |||||||
| 	m_builtinContext(_builtinContext), | 	m_builtinContext(_builtinContext), | ||||||
| 	m_allowStackOpt(_allowStackOpt), | 	m_allowStackOpt(_allowStackOpt), | ||||||
| 	m_useNamedLabelsForFunctions(_useNamedLabelsForFunctions), | 	m_useNamedLabelsForFunctions(_useNamedLabelsForFunctions), | ||||||
| 	m_identifierAccess(move(_identifierAccess)), | 	m_identifierAccessCodeGen(move(_identifierAccessCodeGen)), | ||||||
| 	m_context(move(_context)), | 	m_context(move(_context)), | ||||||
| 	m_delayedReturnVariables(move(_delayedReturnVariables)), | 	m_delayedReturnVariables(move(_delayedReturnVariables)), | ||||||
| 	m_functionExitLabel(_functionExitLabel) | 	m_functionExitLabel(_functionExitLabel) | ||||||
| @ -292,10 +292,10 @@ void CodeTransform::operator()(Identifier const& _identifier) | |||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	yulAssert( | 	yulAssert( | ||||||
| 		m_identifierAccess.generateCode, | 		m_identifierAccessCodeGen, | ||||||
| 		"Identifier not found and no external access available." | 		"Identifier not found and no external access available." | ||||||
| 	); | 	); | ||||||
| 	m_identifierAccess.generateCode(_identifier, IdentifierContext::RValue, m_assembly); | 	m_identifierAccessCodeGen(_identifier, IdentifierContext::RValue, m_assembly); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CodeTransform::operator()(Literal const& _literal) | void CodeTransform::operator()(Literal const& _literal) | ||||||
| @ -391,7 +391,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function) | |||||||
| 		m_allowStackOpt, | 		m_allowStackOpt, | ||||||
| 		m_dialect, | 		m_dialect, | ||||||
| 		m_builtinContext, | 		m_builtinContext, | ||||||
| 		m_identifierAccess, | 		m_identifierAccessCodeGen, | ||||||
| 		m_useNamedLabelsForFunctions, | 		m_useNamedLabelsForFunctions, | ||||||
| 		m_context, | 		m_context, | ||||||
| 		_function.returnVariables, | 		_function.returnVariables, | ||||||
| @ -740,10 +740,10 @@ void CodeTransform::generateAssignment(Identifier const& _variableName) | |||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		yulAssert( | 		yulAssert( | ||||||
| 			m_identifierAccess.generateCode, | 			m_identifierAccessCodeGen, | ||||||
| 			"Identifier not found and no external access available." | 			"Identifier not found and no external access available." | ||||||
| 		); | 		); | ||||||
| 		m_identifierAccess.generateCode(_variableName, IdentifierContext::LValue, m_assembly); | 		m_identifierAccessCodeGen(_variableName, IdentifierContext::LValue, m_assembly); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -65,7 +65,7 @@ class CodeTransform | |||||||
| { | { | ||||||
| public: | public: | ||||||
| 	/// Create the code transformer.
 | 	/// Create the code transformer.
 | ||||||
| 	/// @param _identifierAccess used to resolve identifiers external to the inline assembly
 | 	/// @param _identifierAccessCodeGen used to generate code for identifiers external to the inline assembly
 | ||||||
| 	/// As a side-effect of its construction, translates the Yul code and appends it to the
 | 	/// As a side-effect of its construction, translates the Yul code and appends it to the
 | ||||||
| 	/// given assembly.
 | 	/// given assembly.
 | ||||||
| 	/// Throws StackTooDeepError if a variable is not accessible or if a function has too
 | 	/// Throws StackTooDeepError if a variable is not accessible or if a function has too
 | ||||||
| @ -77,7 +77,7 @@ public: | |||||||
| 		EVMDialect const& _dialect, | 		EVMDialect const& _dialect, | ||||||
| 		BuiltinContext& _builtinContext, | 		BuiltinContext& _builtinContext, | ||||||
| 		bool _allowStackOpt = false, | 		bool _allowStackOpt = false, | ||||||
| 		ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(), | 		ExternalIdentifierAccess::CodeGenerator const& _identifierAccessCodeGen = {}, | ||||||
| 		bool _useNamedLabelsForFunctions = false | 		bool _useNamedLabelsForFunctions = false | ||||||
| 	): CodeTransform( | 	): CodeTransform( | ||||||
| 		_assembly, | 		_assembly, | ||||||
| @ -86,7 +86,7 @@ public: | |||||||
| 		_allowStackOpt, | 		_allowStackOpt, | ||||||
| 		_dialect, | 		_dialect, | ||||||
| 		_builtinContext, | 		_builtinContext, | ||||||
| 		_identifierAccess, | 		_identifierAccessCodeGen, | ||||||
| 		_useNamedLabelsForFunctions, | 		_useNamedLabelsForFunctions, | ||||||
| 		nullptr, | 		nullptr, | ||||||
| 		{}, | 		{}, | ||||||
| @ -107,7 +107,7 @@ protected: | |||||||
| 		bool _allowStackOpt, | 		bool _allowStackOpt, | ||||||
| 		EVMDialect const& _dialect, | 		EVMDialect const& _dialect, | ||||||
| 		BuiltinContext& _builtinContext, | 		BuiltinContext& _builtinContext, | ||||||
| 		ExternalIdentifierAccess _identifierAccess, | 		ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen, | ||||||
| 		bool _useNamedLabelsForFunctions, | 		bool _useNamedLabelsForFunctions, | ||||||
| 		std::shared_ptr<Context> _context, | 		std::shared_ptr<Context> _context, | ||||||
| 		std::vector<TypedName> _delayedReturnVariables, | 		std::vector<TypedName> _delayedReturnVariables, | ||||||
| @ -193,7 +193,7 @@ private: | |||||||
| 	BuiltinContext& m_builtinContext; | 	BuiltinContext& m_builtinContext; | ||||||
| 	bool const m_allowStackOpt = true; | 	bool const m_allowStackOpt = true; | ||||||
| 	bool const m_useNamedLabelsForFunctions = false; | 	bool const m_useNamedLabelsForFunctions = false; | ||||||
| 	ExternalIdentifierAccess m_identifierAccess; | 	ExternalIdentifierAccess::CodeGenerator m_identifierAccessCodeGen; | ||||||
| 	std::shared_ptr<Context> m_context; | 	std::shared_ptr<Context> m_context; | ||||||
| 
 | 
 | ||||||
| 	/// Set of variables whose reference counter has reached zero,
 | 	/// Set of variables whose reference counter has reached zero,
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user