blob: 9b69cc6897d65560d3dc3ee293c69caa03732ffb [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
26TGraphSymbol* TDependencyGraph::getGlobalSymbolByName(const TString& name) const
27{
28 TSymbolNameMap::const_iterator iter = mGlobalSymbolMap.find(name);
29 if (iter == mGlobalSymbolMap.end())
30 return NULL;
31
32 TSymbolNamePair pair = *iter;
33 TGraphSymbol* symbol = pair.second;
34 return symbol;
35}
36
37TGraphArgument* TDependencyGraph::createArgument(TIntermAggregate* intermFunctionCall,
38 int argumentNumber)
39{
40 TGraphArgument* argument = new TGraphArgument(intermFunctionCall, argumentNumber);
41 mAllNodes.push_back(argument);
42 return argument;
43}
44
45TGraphFunctionCall* TDependencyGraph::createFunctionCall(TIntermAggregate* intermFunctionCall)
46{
47 TGraphFunctionCall* functionCall = new TGraphFunctionCall(intermFunctionCall);
48 mAllNodes.push_back(functionCall);
49 if (functionCall->getIntermFunctionCall()->isUserDefined())
50 mUserDefinedFunctionCalls.push_back(functionCall);
51 return functionCall;
52}
53
54TGraphSymbol* TDependencyGraph::getOrCreateSymbol(TIntermSymbol* intermSymbol, bool isGlobalSymbol)
55{
56 TSymbolIdMap::const_iterator iter = mSymbolIdMap.find(intermSymbol->getId());
57
58 TGraphSymbol* symbol = NULL;
59
60 if (iter != mSymbolIdMap.end()) {
61 TSymbolIdPair pair = *iter;
62 symbol = pair.second;
63 } else {
64 symbol = new TGraphSymbol(intermSymbol);
65 mAllNodes.push_back(symbol);
66
67 TSymbolIdPair pair(intermSymbol->getId(), symbol);
68 mSymbolIdMap.insert(pair);
69
70 if (isGlobalSymbol) {
71 // We map all symbols in the global scope by name, so traversers of the graph can
72 // quickly start searches at global symbols with specific names.
73 TSymbolNamePair pair(intermSymbol->getSymbol(), symbol);
74 mGlobalSymbolMap.insert(pair);
75 }
76 }
77
78 return symbol;
79}
80
81TGraphSelection* TDependencyGraph::createSelection(TIntermSelection* intermSelection)
82{
83 TGraphSelection* selection = new TGraphSelection(intermSelection);
84 mAllNodes.push_back(selection);
85 return selection;
86}
87
88TGraphLoop* TDependencyGraph::createLoop(TIntermLoop* intermLoop)
89{
90 TGraphLoop* loop = new TGraphLoop(intermLoop);
91 mAllNodes.push_back(loop);
92 return loop;
93}
94
95TGraphLogicalOp* TDependencyGraph::createLogicalOp(TIntermBinary* intermLogicalOp)
96{
97 TGraphLogicalOp* logicalOp = new TGraphLogicalOp(intermLogicalOp);
98 mAllNodes.push_back(logicalOp);
99 return logicalOp;
100}
101
102const char* TGraphLogicalOp::getOpString() const
103{
104 const char* opString = NULL;
105 switch (getIntermLogicalOp()->getOp()) {
106 case EOpLogicalAnd: opString = "and"; break;
107 case EOpLogicalOr: opString = "or"; break;
108 default: opString = "unknown"; break;
109 }
110 return opString;
111}