1// Copyright (c) 2015-2016 The Khronos Group Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef SOURCE_BINARY_H_
16#define SOURCE_BINARY_H_
17
18#include <string>
19
20#include "source/spirv_definition.h"
21#include "spirv-tools/libspirv.h"
22
23// Functions
24
25// Grabs the header from the SPIR-V module given in the binary parameter. The
26// endian parameter specifies the endianness of the binary module. On success,
27// returns SPV_SUCCESS and writes the parsed header into *header.
28spv_result_t spvBinaryHeaderGet(const spv_const_binary binary,
29 const spv_endianness_t endian,
30 spv_header_t* header);
31
32// Returns the number of non-null characters in str before the first null
33// character, or strsz if there is no null character. Examines at most the
34// first strsz characters in str. Returns 0 if str is nullptr. This is a
35// replacement for C11's strnlen_s which might not exist in all environments.
36size_t spv_strnlen_s(const char* str, size_t strsz);
37
38// Decode the string literal operand with index operand_index from instruction
39// inst.
40std::string spvDecodeLiteralStringOperand(const spv_parsed_instruction_t& inst,
41 const uint16_t operand_index);
42
43#endif // SOURCE_BINARY_H_
44