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.
7 #ifndef _SHHANDLE_INCLUDED_
8 #define _SHHANDLE_INCLUDED_
11 // Machine independent part of the compiler private objects
12 // sent as ShHandle to the driver.
14 // This should not be included by driver code.
17 #include "GLSLANG/ShaderLang.h"
19 #include "ExtensionBehavior.h"
21 #include "SymbolTable.h"
26 // The base class used to back handles returned to the driver.
31 virtual ~TShHandleBase();
32 virtual TCompiler* getAsCompiler() { return 0; }
35 // Memory allocator. Allocates and tracks memory required by the compiler.
36 // Deallocates all memory when compiler is destructed.
37 TPoolAllocator allocator;
41 // The base class for the machine dependent compiler to derive from
42 // for managing object code from the compile.
44 class TCompiler : public TShHandleBase {
46 TCompiler(ShShaderType type, ShShaderSpec spec);
48 virtual TCompiler* getAsCompiler() { return this; }
50 bool Init(const ShBuiltInResources& resources);
51 bool compile(const char* const shaderStrings[],
55 // Get results of the last compilation.
56 TInfoSink& getInfoSink() { return infoSink; }
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.
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;
76 ShShaderType shaderType;
77 ShShaderSpec shaderSpec;
79 unsigned int maxCallStackDepth;
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;
87 // Results of compilation.
88 TInfoSink infoSink; // Output sink.
92 // This is the interface between the machine independent code
93 // and the machine dependent code.
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.
100 TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
101 void DeleteCompiler(TCompiler*);
103 #endif // _SHHANDLE_INCLUDED_