| 166 | } |
| 167 | |
| 168 | spv_result_t LookupOpcode(spv::Op opcode, const InstructionDesc** desc) { |
| 169 | // Metaphor: Look for the needle in the haystack. |
| 170 | const InstructionDesc needle(opcode); |
| 171 | auto where = std::lower_bound( |
| 172 | kInstructionDesc.begin(), kInstructionDesc.end(), needle, |
| 173 | [&](const InstructionDesc& lhs, const InstructionDesc& rhs) { |
| 174 | return uint32_t(lhs.opcode) < uint32_t(rhs.opcode); |
| 175 | }); |
| 176 | if (where != kInstructionDesc.end() && where->opcode == opcode) { |
| 177 | *desc = &*where; |
| 178 | return SPV_SUCCESS; |
| 179 | } |
| 180 | return SPV_ERROR_INVALID_LOOKUP; |
| 181 | } |
| 182 | |
| 183 | spv_result_t LookupOpcode(const char* name, const InstructionDesc** desc) { |
| 184 | // The comparison function knows to use 'name' string to compare against |