blob: 60d8e15f0635d8a949ca4d542a1de3c1facb007e [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
David Neto9f79d782015-10-27 16:27:05 -040015#ifndef LIBSPIRV_OPCODE_H_
16#define LIBSPIRV_OPCODE_H_
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010017
David Netob5dc8fc2015-10-06 16:22:00 -040018#include "instruction.h"
David Neto5a703352016-02-17 14:44:00 -050019#include "spirv-tools/libspirv.h"
Lei Zhang10dba912016-04-14 14:05:53 -040020#include "spirv/1.1/spirv.h"
Lei Zhang7a222e42015-11-11 12:40:25 -050021#include "table.h"
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010022
Lei Zhangaf9906e2015-11-16 10:48:43 -050023// Returns the name of a registered SPIR-V generator as a null-terminated
24// string. If the generator is not known, then returns the string "Unknown".
25// The generator parameter should be most significant 16-bits of the generator
26// word in the SPIR-V module header.
27//
28// See the registry at https://www.khronos.org/registry/spir-v/api/spir-v.xml.
Lei Zhang1a0334e2015-11-02 09:41:20 -050029const char* spvGeneratorStr(uint32_t generator);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010030
Lei Zhangaf9906e2015-11-16 10:48:43 -050031// Combines word_count and opcode enumerant in single word.
32uint32_t spvOpcodeMake(uint16_t word_count, SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010033
Lei Zhangaf9906e2015-11-16 10:48:43 -050034// Splits word into into two constituent parts: word_count and opcode.
Lei Zhang6fa3f8a2016-03-31 17:26:31 -040035void spvOpcodeSplit(const uint32_t word, uint16_t* word_count,
36 uint16_t* opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010037
Lei Zhangaf9906e2015-11-16 10:48:43 -050038// Finds the named opcode in the given opcode table. On success, returns
39// SPV_SUCCESS and writes a handle of the table entry into *entry.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010040spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table,
Lei Zhangaf9906e2015-11-16 10:48:43 -050041 const char* name, spv_opcode_desc* entry);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010042
Lei Zhangaf9906e2015-11-16 10:48:43 -050043// Finds the opcode by enumerant in the given opcode table. On success, returns
44// SPV_SUCCESS and writes a handle of the table entry into *entry.
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010045spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table,
Lei Zhangb36e7042015-10-28 13:40:52 -040046 const SpvOp opcode,
Lei Zhangaf9906e2015-11-16 10:48:43 -050047 spv_opcode_desc* entry);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010048
Lei Zhangaf9906e2015-11-16 10:48:43 -050049// Copies an instruction's word and fixes the endianness to host native. The
50// source instruction's stream/opcode/endianness is in the words/opcode/endian
51// parameter. The word_count parameter specifies the number of words to copy.
52// Writes copied instruction into *inst.
Lei Zhang1a0334e2015-11-02 09:41:20 -050053void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
Lei Zhangaf9906e2015-11-16 10:48:43 -050054 const uint16_t word_count,
55 const spv_endianness_t endian, spv_instruction_t* inst);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010056
Lei Zhangaf9906e2015-11-16 10:48:43 -050057// Gets the name of an instruction, without the "Op" prefix.
Lei Zhang1a0334e2015-11-02 09:41:20 -050058const char* spvOpcodeString(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010059
Lei Zhangaf9906e2015-11-16 10:48:43 -050060// Determine if the given opcode is a scalar type. Returns zero if false,
61// non-zero otherwise.
Lei Zhangb36e7042015-10-28 13:40:52 -040062int32_t spvOpcodeIsScalarType(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010063
Lei Zhangaf9906e2015-11-16 10:48:43 -050064// Determines if the given opcode is a constant. Returns zero if false, non-zero
65// otherwise.
Lei Zhangb36e7042015-10-28 13:40:52 -040066int32_t spvOpcodeIsConstant(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010067
David Neto1f3fb502016-09-14 11:57:20 -040068// Returns true if the given opcode is a constant or undef.
69bool spvOpcodeIsConstantOrUndef(const SpvOp opcode);
70
Lei Zhangaf9906e2015-11-16 10:48:43 -050071// Determines if the given opcode is a composite type. Returns zero if false,
72// non-zero otherwise.
Lei Zhangb36e7042015-10-28 13:40:52 -040073int32_t spvOpcodeIsComposite(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010074
Florian Ziesche66fcb452016-03-02 22:17:54 +010075// Determines if the given opcode results in a pointer when using the logical
76// addressing model. Returns zero if false, non-zero otherwise.
77int32_t spvOpcodeReturnsLogicalPointer(const SpvOp opcode);
Kenneth Benzie (Benie)83e5a292015-05-22 18:26:19 +010078
Lei Zhangaf9906e2015-11-16 10:48:43 -050079// Determines if the given opcode generates a type. Returns zero if false,
80// non-zero otherwise.
81int32_t spvOpcodeGeneratesType(SpvOp opcode);
Andrew Woloszyn537e7762015-09-29 11:28:34 -040082
David Neto9f79d782015-10-27 16:27:05 -040083#endif // LIBSPIRV_OPCODE_H_