Home | History | Annotate | Download | only in compiler
      1 //
      2 // Copyright (c) 2002-2011 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/TranslatorESSL.h"
      8 
      9 #include "compiler/OutputESSL.h"
     10 
     11 TranslatorESSL::TranslatorESSL(ShShaderType type, ShShaderSpec spec)
     12     : TCompiler(type, spec) {
     13 }
     14 
     15 void TranslatorESSL::translate(TIntermNode* root) {
     16     TInfoSinkBase& sink = getInfoSink().obj;
     17 
     18     // Write built-in extension behaviors.
     19     writeExtensionBehavior();
     20 
     21     // Write emulated built-in functions if needed.
     22     getBuiltInFunctionEmulator().OutputEmulatedFunctionDefinition(
     23         sink, getShaderType() == SH_FRAGMENT_SHADER);
     24 
     25     // Write array bounds clamping emulation if needed.
     26     getArrayBoundsClamper().OutputClampingFunctionDefinition(sink);
     27 
     28     // Write translated shader.
     29     TOutputESSL outputESSL(sink, getArrayIndexClampingStrategy(), getHashFunction(), getNameMap(), getSymbolTable());
     30     root->traverse(&outputESSL);
     31 }
     32 
     33 void TranslatorESSL::writeExtensionBehavior() {
     34     TInfoSinkBase& sink = getInfoSink().obj;
     35     const TExtensionBehavior& extensionBehavior = getExtensionBehavior();
     36     for (TExtensionBehavior::const_iterator iter = extensionBehavior.begin();
     37          iter != extensionBehavior.end(); ++iter) {
     38         if (iter->second != EBhUndefined) {
     39             sink << "#extension " << iter->first << " : "
     40                  << getBehaviorString(iter->second) << "\n";
     41         }
     42     }
     43 }
     44