blob: d37a2e905523eec535664b497c18c6b240a47930 [file] [log] [blame]
John Bauman66b8ab22014-05-06 15:57:45 -04001//
John Baumand4ae8632014-05-06 16:18:33 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04003// 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 Capenscc863da2015-01-21 15:50:55 -050019#include "ExtensionBehavior.h"
20#include "InfoSink.h"
21#include "SymbolTable.h"
John Bauman66b8ab22014-05-06 15:57:45 -040022
23class TCompiler;
24
25//
26// The base class used to back handles returned to the driver.
27//
28class TShHandleBase {
29public:
30 TShHandleBase();
31 virtual ~TShHandleBase();
32 virtual TCompiler* getAsCompiler() { return 0; }
33
34protected:
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//
44class TCompiler : public TShHandleBase {
45public:
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 Bauman66b8ab22014-05-06 15:57:45 -040057
58protected:
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 Baumand4ae8632014-05-06 16:18:33 -040065 // Return true if function recursion is detected or call depth exceeded.
66 bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink);
John Bauman66b8ab22014-05-06 15:57:45 -040067 // Returns true if the given shader does not exceed the minimum
68 // functionality mandated in GLSL 1.0 spec Appendix A.
John Baumand4ae8632014-05-06 16:18:33 -040069 bool validateLimitations(TIntermNode *root);
John Bauman66b8ab22014-05-06 15:57:45 -040070 // Translate to object code.
Nicolas Capens014b9a62014-10-15 10:28:29 -040071 virtual bool translate(TIntermNode *root) = 0;
John Bauman66b8ab22014-05-06 15:57:45 -040072 // Get built-in extensions with default behavior.
73 const TExtensionBehavior& getExtensionBehavior() const;
74
75private:
76 ShShaderType shaderType;
77 ShShaderSpec shaderSpec;
78
John Baumand4ae8632014-05-06 16:18:33 -040079 unsigned int maxCallStackDepth;
80
John Bauman66b8ab22014-05-06 15:57:45 -040081 // 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 Bauman66b8ab22014-05-06 15:57:45 -040089};
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//
100TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
101void DeleteCompiler(TCompiler*);
102
103#endif // _SHHANDLE_INCLUDED_