• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2017 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 // FindMain.cpp: Find the main() function definition in a given AST.
8 
9 #include "compiler/translator/tree_util/FindMain.h"
10 
11 #include "compiler/translator/IntermNode.h"
12 #include "compiler/translator/Symbol.h"
13 
14 namespace sh
15 {
16 
FindMainIndex(TIntermBlock * root)17 size_t FindMainIndex(TIntermBlock *root)
18 {
19     const TIntermSequence &sequence = *root->getSequence();
20     for (size_t index = 0; index < sequence.size(); ++index)
21     {
22         TIntermNode *node                       = sequence[index];
23         TIntermFunctionDefinition *nodeFunction = node->getAsFunctionDefinition();
24         if (nodeFunction != nullptr && nodeFunction->getFunction()->isMain())
25         {
26             return index;
27         }
28     }
29     return std::numeric_limits<size_t>::max();
30 }
31 
FindMain(TIntermBlock * root)32 TIntermFunctionDefinition *FindMain(TIntermBlock *root)
33 {
34     for (TIntermNode *node : *root->getSequence())
35     {
36         TIntermFunctionDefinition *nodeFunction = node->getAsFunctionDefinition();
37         if (nodeFunction != nullptr && nodeFunction->getFunction()->isMain())
38         {
39             return nodeFunction;
40         }
41     }
42     return nullptr;
43 }
44 
FindMainBody(TIntermBlock * root)45 TIntermBlock *FindMainBody(TIntermBlock *root)
46 {
47     TIntermFunctionDefinition *main = FindMain(root);
48     ASSERT(main != nullptr);
49     TIntermBlock *mainBody = main->getBody();
50     ASSERT(mainBody != nullptr);
51     return mainBody;
52 }
53 
54 }  // namespace sh
55