| 37 | #include "source/util/string_utils.h" |
| 38 | |
| 39 | spv_result_t spvBinaryHeaderGet(const spv_const_binary binary, |
| 40 | const spv_endianness_t endian, |
| 41 | spv_header_t* pHeader) { |
| 42 | if (!binary->code) return SPV_ERROR_INVALID_BINARY; |
| 43 | if (binary->wordCount < SPV_INDEX_INSTRUCTION) |
| 44 | return SPV_ERROR_INVALID_BINARY; |
| 45 | if (!pHeader) return SPV_ERROR_INVALID_POINTER; |
| 46 | |
| 47 | // TODO: Validation checking? |
| 48 | pHeader->magic = spvFixWord(binary->code[SPV_INDEX_MAGIC_NUMBER], endian); |
| 49 | pHeader->version = spvFixWord(binary->code[SPV_INDEX_VERSION_NUMBER], endian); |
| 50 | // Per 2.3.1 version's high and low bytes are 0 |
| 51 | if ((pHeader->version & 0x000000ff) || pHeader->version & 0xff000000) |
| 52 | return SPV_ERROR_INVALID_BINARY; |
| 53 | // Minimum version was 1.0 and max version is defined by SPV_VERSION. |
| 54 | if (pHeader->version < SPV_SPIRV_VERSION_WORD(1, 0) || |
| 55 | pHeader->version > SPV_VERSION) |
| 56 | return SPV_ERROR_INVALID_BINARY; |
| 57 | |
| 58 | pHeader->generator = |
| 59 | spvFixWord(binary->code[SPV_INDEX_GENERATOR_NUMBER], endian); |
| 60 | pHeader->bound = spvFixWord(binary->code[SPV_INDEX_BOUND], endian); |
| 61 | pHeader->schema = spvFixWord(binary->code[SPV_INDEX_SCHEMA], endian); |
| 62 | pHeader->instructions = &binary->code[SPV_INDEX_INSTRUCTION]; |
| 63 | |
| 64 | return SPV_SUCCESS; |
| 65 | } |
| 66 | |
| 67 | std::string spvDecodeLiteralStringOperand(const spv_parsed_instruction_t& inst, |
| 68 | const uint16_t operand_index) { |