Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
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 //
7 #pragma warning(disable: 4718)
9 #include "compiler/depgraph/DependencyGraph.h"
10 #include "compiler/depgraph/DependencyGraphBuilder.h"
12 TDependencyGraph::TDependencyGraph(TIntermNode* intermNode)
13 {
14 TDependencyGraphBuilder::build(intermNode, this);
15 }
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 }
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 }
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 }
43 TGraphSymbol* TDependencyGraph::getOrCreateSymbol(TIntermSymbol* intermSymbol)
44 {
45 TSymbolIdMap::const_iterator iter = mSymbolIdMap.find(intermSymbol->getId());
47 TGraphSymbol* symbol = NULL;
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);
56 TSymbolIdPair pair(intermSymbol->getId(), symbol);
57 mSymbolIdMap.insert(pair);
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 }
64 return symbol;
65 }
67 TGraphSelection* TDependencyGraph::createSelection(TIntermSelection* intermSelection)
68 {
69 TGraphSelection* selection = new TGraphSelection(intermSelection);
70 mAllNodes.push_back(selection);
71 return selection;
72 }
74 TGraphLoop* TDependencyGraph::createLoop(TIntermLoop* intermLoop)
75 {
76 TGraphLoop* loop = new TGraphLoop(intermLoop);
77 mAllNodes.push_back(loop);
78 return loop;
79 }
81 TGraphLogicalOp* TDependencyGraph::createLogicalOp(TIntermBinary* intermLogicalOp)
82 {
83 TGraphLogicalOp* logicalOp = new TGraphLogicalOp(intermLogicalOp);
84 mAllNodes.push_back(logicalOp);
85 return logicalOp;
86 }
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 }