blob: b792979391f4b4ade0b3d4be976d41635d8df3c8 [file] [log] [blame]
John Kessenich140f3df2015-06-26 16:58:36 -06001//
John Kessenich5e4b1242015-08-06 22:53:06 -06002//Copyright (C) 2014-2015 LunarG, Inc.
John Kessenich140f3df2015-06-26 16:58:36 -06003//
4//All rights reserved.
5//
6//Redistribution and use in source and binary forms, with or without
7//modification, are permitted provided that the following conditions
8//are met:
9//
10// Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12//
13// Redistributions in binary form must reproduce the above
14// copyright notice, this list of conditions and the following
15// disclaimer in the documentation and/or other materials provided
16// with the distribution.
17//
18// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
19// contributors may be used to endorse or promote products derived
20// from this software without specific prior written permission.
21//
22//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33//POSSIBILITY OF SUCH DAMAGE.
34
35//
36// Author: John Kessenich, LunarG
37//
38
39//
40// Parameterize the SPIR-V enumerants.
41//
42
John Kessenich5e4b1242015-08-06 22:53:06 -060043#include "spirv.hpp"
John Kessenich140f3df2015-06-26 16:58:36 -060044
45#include <vector>
46
47namespace spv {
48
49// Fill in all the parameters
50void Parameterize();
51
52// Return the English names of all the enums.
53const char* SourceString(int);
54const char* AddressingString(int);
55const char* MemoryString(int);
56const char* ExecutionModelString(int);
57const char* ExecutionModeString(int);
58const char* StorageClassString(int);
59const char* DecorationString(int);
60const char* BuiltInString(int);
61const char* DimensionString(int);
62const char* SelectControlString(int);
63const char* LoopControlString(int);
64const char* FunctionControlString(int);
65const char* SamplerAddressingModeString(int);
66const char* SamplerFilterModeString(int);
John Kessenich5e4b1242015-08-06 22:53:06 -060067const char* ImageFormatString(int);
68const char* ImageChannelOrderString(int);
69const char* ImageChannelTypeString(int);
Mark Adams18b637f2016-02-23 12:17:11 -050070const char* ImageChannelDataTypeString(int type);
71const char* ImageOperandsString(int format);
John Kessenich5e4b1242015-08-06 22:53:06 -060072const char* ImageOperands(int);
John Kessenich140f3df2015-06-26 16:58:36 -060073const char* FPFastMathString(int);
74const char* FPRoundingModeString(int);
75const char* LinkageTypeString(int);
76const char* FuncParamAttrString(int);
77const char* AccessQualifierString(int);
78const char* MemorySemanticsString(int);
79const char* MemoryAccessString(int);
80const char* ExecutionScopeString(int);
81const char* GroupOperationString(int);
82const char* KernelEnqueueFlagsString(int);
83const char* KernelProfilingInfoString(int);
John Kessenich5e4b1242015-08-06 22:53:06 -060084const char* CapabilityString(int);
John Kessenich140f3df2015-06-26 16:58:36 -060085const char* OpcodeString(int);
Mark Adams18b637f2016-02-23 12:17:11 -050086const char* ScopeString(int mem);
John Kessenich140f3df2015-06-26 16:58:36 -060087
88// For grouping opcodes into subsections
89enum OpcodeClass {
John Kessenich5e4b1242015-08-06 22:53:06 -060090 OpClassMisc,
John Kessenich140f3df2015-06-26 16:58:36 -060091 OpClassDebug,
92 OpClassAnnotate,
93 OpClassExtension,
94 OpClassMode,
95 OpClassType,
96 OpClassConstant,
97 OpClassMemory,
98 OpClassFunction,
John Kessenich5e4b1242015-08-06 22:53:06 -060099 OpClassImage,
John Kessenich140f3df2015-06-26 16:58:36 -0600100 OpClassConvert,
101 OpClassComposite,
102 OpClassArithmetic,
John Kessenich5e4b1242015-08-06 22:53:06 -0600103 OpClassBit,
John Kessenich140f3df2015-06-26 16:58:36 -0600104 OpClassRelationalLogical,
105 OpClassDerivative,
106 OpClassFlowControl,
107 OpClassAtomic,
108 OpClassPrimitive,
109 OpClassBarrier,
110 OpClassGroup,
111 OpClassDeviceSideEnqueue,
112 OpClassPipe,
113
John Kessenich5e4b1242015-08-06 22:53:06 -0600114 OpClassCount,
115 OpClassMissing // all instructions start out as missing
John Kessenich140f3df2015-06-26 16:58:36 -0600116};
117
118// For parameterizing operands.
119enum OperandClass {
120 OperandNone,
121 OperandId,
John Kessenich140f3df2015-06-26 16:58:36 -0600122 OperandVariableIds,
John Kessenich5e4b1242015-08-06 22:53:06 -0600123 OperandOptionalLiteral,
John Kessenich55e7d112015-11-15 21:33:39 -0700124 OperandOptionalLiteralString,
John Kessenich140f3df2015-06-26 16:58:36 -0600125 OperandVariableLiterals,
John Kessenich5e4b1242015-08-06 22:53:06 -0600126 OperandVariableIdLiteral,
John Kessenich140f3df2015-06-26 16:58:36 -0600127 OperandVariableLiteralId,
128 OperandLiteralNumber,
129 OperandLiteralString,
130 OperandSource,
131 OperandExecutionModel,
132 OperandAddressing,
133 OperandMemory,
134 OperandExecutionMode,
135 OperandStorage,
136 OperandDimensionality,
137 OperandSamplerAddressingMode,
138 OperandSamplerFilterMode,
John Kessenich5e4b1242015-08-06 22:53:06 -0600139 OperandSamplerImageFormat,
140 OperandImageChannelOrder,
141 OperandImageChannelDataType,
142 OperandImageOperands,
John Kessenich140f3df2015-06-26 16:58:36 -0600143 OperandFPFastMath,
144 OperandFPRoundingMode,
145 OperandLinkageType,
146 OperandAccessQualifier,
147 OperandFuncParamAttr,
148 OperandDecoration,
149 OperandBuiltIn,
150 OperandSelect,
151 OperandLoop,
152 OperandFunction,
153 OperandMemorySemantics,
154 OperandMemoryAccess,
John Kessenich5e4b1242015-08-06 22:53:06 -0600155 OperandScope,
John Kessenich140f3df2015-06-26 16:58:36 -0600156 OperandGroupOperation,
157 OperandKernelEnqueueFlags,
158 OperandKernelProfilingInfo,
John Kessenich5e4b1242015-08-06 22:53:06 -0600159 OperandCapability,
John Kessenich140f3df2015-06-26 16:58:36 -0600160
161 OperandOpcode,
162
163 OperandCount
164};
165
John Kessenich140f3df2015-06-26 16:58:36 -0600166// Any specific enum can have a set of capabilities that allow it:
167typedef std::vector<Capability> EnumCaps;
168
169// Parameterize a set of operands with their OperandClass(es) and descriptions.
170class OperandParameters {
171public:
172 OperandParameters() { }
John Kessenich55e7d112015-11-15 21:33:39 -0700173 void push(OperandClass oc, const char* d, bool opt = false)
John Kessenich140f3df2015-06-26 16:58:36 -0600174 {
175 opClass.push_back(oc);
176 desc.push_back(d);
John Kessenich55e7d112015-11-15 21:33:39 -0700177 optional.push_back(opt);
John Kessenich140f3df2015-06-26 16:58:36 -0600178 }
John Kessenich55e7d112015-11-15 21:33:39 -0700179 void setOptional();
John Kessenich140f3df2015-06-26 16:58:36 -0600180 OperandClass getClass(int op) const { return opClass[op]; }
181 const char* getDesc(int op) const { return desc[op]; }
John Kessenich55e7d112015-11-15 21:33:39 -0700182 bool isOptional(int op) const { return optional[op]; }
John Kessenich140f3df2015-06-26 16:58:36 -0600183 int getNum() const { return (int)opClass.size(); }
184
185protected:
186 std::vector<OperandClass> opClass;
187 std::vector<const char*> desc;
John Kessenich55e7d112015-11-15 21:33:39 -0700188 std::vector<bool> optional;
John Kessenich140f3df2015-06-26 16:58:36 -0600189};
190
191// Parameterize an enumerant
192class EnumParameters {
193public:
194 EnumParameters() : desc(0) { }
195 EnumCaps caps;
196 const char* desc;
197};
198
199// Parameterize a set of enumerants that form an enum
200class EnumDefinition : public EnumParameters {
201public:
202 EnumDefinition() :
203 ceiling(0), bitmask(false), getName(0), enumParams(0), operandParams(0) { }
204 void set(int ceil, const char* (*name)(int), EnumParameters* ep, bool mask = false)
205 {
206 ceiling = ceil;
207 getName = name;
208 bitmask = mask;
209 enumParams = ep;
210 }
211 void setOperands(OperandParameters* op) { operandParams = op; }
212 int ceiling; // ceiling of enumerants
213 bool bitmask; // true if these enumerants combine into a bitmask
214 const char* (*getName)(int); // a function that returns the name for each enumerant value (or shift)
215 EnumParameters* enumParams; // parameters for each individual enumerant
216 OperandParameters* operandParams; // sets of operands
217};
218
219// Parameterize an instruction's logical format, including its known set of operands,
220// per OperandParameters above.
221class InstructionParameters {
222public:
223 InstructionParameters() :
John Kessenich5e4b1242015-08-06 22:53:06 -0600224 opDesc("TBD"),
225 opClass(OpClassMissing),
Andre Weissfloga5ade512015-07-11 14:45:57 +0200226 typePresent(true), // most normal, only exceptions have to be spelled out
227 resultPresent(true) // most normal, only exceptions have to be spelled out
John Kessenich140f3df2015-06-26 16:58:36 -0600228 { }
229
230 void setResultAndType(bool r, bool t)
231 {
232 resultPresent = r;
233 typePresent = t;
234 }
235
236 bool hasResult() const { return resultPresent != 0; }
237 bool hasType() const { return typePresent != 0; }
238
239 const char* opDesc;
240 EnumCaps capabilities;
241 OpcodeClass opClass;
242 OperandParameters operands;
243
244protected:
245 int typePresent : 1;
246 int resultPresent : 1;
247};
248
John Kessenich6c292d32016-02-15 20:58:50 -0700249const int OpcodeCeiling = 321;
John Kessenich140f3df2015-06-26 16:58:36 -0600250
251// The set of objects that hold all the instruction/operand
252// parameterization information.
253extern InstructionParameters InstructionDesc[];
254
255// These hold definitions of the enumerants used for operands
256extern EnumDefinition OperandClassParams[];
257
258const char* GetOperandDesc(OperandClass operand);
259void PrintImmediateRow(int imm, const char* name, const EnumParameters* enumParams, bool caps, bool hex = false);
260const char* AccessQualifierString(int attr);
261
262void PrintOperands(const OperandParameters& operands, int reservedOperands);
263
264}; // end namespace spv