blob: 8457cc615da51ee27257b89f9862b72f512d9774 [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
John Bauman66b8ab22014-05-06 15:57:45 -040023//
24// The base class for the machine dependent compiler to derive from
25// for managing object code from the compile.
26//
Nicolas Capens7a8ccc42015-02-10 15:42:31 -050027class TCompiler
28{
John Bauman66b8ab22014-05-06 15:57:45 -040029public:
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 Bauman66b8ab22014-05-06 15:57:45 -040041
42protected:
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 Baumand4ae8632014-05-06 16:18:33 -040049 // Return true if function recursion is detected or call depth exceeded.
50 bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink);
John Bauman66b8ab22014-05-06 15:57:45 -040051 // Returns true if the given shader does not exceed the minimum
52 // functionality mandated in GLSL 1.0 spec Appendix A.
John Baumand4ae8632014-05-06 16:18:33 -040053 bool validateLimitations(TIntermNode *root);
John Bauman66b8ab22014-05-06 15:57:45 -040054 // Translate to object code.
Nicolas Capens014b9a62014-10-15 10:28:29 -040055 virtual bool translate(TIntermNode *root) = 0;
John Bauman66b8ab22014-05-06 15:57:45 -040056 // Get built-in extensions with default behavior.
57 const TExtensionBehavior& getExtensionBehavior() const;
58
59private:
60 ShShaderType shaderType;
61 ShShaderSpec shaderSpec;
62
John Baumand4ae8632014-05-06 16:18:33 -040063 unsigned int maxCallStackDepth;
64
John Bauman66b8ab22014-05-06 15:57:45 -040065 // 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 Capens7a8ccc42015-02-10 15:42:31 -050073
74 // Memory allocator. Allocates and tracks memory required by the compiler.
75 // Deallocates all memory when compiler is destructed.
76 TPoolAllocator allocator;
John Bauman66b8ab22014-05-06 15:57:45 -040077};
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//
88TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
89void DeleteCompiler(TCompiler*);
90
91#endif // _SHHANDLE_INCLUDED_