Consolidate: spvOpcodeIsType into spvOpcodeGeneratesType
authorDavid Neto <dneto@google.com>
Mon, 2 Nov 2015 19:59:02 +0000 (14:59 -0500)
committerDavid Neto <dneto@google.com>
Tue, 10 Nov 2015 20:56:54 +0000 (15:56 -0500)
And fix the spvOpcodeGeneratesType: OpTypeForwardPointer
does not generate a new type.

source/binary.cpp
source/opcode.cpp
source/opcode.h
source/validate_id.cpp

index edce883..2160596 100644 (file)
@@ -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];
index 60f1ceb..afb362b 100644 (file)
@@ -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;
 }
index 2fd7a58..d9d9c60 100644 (file)
@@ -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
index 573f8e6..600d1b1 100644 (file)
@@ -376,7 +376,7 @@ bool idUsage::isValid<SpvOpTypeArray>(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 <id> '"
                                   << inst->words[elementTypeIndex]
                                   << "' is not a type.";
@@ -444,7 +444,7 @@ bool idUsage::isValid<SpvOpTypeRuntimeArray>(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 <id> '"
                                   << inst->words[elementTypeIndex]
                                   << "' is not a type.";
@@ -463,7 +463,7 @@ bool idUsage::isValid<SpvOpTypeStruct>(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 <id> '"
                                    << inst->words[memberTypeIndex]
                                    << "' is not a type.";
@@ -481,7 +481,7 @@ bool idUsage::isValid<SpvOpTypePointer>(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 <id> '"
                            << inst->words[typeIndex] << "' is not a type.";
            return false);
@@ -498,7 +498,7 @@ bool idUsage::isValid<SpvOpTypeFunction>(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 <id> '"
                                  << inst->words[returnTypeIndex]
                                  << "' is not a type.";
@@ -511,7 +511,7 @@ bool idUsage::isValid<SpvOpTypeFunction>(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 <id> '"
                                   << inst->words[paramTypeIndex]
                                   << "' is not a type.";