Home | History | Annotate | Download | only in compiler
      1 //
      2 // Copyright (c) 2002-2013 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 // NodeSearch.h: Utilities for searching translator node graphs
      7 //
      8 
      9 #ifndef TRANSLATOR_NODESEARCH_H_
     10 #define TRANSLATOR_NODESEARCH_H_
     11 
     12 namespace sh
     13 {
     14 
     15 template <class Parent>
     16 class NodeSearchTraverser : public TIntermTraverser
     17 {
     18   public:
     19     NodeSearchTraverser()
     20         : mFound(false)
     21     {}
     22 
     23     bool found() const { return mFound; }
     24 
     25     static bool search(TIntermNode *node)
     26     {
     27         Parent searchTraverser;
     28         node->traverse(&searchTraverser);
     29         return searchTraverser.found();
     30     }
     31 
     32   protected:
     33     bool mFound;
     34 };
     35 
     36 class FindDiscard : public NodeSearchTraverser<FindDiscard>
     37 {
     38   public:
     39     virtual bool visitBranch(Visit visit, TIntermBranch *node)
     40     {
     41         switch (node->getFlowOp())
     42         {
     43           case EOpKill:
     44             mFound = true;
     45             break;
     46 
     47           default: break;
     48         }
     49 
     50         return !mFound;
     51     }
     52 };
     53 
     54 class FindSideEffectRewriting : public NodeSearchTraverser<FindSideEffectRewriting>
     55 {
     56   public:
     57     virtual bool visitBinary(Visit visit, TIntermBinary *node)
     58     {
     59         switch (node->getOp())
     60         {
     61           case EOpLogicalOr:
     62           case EOpLogicalAnd:
     63             if (node->getRight()->hasSideEffects())
     64             {
     65                 mFound = true;
     66             }
     67             break;
     68 
     69           default: break;
     70         }
     71 
     72         return !mFound;
     73     }
     74 };
     75 
     76 }
     77 
     78 #endif // TRANSLATOR_NODESEARCH_H_
     79