Create a base GLSL front-end from the 3Dlabs glslang front-end from 20-Sep-2005.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@19944 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
commit
a0af473a8b
80 changed files with 21238 additions and 0 deletions
137
glslang/Include/BaseTypes.h
Normal file
137
glslang/Include/BaseTypes.h
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _BASICTYPES_INCLUDED_
|
||||
#define _BASICTYPES_INCLUDED_
|
||||
|
||||
//
|
||||
// Basic type. Arrays, vectors, etc., are orthogonal to this.
|
||||
//
|
||||
enum TBasicType {
|
||||
EbtVoid,
|
||||
EbtFloat,
|
||||
EbtInt,
|
||||
EbtBool,
|
||||
EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
|
||||
EbtSampler1D,
|
||||
EbtSampler2D,
|
||||
EbtSampler3D,
|
||||
EbtSamplerCube,
|
||||
EbtSampler1DShadow,
|
||||
EbtSampler2DShadow,
|
||||
EbtSamplerRect, // ARB_texture_rectangle
|
||||
EbtSamplerRectShadow, // ARB_texture_rectangle
|
||||
EbtGuardSamplerEnd, // non type: see implementation of IsSampler()
|
||||
EbtStruct,
|
||||
EbtAddress, // should be deprecated??
|
||||
};
|
||||
|
||||
__inline bool IsSampler(TBasicType type)
|
||||
{
|
||||
return type > EbtGuardSamplerBegin && type < EbtGuardSamplerEnd;
|
||||
}
|
||||
|
||||
//
|
||||
// Qualifiers and built-ins. These are mainly used to see what can be read
|
||||
// or written, and by the machine dependent translator to know which registers
|
||||
// to allocate variables in. Since built-ins tend to go to different registers
|
||||
// than varying or uniform, it makes sense they are peers, not sub-classes.
|
||||
//
|
||||
enum TQualifier {
|
||||
EvqTemporary, // For temporaries (within a function), read/write
|
||||
EvqGlobal, // For globals read/write
|
||||
EvqConst, // User defined constants and non-output parameters in functions
|
||||
EvqAttribute, // Readonly
|
||||
EvqVaryingIn, // readonly, fragment shaders only
|
||||
EvqVaryingOut, // vertex shaders only read/write
|
||||
EvqUniform, // Readonly, vertex and fragment
|
||||
|
||||
// pack/unpack input and output
|
||||
EvqInput,
|
||||
EvqOutput,
|
||||
|
||||
// parameters
|
||||
EvqIn,
|
||||
EvqOut,
|
||||
EvqInOut,
|
||||
EvqConstReadOnly,
|
||||
|
||||
// built-ins written by vertex shader
|
||||
EvqPosition,
|
||||
EvqPointSize,
|
||||
EvqClipVertex,
|
||||
|
||||
// built-ins read by fragment shader
|
||||
EvqFace,
|
||||
EvqFragCoord,
|
||||
|
||||
// built-ins written by fragment shader
|
||||
EvqFragColor,
|
||||
EvqFragDepth,
|
||||
|
||||
// end of list
|
||||
EvqLast,
|
||||
};
|
||||
|
||||
//
|
||||
// This is just for debug print out, carried along with the definitions above.
|
||||
//
|
||||
__inline const char* getQualifierString(TQualifier q)
|
||||
{
|
||||
switch (q) {
|
||||
case EvqTemporary: return "Temporary"; break;
|
||||
case EvqGlobal: return "Global"; break;
|
||||
case EvqConst: return "const"; break;
|
||||
case EvqConstReadOnly: return "const"; break;
|
||||
case EvqAttribute: return "attribute"; break;
|
||||
case EvqVaryingIn: return "varying"; break;
|
||||
case EvqVaryingOut: return "varying"; break;
|
||||
case EvqUniform: return "uniform"; break;
|
||||
case EvqIn: return "in"; break;
|
||||
case EvqOut: return "out"; break;
|
||||
case EvqInOut: return "inout"; break;
|
||||
case EvqInput: return "input"; break;
|
||||
case EvqOutput: return "output"; break;
|
||||
case EvqPosition: return "Position"; break;
|
||||
case EvqPointSize: return "PointSize"; break;
|
||||
case EvqClipVertex: return "ClipVertex"; break;
|
||||
case EvqFace: return "Face"; break;
|
||||
case EvqFragCoord: return "FragCoord"; break;
|
||||
case EvqFragColor: return "FragColor"; break;
|
||||
case EvqFragDepth: return "FragDepth"; break;
|
||||
default: return "unknown qualifier";
|
||||
}
|
||||
}
|
||||
|
||||
#endif // _BASICTYPES_INCLUDED_
|
||||
192
glslang/Include/Common.h
Normal file
192
glslang/Include/Common.h
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _COMMON_INCLUDED_
|
||||
#define _COMMON_INCLUDED_
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <basetsd.h>
|
||||
#elif defined (solaris)
|
||||
#include <sys/int_types.h>
|
||||
#define UINT_PTR uintptr_t
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#define UINT_PTR uintptr_t
|
||||
#endif
|
||||
|
||||
/* windows only pragma */
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4786) // Don't warn about too long identifiers
|
||||
#pragma warning(disable : 4514) // unused inline method
|
||||
#pragma warning(disable : 4201) // nameless union
|
||||
#endif
|
||||
|
||||
//
|
||||
// Doing the push and pop below for warnings does not leave the warning state
|
||||
// the way it was. This seems like a defect in the compiler. We would like
|
||||
// to do this, but since it does not work correctly right now, it is turned
|
||||
// off.
|
||||
//
|
||||
//??#pragma warning(push, 3)
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
//??#pragma warning(pop)
|
||||
|
||||
typedef int TSourceLoc;
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "PoolAlloc.h"
|
||||
|
||||
//
|
||||
// Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
|
||||
//
|
||||
#define POOL_ALLOCATOR_NEW_DELETE(A) \
|
||||
void* operator new(size_t s) { return (A).allocate(s); } \
|
||||
void* operator new(size_t, void *_Where) { return (_Where); } \
|
||||
void operator delete(void*) { } \
|
||||
void operator delete(void *, void *) { } \
|
||||
void* operator new[](size_t s) { return (A).allocate(s); } \
|
||||
void* operator new[](size_t, void *_Where) { return (_Where); } \
|
||||
void operator delete[](void*) { } \
|
||||
void operator delete[](void *, void *) { }
|
||||
|
||||
#define TBaseMap std::map
|
||||
#define TBaseList std::list
|
||||
#define TBaseSet std::set
|
||||
|
||||
//
|
||||
// Pool version of string.
|
||||
//
|
||||
typedef pool_allocator<char> TStringAllocator;
|
||||
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator > TString;
|
||||
inline TString* NewPoolTString(const char* s)
|
||||
{
|
||||
void* memory = GlobalPoolAllocator.allocate(sizeof(TString));
|
||||
return new(memory) TString(s);
|
||||
}
|
||||
|
||||
//
|
||||
// Pool allocator versions of vectors, lists, and maps
|
||||
//
|
||||
template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
|
||||
public:
|
||||
typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
|
||||
TVector() : std::vector<T, pool_allocator<T> >() {}
|
||||
TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
|
||||
TVector(size_type i): std::vector<T, pool_allocator<T> >(i) {}
|
||||
};
|
||||
|
||||
template <class T> class TList : public TBaseList <T, pool_allocator<T> > {
|
||||
public:
|
||||
typedef typename TBaseList<T, pool_allocator<T> >::size_type size_type;
|
||||
TList() : TBaseList<T, pool_allocator<T> >() {}
|
||||
TList(const pool_allocator<T>& a) : TBaseList<T, pool_allocator<T> >(a) {}
|
||||
TList(size_type i): TBaseList<T, pool_allocator<T> >(i) {}
|
||||
};
|
||||
|
||||
// This is called TStlSet, because TSet is taken by an existing compiler class.
|
||||
template <class T, class CMP> class TStlSet : public std::set<T, CMP, pool_allocator<T> > {
|
||||
// No pool allocator versions of constructors in std::set.
|
||||
};
|
||||
|
||||
|
||||
template <class K, class D, class CMP = std::less<K> >
|
||||
class TMap : public TBaseMap<K, D, CMP, pool_allocator<std::pair<K, D> > > {
|
||||
public:
|
||||
typedef pool_allocator<std::pair <K, D> > tAllocator;
|
||||
|
||||
TMap() : TBaseMap<K, D, CMP, tAllocator >() {}
|
||||
// use correct two-stage name lookup supported in gcc 3.4 and above
|
||||
TMap(const tAllocator& a) : TBaseMap<K, D, CMP, tAllocator>(TBaseMap<K, D, CMP, tAllocator >::key_compare(), a) {}
|
||||
};
|
||||
|
||||
//
|
||||
// Persistent string memory. Should only be used for strings that survive
|
||||
// across compiles/links.
|
||||
//
|
||||
typedef std::basic_string<char> TPersistString;
|
||||
|
||||
//
|
||||
// templatized min and max functions.
|
||||
//
|
||||
template <class T> T Min(const T a, const T b) { return a < b ? a : b; }
|
||||
template <class T> T Max(const T a, const T b) { return a > b ? a : b; }
|
||||
|
||||
//
|
||||
// Create a TString object from an integer.
|
||||
//
|
||||
inline const TString String(const int i, const int base = 10)
|
||||
{
|
||||
char text[16]; // 32 bit ints are at most 10 digits in base 10
|
||||
|
||||
#ifdef _WIN32
|
||||
itoa(i, text, base);
|
||||
#else
|
||||
// we assume base 10 for all cases
|
||||
sprintf(text, "%d", i);
|
||||
#endif
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
const unsigned int SourceLocLineMask = 0xffff;
|
||||
const unsigned int SourceLocStringShift = 16;
|
||||
|
||||
__inline TPersistString FormatSourceLoc(const TSourceLoc loc)
|
||||
{
|
||||
char locText[64];
|
||||
|
||||
int string = loc >> SourceLocStringShift;
|
||||
int line = loc & SourceLocLineMask;
|
||||
|
||||
if (line)
|
||||
sprintf(locText, "%d:%d", string, line);
|
||||
else
|
||||
sprintf(locText, "%d:? ", string);
|
||||
|
||||
return TPersistString(locText);
|
||||
}
|
||||
|
||||
|
||||
typedef TMap<TString, TString> TPragmaTable;
|
||||
typedef TMap<TString, TString>::tAllocator TPragmaTableAllocator;
|
||||
|
||||
#endif // _COMMON_INCLUDED_
|
||||
315
glslang/Include/ConstantUnion.h
Normal file
315
glslang/Include/ConstantUnion.h
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _CONSTANT_UNION_INCLUDED_
|
||||
#define _CONSTANT_UNION_INCLUDED_
|
||||
|
||||
|
||||
class constUnion {
|
||||
public:
|
||||
|
||||
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
|
||||
void setIConst(int i) {iConst = i; type = EbtInt; }
|
||||
void setFConst(float f) {fConst = f; type = EbtFloat; }
|
||||
void setBConst(bool b) {bConst = b; type = EbtBool; }
|
||||
|
||||
int getIConst() { return iConst; }
|
||||
float getFConst() { return fConst; }
|
||||
bool getBConst() { return bConst; }
|
||||
int getIConst() const { return iConst; }
|
||||
float getFConst() const { return fConst; }
|
||||
bool getBConst() const { return bConst; }
|
||||
|
||||
bool operator==(const int i) const
|
||||
{
|
||||
if (i == iConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const float f) const
|
||||
{
|
||||
if (f == fConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const bool b) const
|
||||
{
|
||||
if (b == bConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const constUnion& constant) const
|
||||
{
|
||||
if (constant.type != type)
|
||||
return false;
|
||||
|
||||
switch (type) {
|
||||
case EbtInt:
|
||||
if (constant.iConst == iConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtFloat:
|
||||
if (constant.fConst == fConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtBool:
|
||||
if (constant.bConst == bConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator!=(const int i) const
|
||||
{
|
||||
return !operator==(i);
|
||||
}
|
||||
|
||||
bool operator!=(const float f) const
|
||||
{
|
||||
return !operator==(f);
|
||||
}
|
||||
|
||||
bool operator!=(const bool b) const
|
||||
{
|
||||
return !operator==(b);
|
||||
}
|
||||
|
||||
bool operator!=(const constUnion& constant) const
|
||||
{
|
||||
return !operator==(constant);
|
||||
}
|
||||
|
||||
bool operator>(const constUnion& constant) const
|
||||
{
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt:
|
||||
if (iConst > constant.iConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtFloat:
|
||||
if (fConst > constant.fConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator<(const constUnion& constant) const
|
||||
{
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt:
|
||||
if (iConst < constant.iConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtFloat:
|
||||
if (fConst < constant.fConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
constUnion operator+(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
|
||||
case EbtFloat: returnValue.setFConst(fConst + constant.fConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator-(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
|
||||
case EbtFloat: returnValue.setFConst(fConst - constant.fConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator*(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
|
||||
case EbtFloat: returnValue.setFConst(fConst * constant.fConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator%(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator>>(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator<<(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator&(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst & constant.iConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator|(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst | constant.iConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator^(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst ^ constant.iConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator&&(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
constUnion operator||(const constUnion& constant) const
|
||||
{
|
||||
constUnion returnValue;
|
||||
assert(type == constant.type);
|
||||
switch (type) {
|
||||
case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
TBasicType getType() { return type; }
|
||||
private:
|
||||
|
||||
union {
|
||||
int iConst; // used for ivec, scalar ints
|
||||
bool bConst; // used for bvec, scalar bools
|
||||
float fConst; // used for vec, mat, scalar floats
|
||||
} ;
|
||||
|
||||
TBasicType type;
|
||||
};
|
||||
|
||||
#endif // _CONSTANT_UNION_INCLUDED_
|
||||
137
glslang/Include/InfoSink.h
Normal file
137
glslang/Include/InfoSink.h
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _INFOSINK_INCLUDED_
|
||||
#define _INFOSINK_INCLUDED_
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include <math.h>
|
||||
|
||||
//
|
||||
// TPrefixType is used to centralize how info log messages start.
|
||||
// See below.
|
||||
//
|
||||
enum TPrefixType {
|
||||
EPrefixNone,
|
||||
EPrefixWarning,
|
||||
EPrefixError,
|
||||
EPrefixInternalError,
|
||||
EPrefixUnimplemented,
|
||||
EPrefixNote
|
||||
};
|
||||
|
||||
enum TOutputStream {
|
||||
ENull = 0,
|
||||
EDebugger = 0x01,
|
||||
EStdOut = 0x02,
|
||||
EString = 0x04,
|
||||
};
|
||||
//
|
||||
// Encapsulate info logs for all objects that have them.
|
||||
//
|
||||
// The methods are a general set of tools for getting a variety of
|
||||
// messages and types inserted into the log.
|
||||
//
|
||||
class TInfoSinkBase {
|
||||
public:
|
||||
TInfoSinkBase() : outputStream(4) {}
|
||||
void erase() { sink.erase(); }
|
||||
TInfoSinkBase& operator<<(const TPersistString& t) { append(t); return *this; }
|
||||
TInfoSinkBase& operator<<(char c) { append(1, c); return *this; }
|
||||
TInfoSinkBase& operator<<(const char* s) { append(s); return *this; }
|
||||
TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; }
|
||||
TInfoSinkBase& operator<<(const unsigned int n) { append(String(n)); return *this; }
|
||||
TInfoSinkBase& operator<<(float n) { char buf[40];
|
||||
sprintf(buf, (fabs(n) > 1e-8 && fabs(n) < 1e8) || n == 0.0f ?
|
||||
"%f" : "%g", n);
|
||||
append(buf);
|
||||
return *this; }
|
||||
TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; }
|
||||
TInfoSinkBase& operator+(const TString& t) { append(t); return *this; }
|
||||
TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; }
|
||||
TInfoSinkBase& operator+(const char* s) { append(s); return *this; }
|
||||
const char* c_str() const { return sink.c_str(); }
|
||||
void prefix(TPrefixType message) {
|
||||
switch(message) {
|
||||
case EPrefixNone: break;
|
||||
case EPrefixWarning: append("WARNING: "); break;
|
||||
case EPrefixError: append("ERROR: "); break;
|
||||
case EPrefixInternalError: append("INTERNAL ERROR: "); break;
|
||||
case EPrefixUnimplemented: append("UNIMPLEMENTED: "); break;
|
||||
case EPrefixNote: append("NOTE: "); break;
|
||||
default: append("UNKOWN ERROR: "); break;
|
||||
}
|
||||
}
|
||||
void location(TSourceLoc loc) {
|
||||
append(FormatSourceLoc(loc).c_str());
|
||||
append(": ");
|
||||
}
|
||||
void message(TPrefixType message, const char* s) {
|
||||
prefix(message);
|
||||
append(s);
|
||||
append("\n");
|
||||
}
|
||||
void message(TPrefixType message, const char* s, TSourceLoc loc) {
|
||||
prefix(message);
|
||||
location(loc);
|
||||
append(s);
|
||||
append("\n");
|
||||
}
|
||||
|
||||
void setOutputStream(int output = 4)
|
||||
{
|
||||
outputStream = output;
|
||||
}
|
||||
|
||||
protected:
|
||||
void append(const char *s);
|
||||
|
||||
void append(int count, char c);
|
||||
void append(const TPersistString& t);
|
||||
void append(const TString& t);
|
||||
|
||||
void checkMem(size_t growth) { if (sink.capacity() < sink.size() + growth + 2)
|
||||
sink.reserve(sink.capacity() + sink.capacity() / 2); }
|
||||
void appendToStream(const char* s);
|
||||
TPersistString sink;
|
||||
int outputStream;
|
||||
};
|
||||
|
||||
class TInfoSink {
|
||||
public:
|
||||
TInfoSinkBase info;
|
||||
TInfoSinkBase debug;
|
||||
};
|
||||
|
||||
#endif // _INFOSINK_INCLUDED_
|
||||
43
glslang/Include/InitializeGlobals.h
Normal file
43
glslang/Include/InitializeGlobals.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef __INITIALIZE_GLOBALS_INCLUDED_
|
||||
#define __INITIALIZE_GLOBALS_INCLUDED_
|
||||
|
||||
void InitializeGlobalPools();
|
||||
void FreeGlobalPools();
|
||||
bool InitializePoolIndex();
|
||||
void FreePoolIndex();
|
||||
|
||||
#endif // __INITIALIZE_GLOBALS_INCLUDED_
|
||||
45
glslang/Include/InitializeParseContext.h
Normal file
45
glslang/Include/InitializeParseContext.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef __INITIALIZE_PARSE_CONTEXT_INCLUDED_
|
||||
#define __INITIALIZE_PARSE_CONTEXT_INCLUDED_
|
||||
#include "osinclude.h"
|
||||
|
||||
bool InitializeParseContextIndex();
|
||||
bool InitializeGlobalParseContext();
|
||||
bool FreeParseContext();
|
||||
bool FreeParseContextIndex();
|
||||
|
||||
|
||||
#endif // __INITIALIZE_PARSE_CONTEXT_INCLUDED_
|
||||
349
glslang/Include/PoolAlloc.h
Normal file
349
glslang/Include/PoolAlloc.h
Normal file
|
|
@ -0,0 +1,349 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _POOLALLOC_INCLUDED_
|
||||
#define _POOLALLOC_INCLUDED_
|
||||
|
||||
#ifdef _DEBUG
|
||||
# define GUARD_BLOCKS // define to enable guard block sanity checking
|
||||
#endif
|
||||
|
||||
//
|
||||
// This header defines an allocator that can be used to efficiently
|
||||
// allocate a large number of small requests for heap memory, with the
|
||||
// intention that they are not individually deallocated, but rather
|
||||
// collectively deallocated at one time.
|
||||
//
|
||||
// This simultaneously
|
||||
//
|
||||
// * Makes each individual allocation much more efficient; the
|
||||
// typical allocation is trivial.
|
||||
// * Completely avoids the cost of doing individual deallocation.
|
||||
// * Saves the trouble of tracking down and plugging a large class of leaks.
|
||||
//
|
||||
// Individual classes can use this allocator by supplying their own
|
||||
// new and delete methods.
|
||||
//
|
||||
// STL containers can use this allocator by using the pool_allocator
|
||||
// class as the allocator (second) template argument.
|
||||
//
|
||||
|
||||
#include <stddef.h>
|
||||
#include <vector>
|
||||
|
||||
// If we are using guard blocks, we must track each indivual
|
||||
// allocation. If we aren't using guard blocks, these
|
||||
// never get instantiated, so won't have any impact.
|
||||
//
|
||||
|
||||
class TAllocation {
|
||||
public:
|
||||
TAllocation(size_t size, unsigned char* mem, TAllocation* prev = 0) :
|
||||
size(size), mem(mem), prevAlloc(prev) {
|
||||
// Allocations are bracketed:
|
||||
// [allocationHeader][initialGuardBlock][userData][finalGuardBlock]
|
||||
// This would be cleaner with if (guardBlockSize)..., but that
|
||||
// makes the compiler print warnings about 0 length memsets,
|
||||
// even with the if() protecting them.
|
||||
# ifdef GUARD_BLOCKS
|
||||
memset(preGuard(), guardBlockBeginVal, guardBlockSize);
|
||||
memset(data(), userDataFill, size);
|
||||
memset(postGuard(), guardBlockEndVal, guardBlockSize);
|
||||
# endif
|
||||
}
|
||||
|
||||
void check() const {
|
||||
checkGuardBlock(preGuard(), guardBlockBeginVal, "before");
|
||||
checkGuardBlock(postGuard(), guardBlockEndVal, "after");
|
||||
}
|
||||
|
||||
void checkAllocList() const;
|
||||
|
||||
// Return total size needed to accomodate user buffer of 'size',
|
||||
// plus our tracking data.
|
||||
inline static size_t allocationSize(size_t size) {
|
||||
return size + 2 * guardBlockSize + headerSize();
|
||||
}
|
||||
|
||||
// Offset from surrounding buffer to get to user data buffer.
|
||||
inline static unsigned char* offsetAllocation(unsigned char* m) {
|
||||
return m + guardBlockSize + headerSize();
|
||||
}
|
||||
|
||||
private:
|
||||
void checkGuardBlock(unsigned char* blockMem, unsigned char val, char* locText) const;
|
||||
|
||||
// Find offsets to pre and post guard blocks, and user data buffer
|
||||
unsigned char* preGuard() const { return mem + headerSize(); }
|
||||
unsigned char* data() const { return preGuard() + guardBlockSize; }
|
||||
unsigned char* postGuard() const { return data() + size; }
|
||||
|
||||
size_t size; // size of the user data area
|
||||
unsigned char* mem; // beginning of our allocation (pts to header)
|
||||
TAllocation* prevAlloc; // prior allocation in the chain
|
||||
|
||||
// Support MSVC++ 6.0
|
||||
const static unsigned char guardBlockBeginVal;
|
||||
const static unsigned char guardBlockEndVal;
|
||||
const static unsigned char userDataFill;
|
||||
|
||||
const static size_t guardBlockSize;
|
||||
# ifdef GUARD_BLOCKS
|
||||
inline static size_t headerSize() { return sizeof(TAllocation); }
|
||||
# else
|
||||
inline static size_t headerSize() { return 0; }
|
||||
# endif
|
||||
};
|
||||
|
||||
//
|
||||
// There are several stacks. One is to track the pushing and popping
|
||||
// of the user, and not yet implemented. The others are simply a
|
||||
// repositories of free pages or used pages.
|
||||
//
|
||||
// Page stacks are linked together with a simple header at the beginning
|
||||
// of each allocation obtained from the underlying OS. Multi-page allocations
|
||||
// are returned to the OS. Individual page allocations are kept for future
|
||||
// re-use.
|
||||
//
|
||||
// The "page size" used is not, nor must it match, the underlying OS
|
||||
// page size. But, having it be about that size or equal to a set of
|
||||
// pages is likely most optimal.
|
||||
//
|
||||
class TPoolAllocator {
|
||||
public:
|
||||
TPoolAllocator(bool global = false, int growthIncrement = 8*1024, int allocationAlignment = 16);
|
||||
|
||||
//
|
||||
// Don't call the destructor just to free up the memory, call pop()
|
||||
//
|
||||
~TPoolAllocator();
|
||||
|
||||
//
|
||||
// Call push() to establish a new place to pop memory too. Does not
|
||||
// have to be called to get things started.
|
||||
//
|
||||
void push();
|
||||
|
||||
//
|
||||
// Call pop() to free all memory allocated since the last call to push(),
|
||||
// or if no last call to push, frees all memory since first allocation.
|
||||
//
|
||||
void pop();
|
||||
|
||||
//
|
||||
// Call popAll() to free all memory allocated.
|
||||
//
|
||||
void popAll();
|
||||
|
||||
//
|
||||
// Call allocate() to actually acquire memory. Returns 0 if no memory
|
||||
// available, otherwise a properly aligned pointer to 'numBytes' of memory.
|
||||
//
|
||||
void* allocate(size_t numBytes);
|
||||
|
||||
//
|
||||
// There is no deallocate. The point of this class is that
|
||||
// deallocation can be skipped by the user of it, as the model
|
||||
// of use is to simultaneously deallocate everything at once
|
||||
// by calling pop(), and to not have to solve memory leak problems.
|
||||
//
|
||||
|
||||
protected:
|
||||
friend struct tHeader;
|
||||
|
||||
struct tHeader {
|
||||
tHeader(tHeader* nextPage, size_t pageCount) :
|
||||
#ifdef GUARD_BLOCKS
|
||||
lastAllocation(0),
|
||||
#endif
|
||||
nextPage(nextPage), pageCount(pageCount) { }
|
||||
|
||||
~tHeader() {
|
||||
#ifdef GUARD_BLOCKS
|
||||
if (lastAllocation)
|
||||
lastAllocation->checkAllocList();
|
||||
#endif
|
||||
}
|
||||
|
||||
tHeader* nextPage;
|
||||
size_t pageCount;
|
||||
#ifdef GUARD_BLOCKS
|
||||
TAllocation* lastAllocation;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct tAllocState {
|
||||
size_t offset;
|
||||
tHeader* page;
|
||||
};
|
||||
typedef std::vector<tAllocState> tAllocStack;
|
||||
|
||||
// Track allocations if and only if we're using guard blocks
|
||||
void* initializeAllocation(tHeader* block, unsigned char* memory, size_t numBytes) {
|
||||
# ifdef GUARD_BLOCKS
|
||||
new(memory) TAllocation(numBytes, memory, block->lastAllocation);
|
||||
block->lastAllocation = reinterpret_cast<TAllocation*>(memory);
|
||||
# endif
|
||||
|
||||
// This is optimized entirely away if GUARD_BLOCKS is not defined.
|
||||
return TAllocation::offsetAllocation(memory);
|
||||
}
|
||||
|
||||
bool global; // should be true if this object is globally scoped
|
||||
size_t pageSize; // granularity of allocation from the OS
|
||||
size_t alignment; // all returned allocations will be aligned at
|
||||
// this granularity, which will be a power of 2
|
||||
size_t alignmentMask;
|
||||
size_t headerSkip; // amount of memory to skip to make room for the
|
||||
// header (basically, size of header, rounded
|
||||
// up to make it aligned
|
||||
size_t currentPageOffset; // next offset in top of inUseList to allocate from
|
||||
tHeader* freeList; // list of popped memory
|
||||
tHeader* inUseList; // list of all memory currently being used
|
||||
tAllocStack stack; // stack of where to allocate from, to partition pool
|
||||
|
||||
int numCalls; // just an interesting statistic
|
||||
size_t totalBytes; // just an interesting statistic
|
||||
private:
|
||||
TPoolAllocator& operator=(const TPoolAllocator&); // dont allow assignment operator
|
||||
TPoolAllocator(const TPoolAllocator&); // dont allow default copy constructor
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// There could potentially be many pools with pops happening at
|
||||
// different times. But a simple use is to have a global pop
|
||||
// with everyone using the same global allocator.
|
||||
//
|
||||
typedef TPoolAllocator* PoolAllocatorPointer;
|
||||
extern TPoolAllocator& GetGlobalPoolAllocator();
|
||||
#define GlobalPoolAllocator GetGlobalPoolAllocator()
|
||||
|
||||
|
||||
struct TThreadGlobalPools
|
||||
{
|
||||
TPoolAllocator* globalPoolAllocator;
|
||||
};
|
||||
|
||||
void SetGlobalPoolAllocatorPtr(TPoolAllocator* poolAllocator);
|
||||
|
||||
//
|
||||
// This STL compatible allocator is intended to be used as the allocator
|
||||
// parameter to templatized STL containers, like vector and map.
|
||||
//
|
||||
// It will use the pools for allocation, and not
|
||||
// do any deallocation, but will still do destruction.
|
||||
//
|
||||
template<class T>
|
||||
class pool_allocator {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T *pointer;
|
||||
typedef const T *const_pointer;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T value_type;
|
||||
template<class Other>
|
||||
struct rebind {
|
||||
typedef pool_allocator<Other> other;
|
||||
};
|
||||
pointer address(reference x) const { return &x; }
|
||||
const_pointer address(const_reference x) const { return &x; }
|
||||
|
||||
#ifdef USING_SGI_STL
|
||||
pool_allocator() { }
|
||||
#else
|
||||
pool_allocator() : allocator(GlobalPoolAllocator) { }
|
||||
pool_allocator(TPoolAllocator& a) : allocator(a) { }
|
||||
pool_allocator(const pool_allocator<T>& p) : allocator(p.allocator) { }
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1300
|
||||
template<class Other>
|
||||
#ifdef USING_SGI_STL
|
||||
pool_allocator(const pool_allocator<Other>& p) /*: allocator(p.getAllocator())*/ { }
|
||||
#else
|
||||
pool_allocator(const pool_allocator<Other>& p) : allocator(p.getAllocator()) { }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
template<class Other>
|
||||
pool_allocator(const pool_allocator<Other>& p) : allocator(p.getAllocator()) { }
|
||||
#endif
|
||||
|
||||
#ifdef USING_SGI_STL
|
||||
static pointer allocate(size_type n) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n)); }
|
||||
pointer allocate(size_type n, const void*) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n)); }
|
||||
|
||||
static void deallocate(void*, size_type) { }
|
||||
static void deallocate(pointer, size_type) { }
|
||||
#else
|
||||
pointer allocate(size_type n) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
|
||||
pointer allocate(size_type n, const void*) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n * sizeof(T))); }
|
||||
|
||||
void deallocate(void*, size_type) { }
|
||||
void deallocate(pointer, size_type) { }
|
||||
#endif
|
||||
|
||||
pointer _Charalloc(size_t n) {
|
||||
return reinterpret_cast<pointer>(getAllocator().allocate(n)); }
|
||||
|
||||
void construct(pointer p, const T& val) { new ((void *)p) T(val); }
|
||||
void destroy(pointer p) { p->T::~T(); }
|
||||
|
||||
bool operator==(const pool_allocator& rhs) const { return &getAllocator() == &rhs.getAllocator(); }
|
||||
bool operator!=(const pool_allocator& rhs) const { return &getAllocator() != &rhs.getAllocator(); }
|
||||
|
||||
size_type max_size() const { return static_cast<size_type>(-1) / sizeof(T); }
|
||||
size_type max_size(int size) const { return static_cast<size_type>(-1) / size; }
|
||||
|
||||
#ifdef USING_SGI_STL
|
||||
//void setAllocator(TPoolAllocator* a) { allocator = a; }
|
||||
static TPoolAllocator& getAllocator() { return GlobalPoolAllocator; }
|
||||
#else
|
||||
void setAllocator(TPoolAllocator* a) { allocator = *a; }
|
||||
TPoolAllocator& getAllocator() const { return allocator; }
|
||||
|
||||
protected:
|
||||
TPoolAllocator& allocator;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _POOLALLOC_INCLUDED_
|
||||
52
glslang/Include/ResourceLimits.h
Normal file
52
glslang/Include/ResourceLimits.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _RESOURCE_LIMITS_INCLUDED_
|
||||
#define _RESOURCE_LIMITS_INCLUDED_
|
||||
|
||||
struct TBuiltInResource {
|
||||
int maxLights;
|
||||
int maxClipPlanes;
|
||||
int maxTextureUnits;
|
||||
int maxTextureCoords;
|
||||
int maxVertexAttribs;
|
||||
int maxVertexUniformComponents;
|
||||
int maxVaryingFloats;
|
||||
int maxVertexTextureImageUnits;
|
||||
int maxCombinedTextureImageUnits;
|
||||
int maxTextureImageUnits;
|
||||
int maxFragmentUniformComponents;
|
||||
int maxDrawBuffers;
|
||||
};
|
||||
#endif // _RESOURCE_LIMITS_INCLUDED_
|
||||
169
glslang/Include/ShHandle.h
Normal file
169
glslang/Include/ShHandle.h
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _SHHANDLE_INCLUDED_
|
||||
#define _SHHANDLE_INCLUDED_
|
||||
|
||||
//
|
||||
// Machine independent part of the compiler private objects
|
||||
// sent as ShHandle to the driver.
|
||||
//
|
||||
// This should not be included by driver code.
|
||||
//
|
||||
|
||||
|
||||
#define SH_EXPORTING
|
||||
#include "../Public/ShaderLang.h"
|
||||
|
||||
#include "InfoSink.h"
|
||||
|
||||
class TCompiler;
|
||||
class TLinker;
|
||||
class TUniformMap;
|
||||
|
||||
|
||||
//
|
||||
// The base class used to back handles returned to the driver.
|
||||
//
|
||||
class TShHandleBase {
|
||||
public:
|
||||
TShHandleBase() { }
|
||||
virtual ~TShHandleBase() { }
|
||||
virtual TCompiler* getAsCompiler() { return 0; }
|
||||
virtual TLinker* getAsLinker() { return 0; }
|
||||
virtual TUniformMap* getAsUniformMap() { return 0; }
|
||||
};
|
||||
|
||||
//
|
||||
// The base class for the machine dependent linker to derive from
|
||||
// for managing where uniforms live.
|
||||
//
|
||||
class TUniformMap : public TShHandleBase {
|
||||
public:
|
||||
TUniformMap() { }
|
||||
virtual ~TUniformMap() { }
|
||||
virtual TUniformMap* getAsUniformMap() { return this; }
|
||||
virtual int getLocation(const char* name) = 0;
|
||||
virtual TInfoSink& getInfoSink() { return infoSink; }
|
||||
TInfoSink infoSink;
|
||||
};
|
||||
class TIntermNode;
|
||||
|
||||
//
|
||||
// The base class for the machine dependent compiler to derive from
|
||||
// for managing object code from the compile.
|
||||
//
|
||||
class TCompiler : public TShHandleBase {
|
||||
public:
|
||||
TCompiler(EShLanguage l, TInfoSink& sink) : infoSink(sink) , language(l), haveValidObjectCode(false) { }
|
||||
virtual ~TCompiler() { }
|
||||
EShLanguage getLanguage() { return language; }
|
||||
virtual TInfoSink& getInfoSink() { return infoSink; }
|
||||
|
||||
virtual bool compile(TIntermNode* root) = 0;
|
||||
|
||||
virtual TCompiler* getAsCompiler() { return this; }
|
||||
virtual bool linkable() { return haveValidObjectCode; }
|
||||
|
||||
TInfoSink& infoSink;
|
||||
protected:
|
||||
EShLanguage language;
|
||||
bool haveValidObjectCode;
|
||||
};
|
||||
|
||||
//
|
||||
// Link operations are base on a list of compile results...
|
||||
//
|
||||
typedef TVector<TCompiler*> TCompilerList;
|
||||
typedef TVector<TShHandleBase*> THandleList;
|
||||
|
||||
//
|
||||
// The base class for the machine dependent linker to derive from
|
||||
// to manage the resulting executable.
|
||||
//
|
||||
|
||||
class TLinker : public TShHandleBase {
|
||||
public:
|
||||
TLinker(EShExecutable e, TInfoSink& iSink) :
|
||||
infoSink(iSink),
|
||||
executable(e),
|
||||
haveReturnableObjectCode(false),
|
||||
appAttributeBindings(0),
|
||||
fixedAttributeBindings(0),
|
||||
excludedAttributes(0),
|
||||
excludedCount(0),
|
||||
uniformBindings(0) { }
|
||||
virtual TLinker* getAsLinker() { return this; }
|
||||
virtual ~TLinker() { }
|
||||
virtual bool link(TCompilerList&, TUniformMap*) = 0;
|
||||
virtual bool link(THandleList&) { return false; }
|
||||
virtual void setAppAttributeBindings(const ShBindingTable* t) { appAttributeBindings = t; }
|
||||
virtual void setFixedAttributeBindings(const ShBindingTable* t) { fixedAttributeBindings = t; }
|
||||
virtual void getAttributeBindings(ShBindingTable const **t) const = 0;
|
||||
virtual void setExcludedAttributes(const int* attributes, int count) { excludedAttributes = attributes; excludedCount = count; }
|
||||
virtual ShBindingTable* getUniformBindings() const { return uniformBindings; }
|
||||
virtual const void* getObjectCode() const { return 0; } // a real compiler would be returning object code here
|
||||
virtual TInfoSink& getInfoSink() { return infoSink; }
|
||||
TInfoSink& infoSink;
|
||||
protected:
|
||||
EShExecutable executable;
|
||||
bool haveReturnableObjectCode; // true when objectCode is acceptable to send to driver
|
||||
|
||||
const ShBindingTable* appAttributeBindings;
|
||||
const ShBindingTable* fixedAttributeBindings;
|
||||
const int* excludedAttributes;
|
||||
int excludedCount;
|
||||
ShBindingTable* uniformBindings; // created by the linker
|
||||
};
|
||||
|
||||
//
|
||||
// This is the interface between the machine independent code
|
||||
// and the machine dependent code.
|
||||
//
|
||||
// The machine dependent code should derive from the classes
|
||||
// above. Then Construct*() and Delete*() will create and
|
||||
// destroy the machine dependent objects, which contain the
|
||||
// above machine independent information.
|
||||
//
|
||||
TCompiler* ConstructCompiler(EShLanguage, int);
|
||||
|
||||
TShHandleBase* ConstructLinker(EShExecutable, int);
|
||||
void DeleteLinker(TShHandleBase*);
|
||||
|
||||
TUniformMap* ConstructUniformMap();
|
||||
void DeleteCompiler(TCompiler*);
|
||||
|
||||
void DeleteUniformMap(TUniformMap*);
|
||||
|
||||
#endif // _SHHANDLE_INCLUDED_
|
||||
322
glslang/Include/Types.h
Normal file
322
glslang/Include/Types.h
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#ifndef _TYPES_INCLUDED
|
||||
#define _TYPES_INCLUDED
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include "../Include/BaseTypes.h"
|
||||
|
||||
//
|
||||
// Need to have association of line numbers to types in a list for building structs.
|
||||
//
|
||||
class TType;
|
||||
struct TTypeLine {
|
||||
TType* type;
|
||||
int line;
|
||||
};
|
||||
typedef TVector<TTypeLine> TTypeList;
|
||||
|
||||
inline TTypeList* NewPoolTTypeList()
|
||||
{
|
||||
void* memory = GlobalPoolAllocator.allocate(sizeof(TTypeList));
|
||||
return new(memory) TTypeList;
|
||||
}
|
||||
|
||||
//
|
||||
// This is a workaround for a problem with the yacc stack, It can't have
|
||||
// types that it thinks have non-trivial constructors. It should
|
||||
// just be used while recognizing the grammar, not anything else. Pointers
|
||||
// could be used, but also trying to avoid lots of memory management overhead.
|
||||
//
|
||||
// Not as bad as it looks, there is no actual assumption that the fields
|
||||
// match up or are name the same or anything like that.
|
||||
//
|
||||
class TPublicType {
|
||||
public:
|
||||
TBasicType type;
|
||||
TQualifier qualifier;
|
||||
int size; // size of vector or matrix, not size of array
|
||||
bool matrix;
|
||||
bool array;
|
||||
int arraySize;
|
||||
TType* userDef;
|
||||
int line;
|
||||
|
||||
void setBasic(TBasicType bt, TQualifier q, int ln = 0)
|
||||
{
|
||||
type = bt;
|
||||
qualifier = q;
|
||||
size = 1;
|
||||
matrix = false;
|
||||
array = false;
|
||||
arraySize = 0;
|
||||
userDef = 0;
|
||||
line = ln;
|
||||
}
|
||||
|
||||
void setAggregate(int s, bool m = false)
|
||||
{
|
||||
size = s;
|
||||
matrix = m;
|
||||
}
|
||||
|
||||
void setArray(bool a, int s = 0)
|
||||
{
|
||||
array = a;
|
||||
arraySize = s;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<TTypeList*, TTypeList*> TStructureMap;
|
||||
typedef std::map<TTypeList*, TTypeList*>::iterator TStructureMapIterator;
|
||||
//
|
||||
// Base class for things that have a type.
|
||||
//
|
||||
class TType {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
|
||||
explicit TType(TBasicType t, TQualifier q = EvqTemporary, int s = 1, bool m = false, bool a = false) :
|
||||
type(t), qualifier(q), size(s), matrix(m), array(a), arraySize(0),
|
||||
structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0)
|
||||
{ }
|
||||
explicit TType(const TPublicType &p) :
|
||||
type(p.type), qualifier(p.qualifier), size(p.size), matrix(p.matrix), array(p.array), arraySize(p.arraySize),
|
||||
structure(0), structureSize(0), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0), typeName(0)
|
||||
{
|
||||
if (p.userDef) {
|
||||
structure = p.userDef->getStruct();
|
||||
typeName = NewPoolTString(p.userDef->getTypeName().c_str());
|
||||
}
|
||||
}
|
||||
explicit TType(TTypeList* userDef, const TString& n) :
|
||||
type(EbtStruct), qualifier(EvqTemporary), size(1), matrix(false), array(false), arraySize(0),
|
||||
structure(userDef), maxArraySize(0), arrayInformationType(0), fieldName(0), mangled(0) {
|
||||
typeName = NewPoolTString(n.c_str());
|
||||
}
|
||||
explicit TType() {}
|
||||
virtual ~TType() {}
|
||||
|
||||
TType(const TType& type) { *this = type; }
|
||||
|
||||
void copyType(const TType& copyOf, TStructureMap& remapper)
|
||||
{
|
||||
type = copyOf.type;
|
||||
qualifier = copyOf.qualifier;
|
||||
size = copyOf.size;
|
||||
matrix = copyOf.matrix;
|
||||
array = copyOf.array;
|
||||
arraySize = copyOf.arraySize;
|
||||
|
||||
TStructureMapIterator iter;
|
||||
if (copyOf.structure) {
|
||||
if ((iter = remapper.find(structure)) == remapper.end()) {
|
||||
// create the new structure here
|
||||
structure = NewPoolTTypeList();
|
||||
for (unsigned int i = 0; i < copyOf.structure->size(); ++i) {
|
||||
TTypeLine typeLine;
|
||||
typeLine.line = (*copyOf.structure)[i].line;
|
||||
typeLine.type = (*copyOf.structure)[i].type->clone(remapper);
|
||||
structure->push_back(typeLine);
|
||||
}
|
||||
} else {
|
||||
structure = iter->second;
|
||||
}
|
||||
} else
|
||||
structure = 0;
|
||||
|
||||
fieldName = 0;
|
||||
if (copyOf.fieldName)
|
||||
fieldName = NewPoolTString(copyOf.fieldName->c_str());
|
||||
typeName = 0;
|
||||
if (copyOf.typeName)
|
||||
typeName = NewPoolTString(copyOf.typeName->c_str());
|
||||
|
||||
mangled = 0;
|
||||
if (copyOf.mangled)
|
||||
mangled = NewPoolTString(copyOf.mangled->c_str());
|
||||
|
||||
structureSize = copyOf.structureSize;
|
||||
maxArraySize = copyOf.maxArraySize;
|
||||
assert(copyOf.arrayInformationType == 0);
|
||||
arrayInformationType = 0; // arrayInformationType should not be set for builtIn symbol table level
|
||||
}
|
||||
|
||||
TType* clone(TStructureMap& remapper)
|
||||
{
|
||||
TType *newType = new TType();
|
||||
newType->copyType(*this, remapper);
|
||||
|
||||
return newType;
|
||||
}
|
||||
|
||||
virtual void setType(TBasicType t, int s, bool m, bool a, int aS = 0)
|
||||
{ type = t; size = s; matrix = m; array = a; arraySize = aS; }
|
||||
virtual void setType(TBasicType t, int s, bool m, TType* userDef = 0)
|
||||
{ type = t;
|
||||
size = s;
|
||||
matrix = m;
|
||||
if (userDef)
|
||||
structure = userDef->getStruct();
|
||||
// leave array information intact.
|
||||
}
|
||||
virtual void setTypeName(const TString& n) { typeName = NewPoolTString(n.c_str()); }
|
||||
virtual void setFieldName(const TString& n) { fieldName = NewPoolTString(n.c_str()); }
|
||||
virtual const TString& getTypeName() const
|
||||
{
|
||||
assert(typeName);
|
||||
return *typeName;
|
||||
}
|
||||
|
||||
virtual const TString& getFieldName() const
|
||||
{
|
||||
assert(fieldName);
|
||||
return *fieldName;
|
||||
}
|
||||
|
||||
virtual TBasicType getBasicType() const { return type; }
|
||||
virtual TQualifier getQualifier() const { return qualifier; }
|
||||
virtual void changeQualifier(TQualifier q) { qualifier = q; }
|
||||
|
||||
// One-dimensional size of single instance type
|
||||
virtual int getNominalSize() const { return size; }
|
||||
|
||||
// Full-dimensional size of single instance of type
|
||||
virtual int getInstanceSize() const
|
||||
{
|
||||
if (matrix)
|
||||
return size * size;
|
||||
else
|
||||
return size;
|
||||
}
|
||||
|
||||
virtual bool isMatrix() const { return matrix ? true : false; }
|
||||
virtual bool isArray() const { return array ? true : false; }
|
||||
int getArraySize() const { return arraySize; }
|
||||
void setArraySize(int s) { array = true; arraySize = s; }
|
||||
void setMaxArraySize (int s) { maxArraySize = s; }
|
||||
int getMaxArraySize () const { return maxArraySize; }
|
||||
void clearArrayness() { array = false; arraySize = 0; maxArraySize = 0; }
|
||||
void setArrayInformationType(TType* t) { arrayInformationType = t; }
|
||||
TType* getArrayInformationType() { return arrayInformationType; }
|
||||
virtual bool isVector() const { return size > 1 && !matrix; }
|
||||
static char* getBasicString(TBasicType t) {
|
||||
switch (t) {
|
||||
case EbtVoid: return "void"; break;
|
||||
case EbtFloat: return "float"; break;
|
||||
case EbtInt: return "int"; break;
|
||||
case EbtBool: return "bool"; break;
|
||||
case EbtSampler1D: return "sampler1D"; break;
|
||||
case EbtSampler2D: return "sampler2D"; break;
|
||||
case EbtSampler3D: return "sampler3D"; break;
|
||||
case EbtSamplerCube: return "samplerCube"; break;
|
||||
case EbtSampler1DShadow: return "sampler1DShadow"; break;
|
||||
case EbtSampler2DShadow: return "sampler2DShadow"; break;
|
||||
case EbtSamplerRect: return "samplerRect"; break; // ARB_texture_rectangle
|
||||
case EbtSamplerRectShadow: return "samplerRectShadow"; break; // ARB_texture_rectangle
|
||||
case EbtStruct: return "structure"; break;
|
||||
default: return "unknown type";
|
||||
}
|
||||
}
|
||||
const char* getBasicString() const { return TType::getBasicString(type); }
|
||||
const char* getQualifierString() const { return ::getQualifierString(qualifier); }
|
||||
TTypeList* getStruct() { return structure; }
|
||||
|
||||
int getObjectSize() const
|
||||
{
|
||||
int totalSize;
|
||||
|
||||
if (getBasicType() == EbtStruct)
|
||||
totalSize = getStructSize();
|
||||
else if (matrix)
|
||||
totalSize = size * size;
|
||||
else
|
||||
totalSize = size;
|
||||
|
||||
if (isArray())
|
||||
totalSize *= Max(getArraySize(), getMaxArraySize());
|
||||
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
TTypeList* getStruct() const { return structure; }
|
||||
TString& getMangledName() {
|
||||
if (!mangled) {
|
||||
mangled = NewPoolTString("");
|
||||
buildMangledName(*mangled);
|
||||
*mangled += ';' ;
|
||||
}
|
||||
|
||||
return *mangled;
|
||||
}
|
||||
bool sameElementType(const TType& right) const {
|
||||
return type == right.type &&
|
||||
size == right.size &&
|
||||
matrix == right.matrix &&
|
||||
structure == right.structure;
|
||||
}
|
||||
bool operator==(const TType& right) const {
|
||||
return type == right.type &&
|
||||
size == right.size &&
|
||||
matrix == right.matrix &&
|
||||
array == right.array && (!array || arraySize == right.arraySize) &&
|
||||
structure == right.structure;
|
||||
// don't check the qualifier, it's not ever what's being sought after
|
||||
}
|
||||
bool operator!=(const TType& right) const {
|
||||
return !operator==(right);
|
||||
}
|
||||
TString getCompleteString() const;
|
||||
|
||||
protected:
|
||||
void buildMangledName(TString&);
|
||||
int getStructSize() const;
|
||||
|
||||
TBasicType type : 6;
|
||||
TQualifier qualifier : 7;
|
||||
int size : 8; // size of vector or matrix, not size of array
|
||||
unsigned int matrix : 1;
|
||||
unsigned int array : 1;
|
||||
int arraySize;
|
||||
|
||||
TTypeList* structure; // 0 unless this is a struct
|
||||
mutable int structureSize;
|
||||
int maxArraySize;
|
||||
TType* arrayInformationType;
|
||||
TString *fieldName; // for structure field names
|
||||
TString *mangled;
|
||||
TString *typeName; // for structure field type name
|
||||
};
|
||||
|
||||
#endif // _TYPES_INCLUDED_
|
||||
522
glslang/Include/intermediate.h
Normal file
522
glslang/Include/intermediate.h
Normal file
|
|
@ -0,0 +1,522 @@
|
|||
//
|
||||
//Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||
//All rights reserved.
|
||||
//
|
||||
//Redistribution and use in source and binary forms, with or without
|
||||
//modification, are permitted provided that the following conditions
|
||||
//are met:
|
||||
//
|
||||
// Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
//"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
//FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
//COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
//INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
//CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
//LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
//ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
//POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
//
|
||||
// Definition of the in-memory high-level intermediate representation
|
||||
// of shaders. This is a tree that parser creates.
|
||||
//
|
||||
// Nodes in the tree are defined as a hierarchy of classes derived from
|
||||
// TIntermNode. Each is a node in a tree. There is no preset branching factor;
|
||||
// each node can have it's own type of list of children.
|
||||
//
|
||||
|
||||
#ifndef __INTERMEDIATE_H
|
||||
#define __INTERMEDIATE_H
|
||||
|
||||
#include "../Include/Common.h"
|
||||
#include "../Include/Types.h"
|
||||
#include "../Include/ConstantUnion.h"
|
||||
|
||||
//
|
||||
// Operators used by the high-level (parse tree) representation.
|
||||
//
|
||||
enum TOperator {
|
||||
EOpNull, // if in a node, should only mean a node is still being built
|
||||
EOpSequence, // denotes a list of statements, or parameters, etc.
|
||||
EOpFunctionCall,
|
||||
EOpFunction, // For function definition
|
||||
EOpParameters, // an aggregate listing the parameters to a function
|
||||
|
||||
//
|
||||
// Unary operators
|
||||
//
|
||||
|
||||
EOpNegative,
|
||||
EOpLogicalNot,
|
||||
EOpVectorLogicalNot,
|
||||
EOpBitwiseNot,
|
||||
|
||||
EOpPostIncrement,
|
||||
EOpPostDecrement,
|
||||
EOpPreIncrement,
|
||||
EOpPreDecrement,
|
||||
|
||||
EOpConvIntToBool,
|
||||
EOpConvFloatToBool,
|
||||
EOpConvBoolToFloat,
|
||||
EOpConvIntToFloat,
|
||||
EOpConvFloatToInt,
|
||||
EOpConvBoolToInt,
|
||||
|
||||
//
|
||||
// binary operations
|
||||
//
|
||||
|
||||
EOpAdd,
|
||||
EOpSub,
|
||||
EOpMul,
|
||||
EOpDiv,
|
||||
EOpMod,
|
||||
EOpRightShift,
|
||||
EOpLeftShift,
|
||||
EOpAnd,
|
||||
EOpInclusiveOr,
|
||||
EOpExclusiveOr,
|
||||
EOpEqual,
|
||||
EOpNotEqual,
|
||||
EOpVectorEqual,
|
||||
EOpVectorNotEqual,
|
||||
EOpLessThan,
|
||||
EOpGreaterThan,
|
||||
EOpLessThanEqual,
|
||||
EOpGreaterThanEqual,
|
||||
EOpComma,
|
||||
|
||||
EOpVectorTimesScalar,
|
||||
EOpVectorTimesMatrix,
|
||||
EOpMatrixTimesVector,
|
||||
EOpMatrixTimesScalar,
|
||||
|
||||
EOpLogicalOr,
|
||||
EOpLogicalXor,
|
||||
EOpLogicalAnd,
|
||||
|
||||
EOpIndexDirect,
|
||||
EOpIndexIndirect,
|
||||
EOpIndexDirectStruct,
|
||||
|
||||
EOpVectorSwizzle,
|
||||
|
||||
//
|
||||
// Built-in functions potentially mapped to operators
|
||||
//
|
||||
|
||||
EOpRadians,
|
||||
EOpDegrees,
|
||||
EOpSin,
|
||||
EOpCos,
|
||||
EOpTan,
|
||||
EOpAsin,
|
||||
EOpAcos,
|
||||
EOpAtan,
|
||||
|
||||
EOpPow,
|
||||
EOpExp,
|
||||
EOpLog,
|
||||
EOpExp2,
|
||||
EOpLog2,
|
||||
EOpSqrt,
|
||||
EOpInverseSqrt,
|
||||
|
||||
EOpAbs,
|
||||
EOpSign,
|
||||
EOpFloor,
|
||||
EOpCeil,
|
||||
EOpFract,
|
||||
EOpMin,
|
||||
EOpMax,
|
||||
EOpClamp,
|
||||
EOpMix,
|
||||
EOpStep,
|
||||
EOpSmoothStep,
|
||||
|
||||
EOpLength,
|
||||
EOpDistance,
|
||||
EOpDot,
|
||||
EOpCross,
|
||||
EOpNormalize,
|
||||
EOpFaceForward,
|
||||
EOpReflect,
|
||||
EOpRefract,
|
||||
|
||||
EOpDPdx, // Fragment only
|
||||
EOpDPdy, // Fragment only
|
||||
EOpFwidth, // Fragment only
|
||||
|
||||
EOpMatrixTimesMatrix,
|
||||
|
||||
EOpAny,
|
||||
EOpAll,
|
||||
|
||||
EOpItof, // pack/unpack only
|
||||
EOpFtoi, // pack/unpack only
|
||||
EOpSkipPixels, // pack/unpack only
|
||||
EOpReadInput, // unpack only
|
||||
EOpWritePixel, // unpack only
|
||||
EOpBitmapLsb, // unpack only
|
||||
EOpBitmapMsb, // unpack only
|
||||
EOpWriteOutput, // pack only
|
||||
EOpReadPixel, // pack only
|
||||
|
||||
//
|
||||
// Branch
|
||||
//
|
||||
|
||||
EOpKill, // Fragment only
|
||||
EOpReturn,
|
||||
EOpBreak,
|
||||
EOpContinue,
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
|
||||
EOpConstructInt,
|
||||
EOpConstructBool,
|
||||
EOpConstructFloat,
|
||||
EOpConstructVec2,
|
||||
EOpConstructVec3,
|
||||
EOpConstructVec4,
|
||||
EOpConstructBVec2,
|
||||
EOpConstructBVec3,
|
||||
EOpConstructBVec4,
|
||||
EOpConstructIVec2,
|
||||
EOpConstructIVec3,
|
||||
EOpConstructIVec4,
|
||||
EOpConstructMat2,
|
||||
EOpConstructMat3,
|
||||
EOpConstructMat4,
|
||||
EOpConstructStruct,
|
||||
|
||||
//
|
||||
// moves
|
||||
//
|
||||
|
||||
EOpAssign,
|
||||
EOpAddAssign,
|
||||
EOpSubAssign,
|
||||
EOpMulAssign,
|
||||
EOpVectorTimesMatrixAssign,
|
||||
EOpVectorTimesScalarAssign,
|
||||
EOpMatrixTimesScalarAssign,
|
||||
EOpMatrixTimesMatrixAssign,
|
||||
EOpDivAssign,
|
||||
EOpModAssign,
|
||||
EOpAndAssign,
|
||||
EOpInclusiveOrAssign,
|
||||
EOpExclusiveOrAssign,
|
||||
EOpLeftShiftAssign,
|
||||
EOpRightShiftAssign,
|
||||
|
||||
//
|
||||
// Array operators
|
||||
//
|
||||
|
||||
EOpArrayLength,
|
||||
};
|
||||
|
||||
class TIntermTraverser;
|
||||
class TIntermAggregate;
|
||||
class TIntermBinary;
|
||||
class TIntermConstantUnion;
|
||||
class TIntermSelection;
|
||||
class TIntermTyped;
|
||||
class TIntermSymbol;
|
||||
class TInfoSink;
|
||||
|
||||
//
|
||||
// Base class for the tree nodes
|
||||
//
|
||||
class TIntermNode {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
|
||||
|
||||
TIntermNode() : line(0) {}
|
||||
virtual TSourceLoc getLine() const { return line; }
|
||||
virtual void setLine(TSourceLoc l) { line = l; }
|
||||
virtual void traverse(TIntermTraverser*) = 0;
|
||||
virtual TIntermTyped* getAsTyped() { return 0; }
|
||||
virtual TIntermConstantUnion* getAsConstantUnion() { return 0; }
|
||||
virtual TIntermAggregate* getAsAggregate() { return 0; }
|
||||
virtual TIntermBinary* getAsBinaryNode() { return 0; }
|
||||
virtual TIntermSelection* getAsSelectionNode() { return 0; }
|
||||
virtual TIntermSymbol* getAsSymbolNode() { return 0; }
|
||||
virtual ~TIntermNode() { }
|
||||
protected:
|
||||
TSourceLoc line;
|
||||
};
|
||||
|
||||
//
|
||||
// This is just to help yacc.
|
||||
//
|
||||
struct TIntermNodePair {
|
||||
TIntermNode* node1;
|
||||
TIntermNode* node2;
|
||||
};
|
||||
|
||||
class TIntermSymbol;
|
||||
class TIntermBinary;
|
||||
|
||||
//
|
||||
// Intermediate class for nodes that have a type.
|
||||
//
|
||||
class TIntermTyped : public TIntermNode {
|
||||
public:
|
||||
TIntermTyped(const TType& t) : type(t) { }
|
||||
virtual TIntermTyped* getAsTyped() { return this; }
|
||||
virtual void setType(const TType& t) { type = t; }
|
||||
virtual TType getType() const { return type; }
|
||||
virtual TType* getTypePointer() { return &type; }
|
||||
|
||||
virtual TBasicType getBasicType() const { return type.getBasicType(); }
|
||||
virtual TQualifier getQualifier() const { return type.getQualifier(); }
|
||||
virtual int getNominalSize() const { return type.getNominalSize(); }
|
||||
virtual int getSize() const { return type.getInstanceSize(); }
|
||||
virtual bool isMatrix() const { return type.isMatrix(); }
|
||||
virtual bool isArray() const { return type.isArray(); }
|
||||
virtual bool isVector() const { return type.isVector(); }
|
||||
const char* getBasicString() const { return type.getBasicString(); }
|
||||
const char* getQualifierString() const { return type.getQualifierString(); }
|
||||
TString getCompleteString() const { return type.getCompleteString(); }
|
||||
|
||||
protected:
|
||||
TType type;
|
||||
};
|
||||
|
||||
//
|
||||
// Handle for, do-while, and while loops.
|
||||
//
|
||||
class TIntermLoop : public TIntermNode {
|
||||
public:
|
||||
TIntermLoop(TIntermNode* aBody, TIntermTyped* aTest, TIntermTyped* aTerminal, bool testFirst) :
|
||||
body(aBody),
|
||||
test(aTest),
|
||||
terminal(aTerminal),
|
||||
first(testFirst) { }
|
||||
virtual void traverse(TIntermTraverser*);
|
||||
TIntermNode* getBody() { return body; }
|
||||
TIntermTyped* getTest() { return test; }
|
||||
TIntermTyped* getTerminal() { return terminal; }
|
||||
bool testFirst() { return first; }
|
||||
protected:
|
||||
TIntermNode* body; // code to loop over
|
||||
TIntermTyped* test; // exit condition associated with loop, could be 0 for 'for' loops
|
||||
TIntermTyped* terminal; // exists for for-loops
|
||||
bool first; // true for while and for, not for do-while
|
||||
};
|
||||
|
||||
//
|
||||
// Handle break, continue, return, and kill.
|
||||
//
|
||||
class TIntermBranch : public TIntermNode {
|
||||
public:
|
||||
TIntermBranch(TOperator op, TIntermTyped* e) :
|
||||
flowOp(op),
|
||||
expression(e) { }
|
||||
virtual void traverse(TIntermTraverser*);
|
||||
TOperator getFlowOp() { return flowOp; }
|
||||
TIntermTyped* getExpression() { return expression; }
|
||||
protected:
|
||||
TOperator flowOp;
|
||||
TIntermTyped* expression; // non-zero except for "return exp;" statements
|
||||
};
|
||||
|
||||
//
|
||||
// Nodes that correspond to symbols or constants in the source code.
|
||||
//
|
||||
class TIntermSymbol : public TIntermTyped {
|
||||
public:
|
||||
// if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from
|
||||
// per process globalpoolallocator, then it causes increased memory usage per compile
|
||||
// it is essential to use "symbol = sym" to assign to symbol
|
||||
TIntermSymbol(int i, const TString& sym, const TType& t) :
|
||||
TIntermTyped(t), id(i) { symbol = sym;}
|
||||
virtual int getId() const { return id; }
|
||||
virtual const TString& getSymbol() const { return symbol; }
|
||||
virtual void traverse(TIntermTraverser*);
|
||||
virtual TIntermSymbol* getAsSymbolNode() { return this; }
|
||||
protected:
|
||||
int id;
|
||||
TString symbol;
|
||||
};
|
||||
|
||||
class TIntermConstantUnion : public TIntermTyped {
|
||||
public:
|
||||
TIntermConstantUnion(constUnion *unionPointer, const TType& t) : TIntermTyped(t), unionArrayPointer(unionPointer) { }
|
||||
constUnion* getUnionArrayPointer() const { return unionArrayPointer; }
|
||||
void setUnionArrayPointer(constUnion *c) { unionArrayPointer = c; }
|
||||
virtual TIntermConstantUnion* getAsConstantUnion() { return this; }
|
||||
virtual void traverse(TIntermTraverser* );
|
||||
virtual TIntermTyped* fold(TOperator, TIntermTyped*, TInfoSink&);
|
||||
protected:
|
||||
constUnion *unionArrayPointer;
|
||||
};
|
||||
|
||||
//
|
||||
// Intermediate class for node types that hold operators.
|
||||
//
|
||||
class TIntermOperator : public TIntermTyped {
|
||||
public:
|
||||
TOperator getOp() { return op; }
|
||||
bool modifiesState() const;
|
||||
bool isConstructor() const;
|
||||
virtual bool promote(TInfoSink&) { return true; }
|
||||
protected:
|
||||
TIntermOperator(TOperator o) : TIntermTyped(TType(EbtFloat)), op(o) {}
|
||||
TIntermOperator(TOperator o, TType& t) : TIntermTyped(t), op(o) {}
|
||||
TOperator op;
|
||||
};
|
||||
|
||||
//
|
||||
// Nodes for all the basic binary math operators.
|
||||
//
|
||||
class TIntermBinary : public TIntermOperator {
|
||||
public:
|
||||
TIntermBinary(TOperator o) : TIntermOperator(o) {}
|
||||
virtual void traverse(TIntermTraverser*);
|
||||
virtual void setLeft(TIntermTyped* n) { left = n; }
|
||||
virtual void setRight(TIntermTyped* n) { right = n; }
|
||||
virtual TIntermTyped* getLeft() const { return left; }
|
||||
virtual TIntermTyped* getRight() const { return right; }
|
||||
virtual TIntermBinary* getAsBinaryNode() { return this; }
|
||||
virtual bool promote(TInfoSink&);
|
||||
protected:
|
||||
TIntermTyped* left;
|
||||
TIntermTyped* right;
|
||||
};
|
||||
|
||||
//
|
||||
// Nodes for unary math operators.
|
||||
//
|
||||
class TIntermUnary : public TIntermOperator {
|
||||
public:
|
||||
TIntermUnary(TOperator o, TType& t) : TIntermOperator(o, t), operand(0) {}
|
||||
TIntermUnary(TOperator o) : TIntermOperator(o), operand(0) {}
|
||||
virtual void traverse(TIntermTraverser*);
|
||||
virtual void setOperand(TIntermTyped* o) { operand = o; }
|
||||
virtual TIntermTyped* getOperand() { return operand; }
|
||||
virtual bool promote(TInfoSink&);
|
||||
protected:
|
||||
TIntermTyped* operand;
|
||||
};
|
||||
|
||||
typedef TVector<TIntermNode*> TIntermSequence;
|
||||
typedef TVector<int> TQualifierList;
|
||||
//
|
||||
// Nodes that operate on an arbitrary sized set of children.
|
||||
//
|
||||
class TIntermAggregate : public TIntermOperator {
|
||||
public:
|
||||
TIntermAggregate() : TIntermOperator(EOpNull), userDefined(false), pragmaTable(0) { }
|
||||
TIntermAggregate(TOperator o) : TIntermOperator(o), pragmaTable(0) { }
|
||||
~TIntermAggregate() { delete pragmaTable; }
|
||||
virtual TIntermAggregate* getAsAggregate() { return this; }
|
||||
virtual void setOperator(TOperator o) { op = o; }
|
||||
virtual TIntermSequence& getSequence() { return sequence; }
|
||||
virtual void setName(const TString& n) { name = n; }
|
||||
virtual const TString& getName() const { return name; }
|
||||
virtual void traverse(TIntermTraverser*);
|
||||
virtual void setUserDefined() { userDefined = true; }
|
||||
virtual bool isUserDefined() { return userDefined; }
|
||||
virtual TQualifierList& getQualifier() { return qualifier; }
|
||||
void setOptimize(bool o) { optimize = o; }
|
||||
void setDebug(bool d) { debug = d; }
|
||||
bool getOptimize() { return optimize; }
|
||||
bool getDebug() { return debug; }
|
||||
void addToPragmaTable(const TPragmaTable& pTable);
|
||||
const TPragmaTable& getPragmaTable() const { return *pragmaTable; }
|
||||
protected:
|
||||
TIntermAggregate(const TIntermAggregate&); // disallow copy constructor
|
||||
TIntermAggregate& operator=(const TIntermAggregate&); // disallow assignment operator
|
||||
TIntermSequence sequence;
|
||||
TQualifierList qualifier;
|
||||
TString name;
|
||||
bool userDefined; // used for user defined function names
|
||||
bool optimize;
|
||||
bool debug;
|
||||
TPragmaTable *pragmaTable;
|
||||
};
|
||||
|
||||
//
|
||||
// For if tests. Simplified since there is no switch statement.
|
||||
//
|
||||
class TIntermSelection : public TIntermTyped {
|
||||
public:
|
||||
TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) :
|
||||
TIntermTyped(TType(EbtVoid)), condition(cond), trueBlock(trueB), falseBlock(falseB) {}
|
||||
TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) :
|
||||
TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB) {}
|
||||
virtual void traverse(TIntermTraverser*);
|
||||
virtual TIntermNode* getCondition() const { return condition; }
|
||||
virtual TIntermNode* getTrueBlock() const { return trueBlock; }
|
||||
virtual TIntermNode* getFalseBlock() const { return falseBlock; }
|
||||
virtual TIntermSelection* getAsSelectionNode() { return this; }
|
||||
protected:
|
||||
TIntermTyped* condition;
|
||||
TIntermNode* trueBlock;
|
||||
TIntermNode* falseBlock;
|
||||
};
|
||||
|
||||
//
|
||||
// For traversing the tree. User should derive from this,
|
||||
// put their traversal specific data in it, and then pass
|
||||
// it to a Traverse method.
|
||||
//
|
||||
// When using this, just fill in the methods for nodes you want visited.
|
||||
// Return false from a pre-visit to skip visiting that node's subtree.
|
||||
//
|
||||
class TIntermTraverser {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
|
||||
|
||||
TIntermTraverser() :
|
||||
visitSymbol(0),
|
||||
visitConstantUnion(0),
|
||||
visitBinary(0),
|
||||
visitUnary(0),
|
||||
visitSelection(0),
|
||||
visitAggregate(0),
|
||||
visitLoop(0),
|
||||
visitBranch(0),
|
||||
depth(0),
|
||||
preVisit(true),
|
||||
postVisit(false),
|
||||
rightToLeft(false) {}
|
||||
|
||||
void (*visitSymbol)(TIntermSymbol*, TIntermTraverser*);
|
||||
void (*visitConstantUnion)(TIntermConstantUnion*, TIntermTraverser*);
|
||||
bool (*visitBinary)(bool preVisit, TIntermBinary*, TIntermTraverser*);
|
||||
bool (*visitUnary)(bool preVisit, TIntermUnary*, TIntermTraverser*);
|
||||
bool (*visitSelection)(bool preVisit, TIntermSelection*, TIntermTraverser*);
|
||||
bool (*visitAggregate)(bool preVisit, TIntermAggregate*, TIntermTraverser*);
|
||||
bool (*visitLoop)(bool preVisit, TIntermLoop*, TIntermTraverser*);
|
||||
bool (*visitBranch)(bool preVisit, TIntermBranch*, TIntermTraverser*);
|
||||
|
||||
int depth;
|
||||
bool preVisit;
|
||||
bool postVisit;
|
||||
bool rightToLeft;
|
||||
};
|
||||
|
||||
#endif // __INTERMEDIATE_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue