blob: a8eeeb78c5f66dabe7d834684235ca8d6a29808f [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
John Bauman66b8ab22014-05-06 15:57:45 -040010#include "GLSLANG/ShaderLang.h"
11
Nicolas Capenscc863da2015-01-21 15:50:55 -050012#include "ExtensionBehavior.h"
13#include "InfoSink.h"
14#include "SymbolTable.h"
John Bauman66b8ab22014-05-06 15:57:45 -040015
John Bauman66b8ab22014-05-06 15:57:45 -040016//
17// The base class for the machine dependent compiler to derive from
18// for managing object code from the compile.
19//
Nicolas Capens7a8ccc42015-02-10 15:42:31 -050020class TCompiler
21{
John Bauman66b8ab22014-05-06 15:57:45 -040022public:
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 Bauman66b8ab22014-05-06 15:57:45 -040034
35protected:
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 Baumand4ae8632014-05-06 16:18:33 -040042 // Return true if function recursion is detected or call depth exceeded.
43 bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink);
John Bauman66b8ab22014-05-06 15:57:45 -040044 // Returns true if the given shader does not exceed the minimum
45 // functionality mandated in GLSL 1.0 spec Appendix A.
John Baumand4ae8632014-05-06 16:18:33 -040046 bool validateLimitations(TIntermNode *root);
John Bauman66b8ab22014-05-06 15:57:45 -040047 // Translate to object code.
Nicolas Capens014b9a62014-10-15 10:28:29 -040048 virtual bool translate(TIntermNode *root) = 0;
John Bauman66b8ab22014-05-06 15:57:45 -040049 // Get built-in extensions with default behavior.
50 const TExtensionBehavior& getExtensionBehavior() const;
51
52private:
53 ShShaderType shaderType;
54 ShShaderSpec shaderSpec;
55
John Baumand4ae8632014-05-06 16:18:33 -040056 unsigned int maxCallStackDepth;
57
John Bauman66b8ab22014-05-06 15:57:45 -040058 // 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 Capens7a8ccc42015-02-10 15:42:31 -050066
67 // Memory allocator. Allocates and tracks memory required by the compiler.
68 // Deallocates all memory when compiler is destructed.
69 TPoolAllocator allocator;
John Bauman66b8ab22014-05-06 15:57:45 -040070};
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//
81TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
82void DeleteCompiler(TCompiler*);
83
84#endif // _SHHANDLE_INCLUDED_