1 //
2 // Copyright 2002 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef COMPILER_TRANSLATOR_OPERATOR_H_
8 #define COMPILER_TRANSLATOR_OPERATOR_H_
9 
10 #include <cstdint>
11 
12 //
13 // Operators used by the high-level (parse tree) representation.
14 //
15 enum TOperator : uint8_t
16 {
17     EOpNull,  // if in a node, should only mean a node is still being built
18 
19     // Call a function defined in the AST. This might be a user-defined function or a function
20     // inserted by an AST transformation.
21     EOpCallFunctionInAST,
22 
23     // Call an internal helper function with a raw implementation - the implementation can't be
24     // subject to AST transformations. Raw functions have a few constraints to keep them compatible
25     // with AST traversers:
26     // * They should not return arrays.
27     // * They should not have out parameters.
28     EOpCallInternalRawFunction,
29 
30     // Call a built-in function like a texture or image function.
31     EOpCallBuiltInFunction,
32 
33     //
34     // Unary operators
35     //
36 
37     EOpNegative,
38     EOpPositive,
39     EOpLogicalNot,
40     EOpBitwiseNot,
41 
42     EOpPostIncrement,
43     EOpPostDecrement,
44     EOpPreIncrement,
45     EOpPreDecrement,
46 
47     EOpArrayLength,
48 
49     //
50     // binary operations (ones with special GLSL syntax are used in TIntermBinary nodes, others in
51     // TIntermAggregate nodes)
52     //
53 
54     EOpAdd,
55     EOpSub,
56     EOpMul,
57     EOpDiv,
58     EOpIMod,
59 
60     EOpEqual,
61     EOpNotEqual,
62     EOpLessThan,
63     EOpGreaterThan,
64     EOpLessThanEqual,
65     EOpGreaterThanEqual,
66 
67     EOpEqualComponentWise,
68     EOpNotEqualComponentWise,
69     EOpLessThanComponentWise,
70     EOpLessThanEqualComponentWise,
71     EOpGreaterThanComponentWise,
72     EOpGreaterThanEqualComponentWise,
73 
74     EOpComma,
75 
76     EOpVectorTimesScalar,
77     EOpVectorTimesMatrix,
78     EOpMatrixTimesVector,
79     EOpMatrixTimesScalar,
80     EOpMatrixTimesMatrix,
81 
82     EOpLogicalOr,
83     EOpLogicalXor,
84     EOpLogicalAnd,
85 
86     EOpBitShiftLeft,
87     EOpBitShiftRight,
88 
89     EOpBitwiseAnd,
90     EOpBitwiseXor,
91     EOpBitwiseOr,
92 
93     EOpIndexDirect,
94     EOpIndexIndirect,
95     EOpIndexDirectStruct,
96     EOpIndexDirectInterfaceBlock,
97 
98     //
99     // Built-in functions mapped to operators (either unary or with multiple parameters)
100     //
101 
102     EOpRadians,
103     EOpDegrees,
104     EOpSin,
105     EOpCos,
106     EOpTan,
107     EOpAsin,
108     EOpAcos,
109     EOpAtan,
110 
111     EOpSinh,
112     EOpCosh,
113     EOpTanh,
114     EOpAsinh,
115     EOpAcosh,
116     EOpAtanh,
117 
118     EOpPow,
119     EOpExp,
120     EOpLog,
121     EOpExp2,
122     EOpLog2,
123     EOpSqrt,
124     EOpInversesqrt,
125 
126     EOpAbs,
127     EOpSign,
128     EOpFloor,
129     EOpTrunc,
130     EOpRound,
131     EOpRoundEven,
132     EOpCeil,
133     EOpFract,
134     EOpMod,
135     EOpModf,
136     EOpMin,
137     EOpMax,
138     EOpClamp,
139     EOpMix,
140     EOpStep,
141     EOpSmoothstep,
142     EOpIsnan,
143     EOpIsinf,
144     EOpFma,
145 
146     EOpFloatBitsToInt,
147     EOpFloatBitsToUint,
148     EOpIntBitsToFloat,
149     EOpUintBitsToFloat,
150 
151     EOpFrexp,
152     EOpLdexp,
153 
154     EOpPackSnorm2x16,
155     EOpPackUnorm2x16,
156     EOpPackHalf2x16,
157     EOpUnpackSnorm2x16,
158     EOpUnpackUnorm2x16,
159     EOpUnpackHalf2x16,
160 
161     EOpPackUnorm4x8,
162     EOpPackSnorm4x8,
163     EOpUnpackUnorm4x8,
164     EOpUnpackSnorm4x8,
165 
166     EOpLength,
167     EOpDistance,
168     EOpDot,
169     EOpCross,
170     EOpNormalize,
171     EOpFaceforward,
172     EOpReflect,
173     EOpRefract,
174 
175     EOpDFdx,    // Fragment only, OES_standard_derivatives extension
176     EOpDFdy,    // Fragment only, OES_standard_derivatives extension
177     EOpFwidth,  // Fragment only, OES_standard_derivatives extension
178 
179     EOpMulMatrixComponentWise,
180     EOpOuterProduct,
181     EOpTranspose,
182     EOpDeterminant,
183     EOpInverse,
184 
185     EOpAny,
186     EOpAll,
187     EOpLogicalNotComponentWise,
188 
189     EOpBitfieldExtract,
190     EOpBitfieldInsert,
191     EOpBitfieldReverse,
192     EOpBitCount,
193     EOpFindLSB,
194     EOpFindMSB,
195     EOpUaddCarry,
196     EOpUsubBorrow,
197     EOpUmulExtended,
198     EOpImulExtended,
199 
200     //
201     // Branch
202     //
203 
204     EOpKill,  // Fragment only
205     EOpReturn,
206     EOpBreak,
207     EOpContinue,
208 
209     //
210     // Constructor
211     //
212 
213     EOpConstruct,
214 
215     //
216     // moves
217     //
218 
219     EOpAssign,
220     EOpInitialize,
221     EOpAddAssign,
222     EOpSubAssign,
223 
224     EOpMulAssign,
225     EOpVectorTimesMatrixAssign,
226     EOpVectorTimesScalarAssign,
227     EOpMatrixTimesScalarAssign,
228     EOpMatrixTimesMatrixAssign,
229 
230     EOpDivAssign,
231     EOpIModAssign,
232     EOpBitShiftLeftAssign,
233     EOpBitShiftRightAssign,
234     EOpBitwiseAndAssign,
235     EOpBitwiseXorAssign,
236     EOpBitwiseOrAssign,
237 
238     // barriers
239     EOpBarrier,
240     EOpMemoryBarrier,
241     EOpMemoryBarrierAtomicCounter,
242     EOpMemoryBarrierBuffer,
243     EOpMemoryBarrierImage,
244     EOpMemoryBarrierShared,
245     EOpGroupMemoryBarrier,
246 
247     // Atomic functions
248     EOpAtomicAdd,
249     EOpAtomicMin,
250     EOpAtomicMax,
251     EOpAtomicAnd,
252     EOpAtomicOr,
253     EOpAtomicXor,
254     EOpAtomicExchange,
255     EOpAtomicCompSwap,
256 
257     // Geometry only
258     EOpEmitVertex,
259     EOpEndPrimitive,
260 
261     // Desktop GLSL functions
262     EOpFTransform,
263     EOpPackDouble2x32,
264     EOpUnpackDouble2x32,
265 };
266 
267 // Returns the string corresponding to the operator in GLSL
268 const char *GetOperatorString(TOperator op);
269 
270 // Say whether or not a binary or unary operation changes the value of a variable.
271 bool IsAssignment(TOperator op);
272 
273 // Say whether or not an operator represents an atomic function.
274 bool IsAtomicFunction(TOperator op);
275 
276 #endif  // COMPILER_TRANSLATOR_OPERATOR_H_
277