blob: ca661d676789a693cb26784401ddd170556e0839 [file] [log] [blame]
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +00001//
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
apatrick@chromium.org679280b2012-05-31 22:41:21 +00007#pragma warning(disable: 4718)
8
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +00009#include "compiler/depgraph/DependencyGraph.h"
10#include "compiler/depgraph/DependencyGraphBuilder.h"
11
12TDependencyGraph::TDependencyGraph(TIntermNode* intermNode)
13{
14 TDependencyGraphBuilder::build(intermNode, this);
15}
16
17TDependencyGraph::~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
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +000026TGraphArgument* 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
34TGraphFunctionCall* 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
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +000043TGraphSymbol* TDependencyGraph::getOrCreateSymbol(TIntermSymbol* intermSymbol)
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +000044{
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
maxvujovic@gmail.com77222c92012-06-04 21:06:05 +000059 // 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);
maxvujovic@gmail.com66ebd012012-05-30 22:18:11 +000062 }
63
64 return symbol;
65}
66
67TGraphSelection* TDependencyGraph::createSelection(TIntermSelection* intermSelection)
68{
69 TGraphSelection* selection = new TGraphSelection(intermSelection);
70 mAllNodes.push_back(selection);
71 return selection;
72}
73
74TGraphLoop* TDependencyGraph::createLoop(TIntermLoop* intermLoop)
75{
76 TGraphLoop* loop = new TGraphLoop(intermLoop);
77 mAllNodes.push_back(loop);
78 return loop;
79}
80
81TGraphLogicalOp* TDependencyGraph::createLogicalOp(TIntermBinary* intermLogicalOp)
82{
83 TGraphLogicalOp* logicalOp = new TGraphLogicalOp(intermLogicalOp);
84 mAllNodes.push_back(logicalOp);
85 return logicalOp;
86}
87
88const 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}