#undef CASE
#undef CASE_CAP
+// Evaluates to the number of elements of array A.
+// If we could use constexpr, then we could make this a template function.
+// If the source arrays were std::array, then we could have used
+// std::array::size.
+#define ARRAY_SIZE(A) (static_cast<uint32_t>(sizeof(A)/sizeof(A[0])))
+
static const spv_operand_desc_group_t opcodeEntryTypes[] = {
+ // TODO(dneto): Reformat this table.
{SPV_OPERAND_TYPE_SOURCE_LANGUAGE,
- sizeof(sourceLanguageEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(sourceLanguageEntries),
sourceLanguageEntries},
{SPV_OPERAND_TYPE_EXECUTION_MODEL,
- sizeof(executionModelEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(executionModelEntries),
executionModelEntries},
{SPV_OPERAND_TYPE_ADDRESSING_MODEL,
- sizeof(addressingModelEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(addressingModelEntries),
addressingModelEntries},
{SPV_OPERAND_TYPE_MEMORY_MODEL,
- sizeof(memoryModelEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(memoryModelEntries),
memoryModelEntries},
{SPV_OPERAND_TYPE_EXECUTION_MODE,
- sizeof(executionModeEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(executionModeEntries),
executionModeEntries},
{SPV_OPERAND_TYPE_STORAGE_CLASS,
- sizeof(storageClassEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(storageClassEntries),
storageClassEntries},
{SPV_OPERAND_TYPE_DIMENSIONALITY,
- sizeof(dimensionalityEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(dimensionalityEntries),
dimensionalityEntries},
{SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE,
- sizeof(samplerAddressingModeEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(samplerAddressingModeEntries),
samplerAddressingModeEntries},
{SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE,
- sizeof(samplerFilterModeEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(samplerFilterModeEntries),
samplerFilterModeEntries},
{SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT,
- sizeof(samplerImageFormatEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(samplerImageFormatEntries),
samplerImageFormatEntries},
{SPV_OPERAND_TYPE_IMAGE_CHANNEL_ORDER,
- sizeof(imageChannelOrderEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(imageChannelOrderEntries),
imageChannelOrderEntries},
{SPV_OPERAND_TYPE_IMAGE_CHANNEL_DATA_TYPE,
- sizeof(imageChannelDataTypeEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(imageChannelDataTypeEntries),
imageChannelDataTypeEntries},
{SPV_OPERAND_TYPE_IMAGE,
- sizeof(imageOperandEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(imageOperandEntries),
imageOperandEntries},
{SPV_OPERAND_TYPE_OPTIONAL_IMAGE, // Same as *_IMAGE
- sizeof(imageOperandEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(imageOperandEntries),
imageOperandEntries},
{SPV_OPERAND_TYPE_FP_FAST_MATH_MODE,
- sizeof(fpFastMathModeEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(fpFastMathModeEntries),
fpFastMathModeEntries},
{SPV_OPERAND_TYPE_FP_ROUNDING_MODE,
- sizeof(fpRoundingModeEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(fpRoundingModeEntries),
fpRoundingModeEntries},
{SPV_OPERAND_TYPE_LINKAGE_TYPE,
- sizeof(linkageTypeEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(linkageTypeEntries),
linkageTypeEntries},
{SPV_OPERAND_TYPE_ACCESS_QUALIFIER,
- sizeof(accessQualifierEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(accessQualifierEntries),
accessQualifierEntries},
{SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE,
- sizeof(functionParameterAttributeEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(functionParameterAttributeEntries),
functionParameterAttributeEntries},
{SPV_OPERAND_TYPE_DECORATION,
- sizeof(decorationEntries) / sizeof(spv_operand_desc_t), decorationEntries},
+ ARRAY_SIZE(decorationEntries), decorationEntries},
{SPV_OPERAND_TYPE_BUILT_IN,
- sizeof(builtInEntries) / sizeof(spv_operand_desc_t), builtInEntries},
+ ARRAY_SIZE(builtInEntries), builtInEntries},
{SPV_OPERAND_TYPE_SELECTION_CONTROL,
- sizeof(selectionControlEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(selectionControlEntries),
selectionControlEntries},
{SPV_OPERAND_TYPE_LOOP_CONTROL,
- sizeof(loopControlEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(loopControlEntries),
loopControlEntries},
{SPV_OPERAND_TYPE_FUNCTION_CONTROL,
- sizeof(functionControlEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(functionControlEntries),
functionControlEntries},
{SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID,
- sizeof(memorySemanticsEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(memorySemanticsEntries),
memorySemanticsEntries},
{SPV_OPERAND_TYPE_MEMORY_ACCESS,
- sizeof(memoryAccessEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(memoryAccessEntries),
memoryAccessEntries},
{SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS, // Same as *_MEMORY_ACCESS
- sizeof(memoryAccessEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(memoryAccessEntries),
memoryAccessEntries},
{SPV_OPERAND_TYPE_SCOPE_ID,
- sizeof(scopeEntries) / sizeof(spv_operand_desc_t), scopeEntries},
+ ARRAY_SIZE(scopeEntries), scopeEntries},
{SPV_OPERAND_TYPE_GROUP_OPERATION,
- sizeof(groupOperationEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(groupOperationEntries),
groupOperationEntries},
{SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS,
- sizeof(kernelKernelEnqueueFlagssEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(kernelKernelEnqueueFlagssEntries),
kernelKernelEnqueueFlagssEntries},
{SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO,
- sizeof(kernelProfilingInfoEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(kernelProfilingInfoEntries),
kernelProfilingInfoEntries},
{SPV_OPERAND_TYPE_CAPABILITY,
- sizeof(capabilityInfoEntries) / sizeof(spv_operand_desc_t),
+ ARRAY_SIZE(capabilityInfoEntries),
capabilityInfoEntries},
};
spv_result_t spvOperandTableGet(spv_operand_table* pOperandTable) {
if (!pOperandTable) return SPV_ERROR_INVALID_POINTER;
- static const spv_operand_table_t table = {
- sizeof(opcodeEntryTypes) / sizeof(spv_operand_desc_group_t),
- opcodeEntryTypes};
+ static const spv_operand_table_t table = {ARRAY_SIZE(opcodeEntryTypes),
+ opcodeEntryTypes};
*pOperandTable = &table;