blob: 385259e607efd90c4272dd14a55bff3213b65336 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
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
alokp@chromium.orgea0e1af2010-03-22 19:33:14 +000017#include "GLSLANG/ShaderLang.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000018
alokp@chromium.orgad771eb2010-09-07 17:36:23 +000019#include "compiler/ExtensionBehavior.h"
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000020#include "compiler/InfoSink.h"
alokp@chromium.orge4249f02010-07-26 18:13:52 +000021#include "compiler/SymbolTable.h"
alokp@chromium.org07620a52010-09-23 17:53:56 +000022#include "compiler/VariableInfo.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000023
24class TCompiler;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025
26//
27// The base class used to back handles returned to the driver.
28//
29class TShHandleBase {
30public:
31 TShHandleBase() { }
32 virtual ~TShHandleBase() { }
33 virtual TCompiler* getAsCompiler() { return 0; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034};
35
36//
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000037// The base class for the machine dependent compiler to derive from
38// for managing object code from the compile.
39//
40class TCompiler : public TShHandleBase {
41public:
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000042 TCompiler(ShShaderType type, ShShaderSpec spec);
43 virtual ~TCompiler();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000044 virtual TCompiler* getAsCompiler() { return this; }
alokp@chromium.org76b82082010-03-24 17:59:39 +000045
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000046 bool Init(const ShBuiltInResources& resources);
alokp@chromium.org07620a52010-09-23 17:53:56 +000047 bool compile(const char* const shaderStrings[],
48 const int numStrings,
49 int compileOptions);
50
51 // Get results of the last compilation.
52 TInfoSink& getInfoSink() { return infoSink; }
53 const TVariableInfoList& getAttribs() const { return attribs; }
54 const TVariableInfoList& getUniforms() const { return uniforms; }
55
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000056protected:
alokp@chromium.org9ecf3952010-10-13 19:28:25 +000057 ShShaderType getShaderType() const { return shaderType; }
58 ShShaderSpec getShaderSpec() const { return shaderSpec; }
alokp@chromium.org07620a52010-09-23 17:53:56 +000059 // Initialize symbol-table with built-in symbols.
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000060 bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
alokp@chromium.org07620a52010-09-23 17:53:56 +000061 // Clears the results from the previous compilation.
62 void clearResults();
63 // Collect info for all attribs and uniforms.
64 void collectAttribsUniforms(TIntermNode* root);
65 // Translate to object code.
66 virtual void translate(TIntermNode* root) = 0;
67
68private:
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000069 ShShaderType shaderType;
70 ShShaderSpec shaderSpec;
alokp@chromium.orge4249f02010-07-26 18:13:52 +000071
72 // Built-in symbol table for the given language, spec, and resources.
73 // It is preserved from compile-to-compile.
74 TSymbolTable symbolTable;
alokp@chromium.orgad771eb2010-09-07 17:36:23 +000075 // Built-in extensions with default behavior.
76 TExtensionBehavior extensionBehavior;
alokp@chromium.org07620a52010-09-23 17:53:56 +000077
78 // Results of compilation.
79 TInfoSink infoSink; // Output sink.
80 TVariableInfoList attribs; // Active attributes in the compiled shader.
81 TVariableInfoList uniforms; // Active uniforms in the compiled shader.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000082};
83
84//
85// This is the interface between the machine independent code
86// and the machine dependent code.
87//
88// The machine dependent code should derive from the classes
89// above. Then Construct*() and Delete*() will create and
90// destroy the machine dependent objects, which contain the
91// above machine independent information.
92//
alokp@chromium.org4888ceb2010-10-01 21:13:12 +000093TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000094void DeleteCompiler(TCompiler*);
95
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000096#endif // _SHHANDLE_INCLUDED_