summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/compiler/translator/FindMain.cpp
blob: 7417fbac8aeb7767910d2d5413b2b86754f86d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// FindMain.cpp: Find the main() function definition in a given AST.

#include "compiler/translator/FindMain.h"

#include "compiler/translator/IntermNode.h"

namespace sh
{

TIntermFunctionDefinition *FindMain(TIntermBlock *root)
{
    for (TIntermNode *node : *root->getSequence())
    {
        TIntermFunctionDefinition *nodeFunction = node->getAsFunctionDefinition();
        if (nodeFunction != nullptr && nodeFunction->getFunctionSymbolInfo()->isMain())
        {
            return nodeFunction;
        }
    }
    return nullptr;
}

TIntermBlock *FindMainBody(TIntermBlock *root)
{
    TIntermFunctionDefinition *main = FindMain(root);
    ASSERT(main != nullptr);
    TIntermBlock *mainBody = main->getBody();
    ASSERT(mainBody != nullptr);
    return mainBody;
}

}  // namespace sh