| 102 | } |
| 103 | |
| 104 | spv_result_t extractOpSource(const spv_position_t& loc, |
| 105 | const spv_parsed_instruction_t& instruction, |
| 106 | spv::Id* filename, std::string* code) { |
| 107 | assert(filename != nullptr && code != nullptr); |
| 108 | assert(instruction.opcode == static_cast<unsigned>(spv::Op::OpSource)); |
| 109 | // OpCode [ Source Language | Version | File (optional) | Source (optional) ] |
| 110 | if (instruction.num_words < 3) { |
| 111 | spvtools::Error(spvtools::utils::CLIMessageConsumer, "", loc, |
| 112 | "Missing operands for OpSource."); |
| 113 | return SPV_ERROR_INVALID_BINARY; |
| 114 | } |
| 115 | |
| 116 | *filename = 0; |
| 117 | *code = ""; |
| 118 | if (instruction.num_words < 4) { |
| 119 | return SPV_SUCCESS; |
| 120 | } |
| 121 | *filename = instruction.words[3]; |
| 122 | |
| 123 | if (instruction.num_words < 5) { |
| 124 | return SPV_SUCCESS; |
| 125 | } |
| 126 | |
| 127 | const char* stringBegin = |
| 128 | reinterpret_cast<const char*>(instruction.words + 4); |
| 129 | const char* stringEnd = |
| 130 | reinterpret_cast<const char*>(instruction.words + instruction.num_words); |
| 131 | return ExtractStringLiteral(loc, stringBegin, stringEnd, code); |
| 132 | } |
| 133 | |
| 134 | } // namespace |
| 135 |
no test coverage detected