Parses an immediate integer from text, guarding against overflow. If successful, adds the parsed value to pInst, advances the context past it, and returns SPV_SUCCESS. Otherwise, leaves pInst alone, emits diagnostics, and returns SPV_ERROR_INVALID_TEXT.
| 161 | /// and returns SPV_SUCCESS. Otherwise, leaves pInst alone, emits diagnostics, |
| 162 | /// and returns SPV_ERROR_INVALID_TEXT. |
| 163 | spv_result_t encodeImmediate(spvtools::AssemblyContext* context, |
| 164 | const char* text, spv_instruction_t* pInst) { |
| 165 | assert(*text == '!'); |
| 166 | uint32_t parse_result; |
| 167 | if (!spvtools::utils::ParseNumber(text + 1, &parse_result)) { |
| 168 | return context->diagnostic(SPV_ERROR_INVALID_TEXT) |
| 169 | << "Invalid immediate integer: !" << text + 1; |
| 170 | } |
| 171 | context->binaryEncodeU32(parse_result, pInst); |
| 172 | context->seekForward(static_cast<uint32_t>(strlen(text))); |
| 173 | return SPV_SUCCESS; |
| 174 | } |
| 175 | |
| 176 | } // anonymous namespace |
| 177 |
no test coverage detected