| 1 | // | 
|---|
| 2 | // Copyright (c) 2016 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 | // IntermNodePatternMatcher is a helper class for matching node trees to given patterns. | 
|---|
| 7 | // It can be used whenever the same checks for certain node structures are common to multiple AST | 
|---|
| 8 | // traversers. | 
|---|
| 9 | // | 
|---|
| 10 |  | 
|---|
| 11 | #ifndef COMPILER_TRANSLATOR_TREEUTIL_INTERMNODEPATTERNMATCHER_H_ | 
|---|
| 12 | #define COMPILER_TRANSLATOR_TREEUTIL_INTERMNODEPATTERNMATCHER_H_ | 
|---|
| 13 |  | 
|---|
| 14 | namespace sh | 
|---|
| 15 | { | 
|---|
| 16 |  | 
|---|
| 17 | class TIntermAggregate; | 
|---|
| 18 | class TIntermBinary; | 
|---|
| 19 | class TIntermDeclaration; | 
|---|
| 20 | class TIntermNode; | 
|---|
| 21 | class TIntermTernary; | 
|---|
| 22 | class TIntermUnary; | 
|---|
| 23 |  | 
|---|
| 24 | class IntermNodePatternMatcher | 
|---|
| 25 | { | 
|---|
| 26 | public: | 
|---|
| 27 | static bool IsDynamicIndexingOfNonSSBOVectorOrMatrix(TIntermBinary *node); | 
|---|
| 28 | static bool IsDynamicIndexingOfVectorOrMatrix(TIntermBinary *node); | 
|---|
| 29 |  | 
|---|
| 30 | enum PatternType | 
|---|
| 31 | { | 
|---|
| 32 | // Matches expressions that are unfolded to if statements by UnfoldShortCircuitToIf | 
|---|
| 33 | kUnfoldedShortCircuitExpression = 0x0001, | 
|---|
| 34 |  | 
|---|
| 35 | // Matches expressions that return arrays with the exception of simple statements where a | 
|---|
| 36 | // constructor or function call result is assigned. | 
|---|
| 37 | kExpressionReturningArray = 0x0001 << 1, | 
|---|
| 38 |  | 
|---|
| 39 | // Matches dynamic indexing of vectors or matrices in l-values. | 
|---|
| 40 | kDynamicIndexingOfVectorOrMatrixInLValue = 0x0001 << 2, | 
|---|
| 41 |  | 
|---|
| 42 | // Matches declarations with more than one declared variables. | 
|---|
| 43 | kMultiDeclaration = 0x0001 << 3, | 
|---|
| 44 |  | 
|---|
| 45 | // Matches declarations of arrays. | 
|---|
| 46 | kArrayDeclaration = 0x0001 << 4, | 
|---|
| 47 |  | 
|---|
| 48 | // Matches declarations of structs where the struct type does not have a name. | 
|---|
| 49 | kNamelessStructDeclaration = 0x0001 << 5, | 
|---|
| 50 |  | 
|---|
| 51 | // Matches array length() method. | 
|---|
| 52 | kArrayLengthMethod = 0x0001 << 6, | 
|---|
| 53 |  | 
|---|
| 54 | // Matches a vector or matrix constructor whose arguments are scalarized by the | 
|---|
| 55 | // SH_SCALARIZE_VEC_OR_MAT_CONSTRUCTOR_ARGUMENTS workaround. | 
|---|
| 56 | kScalarizedVecOrMatConstructor = 0x0001 << 7 | 
|---|
| 57 | }; | 
|---|
| 58 | IntermNodePatternMatcher(const unsigned int mask); | 
|---|
| 59 |  | 
|---|
| 60 | bool match(TIntermUnary *node); | 
|---|
| 61 |  | 
|---|
| 62 | bool match(TIntermBinary *node, TIntermNode *parentNode); | 
|---|
| 63 |  | 
|---|
| 64 | // Use this version for checking binary node matches in case you're using flag | 
|---|
| 65 | // kDynamicIndexingOfVectorOrMatrixInLValue. | 
|---|
| 66 | bool match(TIntermBinary *node, TIntermNode *parentNode, bool isLValueRequiredHere); | 
|---|
| 67 |  | 
|---|
| 68 | bool match(TIntermAggregate *node, TIntermNode *parentNode); | 
|---|
| 69 | bool match(TIntermTernary *node); | 
|---|
| 70 | bool match(TIntermDeclaration *node); | 
|---|
| 71 |  | 
|---|
| 72 | private: | 
|---|
| 73 | const unsigned int mMask; | 
|---|
| 74 |  | 
|---|
| 75 | bool matchInternal(TIntermBinary *node, TIntermNode *parentNode); | 
|---|
| 76 | }; | 
|---|
| 77 |  | 
|---|
| 78 | }  // namespace sh | 
|---|
| 79 |  | 
|---|
| 80 | #endif  // COMPILER_TRANSLATOR_TREEUTIL_INTERMNODEPATTERNMATCHER_H_ | 
|---|
| 81 |  | 
|---|