|
1 // |
|
2 // Copyright (c) 2012 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 #pragma warning(disable: 4718) |
|
8 |
|
9 #include "compiler/depgraph/DependencyGraph.h" |
|
10 #include "compiler/depgraph/DependencyGraphBuilder.h" |
|
11 |
|
12 TDependencyGraph::TDependencyGraph(TIntermNode* intermNode) |
|
13 { |
|
14 TDependencyGraphBuilder::build(intermNode, this); |
|
15 } |
|
16 |
|
17 TDependencyGraph::~TDependencyGraph() |
|
18 { |
|
19 for (TGraphNodeVector::const_iterator iter = mAllNodes.begin(); iter != mAllNodes.end(); ++iter) |
|
20 { |
|
21 TGraphNode* node = *iter; |
|
22 delete node; |
|
23 } |
|
24 } |
|
25 |
|
26 TGraphArgument* TDependencyGraph::createArgument(TIntermAggregate* intermFunctionCall, |
|
27 int argumentNumber) |
|
28 { |
|
29 TGraphArgument* argument = new TGraphArgument(intermFunctionCall, argumentNumber); |
|
30 mAllNodes.push_back(argument); |
|
31 return argument; |
|
32 } |
|
33 |
|
34 TGraphFunctionCall* TDependencyGraph::createFunctionCall(TIntermAggregate* intermFunctionCall) |
|
35 { |
|
36 TGraphFunctionCall* functionCall = new TGraphFunctionCall(intermFunctionCall); |
|
37 mAllNodes.push_back(functionCall); |
|
38 if (functionCall->getIntermFunctionCall()->isUserDefined()) |
|
39 mUserDefinedFunctionCalls.push_back(functionCall); |
|
40 return functionCall; |
|
41 } |
|
42 |
|
43 TGraphSymbol* TDependencyGraph::getOrCreateSymbol(TIntermSymbol* intermSymbol) |
|
44 { |
|
45 TSymbolIdMap::const_iterator iter = mSymbolIdMap.find(intermSymbol->getId()); |
|
46 |
|
47 TGraphSymbol* symbol = NULL; |
|
48 |
|
49 if (iter != mSymbolIdMap.end()) { |
|
50 TSymbolIdPair pair = *iter; |
|
51 symbol = pair.second; |
|
52 } else { |
|
53 symbol = new TGraphSymbol(intermSymbol); |
|
54 mAllNodes.push_back(symbol); |
|
55 |
|
56 TSymbolIdPair pair(intermSymbol->getId(), symbol); |
|
57 mSymbolIdMap.insert(pair); |
|
58 |
|
59 // We save all sampler symbols in a collection, so we can start graph traversals from them quickly. |
|
60 if (IsSampler(intermSymbol->getBasicType())) |
|
61 mSamplerSymbols.push_back(symbol); |
|
62 } |
|
63 |
|
64 return symbol; |
|
65 } |
|
66 |
|
67 TGraphSelection* TDependencyGraph::createSelection(TIntermSelection* intermSelection) |
|
68 { |
|
69 TGraphSelection* selection = new TGraphSelection(intermSelection); |
|
70 mAllNodes.push_back(selection); |
|
71 return selection; |
|
72 } |
|
73 |
|
74 TGraphLoop* TDependencyGraph::createLoop(TIntermLoop* intermLoop) |
|
75 { |
|
76 TGraphLoop* loop = new TGraphLoop(intermLoop); |
|
77 mAllNodes.push_back(loop); |
|
78 return loop; |
|
79 } |
|
80 |
|
81 TGraphLogicalOp* TDependencyGraph::createLogicalOp(TIntermBinary* intermLogicalOp) |
|
82 { |
|
83 TGraphLogicalOp* logicalOp = new TGraphLogicalOp(intermLogicalOp); |
|
84 mAllNodes.push_back(logicalOp); |
|
85 return logicalOp; |
|
86 } |
|
87 |
|
88 const char* TGraphLogicalOp::getOpString() const |
|
89 { |
|
90 const char* opString = NULL; |
|
91 switch (getIntermLogicalOp()->getOp()) { |
|
92 case EOpLogicalAnd: opString = "and"; break; |
|
93 case EOpLogicalOr: opString = "or"; break; |
|
94 default: opString = "unknown"; break; |
|
95 } |
|
96 return opString; |
|
97 } |