Edit

kc3-lang/angle/src/compiler/ShHandle.h

Branch :

  • Show log

    Commit

  • Author : alokp@chromium.org
    Date : 2010-09-23 17:53:56
    Hash : 07620a58
    Message : - Moved the implementation for ShCompile to the compiler class so that internal details about compiler can be encapsulated. Now we do not need to expose built-in symbol table. - Fixed a few const violations. - Added CollectAttribsUniforms class. BUG=26 Review URL: http://codereview.appspot.com/2263041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@437 736b8ea6-26fd-11df-bfd4-992fa37f6226

  • src/compiler/ShHandle.h
  • //
    // Copyright (c) 2002-2010 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.
    //
    
    #ifndef _SHHANDLE_INCLUDED_
    #define _SHHANDLE_INCLUDED_
    
    //
    // Machine independent part of the compiler private objects
    // sent as ShHandle to the driver.
    //
    // This should not be included by driver code.
    //
    
    #include "GLSLANG/ShaderLang.h"
    
    #include "compiler/ExtensionBehavior.h"
    #include "compiler/InfoSink.h"
    #include "compiler/SymbolTable.h"
    #include "compiler/VariableInfo.h"
    
    class TCompiler;
    
    //
    // The base class used to back handles returned to the driver.
    //
    class TShHandleBase {
    public:
        TShHandleBase() { }
        virtual ~TShHandleBase() { }
        virtual TCompiler* getAsCompiler() { return 0; }
    };
    
    //
    // The base class for the machine dependent compiler to derive from
    // for managing object code from the compile.
    //
    class TCompiler : public TShHandleBase {
    public:
        TCompiler(EShLanguage l, EShSpec s) : language(l), spec(s) {}
        virtual ~TCompiler() {}
        virtual TCompiler* getAsCompiler() { return this; }
    
        bool Init(const TBuiltInResource& resources);
        bool compile(const char* const shaderStrings[],
                     const int numStrings,
                     int compileOptions);
    
        // Get results of the last compilation.
        TInfoSink& getInfoSink() { return infoSink; }
        const TVariableInfoList& getAttribs() const { return attribs; }
        const TVariableInfoList& getUniforms() const { return uniforms; }
    
    protected:
        // Initialize symbol-table with built-in symbols.
        bool InitBuiltInSymbolTable(const TBuiltInResource& resources);
        // Clears the results from the previous compilation.
        void clearResults();
        // Collect info for all attribs and uniforms.
        void collectAttribsUniforms(TIntermNode* root);
        // Translate to object code.
        virtual void translate(TIntermNode* root) = 0;
    
    private:
        EShLanguage language;
        EShSpec spec;
    
        // Built-in symbol table for the given language, spec, and resources.
        // It is preserved from compile-to-compile.
        TSymbolTable symbolTable;
        // Built-in extensions with default behavior.
        TExtensionBehavior extensionBehavior;
    
        // Results of compilation.
        TInfoSink infoSink;  // Output sink.
        TVariableInfoList attribs;  // Active attributes in the compiled shader.
        TVariableInfoList uniforms;  // Active uniforms in the compiled shader.
    };
    
    //
    // This is the interface between the machine independent code
    // and the machine dependent code.
    //
    // The machine dependent code should derive from the classes
    // above. Then Construct*() and Delete*() will create and 
    // destroy the machine dependent objects, which contain the
    // above machine independent information.
    //
    TCompiler* ConstructCompiler(EShLanguage, EShSpec);
    void DeleteCompiler(TCompiler*);
    
    #endif // _SHHANDLE_INCLUDED_