1 //
2 // Copyright (c) 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/FindMain.h"
10 
11 #include "compiler/translator/IntermNode.h"
12 
13 namespace sh
14 {
15 
FindMain(TIntermBlock * root)16 TIntermFunctionDefinition *FindMain(TIntermBlock *root)
17 {
18     for (TIntermNode *node : *root->getSequence())
19     {
20         TIntermFunctionDefinition *nodeFunction = node->getAsFunctionDefinition();
21         if (nodeFunction != nullptr && nodeFunction->getFunctionSymbolInfo()->isMain())
22         {
23             return nodeFunction;
24         }
25     }
26     return nullptr;
27 }
28 
FindMainBody(TIntermBlock * root)29 TIntermBlock *FindMainBody(TIntermBlock *root)
30 {
31     TIntermFunctionDefinition *main = FindMain(root);
32     ASSERT(main != nullptr);
33     TIntermBlock *mainBody = main->getBody();
34     ASSERT(mainBody != nullptr);
35     return mainBody;
36 }
37 
38 }  // namespace sh
39