1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef COMPILER_ANALYZE_CALL_DEPTH_H_ 16 #define COMPILER_ANALYZE_CALL_DEPTH_H_ 17 18 #include "intermediate.h" 19 20 #include <set> 21 #include <limits.h> 22 23 // Traverses intermediate tree to analyze call depth or detect function recursion 24 class AnalyzeCallDepth : public TIntermTraverser 25 { 26 public: 27 AnalyzeCallDepth(TIntermNode *root); 28 ~AnalyzeCallDepth(); 29 30 virtual bool visitAggregate(Visit, TIntermAggregate*); 31 32 unsigned int analyzeCallDepth(); 33 34 private: 35 class FunctionNode 36 { 37 public: 38 FunctionNode(TIntermAggregate *node); 39 40 const TString &getName() const; 41 void addCallee(FunctionNode *callee); 42 unsigned int analyzeCallDepth(AnalyzeCallDepth *analyzeCallDepth); 43 unsigned int getLastDepth() const; 44 45 void removeIfUnreachable(); 46 47 private: 48 TIntermAggregate *const node; 49 TVector<FunctionNode*> callees; 50 51 Visit visit; 52 unsigned int callDepth; 53 }; 54 55 FunctionNode *findFunctionByName(const TString &name); 56 57 std::vector<FunctionNode*> functions; 58 typedef std::set<FunctionNode*> FunctionSet; 59 FunctionSet globalFunctionCalls; 60 FunctionNode *currentFunction; 61 }; 62 63 #endif // COMPILER_ANALYZE_CALL_DEPTH_H_ 64