spv_operand_type_t cleanup.

- Concrete operand types are never optional.
  Split them to make this so, e.g. add SPV_OPERAND_TYPE_IMAGE
  since there was SPV_OPERAND_TYPE_OPTIONAL_IMAGE.
  Similarly for SPV_OPERAND_TYPE_MEMORY_ACCESS.
  This entails duplicating two operand table entries.

- The above, plus some rearranging of enums, allows us to define
  first and last optional operand types, and first and last
  variable operand types.
  This lets us simplify the code for spvOperandIsOptional, and
  spvOperandIsVariable.

- Replace SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER with the
  more accurately named SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER.
  Its special characteristic is that the type of the literal
  number is determined by some previous operand in the instruction.
  This is used for literals in OpSwitch, OpConstant, and OpSpecConstant.
  This lets us refactor operand parsing cases in the assembler.

- Remove the special required-thing-in-optional-tuple in favour of
  the corresponding concrete operand type:
        SPV_OPERAND_TYPE_ID_IN_OPTIONAL_TUPLE
    --> SPV_OPERAND_TYPE_ID
        SPV_OPERAND_TYPE_INTEGER_LITERAL_IN_OPTIONAL_TUPLE
    --> SPV_OPERAND_TYPE_INTEGER_LITERAL

- Constrain spvOpeandTypeStr to only have to work for non-variable
  operand types.  Add a test for this.
This commit is contained in:
David Neto
2015-11-04 17:38:17 -05:00
parent 97e4a5d83d
commit 201caf7001
9 changed files with 218 additions and 167 deletions
+12 -14
View File
@@ -52,17 +52,13 @@ spv_opcode_desc_t opcodeTableEntries[] = {
#define Capability2(X, Y) Capability(X) | Capability(Y)
#define SpvCapabilityNone \
0 // Needed so Capability(None) still expands to valid syntax.
#define Instruction(Name, HasResult, HasType, NumLogicalOperands, \
NumCapabilities, CapabilityRequired, IsVariable, \
LogicalArgsList) \
{ \
#Name, SpvOp##Name, \
(NumCapabilities) ? (CapabilityRequired) : 0, 0, \
{}, /* Filled in later. Operand list, including \
result id and type id, if needed */ \
HasResult, HasType, LogicalArgsList \
} \
,
#define Instruction(Name, HasResult, HasType, NumLogicalOperands, \
NumCapabilities, CapabilityRequired, IsVariable, \
LogicalArgsList) \
{#Name, SpvOp##Name, (NumCapabilities) ? (CapabilityRequired) : 0, \
0, {}, /* Filled in later. Operand list, including \
result id and type id, if needed */ \
HasResult, HasType, LogicalArgsList},
#include "opcode.inc"
#undef EmptyList
#undef List
@@ -101,8 +97,10 @@ spv_operand_type_t convertOperandClassToType(SpvOp opcode,
break;
}
} else if (operandClass == OperandVariableLiterals) {
if (opcode == SpvOpConstant || opcode == SpvOpSpecConstant)
return SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER;
if (opcode == SpvOpConstant || opcode == SpvOpSpecConstant) {
// The number type is determined by the type Id operand.
return SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER;
}
}
switch (operandClass) {
@@ -384,7 +382,7 @@ void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
}
const char* spvOpcodeString(const SpvOp opcode) {
// Use the syntax table so it's sure to be complete.
// Use the syntax table so it's sure to be complete.
#define Instruction(Name, ...) \
case SpvOp##Name: \
return #Name;