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