michael@0: // michael@0: // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #pragma warning(disable: 4718) michael@0: michael@0: #include "compiler/depgraph/DependencyGraph.h" michael@0: #include "compiler/depgraph/DependencyGraphBuilder.h" michael@0: michael@0: TDependencyGraph::TDependencyGraph(TIntermNode* intermNode) michael@0: { michael@0: TDependencyGraphBuilder::build(intermNode, this); michael@0: } michael@0: michael@0: TDependencyGraph::~TDependencyGraph() michael@0: { michael@0: for (TGraphNodeVector::const_iterator iter = mAllNodes.begin(); iter != mAllNodes.end(); ++iter) michael@0: { michael@0: TGraphNode* node = *iter; michael@0: delete node; michael@0: } michael@0: } michael@0: michael@0: TGraphArgument* TDependencyGraph::createArgument(TIntermAggregate* intermFunctionCall, michael@0: int argumentNumber) michael@0: { michael@0: TGraphArgument* argument = new TGraphArgument(intermFunctionCall, argumentNumber); michael@0: mAllNodes.push_back(argument); michael@0: return argument; michael@0: } michael@0: michael@0: TGraphFunctionCall* TDependencyGraph::createFunctionCall(TIntermAggregate* intermFunctionCall) michael@0: { michael@0: TGraphFunctionCall* functionCall = new TGraphFunctionCall(intermFunctionCall); michael@0: mAllNodes.push_back(functionCall); michael@0: if (functionCall->getIntermFunctionCall()->isUserDefined()) michael@0: mUserDefinedFunctionCalls.push_back(functionCall); michael@0: return functionCall; michael@0: } michael@0: michael@0: TGraphSymbol* TDependencyGraph::getOrCreateSymbol(TIntermSymbol* intermSymbol) michael@0: { michael@0: TSymbolIdMap::const_iterator iter = mSymbolIdMap.find(intermSymbol->getId()); michael@0: michael@0: TGraphSymbol* symbol = NULL; michael@0: michael@0: if (iter != mSymbolIdMap.end()) { michael@0: TSymbolIdPair pair = *iter; michael@0: symbol = pair.second; michael@0: } else { michael@0: symbol = new TGraphSymbol(intermSymbol); michael@0: mAllNodes.push_back(symbol); michael@0: michael@0: TSymbolIdPair pair(intermSymbol->getId(), symbol); michael@0: mSymbolIdMap.insert(pair); michael@0: michael@0: // We save all sampler symbols in a collection, so we can start graph traversals from them quickly. michael@0: if (IsSampler(intermSymbol->getBasicType())) michael@0: mSamplerSymbols.push_back(symbol); michael@0: } michael@0: michael@0: return symbol; michael@0: } michael@0: michael@0: TGraphSelection* TDependencyGraph::createSelection(TIntermSelection* intermSelection) michael@0: { michael@0: TGraphSelection* selection = new TGraphSelection(intermSelection); michael@0: mAllNodes.push_back(selection); michael@0: return selection; michael@0: } michael@0: michael@0: TGraphLoop* TDependencyGraph::createLoop(TIntermLoop* intermLoop) michael@0: { michael@0: TGraphLoop* loop = new TGraphLoop(intermLoop); michael@0: mAllNodes.push_back(loop); michael@0: return loop; michael@0: } michael@0: michael@0: TGraphLogicalOp* TDependencyGraph::createLogicalOp(TIntermBinary* intermLogicalOp) michael@0: { michael@0: TGraphLogicalOp* logicalOp = new TGraphLogicalOp(intermLogicalOp); michael@0: mAllNodes.push_back(logicalOp); michael@0: return logicalOp; michael@0: } michael@0: michael@0: const char* TGraphLogicalOp::getOpString() const michael@0: { michael@0: const char* opString = NULL; michael@0: switch (getIntermLogicalOp()->getOp()) { michael@0: case EOpLogicalAnd: opString = "and"; break; michael@0: case EOpLogicalOr: opString = "or"; break; michael@0: default: opString = "unknown"; break; michael@0: } michael@0: return opString; michael@0: }