1//
2// Copyright (c) 2002-2010 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#ifndef _SHHANDLE_INCLUDED_
8#define _SHHANDLE_INCLUDED_
9
10//
11// Machine independent part of the compiler private objects
12// sent as ShHandle to the driver.
13//
14// This should not be included by driver code.
15//
16
17#include "GLSLANG/ShaderLang.h"
18
19#include "compiler/ExtensionBehavior.h"
20#include "compiler/InfoSink.h"
21#include "compiler/SymbolTable.h"
22#include "compiler/VariableInfo.h"
23
24class TCompiler;
25
26//
27// The base class used to back handles returned to the driver.
28//
29class TShHandleBase {
30public:
31    TShHandleBase();
32    virtual ~TShHandleBase();
33    virtual TCompiler* getAsCompiler() { return 0; }
34
35protected:
36    // Memory allocator. Allocates and tracks memory required by the compiler.
37    // Deallocates all memory when compiler is destructed.
38    TPoolAllocator allocator;
39};
40
41//
42// The base class for the machine dependent compiler to derive from
43// for managing object code from the compile.
44//
45class TCompiler : public TShHandleBase {
46public:
47    TCompiler(ShShaderType type, ShShaderSpec spec);
48    virtual ~TCompiler();
49    virtual TCompiler* getAsCompiler() { return this; }
50
51    bool Init(const ShBuiltInResources& resources);
52    bool compile(const char* const shaderStrings[],
53                 const int numStrings,
54                 int compileOptions);
55
56    // Get results of the last compilation.
57    TInfoSink& getInfoSink() { return infoSink; }
58    const TVariableInfoList& getAttribs() const { return attribs; }
59    const TVariableInfoList& getUniforms() const { return uniforms; }
60
61protected:
62    ShShaderType getShaderType() const { return shaderType; }
63    ShShaderSpec getShaderSpec() const { return shaderSpec; }
64    // Initialize symbol-table with built-in symbols.
65    bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
66    // Clears the results from the previous compilation.
67    void clearResults();
68    // Returns true if the given shader does not exceed the minimum
69    // functionality mandated in GLSL 1.0 spec Appendix A.
70    bool validateLimitations(TIntermNode* root);
71    // Collect info for all attribs and uniforms.
72    void collectAttribsUniforms(TIntermNode* root);
73    // Translate to object code.
74    virtual void translate(TIntermNode* root) = 0;
75
76private:
77    ShShaderType shaderType;
78    ShShaderSpec shaderSpec;
79
80    // Built-in symbol table for the given language, spec, and resources.
81    // It is preserved from compile-to-compile.
82    TSymbolTable symbolTable;
83    // Built-in extensions with default behavior.
84    TExtensionBehavior extensionBehavior;
85
86    // Results of compilation.
87    TInfoSink infoSink;  // Output sink.
88    TVariableInfoList attribs;  // Active attributes in the compiled shader.
89    TVariableInfoList uniforms;  // Active uniforms in the compiled shader.
90};
91
92//
93// This is the interface between the machine independent code
94// and the machine dependent code.
95//
96// The machine dependent code should derive from the classes
97// above. Then Construct*() and Delete*() will create and
98// destroy the machine dependent objects, which contain the
99// above machine independent information.
100//
101TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
102void DeleteCompiler(TCompiler*);
103
104#endif // _SHHANDLE_INCLUDED_