| 233 | } |
| 234 | |
| 235 | spv_result_t LookupOperand(spv_operand_type_t type, uint32_t value, |
| 236 | const OperandDesc** desc) { |
| 237 | auto ir = OperandByValueRangeForKind(type); |
| 238 | if (ir.empty()) { |
| 239 | return SPV_ERROR_INVALID_LOOKUP; |
| 240 | } |
| 241 | |
| 242 | auto span = ir.apply(kOperandsByValue.data()); |
| 243 | |
| 244 | // Metaphor: Look for the needle in the haystack. |
| 245 | // The operand value is the first member. |
| 246 | const OperandDesc needle{value}; |
| 247 | auto where = |
| 248 | std::lower_bound(span.begin(), span.end(), needle, |
| 249 | [&](const OperandDesc& lhs, const OperandDesc& rhs) { |
| 250 | return lhs.value < rhs.value; |
| 251 | }); |
| 252 | if (where != span.end() && where->value == value) { |
| 253 | *desc = &*where; |
| 254 | return SPV_SUCCESS; |
| 255 | } |
| 256 | return SPV_ERROR_INVALID_LOOKUP; |
| 257 | } |
| 258 | |
| 259 | spv_result_t LookupOperand(spv_operand_type_t type, const char* name, |
| 260 | size_t name_len, const OperandDesc** desc) { |