Line data Source code
1 : //
2 : // Copyright (c) 2002-2015 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 : #include "compiler/translator/Operator.h"
8 :
9 0 : const char *GetOperatorString(TOperator op)
10 : {
11 0 : switch (op)
12 : {
13 : // Note: ops from EOpNull to EOpPrototype can't be handled here.
14 :
15 0 : case EOpNegative: return "-";
16 0 : case EOpPositive: return "+";
17 0 : case EOpLogicalNot: return "!";
18 0 : case EOpVectorLogicalNot: return "not";
19 0 : case EOpBitwiseNot: return "~";
20 :
21 0 : case EOpPostIncrement: return "++";
22 0 : case EOpPostDecrement: return "--";
23 0 : case EOpPreIncrement: return "++";
24 0 : case EOpPreDecrement: return "--";
25 :
26 0 : case EOpAdd: return "+";
27 0 : case EOpSub: return "-";
28 0 : case EOpMul: return "*";
29 0 : case EOpDiv: return "/";
30 0 : case EOpIMod: return "%";
31 0 : case EOpEqual: return "==";
32 0 : case EOpNotEqual: return "!=";
33 0 : case EOpVectorEqual: return "equal";
34 0 : case EOpVectorNotEqual: return "notEqual";
35 0 : case EOpLessThan: return "<";
36 0 : case EOpGreaterThan: return ">";
37 0 : case EOpLessThanEqual: return "<=";
38 0 : case EOpGreaterThanEqual: return ">=";
39 0 : case EOpComma: return ",";
40 :
41 : // Fall-through.
42 : case EOpVectorTimesScalar:
43 : case EOpVectorTimesMatrix:
44 : case EOpMatrixTimesVector:
45 0 : case EOpMatrixTimesScalar: return "*";
46 :
47 0 : case EOpLogicalOr: return "||";
48 0 : case EOpLogicalXor: return "^^";
49 0 : case EOpLogicalAnd: return "&&";
50 :
51 0 : case EOpBitShiftLeft: return "<<";
52 0 : case EOpBitShiftRight: return ">>";
53 :
54 0 : case EOpBitwiseAnd: return "&";
55 0 : case EOpBitwiseXor: return "^";
56 0 : case EOpBitwiseOr: return "|";
57 :
58 : // Fall-through.
59 : case EOpIndexDirect:
60 0 : case EOpIndexIndirect: return "[]";
61 :
62 : case EOpIndexDirectStruct:
63 0 : case EOpIndexDirectInterfaceBlock: return ".";
64 :
65 0 : case EOpRadians: return "radians";
66 0 : case EOpDegrees: return "degrees";
67 0 : case EOpSin: return "sin";
68 0 : case EOpCos: return "cos";
69 0 : case EOpTan: return "tan";
70 0 : case EOpAsin: return "asin";
71 0 : case EOpAcos: return "acos";
72 0 : case EOpAtan: return "atan";
73 :
74 0 : case EOpSinh: return "sinh";
75 0 : case EOpCosh: return "cosh";
76 0 : case EOpTanh: return "tanh";
77 0 : case EOpAsinh: return "asinh";
78 0 : case EOpAcosh: return "acosh";
79 0 : case EOpAtanh: return "atanh";
80 :
81 0 : case EOpPow: return "pow";
82 0 : case EOpExp: return "exp";
83 0 : case EOpLog: return "log";
84 0 : case EOpExp2: return "exp2";
85 0 : case EOpLog2: return "log2";
86 0 : case EOpSqrt: return "sqrt";
87 0 : case EOpInverseSqrt: return "inversesqrt";
88 :
89 0 : case EOpAbs: return "abs";
90 0 : case EOpSign: return "sign";
91 0 : case EOpFloor: return "floor";
92 0 : case EOpTrunc: return "trunc";
93 0 : case EOpRound: return "round";
94 0 : case EOpRoundEven: return "roundEven";
95 0 : case EOpCeil: return "ceil";
96 0 : case EOpFract: return "fract";
97 0 : case EOpMod: return "mod";
98 0 : case EOpModf: return "modf";
99 0 : case EOpMin: return "min";
100 0 : case EOpMax: return "max";
101 0 : case EOpClamp: return "clamp";
102 0 : case EOpMix: return "mix";
103 0 : case EOpStep: return "step";
104 0 : case EOpSmoothStep: return "smoothstep";
105 0 : case EOpIsNan: return "isnan";
106 0 : case EOpIsInf: return "isinf";
107 :
108 0 : case EOpFloatBitsToInt: return "floatBitsToInt";
109 0 : case EOpFloatBitsToUint: return "floatBitsToUint";
110 0 : case EOpIntBitsToFloat: return "intBitsToFloat";
111 0 : case EOpUintBitsToFloat: return "uintBitsToFloat";
112 :
113 0 : case EOpPackSnorm2x16: return "packSnorm2x16";
114 0 : case EOpPackUnorm2x16: return "packUnorm2x16";
115 0 : case EOpPackHalf2x16: return "packHalf2x16";
116 0 : case EOpUnpackSnorm2x16: return "unpackSnorm2x16";
117 0 : case EOpUnpackUnorm2x16: return "unpackUnorm2x16";
118 0 : case EOpUnpackHalf2x16: return "unpackHalf2x16";
119 :
120 0 : case EOpLength: return "length";
121 0 : case EOpDistance: return "distance";
122 0 : case EOpDot: return "dot";
123 0 : case EOpCross: return "cross";
124 0 : case EOpNormalize: return "normalize";
125 0 : case EOpFaceForward: return "faceforward";
126 0 : case EOpReflect: return "reflect";
127 0 : case EOpRefract: return "refract";
128 :
129 0 : case EOpDFdx: return "dFdx";
130 0 : case EOpDFdy: return "dFdy";
131 0 : case EOpFwidth: return "fwidth";
132 :
133 0 : case EOpMatrixTimesMatrix: return "*";
134 :
135 0 : case EOpOuterProduct: return "outerProduct";
136 0 : case EOpTranspose: return "transpose";
137 0 : case EOpDeterminant: return "determinant";
138 0 : case EOpInverse: return "inverse";
139 :
140 0 : case EOpAny: return "any";
141 0 : case EOpAll: return "all";
142 :
143 0 : case EOpKill: return "kill";
144 0 : case EOpReturn: return "return";
145 0 : case EOpBreak: return "break";
146 0 : case EOpContinue: return "continue";
147 :
148 0 : case EOpConstructInt: return "int";
149 0 : case EOpConstructUInt: return "uint";
150 0 : case EOpConstructBool: return "bool";
151 0 : case EOpConstructFloat: return "float";
152 0 : case EOpConstructVec2: return "vec2";
153 0 : case EOpConstructVec3: return "vec3";
154 0 : case EOpConstructVec4: return "vec4";
155 0 : case EOpConstructBVec2: return "bvec2";
156 0 : case EOpConstructBVec3: return "bvec3";
157 0 : case EOpConstructBVec4: return "bvec4";
158 0 : case EOpConstructIVec2: return "ivec2";
159 0 : case EOpConstructIVec3: return "ivec3";
160 0 : case EOpConstructIVec4: return "ivec4";
161 0 : case EOpConstructUVec2: return "uvec2";
162 0 : case EOpConstructUVec3: return "uvec3";
163 0 : case EOpConstructUVec4: return "uvec4";
164 0 : case EOpConstructMat2: return "mat2";
165 0 : case EOpConstructMat2x3: return "mat2x3";
166 0 : case EOpConstructMat2x4: return "mat2x4";
167 0 : case EOpConstructMat3x2: return "mat3x2";
168 0 : case EOpConstructMat3: return "mat3";
169 0 : case EOpConstructMat3x4: return "mat3x4";
170 0 : case EOpConstructMat4x2: return "mat4x2";
171 0 : case EOpConstructMat4x3: return "mat4x3";
172 0 : case EOpConstructMat4: return "mat4";
173 : // Note: EOpConstructStruct can't be handled here
174 :
175 0 : case EOpAssign: return "=";
176 0 : case EOpInitialize: return "=";
177 0 : case EOpAddAssign: return "+=";
178 0 : case EOpSubAssign: return "-=";
179 :
180 : // Fall-through.
181 : case EOpMulAssign:
182 : case EOpVectorTimesMatrixAssign:
183 : case EOpVectorTimesScalarAssign:
184 : case EOpMatrixTimesScalarAssign:
185 0 : case EOpMatrixTimesMatrixAssign: return "*=";
186 :
187 0 : case EOpDivAssign: return "/=";
188 0 : case EOpIModAssign: return "%=";
189 0 : case EOpBitShiftLeftAssign: return "<<=";
190 0 : case EOpBitShiftRightAssign: return ">>=";
191 0 : case EOpBitwiseAndAssign: return "&=";
192 0 : case EOpBitwiseXorAssign: return "^=";
193 0 : case EOpBitwiseOrAssign: return "|=";
194 :
195 0 : default: break;
196 : }
197 0 : return "";
198 : }
199 :
200 0 : bool IsAssignment(TOperator op)
201 : {
202 0 : switch (op)
203 : {
204 : case EOpPostIncrement:
205 : case EOpPostDecrement:
206 : case EOpPreIncrement:
207 : case EOpPreDecrement:
208 : case EOpAssign:
209 : case EOpAddAssign:
210 : case EOpSubAssign:
211 : case EOpMulAssign:
212 : case EOpVectorTimesMatrixAssign:
213 : case EOpVectorTimesScalarAssign:
214 : case EOpMatrixTimesScalarAssign:
215 : case EOpMatrixTimesMatrixAssign:
216 : case EOpDivAssign:
217 : case EOpIModAssign:
218 : case EOpBitShiftLeftAssign:
219 : case EOpBitShiftRightAssign:
220 : case EOpBitwiseAndAssign:
221 : case EOpBitwiseXorAssign:
222 : case EOpBitwiseOrAssign:
223 0 : return true;
224 : default:
225 0 : return false;
226 : }
227 : }
|