Encodes an instruction started by ! at the given position in text. Puts the encoded words into *pInst. If successful, moves position past the instruction and returns SPV_SUCCESS. Otherwise, returns an error code and leaves position pointing to the error in text.
| 491 | /// instruction and returns SPV_SUCCESS. Otherwise, returns an error code and |
| 492 | /// leaves position pointing to the error in text. |
| 493 | spv_result_t encodeInstructionStartingWithImmediate( |
| 494 | const spvtools::AssemblyGrammar& grammar, |
| 495 | spvtools::AssemblyContext* context, spv_instruction_t* pInst) { |
| 496 | std::string firstWord; |
| 497 | spv_position_t nextPosition = {}; |
| 498 | auto error = context->getWord(&firstWord, &nextPosition); |
| 499 | if (error) return context->diagnostic(error) << "Internal Error"; |
| 500 | |
| 501 | if ((error = encodeImmediate(context, firstWord.c_str(), pInst))) { |
| 502 | return error; |
| 503 | } |
| 504 | while (context->advance() != SPV_END_OF_STREAM) { |
| 505 | // A beginning of a new instruction means we're done. |
| 506 | if (context->isStartOfNewInst()) return SPV_SUCCESS; |
| 507 | |
| 508 | // Otherwise, there must be an operand that's either a literal, an ID, or |
| 509 | // an immediate. |
| 510 | std::string operandValue; |
| 511 | if ((error = context->getWord(&operandValue, &nextPosition))) |
| 512 | return context->diagnostic(error) << "Internal Error"; |
| 513 | |
| 514 | if (operandValue == "=") |
| 515 | return context->diagnostic() << firstWord << " not allowed before =."; |
| 516 | |
| 517 | // Needed to pass to spvTextEncodeOperand(), but it shouldn't ever be |
| 518 | // expanded. |
| 519 | spv_operand_pattern_t dummyExpectedOperands; |
| 520 | error = spvTextEncodeOperand( |
| 521 | grammar, context, SPV_OPERAND_TYPE_OPTIONAL_CIV, operandValue.c_str(), |
| 522 | pInst, &dummyExpectedOperands); |
| 523 | if (error) return error; |
| 524 | context->setPosition(nextPosition); |
| 525 | } |
| 526 | return SPV_SUCCESS; |
| 527 | } |
| 528 | |
| 529 | /// @brief Translate an instruction started by OpUnknown and the following |
| 530 | /// operands to binary form |
no test coverage detected