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