1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | #ifndef _LOCAL_INTERMEDIATE_INCLUDED_ |
16 | #define _LOCAL_INTERMEDIATE_INCLUDED_ |
17 | |
18 | #include "intermediate.h" |
19 | |
20 | struct TVectorFields { |
21 | int offsets[4]; |
22 | int num; |
23 | }; |
24 | |
25 | // |
26 | // Set of helper functions to help parse and build the tree. |
27 | // |
28 | class TInfoSink; |
29 | class TIntermediate { |
30 | public: |
31 | POOL_ALLOCATOR_NEW_DELETE() |
32 | |
33 | TIntermediate(TInfoSink& i) : infoSink(i) { } |
34 | TIntermSymbol* addSymbol(int Id, const TString&, const TType&, const TSourceLoc&); |
35 | TIntermTyped* addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&); |
36 | TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, const TSourceLoc&); |
37 | TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, const TSourceLoc&); |
38 | TIntermTyped* addUnaryMath(TOperator op, TIntermTyped* child, const TSourceLoc&, const TType*); |
39 | TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc&); |
40 | TIntermAggregate* makeAggregate(TIntermNode* node, const TSourceLoc&); |
41 | TIntermAggregate* setAggregateOperator(TIntermNode*, TOperator, const TSourceLoc&); |
42 | TIntermNode* addSelection(TIntermTyped* cond, TIntermNodePair code, const TSourceLoc&); |
43 | TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, const TSourceLoc&); |
44 | TIntermSwitch *addSwitch(TIntermTyped *init, TIntermAggregate *statementList, const TSourceLoc &line); |
45 | TIntermCase *addCase(TIntermTyped *condition, const TSourceLoc &line); |
46 | TIntermTyped* addComma(TIntermTyped* left, TIntermTyped* right, const TSourceLoc&); |
47 | TIntermConstantUnion* addConstantUnion(ConstantUnion*, const TType&, const TSourceLoc&); |
48 | TIntermTyped* promoteConstantUnion(TBasicType, TIntermConstantUnion*); |
49 | bool parseConstTree(const TSourceLoc&, TIntermNode*, ConstantUnion*, TOperator, TType, bool singleConstantParam = false); |
50 | TIntermNode* addLoop(TLoopType, TIntermNode*, TIntermTyped*, TIntermTyped*, TIntermNode*, const TSourceLoc&); |
51 | TIntermBranch* addBranch(TOperator, const TSourceLoc&); |
52 | TIntermBranch* addBranch(TOperator, TIntermTyped*, const TSourceLoc&); |
53 | TIntermTyped* addSwizzle(TVectorFields&, const TSourceLoc&); |
54 | bool postProcess(TIntermNode*); |
55 | void outputTree(TIntermNode*); |
56 | |
57 | protected: |
58 | TInfoSink& infoSink; |
59 | |
60 | private: |
61 | void operator=(TIntermediate&); // prevent assignments |
62 | }; |
63 | |
64 | #endif // _LOCAL_INTERMEDIATE_INCLUDED_ |
65 | |