const UseDefTracker& usedefs,
          const std::vector<uint32_t>& entry_points, spv_position positionArg,
          spv_diagnostic* pDiagnosticArg)
      : opcodeTable(opcodeTableArg),
        operandTable(operandTableArg),
        extInstTable(extInstTableArg),
        firstInst(pInsts),
        instCount(instCountArg),
        position(positionArg),
        pDiagnostic(pDiagnosticArg),
        usedefs_(usedefs),
        entry_points_(entry_points) {}

  bool isValid(const spv_instruction_t* inst);

  template <SpvOp>
  bool isValid(const spv_instruction_t* inst, const spv_opcode_desc);

 private:
  const spv_opcode_table opcodeTable;
  const spv_operand_table operandTable;
  const spv_ext_inst_table extInstTable;
  const spv_instruction_t* const firstInst;
  const uint64_t instCount;
  spv_position position;
  spv_diagnostic* pDiagnostic;
  UseDefTracker usedefs_;
  std::vector<uint32_t> entry_points_;
};

#define DIAG(INDEX)         \
  position->index += INDEX; \
  DIAGNOSTIC

#if 0
template <>
bool idUsage::isValid<SpvOpUndef>(const spv_instruction_t *inst,
                                  const spv_opcode_desc) {
  assert(0 && "Unimplemented!");
  return false;
}
#endif  // 0

template <>
bool idUsage::isValid<SpvOpMemberName>(const spv_instruction_t* inst,
                                       const spv_opcode_desc) {
  auto typeIndex = 1;
  auto type = usedefs_.FindDef(inst->words[typeIndex]);
  if (!type.first || SpvOpTypeStruct != type.second.opcode) {
    DIAG(typeIndex) << "OpMemberName Type <id> '" << inst->words[typeIndex]
                    << "' is not a struct type.";
    return false;
  }
  auto memberIndex = 2;
  auto member = inst->words[memberIndex];
  auto memberCount = (uint32_t)(type.second.words.size() - 2);
  spvCheck(memberCount <= member, DIAG(memberIndex)
                                      << "OpMemberName Member <id> '"
                                      << inst->words[memberIndex]
                                      << "' index is larger than Type <id> '"
             