John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1 | // |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 10 | #include "GLSLANG/ShaderLang.h" |
| 11 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 12 | #include "ExtensionBehavior.h" |
| 13 | #include "InfoSink.h" |
| 14 | #include "SymbolTable.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 15 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 16 | // |
| 17 | // The base class for the machine dependent compiler to derive from |
| 18 | // for managing object code from the compile. |
| 19 | // |
Nicolas Capens | 7a8ccc4 | 2015-02-10 15:42:31 -0500 | [diff] [blame] | 20 | class TCompiler |
| 21 | { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 22 | public: |
| 23 | TCompiler(ShShaderType type, ShShaderSpec spec); |
| 24 | virtual ~TCompiler(); |
| 25 | virtual TCompiler* getAsCompiler() { return this; } |
| 26 | |
| 27 | bool Init(const ShBuiltInResources& resources); |
| 28 | bool compile(const char* const shaderStrings[], |
| 29 | const int numStrings, |
| 30 | int compileOptions); |
| 31 | |
| 32 | // Get results of the last compilation. |
| 33 | TInfoSink& getInfoSink() { return infoSink; } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 34 | |
| 35 | protected: |
| 36 | ShShaderType getShaderType() const { return shaderType; } |
| 37 | ShShaderSpec getShaderSpec() const { return shaderSpec; } |
| 38 | // Initialize symbol-table with built-in symbols. |
| 39 | bool InitBuiltInSymbolTable(const ShBuiltInResources& resources); |
| 40 | // Clears the results from the previous compilation. |
| 41 | void clearResults(); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 42 | // Return true if function recursion is detected or call depth exceeded. |
| 43 | bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 44 | // Returns true if the given shader does not exceed the minimum |
| 45 | // functionality mandated in GLSL 1.0 spec Appendix A. |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 46 | bool validateLimitations(TIntermNode *root); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 47 | // Translate to object code. |
Nicolas Capens | 014b9a6 | 2014-10-15 10:28:29 -0400 | [diff] [blame] | 48 | virtual bool translate(TIntermNode *root) = 0; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 49 | // Get built-in extensions with default behavior. |
| 50 | const TExtensionBehavior& getExtensionBehavior() const; |
| 51 | |
| 52 | private: |
| 53 | ShShaderType shaderType; |
| 54 | ShShaderSpec shaderSpec; |
| 55 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 56 | unsigned int maxCallStackDepth; |
| 57 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 58 | // Built-in symbol table for the given language, spec, and resources. |
| 59 | // It is preserved from compile-to-compile. |
| 60 | TSymbolTable symbolTable; |
| 61 | // Built-in extensions with default behavior. |
| 62 | TExtensionBehavior extensionBehavior; |
| 63 | |
| 64 | // Results of compilation. |
| 65 | TInfoSink infoSink; // Output sink. |
Nicolas Capens | 7a8ccc4 | 2015-02-10 15:42:31 -0500 | [diff] [blame] | 66 | |
| 67 | // Memory allocator. Allocates and tracks memory required by the compiler. |
| 68 | // Deallocates all memory when compiler is destructed. |
| 69 | TPoolAllocator allocator; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | // |
| 73 | // This is the interface between the machine independent code |
| 74 | // and the machine dependent code. |
| 75 | // |
| 76 | // The machine dependent code should derive from the classes |
| 77 | // above. Then Construct*() and Delete*() will create and |
| 78 | // destroy the machine dependent objects, which contain the |
| 79 | // above machine independent information. |
| 80 | // |
| 81 | TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec); |
| 82 | void DeleteCompiler(TCompiler*); |
| 83 | |
| 84 | #endif // _SHHANDLE_INCLUDED_ |