From aef608c40d65d24bc30cfaac8039e3b5403ff16c Mon Sep 17 00:00:00 2001 From: David Neto Date: Mon, 2 Nov 2015 14:59:02 -0500 Subject: [PATCH] Consolidate: spvOpcodeIsType into spvOpcodeGeneratesType And fix the spvOpcodeGeneratesType: OpTypeForwardPointer does not generate a new type. --- source/binary.cpp | 2 +- source/opcode.cpp | 34 +++++----------------------------- source/opcode.h | 7 ------- source/validate_id.cpp | 12 ++++++------ 4 files changed, 12 insertions(+), 43 deletions(-) diff --git a/source/binary.cpp b/source/binary.cpp index edce883..2160596 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -324,7 +324,7 @@ spv_result_t spvRegisterIdForOpcode(const spv_instruction_t* pInst, spv_position position, spv_diagnostic* pDiagnostic) { libspirv::IdType detected_type = libspirv::kUnknownType; - if (spvOpcodeIsType(pOpcodeEntry->opcode)) { + if (spvOpcodeGeneratesType(pOpcodeEntry->opcode)) { if (SpvOpTypeInt == pOpcodeEntry->opcode) { detected_type.type_class = libspirv::IdTypeClass::kScalarIntegerType; detected_type.bitwidth = pInst->words[2]; diff --git a/source/opcode.cpp b/source/opcode.cpp index 60f1ceb..afb362b 100644 --- a/source/opcode.cpp +++ b/source/opcode.cpp @@ -625,33 +625,6 @@ const char* spvOpcodeString(const SpvOp opcode) { return "unknown"; } -int32_t spvOpcodeIsType(const SpvOp opcode) { - switch (opcode) { - case SpvOpTypeVoid: - case SpvOpTypeBool: - case SpvOpTypeInt: - case SpvOpTypeFloat: - case SpvOpTypeVector: - case SpvOpTypeMatrix: - case SpvOpTypeSampler: - case SpvOpTypeSampledImage: - case SpvOpTypeArray: - case SpvOpTypeRuntimeArray: - case SpvOpTypeStruct: - case SpvOpTypeOpaque: - case SpvOpTypePointer: - case SpvOpTypeFunction: - case SpvOpTypeEvent: - case SpvOpTypeDeviceEvent: - case SpvOpTypeReserveId: - case SpvOpTypeQueue: - case SpvOpTypePipe: - return true; - default: - return false; - } -} - int32_t spvOpcodeIsScalarType(const SpvOp opcode) { switch (opcode) { case SpvOpTypeInt: @@ -888,9 +861,12 @@ int32_t spvOpcodeGeneratesType(SpvOp op) { case SpvOpTypeReserveId: case SpvOpTypeQueue: case SpvOpTypePipe: - case SpvOpTypeForwardPointer: return true; - default:; + default: + // In particular, OpTypeForwardPointer does not generate a type, + // but declares a storage class for a pointer type generated + // by a different instruction. + break; } return 0; } diff --git a/source/opcode.h b/source/opcode.h index 2fd7a58..d9d9c60 100644 --- a/source/opcode.h +++ b/source/opcode.h @@ -118,13 +118,6 @@ void spvInstructionCopy(const uint32_t* words, const SpvOp opcode, /// @return the opcode string const char* spvOpcodeString(const SpvOp opcode); -/// @brief Determine if the Opcode is a type -/// -/// @param[in] opcode the opcode -/// -/// @return zero if false, non-zero otherwise -int32_t spvOpcodeIsType(const SpvOp opcode); - /// @brief Determine if the OpCode is a scalar type /// /// @param[in] opcode the opcode diff --git a/source/validate_id.cpp b/source/validate_id.cpp index 573f8e6..600d1b1 100644 --- a/source/validate_id.cpp +++ b/source/validate_id.cpp @@ -376,7 +376,7 @@ bool idUsage::isValid(const spv_instruction_t* inst, << inst->words[elementTypeIndex] << "' is not defined."; return false); - spvCheck(!spvOpcodeIsType(elementType->second.opcode), + spvCheck(!spvOpcodeGeneratesType(elementType->second.opcode), DIAG(elementTypeIndex) << "OpTypeArray Element Type '" << inst->words[elementTypeIndex] << "' is not a type."; @@ -444,7 +444,7 @@ bool idUsage::isValid(const spv_instruction_t* inst, << inst->words[elementTypeIndex] << "' is not defined."; return false); - spvCheck(!spvOpcodeIsType(elementType->second.opcode), + spvCheck(!spvOpcodeGeneratesType(elementType->second.opcode), DIAG(elementTypeIndex) << "OpTypeRuntimeArray Element Type '" << inst->words[elementTypeIndex] << "' is not a type."; @@ -463,7 +463,7 @@ bool idUsage::isValid(const spv_instruction_t* inst, << inst->words[memberTypeIndex] << "' is not defined."; return false); - spvCheck(!spvOpcodeIsType(memberType->second.opcode), + spvCheck(!spvOpcodeGeneratesType(memberType->second.opcode), DIAG(memberTypeIndex) << "OpTypeStruct Member Type '" << inst->words[memberTypeIndex] << "' is not a type."; @@ -481,7 +481,7 @@ bool idUsage::isValid(const spv_instruction_t* inst, << inst->words[typeIndex] << "' is not defined."; return false); - spvCheck(!spvOpcodeIsType(type->second.opcode), + spvCheck(!spvOpcodeGeneratesType(type->second.opcode), DIAG(typeIndex) << "OpTypePointer Type '" << inst->words[typeIndex] << "' is not a type."; return false); @@ -498,7 +498,7 @@ bool idUsage::isValid(const spv_instruction_t* inst, << inst->words[returnTypeIndex] << "' is not defined"; return false); - spvCheck(!spvOpcodeIsType(returnType->second.opcode), + spvCheck(!spvOpcodeGeneratesType(returnType->second.opcode), DIAG(returnTypeIndex) << "OpTypeFunction Return Type '" << inst->words[returnTypeIndex] << "' is not a type."; @@ -511,7 +511,7 @@ bool idUsage::isValid(const spv_instruction_t* inst, << inst->words[paramTypeIndex] << "' is not defined."; return false); - spvCheck(!spvOpcodeIsType(paramType->second.opcode), + spvCheck(!spvOpcodeGeneratesType(paramType->second.opcode), DIAG(paramTypeIndex) << "OpTypeFunction Parameter Type '" << inst->words[paramTypeIndex] << "' is not a type."; -- 2.7.4