• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/MapSymbols.h"
8 #include "compiler/translator/TranslatorMetalDirect/IntermRebuild.h"
9 
10 using namespace sh;
11 
12 ////////////////////////////////////////////////////////////////////////////////
13 
14 namespace
15 {
16 
17 class Rewriter : public TIntermRebuild
18 {
19   private:
20     std::function<TIntermNode &(const TFunction *, TIntermSymbol &)> mMap;
21 
22   public:
Rewriter(TCompiler & compiler,std::function<TIntermNode & (const TFunction *,TIntermSymbol &)> map)23     Rewriter(TCompiler &compiler,
24              std::function<TIntermNode &(const TFunction *, TIntermSymbol &)> map)
25         : TIntermRebuild(compiler, false, true), mMap(map)
26     {}
27 
visitSymbolPost(TIntermSymbol & symbolNode)28     PostResult visitSymbolPost(TIntermSymbol &symbolNode) override
29     {
30         return mMap(getParentFunction(), symbolNode);
31     }
32 };
33 
34 }  // namespace
35 
MapSymbols(TCompiler & compiler,TIntermBlock & root,std::function<TIntermNode & (const TFunction *,TIntermSymbol &)> map)36 bool sh::MapSymbols(TCompiler &compiler,
37                     TIntermBlock &root,
38                     std::function<TIntermNode &(const TFunction *, TIntermSymbol &)> map)
39 {
40     Rewriter rewriter(compiler, std::move(map));
41     if (!rewriter.rebuildRoot(root))
42     {
43         return false;
44     }
45     return true;
46 }
47