Parses operand indices and returns the corresponding Values from the valueIndexList. If numOperandsToRead is std::nullopt, it first reads the number of operands as a VarInt. Otherwise, it uses the provided count.
| 1167 | /// valueIndexList. If numOperandsToRead is std::nullopt, it first reads the |
| 1168 | /// number of operands as a VarInt. Otherwise, it uses the provided count. |
| 1169 | static LogicalResult |
| 1170 | parseOperands(EncodingReader &reader, Location loc, |
| 1171 | ArrayRef<Value> valueIndexList, SmallVectorImpl<Value> &results, |
| 1172 | std::optional<uint64_t> numOperandsToRead = std::nullopt) { |
| 1173 | uint64_t numOperands; |
| 1174 | if (numOperandsToRead.has_value()) |
| 1175 | numOperands = *numOperandsToRead; |
| 1176 | else if (failed(reader.readVarInt( |
| 1177 | numOperands, std::numeric_limits<uint32_t>::max() - 1))) |
| 1178 | return reader.emitError() << "failed to read operand count"; |
| 1179 | |
| 1180 | results.reserve(numOperands); |
| 1181 | for (uint64_t i = 0; i < numOperands; ++i) { |
| 1182 | uint64_t operandIdx; |
| 1183 | if (failed(reader.readVarInt(operandIdx))) |
| 1184 | return reader.emitError() << "failed to read operand index " << i; |
| 1185 | if (operandIdx >= valueIndexList.size()) |
| 1186 | return reader.emitError() |
| 1187 | << "operand index " << operandIdx |
| 1188 | << " out of bounds (size=" << valueIndexList.size() |
| 1189 | << ") for operand " << i; |
| 1190 | results.push_back(valueIndexList[operandIdx]); |
| 1191 | } |
| 1192 | return success(); |
| 1193 | } |
| 1194 | |
| 1195 | /// Helper function to parse a given block during deserialization. |
| 1196 | static LogicalResult |
nothing calls this directly
no test coverage detected