/src/shaderc/third_party/glslang/glslang/HLSL/hlslOpMap.cpp
Line | Count | Source |
1 | | // |
2 | | // Copyright (C) 2016 Google, Inc. |
3 | | // |
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 Google, Inc., 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 | | // Map from physical token form (e.g. '-') to logical operator |
37 | | // form (e.g., binary subtract or unary negate). |
38 | | |
39 | | #include "hlslOpMap.h" |
40 | | |
41 | | namespace glslang { |
42 | | |
43 | | // Map parsing tokens that could be assignments into assignment operators. |
44 | | TOperator HlslOpMap::assignment(EHlslTokenClass op) |
45 | 81.0k | { |
46 | 81.0k | switch (op) { |
47 | 1.39k | case EHTokAssign: return EOpAssign; |
48 | 166 | case EHTokMulAssign: return EOpMulAssign; |
49 | 512 | case EHTokDivAssign: return EOpDivAssign; |
50 | 112 | case EHTokAddAssign: return EOpAddAssign; |
51 | 12 | case EHTokModAssign: return EOpModAssign; |
52 | 4 | case EHTokLeftAssign: return EOpLeftShiftAssign; |
53 | 2 | case EHTokRightAssign: return EOpRightShiftAssign; |
54 | 2 | case EHTokAndAssign: return EOpAndAssign; |
55 | 0 | case EHTokXorAssign: return EOpExclusiveOrAssign; |
56 | 4 | case EHTokOrAssign: return EOpInclusiveOrAssign; |
57 | 106 | case EHTokSubAssign: return EOpSubAssign; |
58 | | |
59 | 78.6k | default: |
60 | 78.6k | return EOpNull; |
61 | 81.0k | } |
62 | 81.0k | } |
63 | | |
64 | | // Map parsing tokens that could be binary operations into binary operators. |
65 | | TOperator HlslOpMap::binary(EHlslTokenClass op) |
66 | 913k | { |
67 | 913k | switch (op) { |
68 | 3.86k | case EHTokPlus: return EOpAdd; |
69 | 974 | case EHTokDash: return EOpSub; |
70 | 460 | case EHTokStar: return EOpMul; |
71 | 416 | case EHTokSlash: return EOpDiv; |
72 | 74 | case EHTokPercent: return EOpMod; |
73 | 84 | case EHTokRightOp: return EOpRightShift; |
74 | 6 | case EHTokLeftOp: return EOpLeftShift; |
75 | 240 | case EHTokAmpersand: return EOpAnd; |
76 | 18 | case EHTokVerticalBar: return EOpInclusiveOr; |
77 | 70 | case EHTokCaret: return EOpExclusiveOr; |
78 | 1.32k | case EHTokEqOp: return EOpEqual; |
79 | 890 | case EHTokNeOp: return EOpNotEqual; |
80 | 2.05k | case EHTokLeftAngle: return EOpLessThan; |
81 | 584 | case EHTokRightAngle: return EOpGreaterThan; |
82 | 288 | case EHTokLeOp: return EOpLessThanEqual; |
83 | 376 | case EHTokGeOp: return EOpGreaterThanEqual; |
84 | 74 | case EHTokOrOp: return EOpLogicalOr; |
85 | 40 | case EHTokXorOp: return EOpLogicalXor; |
86 | 1.37k | case EHTokAndOp: return EOpLogicalAnd; |
87 | | |
88 | 900k | default: |
89 | 900k | return EOpNull; |
90 | 913k | } |
91 | 913k | } |
92 | | |
93 | | // Map parsing tokens that could be unary operations into unary operators. |
94 | | // These are just the ones that can appear in front of its operand. |
95 | | TOperator HlslOpMap::preUnary(EHlslTokenClass op) |
96 | 93.0k | { |
97 | 93.0k | switch (op) { |
98 | 372 | case EHTokPlus: return EOpAdd; // means no-op, but still a unary op was present |
99 | 1.11k | case EHTokDash: return EOpNegative; |
100 | 40 | case EHTokBang: return EOpLogicalNot; |
101 | 386 | case EHTokTilde: return EOpBitwiseNot; |
102 | | |
103 | 394 | case EHTokIncOp: return EOpPreIncrement; |
104 | 78 | case EHTokDecOp: return EOpPreDecrement; |
105 | | |
106 | 90.6k | default: return EOpNull; // means not a pre-unary op |
107 | 93.0k | } |
108 | 93.0k | } |
109 | | |
110 | | // Map parsing tokens that could be unary operations into unary operators. |
111 | | // These are just the ones that can appear behind its operand. |
112 | | TOperator HlslOpMap::postUnary(EHlslTokenClass op) |
113 | 92.5k | { |
114 | 92.5k | switch (op) { |
115 | 3.89k | case EHTokDot: return EOpIndexDirectStruct; |
116 | 866 | case EHTokLeftBracket: return EOpIndexIndirect; |
117 | | |
118 | 442 | case EHTokIncOp: return EOpPostIncrement; |
119 | 464 | case EHTokDecOp: return EOpPostDecrement; |
120 | | |
121 | 0 | case EHTokColonColon: return EOpScoping; |
122 | | |
123 | 86.9k | default: return EOpNull; // means not a post-unary op |
124 | 92.5k | } |
125 | 92.5k | } |
126 | | |
127 | | // Map operators into their level of precedence. |
128 | | PrecedenceLevel HlslOpMap::precedenceLevel(TOperator op) |
129 | 913k | { |
130 | 913k | switch (op) { |
131 | 74 | case EOpLogicalOr: |
132 | 74 | return PlLogicalOr; |
133 | 40 | case EOpLogicalXor: |
134 | 40 | return PlLogicalXor; |
135 | 1.37k | case EOpLogicalAnd: |
136 | 1.37k | return PlLogicalAnd; |
137 | | |
138 | 18 | case EOpInclusiveOr: |
139 | 18 | return PlBitwiseOr; |
140 | 70 | case EOpExclusiveOr: |
141 | 70 | return PlBitwiseXor; |
142 | 240 | case EOpAnd: |
143 | 240 | return PlBitwiseAnd; |
144 | | |
145 | 1.32k | case EOpEqual: |
146 | 2.21k | case EOpNotEqual: |
147 | 2.21k | return PlEquality; |
148 | | |
149 | 2.05k | case EOpLessThan: |
150 | 2.63k | case EOpGreaterThan: |
151 | 2.92k | case EOpLessThanEqual: |
152 | 3.30k | case EOpGreaterThanEqual: |
153 | 3.30k | return PlRelational; |
154 | | |
155 | 84 | case EOpRightShift: |
156 | 90 | case EOpLeftShift: |
157 | 90 | return PlShift; |
158 | | |
159 | 3.86k | case EOpAdd: |
160 | 4.84k | case EOpSub: |
161 | 4.84k | return PlAdd; |
162 | | |
163 | 460 | case EOpMul: |
164 | 876 | case EOpDiv: |
165 | 950 | case EOpMod: |
166 | 950 | return PlMul; |
167 | | |
168 | 900k | default: |
169 | 900k | return PlBad; |
170 | 913k | } |
171 | 913k | } |
172 | | |
173 | | } // end namespace glslang |