1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef COMPILER_ANALYZE_CALL_DEPTH_H_
16 #define COMPILER_ANALYZE_CALL_DEPTH_H_
18 #include "intermediate.h"
23 // Traverses intermediate tree to analyze call depth or detect function recursion
24 class AnalyzeCallDepth : public TIntermTraverser
27 AnalyzeCallDepth(TIntermNode *root);
30 virtual bool visitSwitch(Visit, TIntermSwitch*);
31 virtual bool visitAggregate(Visit, TIntermAggregate*);
33 unsigned int analyzeCallDepth();
39 FunctionNode(TIntermAggregate *node);
41 const TString &getName() const;
42 void addCallee(FunctionNode *callee);
43 unsigned int analyzeCallDepth(AnalyzeCallDepth *analyzeCallDepth);
44 unsigned int getLastDepth() const;
46 void removeIfUnreachable();
49 TIntermAggregate *const node;
50 TVector<FunctionNode*> callees;
53 unsigned int callDepth;
56 FunctionNode *findFunctionByName(const TString &name);
58 std::vector<FunctionNode*> functions;
59 typedef std::set<FunctionNode*> FunctionSet;
60 FunctionSet globalFunctionCalls;
61 FunctionNode *currentFunction;
64 #endif // COMPILER_ANALYZE_CALL_DEPTH_H_