1 //
2 // Copyright 2020 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 #include "compiler/translator/TranslatorMetalDirect/MapFunctionsToDefinitions.h"
8 #include "compiler/translator/Symbol.h"
9 
10 using namespace sh;
11 
12 class Mapper : public TIntermTraverser
13 {
14   public:
15     FunctionToDefinition mFuncToDef;
16 
17   public:
Mapper()18     Mapper() : TIntermTraverser(true, false, false) {}
19 
visitFunctionDefinition(Visit,TIntermFunctionDefinition * funcDefNode)20     bool visitFunctionDefinition(Visit, TIntermFunctionDefinition *funcDefNode) override
21     {
22         const TFunction *func = funcDefNode->getFunction();
23         ASSERT(func->getBuiltInOp() == TOperator::EOpNull);
24         mFuncToDef[func] = funcDefNode;
25         return false;
26     }
27 };
28 
MapFunctionsToDefinitions(TIntermBlock & root)29 FunctionToDefinition sh::MapFunctionsToDefinitions(TIntermBlock &root)
30 {
31     Mapper mapper;
32     root.traverse(&mapper);
33     return std::move(mapper.mFuncToDef);
34 }
35