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 | |
| 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; } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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(); |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 65 | // Return true if function recursion is detected or call depth exceeded. |
| 66 | bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 67 | // Returns true if the given shader does not exceed the minimum |
| 68 | // functionality mandated in GLSL 1.0 spec Appendix A. |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 69 | bool validateLimitations(TIntermNode *root); |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 70 | // Translate to object code. |
Nicolas Capens | 014b9a6 | 2014-10-15 10:28:29 -0400 | [diff] [blame] | 71 | virtual bool translate(TIntermNode *root) = 0; |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 72 | // Get built-in extensions with default behavior. |
| 73 | const TExtensionBehavior& getExtensionBehavior() const; |
| 74 | |
| 75 | private: |
| 76 | ShShaderType shaderType; |
| 77 | ShShaderSpec shaderSpec; |
| 78 | |
John Bauman | d4ae863 | 2014-05-06 16:18:33 -0400 | [diff] [blame] | 79 | unsigned int maxCallStackDepth; |
| 80 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 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_ |