blob: eb3beacac34bad16bcb88d39d02389cbe210eb9c [file] [log] [blame]
Dejan Mircevskib6fe02f2016-01-07 13:44:22 -05001// Copyright (c) 2015-2016 The Khronos Group Inc.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01002//
David Neto9fc86582016-09-01 15:33:59 -04003// 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
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01006//
David Neto9fc86582016-09-01 15:33:59 -04007// http://www.apache.org/licenses/LICENSE-2.0
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +01008//
David Neto9fc86582016-09-01 15:33:59 -04009// 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.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010014
dan sinclair58a68762018-08-03 08:05:33 -040015#ifndef SOURCE_BINARY_H_
16#define SOURCE_BINARY_H_
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010017
Marius Hillenbrand1ed847f2021-12-08 18:01:26 +010018#include <string>
19
dan sinclaireda2cfb2018-08-03 15:06:09 -040020#include "source/spirv_definition.h"
David Neto5a703352016-02-17 14:44:00 -050021#include "spirv-tools/libspirv.h"
David Neto0ca6b592015-10-30 16:06:15 -040022
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010023// Functions
24
Lei Zhangaf9906e2015-11-16 10:48:43 -050025// 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.
Andrew Woloszyn55ecc2e2015-11-11 11:05:07 -050028spv_result_t spvBinaryHeaderGet(const spv_const_binary binary,
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010029 const spv_endianness_t endian,
Lei Zhangaf9906e2015-11-16 10:48:43 -050030 spv_header_t* header);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010031
David Neto37422e92016-12-19 13:26:42 -050032// 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
Marius Hillenbrand1ed847f2021-12-08 18:01:26 +010038// 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
dan sinclair58a68762018-08-03 08:05:33 -040043#endif // SOURCE_BINARY_H_