blob: cf9e059bcda1c05505b530130c9422dfe6cb5ffe [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//
John Kessenich140f3df2015-06-26 16:58:36 -060036// Parameterize the SPIR-V enumerants.
37//
38
John Kessenich5e4b1242015-08-06 22:53:06 -060039#include "spirv.hpp"
John Kessenich140f3df2015-06-26 16:58:36 -060040
41#include <vector>
42
43namespace spv {
44
45// Fill in all the parameters
46void Parameterize();
47
48// Return the English names of all the enums.
49const char* SourceString(int);
50const char* AddressingString(int);
51const char* MemoryString(int);
52const char* ExecutionModelString(int);
53const char* ExecutionModeString(int);
54const char* StorageClassString(int);
55const char* DecorationString(int);
56const char* BuiltInString(int);
57const char* DimensionString(int);
58const char* SelectControlString(int);
59const char* LoopControlString(int);
60const char* FunctionControlString(int);
61const char* SamplerAddressingModeString(int);
62const char* SamplerFilterModeString(int);
John Kessenich5e4b1242015-08-06 22:53:06 -060063const char* ImageFormatString(int);
64const char* ImageChannelOrderString(int);
65const char* ImageChannelTypeString(int);
Mark Adams18b637f2016-02-23 12:17:11 -050066const char* ImageChannelDataTypeString(int type);
67const char* ImageOperandsString(int format);
John Kessenich5e4b1242015-08-06 22:53:06 -060068const char* ImageOperands(int);
John Kessenich140f3df2015-06-26 16:58:36 -060069const char* FPFastMathString(int);
70const char* FPRoundingModeString(int);
71const char* LinkageTypeString(int);
72const char* FuncParamAttrString(int);
73const char* AccessQualifierString(int);
74const char* MemorySemanticsString(int);
75const char* MemoryAccessString(int);
76const char* ExecutionScopeString(int);
77const char* GroupOperationString(int);
78const char* KernelEnqueueFlagsString(int);
79const char* KernelProfilingInfoString(int);
John Kessenich5e4b1242015-08-06 22:53:06 -060080const char* CapabilityString(int);
John Kessenich140f3df2015-06-26 16:58:36 -060081const char* OpcodeString(int);
Mark Adams18b637f2016-02-23 12:17:11 -050082const char* ScopeString(int mem);
John Kessenich140f3df2015-06-26 16:58:36 -060083
84// For grouping opcodes into subsections
85enum OpcodeClass {
John Kessenich5e4b1242015-08-06 22:53:06 -060086 OpClassMisc,
John Kessenich140f3df2015-06-26 16:58:36 -060087 OpClassDebug,
88 OpClassAnnotate,
89 OpClassExtension,
90 OpClassMode,
91 OpClassType,
92 OpClassConstant,
93 OpClassMemory,
94 OpClassFunction,
John Kessenich5e4b1242015-08-06 22:53:06 -060095 OpClassImage,
John Kessenich140f3df2015-06-26 16:58:36 -060096 OpClassConvert,
97 OpClassComposite,
98 OpClassArithmetic,
John Kessenich5e4b1242015-08-06 22:53:06 -060099 OpClassBit,
John Kessenich140f3df2015-06-26 16:58:36 -0600100 OpClassRelationalLogical,
101 OpClassDerivative,
102 OpClassFlowControl,
103 OpClassAtomic,
104 OpClassPrimitive,
105 OpClassBarrier,
106 OpClassGroup,
107 OpClassDeviceSideEnqueue,
108 OpClassPipe,
109
John Kessenich5e4b1242015-08-06 22:53:06 -0600110 OpClassCount,
111 OpClassMissing // all instructions start out as missing
John Kessenich140f3df2015-06-26 16:58:36 -0600112};
113
114// For parameterizing operands.
115enum OperandClass {
116 OperandNone,
117 OperandId,
John Kessenich140f3df2015-06-26 16:58:36 -0600118 OperandVariableIds,
John Kessenich5e4b1242015-08-06 22:53:06 -0600119 OperandOptionalLiteral,
John Kessenich55e7d112015-11-15 21:33:39 -0700120 OperandOptionalLiteralString,
John Kessenich140f3df2015-06-26 16:58:36 -0600121 OperandVariableLiterals,
John Kessenich5e4b1242015-08-06 22:53:06 -0600122 OperandVariableIdLiteral,
John Kessenich140f3df2015-06-26 16:58:36 -0600123 OperandVariableLiteralId,
124 OperandLiteralNumber,
125 OperandLiteralString,
126 OperandSource,
127 OperandExecutionModel,
128 OperandAddressing,
129 OperandMemory,
130 OperandExecutionMode,
131 OperandStorage,
132 OperandDimensionality,
133 OperandSamplerAddressingMode,
134 OperandSamplerFilterMode,
John Kessenich5e4b1242015-08-06 22:53:06 -0600135 OperandSamplerImageFormat,
136 OperandImageChannelOrder,
137 OperandImageChannelDataType,
138 OperandImageOperands,
John Kessenich140f3df2015-06-26 16:58:36 -0600139 OperandFPFastMath,
140 OperandFPRoundingMode,
141 OperandLinkageType,
142 OperandAccessQualifier,
143 OperandFuncParamAttr,
144 OperandDecoration,
145 OperandBuiltIn,
146 OperandSelect,
147 OperandLoop,
148 OperandFunction,
149 OperandMemorySemantics,
150 OperandMemoryAccess,
John Kessenich5e4b1242015-08-06 22:53:06 -0600151 OperandScope,
John Kessenich140f3df2015-06-26 16:58:36 -0600152 OperandGroupOperation,
153 OperandKernelEnqueueFlags,
154 OperandKernelProfilingInfo,
John Kessenich5e4b1242015-08-06 22:53:06 -0600155 OperandCapability,
John Kessenich140f3df2015-06-26 16:58:36 -0600156
157 OperandOpcode,
158
159 OperandCount
160};
161
John Kessenich140f3df2015-06-26 16:58:36 -0600162// Any specific enum can have a set of capabilities that allow it:
163typedef std::vector<Capability> EnumCaps;
164
165// Parameterize a set of operands with their OperandClass(es) and descriptions.
166class OperandParameters {
167public:
168 OperandParameters() { }
John Kessenich55e7d112015-11-15 21:33:39 -0700169 void push(OperandClass oc, const char* d, bool opt = false)
John Kessenich140f3df2015-06-26 16:58:36 -0600170 {
171 opClass.push_back(oc);
172 desc.push_back(d);
John Kessenich55e7d112015-11-15 21:33:39 -0700173 optional.push_back(opt);
John Kessenich140f3df2015-06-26 16:58:36 -0600174 }
John Kessenich55e7d112015-11-15 21:33:39 -0700175 void setOptional();
John Kessenich140f3df2015-06-26 16:58:36 -0600176 OperandClass getClass(int op) const { return opClass[op]; }
177 const char* getDesc(int op) const { return desc[op]; }
John Kessenich55e7d112015-11-15 21:33:39 -0700178 bool isOptional(int op) const { return optional[op]; }
John Kessenich140f3df2015-06-26 16:58:36 -0600179 int getNum() const { return (int)opClass.size(); }
180
181protected:
182 std::vector<OperandClass> opClass;
183 std::vector<const char*> desc;
John Kessenich55e7d112015-11-15 21:33:39 -0700184 std::vector<bool> optional;
John Kessenich140f3df2015-06-26 16:58:36 -0600185};
186
187// Parameterize an enumerant
188class EnumParameters {
189public:
190 EnumParameters() : desc(0) { }
191 EnumCaps caps;
192 const char* desc;
193};
194
195// Parameterize a set of enumerants that form an enum
196class EnumDefinition : public EnumParameters {
197public:
198 EnumDefinition() :
199 ceiling(0), bitmask(false), getName(0), enumParams(0), operandParams(0) { }
200 void set(int ceil, const char* (*name)(int), EnumParameters* ep, bool mask = false)
201 {
202 ceiling = ceil;
203 getName = name;
204 bitmask = mask;
205 enumParams = ep;
206 }
207 void setOperands(OperandParameters* op) { operandParams = op; }
208 int ceiling; // ceiling of enumerants
209 bool bitmask; // true if these enumerants combine into a bitmask
210 const char* (*getName)(int); // a function that returns the name for each enumerant value (or shift)
211 EnumParameters* enumParams; // parameters for each individual enumerant
212 OperandParameters* operandParams; // sets of operands
213};
214
215// Parameterize an instruction's logical format, including its known set of operands,
216// per OperandParameters above.
217class InstructionParameters {
218public:
219 InstructionParameters() :
John Kessenich5e4b1242015-08-06 22:53:06 -0600220 opDesc("TBD"),
221 opClass(OpClassMissing),
Andre Weissfloga5ade512015-07-11 14:45:57 +0200222 typePresent(true), // most normal, only exceptions have to be spelled out
223 resultPresent(true) // most normal, only exceptions have to be spelled out
John Kessenich140f3df2015-06-26 16:58:36 -0600224 { }
225
226 void setResultAndType(bool r, bool t)
227 {
228 resultPresent = r;
229 typePresent = t;
230 }
231
232 bool hasResult() const { return resultPresent != 0; }
233 bool hasType() const { return typePresent != 0; }
234
235 const char* opDesc;
236 EnumCaps capabilities;
237 OpcodeClass opClass;
238 OperandParameters operands;
239
240protected:
241 int typePresent : 1;
242 int resultPresent : 1;
243};
244
John Kessenich6c292d32016-02-15 20:58:50 -0700245const int OpcodeCeiling = 321;
John Kessenich140f3df2015-06-26 16:58:36 -0600246
247// The set of objects that hold all the instruction/operand
248// parameterization information.
249extern InstructionParameters InstructionDesc[];
250
251// These hold definitions of the enumerants used for operands
252extern EnumDefinition OperandClassParams[];
253
254const char* GetOperandDesc(OperandClass operand);
255void PrintImmediateRow(int imm, const char* name, const EnumParameters* enumParams, bool caps, bool hex = false);
256const char* AccessQualifierString(int attr);
257
258void PrintOperands(const OperandParameters& operands, int reservedOperands);
259
260}; // end namespace spv