OSDN Git Service

Remove the Radiance compiler copy and use OpenGL's instead.
[android-x86/external-swiftshader.git] / src / OpenGL / compiler / ShHandle.h
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
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 "ExtensionBehavior.h"
20 #include "InfoSink.h"
21 #include "SymbolTable.h"
22
23 class TCompiler;
24
25 //
26 // The base class used to back handles returned to the driver.
27 //
28 class TShHandleBase {
29 public:
30     TShHandleBase();
31     virtual ~TShHandleBase();
32     virtual TCompiler* getAsCompiler() { return 0; }
33
34 protected:
35     // Memory allocator. Allocates and tracks memory required by the compiler.
36     // Deallocates all memory when compiler is destructed.
37     TPoolAllocator allocator;
38 };
39
40 //
41 // The base class for the machine dependent compiler to derive from
42 // for managing object code from the compile.
43 //
44 class TCompiler : public TShHandleBase {
45 public:
46     TCompiler(ShShaderType type, ShShaderSpec spec);
47     virtual ~TCompiler();
48     virtual TCompiler* getAsCompiler() { return this; }
49
50     bool Init(const ShBuiltInResources& resources);
51     bool compile(const char* const shaderStrings[],
52                  const int numStrings,
53                  int compileOptions);
54
55     // Get results of the last compilation.
56     TInfoSink& getInfoSink() { return infoSink; }
57
58 protected:
59     ShShaderType getShaderType() const { return shaderType; }
60     ShShaderSpec getShaderSpec() const { return shaderSpec; }
61     // Initialize symbol-table with built-in symbols.
62     bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
63     // Clears the results from the previous compilation.
64     void clearResults();
65     // Return true if function recursion is detected or call depth exceeded.
66     bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink);
67     // Returns true if the given shader does not exceed the minimum
68     // functionality mandated in GLSL 1.0 spec Appendix A.
69     bool validateLimitations(TIntermNode *root);
70     // Translate to object code.
71     virtual bool translate(TIntermNode *root) = 0;
72     // Get built-in extensions with default behavior.
73     const TExtensionBehavior& getExtensionBehavior() const;
74
75 private:
76     ShShaderType shaderType;
77     ShShaderSpec shaderSpec;
78
79     unsigned int maxCallStackDepth;
80
81     // Built-in symbol table for the given language, spec, and resources.
82     // It is preserved from compile-to-compile.
83     TSymbolTable symbolTable;
84     // Built-in extensions with default behavior.
85     TExtensionBehavior extensionBehavior;
86
87     // Results of compilation.
88     TInfoSink infoSink;  // Output sink.
89 };
90
91 //
92 // This is the interface between the machine independent code
93 // and the machine dependent code.
94 //
95 // The machine dependent code should derive from the classes
96 // above. Then Construct*() and Delete*() will create and 
97 // destroy the machine dependent objects, which contain the
98 // above machine independent information.
99 //
100 TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
101 void DeleteCompiler(TCompiler*);
102
103 #endif // _SHHANDLE_INCLUDED_