SpirvShader: Move type declaration out to its own function

Reduces function size, increases readability.

Bug: b/126126820
Change-Id: I073dd40114d3c5e6e7c6088db9fc8f2a0b9d8bac
Reviewed-on: https://swiftshader-review.googlesource.com/c/25550
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index c8b57d7..42d4d89 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -115,54 +115,8 @@
 			case spv::OpTypeStruct:
 			case spv::OpTypePointer:
 			case spv::OpTypeFunction:
-			{
-				TypeID resultId = insn.word(1);
-				auto &type = types[resultId];
-				type.definition = insn;
-				type.sizeInComponents = ComputeTypeSize(insn);
-
-				// A structure is a builtin block if it has a builtin
-				// member. All members of such a structure are builtins.
-				switch (insn.opcode())
-				{
-				case spv::OpTypeStruct:
-				{
-					auto d = memberDecorations.find(resultId);
-					if (d != memberDecorations.end())
-					{
-						for (auto &m : d->second)
-						{
-							if (m.HasBuiltIn)
-							{
-								type.isBuiltInBlock = true;
-								break;
-							}
-						}
-					}
-					break;
-				}
-				case spv::OpTypePointer:
-				{
-					TypeID elementTypeId = insn.word(3);
-					type.element = elementTypeId;
-					type.isBuiltInBlock = getType(elementTypeId).isBuiltInBlock;
-					type.storageClass = static_cast<spv::StorageClass>(insn.word(2));
-					break;
-				}
-				case spv::OpTypeVector:
-				case spv::OpTypeMatrix:
-				case spv::OpTypeArray:
-				case spv::OpTypeRuntimeArray:
-				{
-					TypeID elementTypeId = insn.word(2);
-					type.element = elementTypeId;
-					break;
-				}
-				default:
-					break;
-				}
+				DeclareType(insn);
 				break;
-			}
 
 			case spv::OpVariable:
 			{
@@ -299,6 +253,56 @@
 		}
 	}
 
+	void SpirvShader::DeclareType(InsnIterator insn)
+	{
+		TypeID resultId = insn.word(1);
+
+		auto &type = types[resultId];
+		type.definition = insn;
+		type.sizeInComponents = ComputeTypeSize(insn);
+
+		// A structure is a builtin block if it has a builtin
+		// member. All members of such a structure are builtins.
+		switch (insn.opcode())
+		{
+		case spv::OpTypeStruct:
+		{
+			auto d = memberDecorations.find(resultId);
+			if (d != memberDecorations.end())
+			{
+				for (auto &m : d->second)
+				{
+					if (m.HasBuiltIn)
+					{
+						type.isBuiltInBlock = true;
+						break;
+					}
+				}
+			}
+			break;
+		}
+		case spv::OpTypePointer:
+		{
+			TypeID elementTypeId = insn.word(3);
+			type.element = elementTypeId;
+			type.isBuiltInBlock = getType(elementTypeId).isBuiltInBlock;
+			type.storageClass = static_cast<spv::StorageClass>(insn.word(2));
+			break;
+		}
+		case spv::OpTypeVector:
+		case spv::OpTypeMatrix:
+		case spv::OpTypeArray:
+		case spv::OpTypeRuntimeArray:
+		{
+			TypeID elementTypeId = insn.word(2);
+			type.element = elementTypeId;
+			break;
+		}
+		default:
+			break;
+		}
+	}
+
 	SpirvShader::Object& SpirvShader::CreateConstant(InsnIterator insn)
 	{
 		TypeID typeId = insn.word(1);
diff --git a/src/Pipeline/SpirvShader.hpp b/src/Pipeline/SpirvShader.hpp
index 3b8d055..64d4fd7 100644
--- a/src/Pipeline/SpirvShader.hpp
+++ b/src/Pipeline/SpirvShader.hpp
@@ -357,6 +357,10 @@
 		HandleMap<Type> types;
 		HandleMap<Object> defs;
 
+		// DeclareType creates a Type for the given OpTypeX instruction, storing
+		// it into the types map. It is called from the analysis pass (constructor).
+		void DeclareType(InsnIterator insn);
+
 		void ProcessExecutionMode(InsnIterator it);
 
 		uint32_t ComputeTypeSize(InsnIterator insn);