diff options
author | David Neto <dneto@google.com> | 2020-07-27 20:14:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-27 20:14:03 +0300 |
commit | 31c8213935118366892808db5735329fba2ed832 (patch) | |
tree | 08fbb2e8911ed0ac2e3918333756997d63ec902b /include | |
parent | 6a3eb679bd0f4cab814da931fe4c07c399f5e4a3 (diff) |
Avoid operand type range checks (#3379)
* Avoid operand type range checks
Deprecates the SPV_OPERAND_TYPE_FIRST_* and SPV_OPERAND_TYPE_LAST_*
macros.
The "variable" and "optional" operand types are only for internal use.
Export spvOperandIsConcrete instead, as that should cover intended
external uses.
Test that each operand type is classified either as one of:
- a sentinel value
- a concrete operand type
- an optional operand type (which includes variable-expansion types)
Test that each concrete and optional non-variable operand type
has a name for use internally when generating messages.
Co-authored-by: Steven Perron <stevenperron@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/spirv-tools/libspirv.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/include/spirv-tools/libspirv.h b/include/spirv-tools/libspirv.h index 68afd6494..f5fa8937f 100644 --- a/include/spirv-tools/libspirv.h +++ b/include/spirv-tools/libspirv.h @@ -48,8 +48,8 @@ extern "C" { #define SPV_BIT(shift) (1 << (shift)) -#define SPV_FORCE_16_BIT_ENUM(name) _##name = 0x7fff -#define SPV_FORCE_32_BIT_ENUM(name) _##name = 0x7fffffff +#define SPV_FORCE_16_BIT_ENUM(name) SPV_FORCE_16BIT_##name = 0x7fff +#define SPV_FORCE_32_BIT_ENUM(name) SPV_FORCE_32BIT_##name = 0x7fffffff // Enumerations @@ -189,8 +189,17 @@ typedef enum spv_operand_type_t { // Variable : expands to 0, 1 or many operands or pairs of operands. // This is similar to * in regular expressions. +// NOTE: These FIRST_* and LAST_* enum values are DEPRECATED. +// The concept of "optional" and "variable" operand types are only intended +// for use as an implementation detail of parsing SPIR-V, either in text or +// binary form. Instead of using enum ranges, use characteristic function +// spvOperandIsConcrete. +// The use of enum value ranges in a public API makes it difficult to insert +// new values into a range without also breaking binary compatibility. +// // Macros for defining bounds on optional and variable operand types. // Any variable operand type is also optional. +// TODO(dneto): Remove SPV_OPERAND_TYPE_FIRST_* and SPV_OPERAND_TYPE_LAST_* #define FIRST_OPTIONAL(ENUM) ENUM, SPV_OPERAND_TYPE_FIRST_OPTIONAL_TYPE = ENUM #define FIRST_VARIABLE(ENUM) ENUM, SPV_OPERAND_TYPE_FIRST_VARIABLE_TYPE = ENUM #define LAST_VARIABLE(ENUM) \ @@ -257,6 +266,12 @@ typedef enum spv_operand_type_t { SPV_FORCE_32_BIT_ENUM(spv_operand_type_t) } spv_operand_type_t; +// Returns true if the given type is concrete. +bool spvOperandIsConcrete(spv_operand_type_t type); + +// Returns true if the given type is concrete and also a mask. +bool spvOperandIsConcreteMask(spv_operand_type_t type); + typedef enum spv_ext_inst_type_t { SPV_EXT_INST_TYPE_NONE = 0, SPV_EXT_INST_TYPE_GLSL_STD_450, |