initial import
[vuplus_webkit] / Source / ThirdParty / ANGLE / src / compiler / ShHandle.h
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
24 class TCompiler;
25
26 //
27 // The base class used to back handles returned to the driver.
28 //
29 class TShHandleBase {
30 public:
31     TShHandleBase();
32     virtual ~TShHandleBase();
33     virtual TCompiler* getAsCompiler() { return 0; }
34
35 protected:
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 //
45 class TCompiler : public TShHandleBase {
46 public:
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     int getMappedNameMaxLength() const;
61
62 protected:
63     ShShaderType getShaderType() const { return shaderType; }
64     ShShaderSpec getShaderSpec() const { return shaderSpec; }
65     // Initialize symbol-table with built-in symbols.
66     bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
67     // Clears the results from the previous compilation.
68     void clearResults();
69     // Returns true if the given shader does not exceed the minimum
70     // functionality mandated in GLSL 1.0 spec Appendix A.
71     bool validateLimitations(TIntermNode* root);
72     // Collect info for all attribs and uniforms.
73     void collectAttribsUniforms(TIntermNode* root);
74     // Map long variable names into shorter ones.
75     void mapLongVariableNames(TIntermNode* root);
76     // Translate to object code.
77     virtual void translate(TIntermNode* root) = 0;
78     // Get built-in extensions with default behavior.
79     const TExtensionBehavior& getExtensionBehavior() const;
80
81 private:
82     ShShaderType shaderType;
83     ShShaderSpec shaderSpec;
84
85     // Built-in symbol table for the given language, spec, and resources.
86     // It is preserved from compile-to-compile.
87     TSymbolTable symbolTable;
88     // Built-in extensions with default behavior.
89     TExtensionBehavior extensionBehavior;
90
91     // Results of compilation.
92     TInfoSink infoSink;  // Output sink.
93     TVariableInfoList attribs;  // Active attributes in the compiled shader.
94     TVariableInfoList uniforms;  // Active uniforms in the compiled shader.
95
96     // Pair of long varying varibale name <originalName, mappedName>.
97     TMap<TString, TString> varyingLongNameMap;
98 };
99
100 //
101 // This is the interface between the machine independent code
102 // and the machine dependent code.
103 //
104 // The machine dependent code should derive from the classes
105 // above. Then Construct*() and Delete*() will create and 
106 // destroy the machine dependent objects, which contain the
107 // above machine independent information.
108 //
109 TCompiler* ConstructCompiler(
110     ShShaderType type, ShShaderSpec spec, ShShaderOutput output);
111 void DeleteCompiler(TCompiler*);
112
113 #endif // _SHHANDLE_INCLUDED_