@brief Translate an instruction started by OpUnknown and the following operands to binary form @param[in] grammar the grammar to use for compilation @param[in, out] context the dynamic compilation info @param[out] pInst returned binary Opcode @return result code
| 535 | /// |
| 536 | /// @return result code |
| 537 | spv_result_t encodeInstructionStartingWithOpUnknown( |
| 538 | const spvtools::AssemblyGrammar& grammar, |
| 539 | spvtools::AssemblyContext* context, spv_instruction_t* pInst) { |
| 540 | spv_position_t nextPosition = {}; |
| 541 | |
| 542 | uint16_t opcode; |
| 543 | uint16_t wordCount; |
| 544 | |
| 545 | // The '(' character. |
| 546 | if (context->advance()) |
| 547 | return context->diagnostic() << "Expected '(', found end of stream."; |
| 548 | if ('(' != context->peek()) { |
| 549 | return context->diagnostic() << "'(' expected after OpUnknown but found '" |
| 550 | << context->peek() << "'."; |
| 551 | } |
| 552 | context->seekForward(1); |
| 553 | |
| 554 | // The opcode enumerant. |
| 555 | if (context->advance()) |
| 556 | return context->diagnostic() |
| 557 | << "Expected opcode enumerant, found end of stream."; |
| 558 | std::string opcodeString; |
| 559 | spv_result_t error = context->getWord(&opcodeString, &nextPosition); |
| 560 | if (error) return context->diagnostic(error) << "Internal Error"; |
| 561 | |
| 562 | if (!spvtools::utils::ParseNumber(opcodeString.c_str(), &opcode)) { |
| 563 | return context->diagnostic() |
| 564 | << "Invalid opcode enumerant: \"" << opcodeString << "\"."; |
| 565 | } |
| 566 | |
| 567 | context->setPosition(nextPosition); |
| 568 | |
| 569 | // The ',' character. |
| 570 | if (context->advance()) |
| 571 | return context->diagnostic() << "Expected ',', found end of stream."; |
| 572 | if (',' != context->peek()) { |
| 573 | return context->diagnostic() |
| 574 | << "',' expected after opcode enumerant but found '" |
| 575 | << context->peek() << "'."; |
| 576 | } |
| 577 | context->seekForward(1); |
| 578 | |
| 579 | // The number of words. |
| 580 | if (context->advance()) |
| 581 | return context->diagnostic() |
| 582 | << "Expected number of words, found end of stream."; |
| 583 | std::string wordCountString; |
| 584 | error = context->getWord(&wordCountString, &nextPosition); |
| 585 | if (error) return context->diagnostic(error) << "Internal Error"; |
| 586 | |
| 587 | if (!spvtools::utils::ParseNumber(wordCountString.c_str(), &wordCount)) { |
| 588 | return context->diagnostic() |
| 589 | << "Invalid number of words: \"" << wordCountString << "\"."; |
| 590 | } |
| 591 | |
| 592 | if (wordCount == 0) { |
| 593 | return context->diagnostic() << "Number of words (which includes the " |
| 594 | "opcode) must be greater than zero."; |
no test coverage detected