blob: 51640b5a9e90843a1dc54922587b66957cfe0ab2 [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
daniel@transgaming.combbf56f72010-04-20 18:52:13 +000019#include "compiler/InfoSink.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000020
21class TCompiler;
22class TLinker;
23class TUniformMap;
24
25
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; }
34 virtual TLinker* getAsLinker() { return 0; }
35 virtual TUniformMap* getAsUniformMap() { return 0; }
36};
37
38//
39// The base class for the machine dependent linker to derive from
40// for managing where uniforms live.
41//
42class TUniformMap : public TShHandleBase {
43public:
44 TUniformMap() { }
45 virtual ~TUniformMap() { }
46 virtual TUniformMap* getAsUniformMap() { return this; }
47 virtual int getLocation(const char* name) = 0;
48 virtual TInfoSink& getInfoSink() { return infoSink; }
49 TInfoSink infoSink;
50};
51class TIntermNode;
52
53//
54// The base class for the machine dependent compiler to derive from
55// for managing object code from the compile.
56//
57class TCompiler : public TShHandleBase {
58public:
alokp@chromium.org29cd91a2010-07-16 19:30:45 +000059 TCompiler(EShLanguage l, EShSpec s) : language(l), spec(s), haveValidObjectCode(false) { }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000060 virtual ~TCompiler() { }
alokp@chromium.org613ef312010-07-21 18:54:22 +000061
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000062 EShLanguage getLanguage() { return language; }
alokp@chromium.org613ef312010-07-21 18:54:22 +000063 EShSpec getSpec() { return spec; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064 virtual TInfoSink& getInfoSink() { return infoSink; }
65
66 virtual bool compile(TIntermNode* root) = 0;
67
68 virtual TCompiler* getAsCompiler() { return this; }
69 virtual bool linkable() { return haveValidObjectCode; }
alokp@chromium.org76b82082010-03-24 17:59:39 +000070
71 TInfoSink infoSink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000072protected:
73 EShLanguage language;
alokp@chromium.org29cd91a2010-07-16 19:30:45 +000074 EShSpec spec;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000075 bool haveValidObjectCode;
76};
77
78//
79// Link operations are base on a list of compile results...
80//
81typedef TVector<TCompiler*> TCompilerList;
82typedef TVector<TShHandleBase*> THandleList;
83
84//
85// The base class for the machine dependent linker to derive from
86// to manage the resulting executable.
87//
88
89class TLinker : public TShHandleBase {
90public:
alokp@chromium.org76b82082010-03-24 17:59:39 +000091 TLinker(EShExecutable e) :
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000092 executable(e),
93 haveReturnableObjectCode(false),
94 appAttributeBindings(0),
95 fixedAttributeBindings(0),
alokp@chromium.org76b82082010-03-24 17:59:39 +000096 excludedAttributes(0),
97 excludedCount(0),
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098 uniformBindings(0) { }
99 virtual TLinker* getAsLinker() { return this; }
100 virtual ~TLinker() { }
101 virtual bool link(TCompilerList&, TUniformMap*) = 0;
102 virtual bool link(THandleList&) { return false; }
103 virtual void setAppAttributeBindings(const ShBindingTable* t) { appAttributeBindings = t; }
104 virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }
alokp@chromium.org76b82082010-03-24 17:59:39 +0000105 virtual void getAttributeBindings(ShBindingTable const **t) const = 0;
106 virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000107 virtual ShBindingTable* getUniformBindings() const { return uniformBindings; }
108 virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here
109 virtual TInfoSink& getInfoSink() { return infoSink; }
alokp@chromium.org76b82082010-03-24 17:59:39 +0000110 TInfoSink infoSink;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000111protected:
112 EShExecutable executable;
113 bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver
114
115 const ShBindingTable* appAttributeBindings;
116 const ShBindingTable* fixedAttributeBindings;
alokp@chromium.org76b82082010-03-24 17:59:39 +0000117 const int* excludedAttributes;
118 int excludedCount;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000119 ShBindingTable* uniformBindings; // created by the linker
120};
121
122//
123// This is the interface between the machine independent code
124// and the machine dependent code.
125//
126// The machine dependent code should derive from the classes
127// above. Then Construct*() and Delete*() will create and
128// destroy the machine dependent objects, which contain the
129// above machine independent information.
130//
alokp@chromium.org29cd91a2010-07-16 19:30:45 +0000131TCompiler* ConstructCompiler(EShLanguage, EShSpec);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000132
133TShHandleBase* ConstructLinker(EShExecutable, int);
134void DeleteLinker(TShHandleBase*);
alokp@chromium.org76b82082010-03-24 17:59:39 +0000135
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000136TUniformMap* ConstructUniformMap();
137void DeleteCompiler(TCompiler*);
138
139void DeleteUniformMap(TUniformMap*);
140
141#endif // _SHHANDLE_INCLUDED_