Commit 103896ba by Nicolas Capens Committed by Nicolas Capens

Copy the OpenGL folder to Radiance.

BUG=18218488 Change-Id: I561dab264540dabaf479f5acc9265e83941f51f0 Reviewed-on: https://swiftshader-review.googlesource.com/1321Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent e8321394
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2012 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// debug.cpp: Debugging utilities.
#include "common/debug.h"
#include <stdio.h>
#include <stdarg.h>
namespace es
{
static void output(const char *format, va_list vararg)
{
if(false)
{
FILE* file = fopen(TRACE_OUTPUT_FILE, "a");
if(file)
{
vfprintf(file, format, vararg);
fclose(file);
}
}
}
void trace(const char *format, ...)
{
va_list vararg;
va_start(vararg, format);
output(format, vararg);
va_end(vararg);
}
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2012 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
// debug.h: Debugging utilities.
#ifndef COMMON_DEBUG_H_
#define COMMON_DEBUG_H_
#include <stdio.h>
#include <assert.h>
#if !defined(TRACE_OUTPUT_FILE)
#define TRACE_OUTPUT_FILE "debug.txt"
#endif
namespace es
{
// Outputs text to the debugging log
void trace(const char *format, ...);
}
// A macro to output a trace of a function call and its arguments to the debugging log
#if defined(ANGLE_DISABLE_TRACE)
#define TRACE(message, ...) (void(0))
#else
#define TRACE(message, ...) es::trace("trace: %s(%d): "message"\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#endif
// A macro to output a function call and its arguments to the debugging log, to denote an item in need of fixing.
#if defined(ANGLE_DISABLE_TRACE)
#define FIXME(message, ...) (void(0))
#else
#define FIXME(message, ...) do {es::trace("fixme: %s(%d): "message"\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); assert(false);} while(false)
#endif
// A macro to output a function call and its arguments to the debugging log, in case of error.
#if defined(ANGLE_DISABLE_TRACE)
#define ERR(message, ...) (void(0))
#else
#define ERR(message, ...) do {es::trace("err: %s(%d): "message"\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); assert(false);} while(false)
#endif
// A macro asserting a condition and outputting failures to the debug log
#if !defined(NDEBUG)
#define ASSERT(expression) do { \
if(!(expression)) \
ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
assert(expression); \
} while(0)
#else
#define ASSERT(expression) (void(0))
#endif
// A macro to indicate unimplemented functionality
#if !defined(NDEBUG)
#define UNIMPLEMENTED() do { \
FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \
assert(false); \
} while(0)
#else
#define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
#endif
// A macro for code which is not expected to be reached under valid assumptions
#if !defined(NDEBUG)
#define UNREACHABLE() do { \
ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \
assert(false); \
} while(0)
#else
#define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)
#endif
// A macro functioning as a compile-time assert to validate constant conditions
#define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition) ? 1 : -1]
#endif // COMMON_DEBUG_H_
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/AnalyzeCallDepth.h"
AnalyzeCallDepth::FunctionNode::FunctionNode(TIntermAggregate *node) : node(node)
{
visit = PreVisit;
callDepth = 0;
}
const TString &AnalyzeCallDepth::FunctionNode::getName() const
{
return node->getName();
}
void AnalyzeCallDepth::FunctionNode::addCallee(AnalyzeCallDepth::FunctionNode *callee)
{
for(size_t i = 0; i < callees.size(); i++)
{
if(callees[i] == callee)
{
return;
}
}
callees.push_back(callee);
}
unsigned int AnalyzeCallDepth::FunctionNode::analyzeCallDepth(AnalyzeCallDepth *analyzeCallDepth)
{
ASSERT(visit == PreVisit);
ASSERT(analyzeCallDepth);
callDepth = 0;
visit = InVisit;
for(size_t i = 0; i < callees.size(); i++)
{
switch(callees[i]->visit)
{
case InVisit:
// Cycle detected (recursion)
return UINT_MAX;
case PostVisit:
callDepth = std::max(callDepth, 1 + callees[i]->getLastDepth());
break;
case PreVisit:
callDepth = std::max(callDepth, 1 + callees[i]->analyzeCallDepth(analyzeCallDepth));
break;
default:
UNREACHABLE();
break;
}
}
visit = PostVisit;
return callDepth;
}
unsigned int AnalyzeCallDepth::FunctionNode::getLastDepth() const
{
return callDepth;
}
void AnalyzeCallDepth::FunctionNode::removeIfUnreachable()
{
if(visit == PreVisit)
{
node->setOp(EOpPrototype);
node->getSequence().resize(1); // Remove function body
}
}
AnalyzeCallDepth::AnalyzeCallDepth(TIntermNode *root)
: TIntermTraverser(true, false, true, false),
currentFunction(0)
{
root->traverse(this);
}
AnalyzeCallDepth::~AnalyzeCallDepth()
{
for(size_t i = 0; i < functions.size(); i++)
{
delete functions[i];
}
}
bool AnalyzeCallDepth::visitAggregate(Visit visit, TIntermAggregate *node)
{
switch(node->getOp())
{
case EOpFunction: // Function definition
{
if(visit == PreVisit)
{
currentFunction = findFunctionByName(node->getName());
if(!currentFunction)
{
currentFunction = new FunctionNode(node);
functions.push_back(currentFunction);
}
}
else if(visit == PostVisit)
{
currentFunction = 0;
}
}
break;
case EOpFunctionCall:
{
if(!node->isUserDefined())
{
return true; // Check the arguments for function calls
}
if(visit == PreVisit)
{
FunctionNode *function = findFunctionByName(node->getName());
if(!function)
{
function = new FunctionNode(node);
functions.push_back(function);
}
if(currentFunction)
{
currentFunction->addCallee(function);
}
else
{
globalFunctionCalls.insert(function);
}
}
}
break;
default:
break;
}
return true;
}
unsigned int AnalyzeCallDepth::analyzeCallDepth()
{
FunctionNode *main = findFunctionByName("main(");
if(!main)
{
return 0;
}
unsigned int depth = 1 + main->analyzeCallDepth(this);
for(FunctionSet::iterator globalCall = globalFunctionCalls.begin(); globalCall != globalFunctionCalls.end(); globalCall++)
{
unsigned int globalDepth = 1 + (*globalCall)->analyzeCallDepth(this);
if(globalDepth > depth)
{
depth = globalDepth;
}
}
for(size_t i = 0; i < functions.size(); i++)
{
functions[i]->removeIfUnreachable();
}
return depth;
}
AnalyzeCallDepth::FunctionNode *AnalyzeCallDepth::findFunctionByName(const TString &name)
{
for(size_t i = 0; i < functions.size(); i++)
{
if(functions[i]->getName() == name)
{
return functions[i];
}
}
return 0;
}
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_ANALYZE_CALL_DEPTH_H_
#define COMPILER_ANALYZE_CALL_DEPTH_H_
#include "compiler/intermediate.h"
#include <set>
#include <limits.h>
// Traverses intermediate tree to analyze call depth or detect function recursion
class AnalyzeCallDepth : public TIntermTraverser
{
public:
AnalyzeCallDepth(TIntermNode *root);
~AnalyzeCallDepth();
virtual bool visitAggregate(Visit, TIntermAggregate*);
unsigned int analyzeCallDepth();
private:
class FunctionNode
{
public:
FunctionNode(TIntermAggregate *node);
const TString &getName() const;
void addCallee(FunctionNode *callee);
unsigned int analyzeCallDepth(AnalyzeCallDepth *analyzeCallDepth);
unsigned int getLastDepth() const;
void removeIfUnreachable();
private:
TIntermAggregate *const node;
TVector<FunctionNode*> callees;
Visit visit;
unsigned int callDepth;
};
FunctionNode *findFunctionByName(const TString &name);
std::vector<FunctionNode*> functions;
typedef std::set<FunctionNode*> FunctionSet;
FunctionSet globalFunctionCalls;
FunctionNode *currentFunction;
};
#endif // COMPILER_ANALYZE_CALL_DEPTH_H_
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _BASICTYPES_INCLUDED_
#define _BASICTYPES_INCLUDED_
//
// Precision qualifiers
//
enum TPrecision
{
// These need to be kept sorted
EbpUndefined,
EbpLow,
EbpMedium,
EbpHigh
};
inline const char* getPrecisionString(TPrecision p)
{
switch(p)
{
case EbpHigh: return "highp"; break;
case EbpMedium: return "mediump"; break;
case EbpLow: return "lowp"; break;
default: return "mediump"; break; // Safest fallback
}
}
//
// Basic type. Arrays, vectors, etc., are orthogonal to this.
//
enum TBasicType
{
EbtVoid,
EbtFloat,
EbtInt,
EbtBool,
EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
EbtSampler2D,
EbtSamplerCube,
EbtSamplerExternalOES,
EbtGuardSamplerEnd, // non type: see implementation of IsSampler()
EbtStruct,
EbtAddress, // should be deprecated??
EbtInvariant // used as a type when qualifying a previously declared variable as being invariant
};
inline const char* getBasicString(TBasicType t)
{
switch (t)
{
case EbtVoid: return "void";
case EbtFloat: return "float";
case EbtInt: return "int";
case EbtBool: return "bool";
case EbtSampler2D: return "sampler2D";
case EbtSamplerCube: return "samplerCube";
case EbtSamplerExternalOES: return "samplerExternalOES";
case EbtStruct: return "structure";
default: return "unknown type";
}
}
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
EvqInvariantVaryingIn, // readonly, fragment shaders only
EvqInvariantVaryingOut, // 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,
// built-ins read by fragment shader
EvqFragCoord,
EvqFrontFacing,
EvqPointCoord,
// built-ins written by fragment shader
EvqFragColor,
EvqFragData,
// 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 EvqInvariantVaryingIn: return "invariant varying"; break;
case EvqInvariantVaryingOut:return "invariant 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 EvqFragCoord: return "FragCoord"; break;
case EvqFrontFacing: return "FrontFacing"; break;
case EvqFragColor: return "FragColor"; break;
case EvqFragData: return "FragData"; break;
default: return "unknown qualifier";
}
}
#endif // _BASICTYPES_INCLUDED_
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _COMMON_INCLUDED_
#define _COMMON_INCLUDED_
#include <map>
#include <sstream>
#include <string>
#include <vector>
#include "compiler/PoolAlloc.h"
// We need two pieces of information to report errors/warnings - string and
// line number. We encode these into a single int so that it can be easily
// incremented/decremented by lexer. The right SOURCE_LOC_LINE_SIZE bits store
// line number while the rest store the string number. Since the shaders are
// usually small, we should not run out of memory. SOURCE_LOC_LINE_SIZE
// can be increased to alleviate this issue.
typedef int TSourceLoc;
const unsigned int SOURCE_LOC_LINE_SIZE = 16; // in bits.
const unsigned int SOURCE_LOC_LINE_MASK = (1 << SOURCE_LOC_LINE_SIZE) - 1;
inline TSourceLoc EncodeSourceLoc(int string, int line) {
return (string << SOURCE_LOC_LINE_SIZE) | (line & SOURCE_LOC_LINE_MASK);
}
inline void DecodeSourceLoc(TSourceLoc loc, int* string, int* line) {
if (string) *string = loc >> SOURCE_LOC_LINE_SIZE;
if (line) *line = loc & SOURCE_LOC_LINE_MASK;
}
//
// 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 *) { }
//
// Pool version of string.
//
typedef pool_allocator<char> TStringAllocator;
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
typedef std::basic_ostringstream<char, std::char_traits<char>, TStringAllocator> TStringStream;
inline TString* NewPoolTString(const char* s)
{
void* memory = GlobalPoolAllocator.allocate(sizeof(TString));
return new(memory) TString(s);
}
//
// Persistent string memory. Should only be used for strings that survive
// across compiles.
//
#define TPersistString std::string
#define TPersistStringStream std::ostringstream
//
// 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 K, class D, class CMP = std::less<K> >
class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<const K, D> > > {
public:
typedef pool_allocator<std::pair<const K, D> > tAllocator;
TMap() : std::map<K, D, CMP, tAllocator>() {}
// use correct two-stage name lookup supported in gcc 3.4 and above
TMap(const tAllocator& a) : std::map<K, D, CMP, tAllocator>(std::map<K, D, CMP, tAllocator>::key_compare(), a) {}
};
#endif // _COMMON_INCLUDED_
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/AnalyzeCallDepth.h"
#include "compiler/Initialize.h"
#include "compiler/InitializeParseContext.h"
#include "compiler/ParseHelper.h"
#include "compiler/ShHandle.h"
#include "compiler/ValidateLimitations.h"
namespace
{
class TScopedPoolAllocator {
public:
TScopedPoolAllocator(TPoolAllocator* allocator, bool pushPop)
: mAllocator(allocator), mPushPopAllocator(pushPop) {
if (mPushPopAllocator) mAllocator->push();
SetGlobalPoolAllocator(mAllocator);
}
~TScopedPoolAllocator() {
SetGlobalPoolAllocator(NULL);
if (mPushPopAllocator) mAllocator->pop();
}
private:
TPoolAllocator* mAllocator;
bool mPushPopAllocator;
};
} // namespace
TShHandleBase::TShHandleBase() {
allocator.push();
SetGlobalPoolAllocator(&allocator);
}
TShHandleBase::~TShHandleBase() {
SetGlobalPoolAllocator(NULL);
allocator.popAll();
}
TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec)
: shaderType(type),
shaderSpec(spec),
maxCallStackDepth(UINT_MAX)
{
}
TCompiler::~TCompiler()
{
}
bool TCompiler::Init(const ShBuiltInResources& resources)
{
maxCallStackDepth = resources.MaxCallStackDepth;
TScopedPoolAllocator scopedAlloc(&allocator, false);
// Generate built-in symbol table.
if (!InitBuiltInSymbolTable(resources))
return false;
InitExtensionBehavior(resources, extensionBehavior);
return true;
}
bool TCompiler::compile(const char* const shaderStrings[],
const int numStrings,
int compileOptions)
{
TScopedPoolAllocator scopedAlloc(&allocator, true);
clearResults();
if (numStrings == 0)
return true;
// If compiling for WebGL, validate loop and indexing as well.
if (shaderSpec == SH_WEBGL_SPEC)
compileOptions |= SH_VALIDATE_LOOP_INDEXING;
// First string is path of source file if flag is set. The actual source follows.
const char* sourcePath = NULL;
int firstSource = 0;
if (compileOptions & SH_SOURCE_PATH)
{
sourcePath = shaderStrings[0];
++firstSource;
}
TIntermediate intermediate(infoSink);
TParseContext parseContext(symbolTable, extensionBehavior, intermediate,
shaderType, shaderSpec, compileOptions, true,
sourcePath, infoSink);
GlobalParseContext = &parseContext;
// We preserve symbols at the built-in level from compile-to-compile.
// Start pushing the user-defined symbols at global level.
symbolTable.push();
if (!symbolTable.atGlobalLevel())
infoSink.info.message(EPrefixInternalError, "Wrong symbol table level");
// Parse shader.
bool success =
(PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) &&
(parseContext.treeRoot != NULL);
if (success) {
TIntermNode* root = parseContext.treeRoot;
success = intermediate.postProcess(root);
if (success)
success = validateCallDepth(root, infoSink);
if (success && (compileOptions & SH_VALIDATE_LOOP_INDEXING))
success = validateLimitations(root);
if (success && (compileOptions & SH_INTERMEDIATE_TREE))
intermediate.outputTree(root);
if (success && (compileOptions & SH_OBJECT_CODE))
success = translate(root);
}
// Cleanup memory.
intermediate.remove(parseContext.treeRoot);
// Ensure symbol table is returned to the built-in level,
// throwing away all but the built-ins.
while (!symbolTable.atBuiltInLevel())
symbolTable.pop();
return success;
}
bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
{
assert(symbolTable.isEmpty());
//
// Push the symbol table to give it an initial scope. This
// push should not have a corresponding pop, so that built-ins
// are preserved, and the test for an empty table fails.
//
symbolTable.push();
TPublicType integer;
integer.type = EbtInt;
integer.size = 1;
integer.matrix = false;
integer.array = false;
TPublicType floatingPoint;
floatingPoint.type = EbtFloat;
floatingPoint.size = 1;
floatingPoint.matrix = false;
floatingPoint.array = false;
switch(shaderType)
{
case SH_FRAGMENT_SHADER:
symbolTable.setDefaultPrecision(integer, EbpMedium);
break;
case SH_VERTEX_SHADER:
symbolTable.setDefaultPrecision(integer, EbpHigh);
symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
break;
default: assert(false && "Language not supported");
}
InsertBuiltInFunctions(shaderType, resources, symbolTable);
IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
return true;
}
void TCompiler::clearResults()
{
infoSink.info.erase();
infoSink.obj.erase();
infoSink.debug.erase();
}
bool TCompiler::validateCallDepth(TIntermNode *root, TInfoSink &infoSink)
{
AnalyzeCallDepth validator(root);
unsigned int depth = validator.analyzeCallDepth();
if(depth == 0)
{
infoSink.info.prefix(EPrefixError);
infoSink.info << "Missing main()";
return false;
}
else if(depth == UINT_MAX)
{
infoSink.info.prefix(EPrefixError);
infoSink.info << "Function recursion detected";
return false;
}
else if(depth > maxCallStackDepth)
{
infoSink.info.prefix(EPrefixError);
infoSink.info << "Function call stack too deep";
return false;
}
return true;
}
bool TCompiler::validateLimitations(TIntermNode* root) {
ValidateLimitations validate(shaderType, infoSink.info);
root->traverse(&validate);
return validate.numErrors() == 0;
}
const TExtensionBehavior& TCompiler::getExtensionBehavior() const
{
return extensionBehavior;
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Source Files\generated">
<UniqueIdentifier>{1add4406-d193-4c4e-a8ec-c41c8d0bd499}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Header Files\generated">
<UniqueIdentifier>{a56a1771-4799-47ac-ace9-6955dd3f055b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Compiler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="InfoSink.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Initialize.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="InitializeDll.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Intermediate.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="intermOut.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="IntermTraverse.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ossource_win.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="parseConst.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ParseHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PoolAlloc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RemoveTree.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ShaderLang.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SymbolTable.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ValidateLimitations.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="glslang_lex.cpp">
<Filter>Source Files\generated</Filter>
</ClCompile>
<ClCompile Include="glslang_tab.cpp">
<Filter>Source Files\generated</Filter>
</ClCompile>
<ClCompile Include="OutputASM.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TranslatorASM.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="debug.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Diagnostics.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DirectiveHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="InitializeParseContext.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="AnalyzeCallDepth.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BaseTypes.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Common.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ConstantUnion.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="InfoSink.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Initialize.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="InitializeDll.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="InitializeGlobals.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="InitializeParseContext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="intermediate.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="localintermediate.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MMap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="osinclude.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ParseHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PoolAlloc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RemoveTree.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ShHandle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SymbolTable.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Types.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="util.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ValidateLimitations.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="glslang_tab.h">
<Filter>Header Files\generated</Filter>
</ClInclude>
<ClInclude Include="..\include\GLSLANG\ShaderLang.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OutputASM.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="TranslatorASM.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="debug.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Diagnostics.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Pragma.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AnalyzeCallDepth.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="glslang.l">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="glslang.y">
<Filter>Source Files</Filter>
</CustomBuild>
</ItemGroup>
</Project>
\ No newline at end of file
//
// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _CONSTANT_UNION_INCLUDED_
#define _CONSTANT_UNION_INCLUDED_
#include <assert.h>
class ConstantUnion {
public:
ConstantUnion()
{
iConst = 0;
type = EbtVoid;
}
bool cast(TBasicType newType, const ConstantUnion &constant)
{
switch (newType)
{
case EbtFloat:
switch (constant.type)
{
case EbtInt: setFConst(static_cast<float>(constant.getIConst())); break;
case EbtBool: setFConst(static_cast<float>(constant.getBConst())); break;
case EbtFloat: setFConst(static_cast<float>(constant.getFConst())); break;
default: return false;
}
break;
case EbtInt:
switch (constant.type)
{
case EbtInt: setIConst(static_cast<int>(constant.getIConst())); break;
case EbtBool: setIConst(static_cast<int>(constant.getBConst())); break;
case EbtFloat: setIConst(static_cast<int>(constant.getFConst())); break;
default: return false;
}
break;
case EbtBool:
switch (constant.type)
{
case EbtInt: setBConst(constant.getIConst() != 0); break;
case EbtBool: setBConst(constant.getBConst()); break;
case EbtFloat: setBConst(constant.getFConst() != 0.0f); break;
default: return false;
}
break;
case EbtStruct: // Struct fields don't get cast
switch (constant.type)
{
case EbtInt: setIConst(constant.getIConst()); break;
case EbtBool: setBConst(constant.getBConst()); break;
case EbtFloat: setFConst(constant.getFConst()); break;
default: return false;
}
break;
default:
return false;
}
return true;
}
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() const { return iConst; }
float getFConst() const { return fConst; }
bool getBConst() const { return bConst; }
float getAsFloat()
{
const int FFFFFFFFh = 0xFFFFFFFF;
switch(type)
{
case EbtInt: return (float)iConst;
case EbtFloat: return fConst;
case EbtBool: return (bConst == true) ? (float&)FFFFFFFFh : 0;
default: return 0;
}
}
bool operator==(const int i) const
{
return i == iConst;
}
bool operator==(const float f) const
{
return f == fConst;
}
bool operator==(const bool b) const
{
return b == bConst;
}
bool operator==(const ConstantUnion& constant) const
{
if (constant.type != type)
return false;
switch (type) {
case EbtInt:
return constant.iConst == iConst;
case EbtFloat:
return constant.fConst == fConst;
case EbtBool:
return constant.bConst == bConst;
default:
return false;
}
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 ConstantUnion& constant) const
{
return !operator==(constant);
}
bool operator>(const ConstantUnion& constant) const
{
assert(type == constant.type);
switch (type) {
case EbtInt:
return iConst > constant.iConst;
case EbtFloat:
return fConst > constant.fConst;
default:
return false; // Invalid operation, handled at semantic analysis
}
return false;
}
bool operator<(const ConstantUnion& constant) const
{
assert(type == constant.type);
switch (type) {
case EbtInt:
return iConst < constant.iConst;
case EbtFloat:
return fConst < constant.fConst;
default:
return false; // Invalid operation, handled at semantic analysis
}
return false;
}
ConstantUnion operator+(const ConstantUnion& constant) const
{
ConstantUnion 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;
}
ConstantUnion operator-(const ConstantUnion& constant) const
{
ConstantUnion 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;
}
ConstantUnion operator*(const ConstantUnion& constant) const
{
ConstantUnion 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;
}
ConstantUnion operator%(const ConstantUnion& constant) const
{
ConstantUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
ConstantUnion operator>>(const ConstantUnion& constant) const
{
ConstantUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
ConstantUnion operator<<(const ConstantUnion& constant) const
{
ConstantUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
ConstantUnion operator&(const ConstantUnion& constant) const
{
ConstantUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst & constant.iConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
ConstantUnion operator|(const ConstantUnion& constant) const
{
ConstantUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst | constant.iConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
ConstantUnion operator^(const ConstantUnion& constant) const
{
ConstantUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtInt: returnValue.setIConst(iConst ^ constant.iConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
ConstantUnion operator&&(const ConstantUnion& constant) const
{
ConstantUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
ConstantUnion operator||(const ConstantUnion& constant) const
{
ConstantUnion returnValue;
assert(type == constant.type);
switch (type) {
case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
default: assert(false && "Default missing");
}
return returnValue;
}
TBasicType getType() const { 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_
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/Diagnostics.h"
#include "compiler/debug.h"
#include "compiler/InfoSink.h"
#include "compiler/preprocessor/SourceLocation.h"
TDiagnostics::TDiagnostics(TInfoSink& infoSink) :
mInfoSink(infoSink),
mNumErrors(0),
mNumWarnings(0)
{
}
TDiagnostics::~TDiagnostics()
{
}
void TDiagnostics::writeInfo(Severity severity,
const pp::SourceLocation& loc,
const std::string& reason,
const std::string& token,
const std::string& extra)
{
TPrefixType prefix = EPrefixNone;
switch (severity)
{
case PP_ERROR:
++mNumErrors;
prefix = EPrefixError;
break;
case PP_WARNING:
++mNumWarnings;
prefix = EPrefixWarning;
break;
default:
UNREACHABLE();
break;
}
TInfoSinkBase& sink = mInfoSink.info;
/* VC++ format: file(linenum) : error #: 'token' : extrainfo */
sink.prefix(prefix);
sink.location(EncodeSourceLoc(loc.file, loc.line));
sink << "'" << token << "' : " << reason << " " << extra << "\n";
}
void TDiagnostics::writeDebug(const std::string& str)
{
mInfoSink.debug << str;
}
void TDiagnostics::print(ID id,
const pp::SourceLocation& loc,
const std::string& text)
{
writeInfo(severity(id), loc, message(id), text, "");
}
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_DIAGNOSTICS_H_
#define COMPILER_DIAGNOSTICS_H_
#include "compiler/preprocessor/Diagnostics.h"
class TInfoSink;
class TDiagnostics : public pp::Diagnostics
{
public:
TDiagnostics(TInfoSink& infoSink);
virtual ~TDiagnostics();
TInfoSink& infoSink() { return mInfoSink; }
int numErrors() const { return mNumErrors; }
int numWarnings() const { return mNumWarnings; }
void writeInfo(Severity severity,
const pp::SourceLocation& loc,
const std::string& reason,
const std::string& token,
const std::string& extra);
void writeDebug(const std::string& str);
protected:
virtual void print(ID id,
const pp::SourceLocation& loc,
const std::string& text);
private:
TInfoSink& mInfoSink;
int mNumErrors;
int mNumWarnings;
};
#endif // COMPILER_DIAGNOSTICS_H_
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/DirectiveHandler.h"
#include <sstream>
#include "compiler/debug.h"
#include "compiler/Diagnostics.h"
static TBehavior getBehavior(const std::string& str)
{
static const std::string kRequire("require");
static const std::string kEnable("enable");
static const std::string kDisable("disable");
static const std::string kWarn("warn");
if (str == kRequire) return EBhRequire;
else if (str == kEnable) return EBhEnable;
else if (str == kDisable) return EBhDisable;
else if (str == kWarn) return EBhWarn;
return EBhUndefined;
}
TDirectiveHandler::TDirectiveHandler(TExtensionBehavior& extBehavior,
TDiagnostics& diagnostics)
: mExtensionBehavior(extBehavior),
mDiagnostics(diagnostics)
{
}
TDirectiveHandler::~TDirectiveHandler()
{
}
void TDirectiveHandler::handleError(const pp::SourceLocation& loc,
const std::string& msg)
{
mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR, loc, msg, "", "");
}
void TDirectiveHandler::handlePragma(const pp::SourceLocation& loc,
const std::string& name,
const std::string& value)
{
static const std::string kSTDGL("STDGL");
static const std::string kOptimize("optimize");
static const std::string kDebug("debug");
static const std::string kOn("on");
static const std::string kOff("off");
bool invalidValue = false;
if (name == kSTDGL)
{
// The STDGL pragma is used to reserve pragmas for use by future
// revisions of GLSL. Ignore it.
return;
}
else if (name == kOptimize)
{
if (value == kOn) mPragma.optimize = true;
else if (value == kOff) mPragma.optimize = false;
else invalidValue = true;
}
else if (name == kDebug)
{
if (value == kOn) mPragma.debug = true;
else if (value == kOff) mPragma.debug = false;
else invalidValue = true;
}
else
{
mDiagnostics.report(pp::Diagnostics::UNRECOGNIZED_PRAGMA, loc, name);
return;
}
if (invalidValue)
mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR, loc,
"invalid pragma value", value,
"'on' or 'off' expected");
}
void TDirectiveHandler::handleExtension(const pp::SourceLocation& loc,
const std::string& name,
const std::string& behavior)
{
static const std::string kExtAll("all");
TBehavior behaviorVal = getBehavior(behavior);
if (behaviorVal == EBhUndefined)
{
mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR, loc,
"behavior", name, "invalid");
return;
}
if (name == kExtAll)
{
if (behaviorVal == EBhRequire)
{
mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR, loc,
"extension", name,
"cannot have 'require' behavior");
}
else if (behaviorVal == EBhEnable)
{
mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR, loc,
"extension", name,
"cannot have 'enable' behavior");
}
else
{
for (TExtensionBehavior::iterator iter = mExtensionBehavior.begin();
iter != mExtensionBehavior.end(); ++iter)
iter->second = behaviorVal;
}
return;
}
TExtensionBehavior::iterator iter = mExtensionBehavior.find(name);
if (iter != mExtensionBehavior.end())
{
iter->second = behaviorVal;
return;
}
pp::Diagnostics::Severity severity = pp::Diagnostics::PP_ERROR;
switch (behaviorVal) {
case EBhRequire:
severity = pp::Diagnostics::PP_ERROR;
break;
case EBhEnable:
case EBhWarn:
case EBhDisable:
severity = pp::Diagnostics::PP_WARNING;
break;
default:
UNREACHABLE();
break;
}
mDiagnostics.writeInfo(severity, loc,
"extension", name, "is not supported");
}
void TDirectiveHandler::handleVersion(const pp::SourceLocation& loc,
int version)
{
static const int kVersion = 100;
if (version != kVersion)
{
std::stringstream stream;
stream << version;
std::string str = stream.str();
mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR, loc,
"version number", str, "not supported");
}
}
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_DIRECTIVE_HANDLER_H_
#define COMPILER_DIRECTIVE_HANDLER_H_
#include "compiler/ExtensionBehavior.h"
#include "compiler/Pragma.h"
#include "compiler/preprocessor/DirectiveHandler.h"
class TDiagnostics;
class TDirectiveHandler : public pp::DirectiveHandler
{
public:
TDirectiveHandler(TExtensionBehavior& extBehavior,
TDiagnostics& diagnostics);
virtual ~TDirectiveHandler();
const TPragma& pragma() const { return mPragma; }
const TExtensionBehavior& extensionBehavior() const { return mExtensionBehavior; }
virtual void handleError(const pp::SourceLocation& loc,
const std::string& msg);
virtual void handlePragma(const pp::SourceLocation& loc,
const std::string& name,
const std::string& value);
virtual void handleExtension(const pp::SourceLocation& loc,
const std::string& name,
const std::string& behavior);
virtual void handleVersion(const pp::SourceLocation& loc,
int version);
private:
TPragma mPragma;
TExtensionBehavior& mExtensionBehavior;
TDiagnostics& mDiagnostics;
};
#endif // COMPILER_DIRECTIVE_HANDLER_H_
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _EXTENSION_BEHAVIOR_INCLUDED_
#define _EXTENSION_BEHAVIOR_INCLUDED_
#include <map>
#include <string>
typedef enum
{
EBhRequire,
EBhEnable,
EBhWarn,
EBhDisable,
EBhUndefined
} TBehavior;
inline const char *getBehaviorString(TBehavior b)
{
switch(b)
{
case EBhRequire: return "require";
case EBhEnable: return "enable";
case EBhWarn: return "warn";
case EBhDisable: return "disable";
default: return NULL;
}
}
// Mapping between extension name and behavior.
typedef std::map<std::string, TBehavior> TExtensionBehavior;
#endif // _EXTENSION_TABLE_INCLUDED_
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/InfoSink.h"
void TInfoSinkBase::prefix(TPrefixType message) {
switch(message) {
case EPrefixNone:
break;
case EPrefixWarning:
sink.append("WARNING: ");
break;
case EPrefixError:
sink.append("ERROR: ");
break;
case EPrefixInternalError:
sink.append("INTERNAL ERROR: ");
break;
case EPrefixUnimplemented:
sink.append("UNIMPLEMENTED: ");
break;
case EPrefixNote:
sink.append("NOTE: ");
break;
default:
sink.append("UNKOWN ERROR: ");
break;
}
}
void TInfoSinkBase::location(TSourceLoc loc) {
int string = 0, line = 0;
DecodeSourceLoc(loc, &string, &line);
TPersistStringStream stream;
if (line)
stream << string << ":" << line;
else
stream << string << ":? ";
stream << ": ";
sink.append(stream.str());
}
void TInfoSinkBase::message(TPrefixType message, const char* s) {
prefix(message);
sink.append(s);
sink.append("\n");
}
void TInfoSinkBase::message(TPrefixType message, const char* s, TSourceLoc loc) {
prefix(message);
location(loc);
sink.append(s);
sink.append("\n");
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _INFOSINK_INCLUDED_
#define _INFOSINK_INCLUDED_
#include <math.h>
#include "compiler/Common.h"
// Returns the fractional part of the given floating-point number.
inline float fractionalPart(float f) {
float intPart = 0.0f;
return modff(f, &intPart);
}
//
// TPrefixType is used to centralize how info log messages start.
// See below.
//
enum TPrefixType {
EPrefixNone,
EPrefixWarning,
EPrefixError,
EPrefixInternalError,
EPrefixUnimplemented,
EPrefixNote
};
//
// 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() {}
template <typename T>
TInfoSinkBase& operator<<(const T& t) {
TPersistStringStream stream;
stream << t;
sink.append(stream.str());
return *this;
}
// Override << operator for specific types. It is faster to append strings
// and characters directly to the sink.
TInfoSinkBase& operator<<(char c) {
sink.append(1, c);
return *this;
}
TInfoSinkBase& operator<<(const char* str) {
sink.append(str);
return *this;
}
TInfoSinkBase& operator<<(const TPersistString& str) {
sink.append(str);
return *this;
}
TInfoSinkBase& operator<<(const TString& str) {
sink.append(str.c_str());
return *this;
}
// Make sure floats are written with correct precision.
TInfoSinkBase& operator<<(float f) {
// Make sure that at least one decimal point is written. If a number
// does not have a fractional part, the default precision format does
// not write the decimal portion which gets interpreted as integer by
// the compiler.
TPersistStringStream stream;
if (fractionalPart(f) == 0.0f) {
stream.precision(1);
stream << std::showpoint << std::fixed << f;
} else {
stream.unsetf(std::ios::fixed);
stream.unsetf(std::ios::scientific);
stream.precision(8);
stream << f;
}
sink.append(stream.str());
return *this;
}
// Write boolean values as their names instead of integral value.
TInfoSinkBase& operator<<(bool b) {
const char* str = b ? "true" : "false";
sink.append(str);
return *this;
}
void erase() { sink.clear(); }
int size() { return static_cast<int>(sink.size()); }
const TPersistString& str() const { return sink; }
const char* c_str() const { return sink.c_str(); }
void prefix(TPrefixType message);
void location(TSourceLoc loc);
void message(TPrefixType message, const char* s);
void message(TPrefixType message, const char* s, TSourceLoc loc);
private:
TPersistString sink;
};
class TInfoSink {
public:
TInfoSinkBase info;
TInfoSinkBase debug;
TInfoSinkBase obj;
};
#endif // _INFOSINK_INCLUDED_
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _INITIALIZE_INCLUDED_
#define _INITIALIZE_INCLUDED_
#include "compiler/Common.h"
#include "compiler/ShHandle.h"
#include "compiler/SymbolTable.h"
void InsertBuiltInFunctions(ShShaderType type, const ShBuiltInResources &resources, TSymbolTable &table);
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources,
TSymbolTable& symbolTable);
void InitExtensionBehavior(const ShBuiltInResources& resources,
TExtensionBehavior& extensionBehavior);
#endif // _INITIALIZE_INCLUDED_
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/InitializeDll.h"
#include "compiler/InitializeGlobals.h"
#include "compiler/InitializeParseContext.h"
#include "compiler/osinclude.h"
OS_TLSIndex ThreadInitializeIndex = OS_INVALID_TLS_INDEX;
bool InitProcess()
{
if (ThreadInitializeIndex != OS_INVALID_TLS_INDEX) {
//
// Function is re-entrant.
//
return true;
}
ThreadInitializeIndex = OS_AllocTLSIndex();
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "InitProcess(): Failed to allocate TLS area for init flag");
return false;
}
if (!InitializePoolIndex()) {
assert(0 && "InitProcess(): Failed to initalize global pool");
return false;
}
if (!InitializeParseContextIndex()) {
assert(0 && "InitProcess(): Failed to initalize parse context");
return false;
}
return InitThread();
}
bool DetachProcess()
{
bool success = true;
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
return true;
success = DetachThread();
if (!FreeParseContextIndex())
success = false;
FreePoolIndex();
OS_FreeTLSIndex(ThreadInitializeIndex);
ThreadInitializeIndex = OS_INVALID_TLS_INDEX;
return success;
}
bool InitThread()
{
//
// This function is re-entrant
//
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "InitThread(): Process hasn't been initalised.");
return false;
}
if (OS_GetTLSValue(ThreadInitializeIndex) != 0)
return true;
InitializeGlobalPools();
if (!InitializeGlobalParseContext())
return false;
if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {
assert(0 && "InitThread(): Unable to set init flag.");
return false;
}
return true;
}
bool DetachThread()
{
bool success = true;
if (ThreadInitializeIndex == OS_INVALID_TLS_INDEX)
return true;
//
// Function is re-entrant and this thread may not have been initalised.
//
if (OS_GetTLSValue(ThreadInitializeIndex) != 0) {
if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)0)) {
assert(0 && "DetachThread(): Unable to clear init flag.");
success = false;
}
if (!FreeParseContext())
success = false;
FreeGlobalPools();
}
return success;
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef __INITIALIZEDLL_H
#define __INITIALIZEDLL_H
bool InitProcess();
bool DetachProcess();
bool InitThread();
bool DetachThread();
#endif // __INITIALIZEDLL_H
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef __INITIALIZE_GLOBALS_INCLUDED_
#define __INITIALIZE_GLOBALS_INCLUDED_
void InitializeGlobalPools();
void FreeGlobalPools();
bool InitializePoolIndex();
void FreePoolIndex();
#endif // __INITIALIZE_GLOBALS_INCLUDED_
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/InitializeParseContext.h"
#include "compiler/osinclude.h"
OS_TLSIndex GlobalParseContextIndex = OS_INVALID_TLS_INDEX;
bool InitializeParseContextIndex()
{
if (GlobalParseContextIndex != OS_INVALID_TLS_INDEX) {
assert(0 && "InitializeParseContextIndex(): Parse Context already initalized");
return false;
}
//
// Allocate a TLS index.
//
GlobalParseContextIndex = OS_AllocTLSIndex();
if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "InitializeParseContextIndex(): Parse Context already initalized");
return false;
}
return true;
}
bool FreeParseContextIndex()
{
OS_TLSIndex tlsiIndex = GlobalParseContextIndex;
if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "FreeParseContextIndex(): Parse Context index not initalized");
return false;
}
GlobalParseContextIndex = OS_INVALID_TLS_INDEX;
return OS_FreeTLSIndex(tlsiIndex);
}
bool InitializeGlobalParseContext()
{
if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "InitializeGlobalParseContext(): Parse Context index not initalized");
return false;
}
TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));
if (lpParseContext != 0) {
assert(0 && "InitializeParseContextIndex(): Parse Context already initalized");
return false;
}
TThreadParseContext *lpThreadData = new TThreadParseContext();
if (lpThreadData == 0) {
assert(0 && "InitializeGlobalParseContext(): Unable to create thread parse context");
return false;
}
lpThreadData->lpGlobalParseContext = 0;
OS_SetTLSValue(GlobalParseContextIndex, lpThreadData);
return true;
}
bool FreeParseContext()
{
if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "FreeParseContext(): Parse Context index not initalized");
return false;
}
TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));
if (lpParseContext)
delete lpParseContext;
return true;
}
TParseContextPointer& GetGlobalParseContext()
{
//
// Minimal error checking for speed
//
TThreadParseContext *lpParseContext = static_cast<TThreadParseContext *>(OS_GetTLSValue(GlobalParseContextIndex));
return lpParseContext->lpGlobalParseContext;
}
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef __INITIALIZE_PARSE_CONTEXT_INCLUDED_
#define __INITIALIZE_PARSE_CONTEXT_INCLUDED_
bool InitializeParseContextIndex();
bool FreeParseContextIndex();
bool InitializeGlobalParseContext();
bool FreeParseContext();
struct TParseContext;
typedef TParseContext* TParseContextPointer;
extern TParseContextPointer& GetGlobalParseContext();
#define GlobalParseContext GetGlobalParseContext()
typedef struct TThreadParseContextRec
{
TParseContext *lpGlobalParseContext;
} TThreadParseContext;
#endif // __INITIALIZE_PARSE_CONTEXT_INCLUDED_
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/intermediate.h"
//
// Traverse the intermediate representation tree, and
// call a node type specific function for each node.
// Done recursively through the member function Traverse().
// Node types can be skipped if their function to call is 0,
// but their subtree will still be traversed.
// Nodes with children can have their whole subtree skipped
// if preVisit is turned on and the type specific function
// returns false.
//
// preVisit, postVisit, and rightToLeft control what order
// nodes are visited in.
//
//
// Traversal functions for terminals are straighforward....
//
void TIntermSymbol::traverse(TIntermTraverser* it)
{
it->visitSymbol(this);
}
void TIntermConstantUnion::traverse(TIntermTraverser* it)
{
it->visitConstantUnion(this);
}
//
// Traverse a binary node.
//
void TIntermBinary::traverse(TIntermTraverser* it)
{
bool visit = true;
//
// visit the node before children if pre-visiting.
//
if(it->preVisit)
{
visit = it->visitBinary(PreVisit, this);
}
//
// Visit the children, in the right order.
//
if(visit)
{
it->incrementDepth();
if(it->rightToLeft)
{
if(right)
{
right->traverse(it);
}
if(it->inVisit)
{
visit = it->visitBinary(InVisit, this);
}
if(visit && left)
{
left->traverse(it);
}
}
else
{
if(left)
{
left->traverse(it);
}
if(it->inVisit)
{
visit = it->visitBinary(InVisit, this);
}
if(visit && right)
{
right->traverse(it);
}
}
it->decrementDepth();
}
//
// Visit the node after the children, if requested and the traversal
// hasn't been cancelled yet.
//
if(visit && it->postVisit)
{
it->visitBinary(PostVisit, this);
}
}
//
// Traverse a unary node. Same comments in binary node apply here.
//
void TIntermUnary::traverse(TIntermTraverser* it)
{
bool visit = true;
if (it->preVisit)
visit = it->visitUnary(PreVisit, this);
if (visit) {
it->incrementDepth();
operand->traverse(it);
it->decrementDepth();
}
if (visit && it->postVisit)
it->visitUnary(PostVisit, this);
}
//
// Traverse an aggregate node. Same comments in binary node apply here.
//
void TIntermAggregate::traverse(TIntermTraverser* it)
{
bool visit = true;
if(it->preVisit)
{
visit = it->visitAggregate(PreVisit, this);
}
if(visit)
{
it->incrementDepth();
if(it->rightToLeft)
{
for(TIntermSequence::reverse_iterator sit = sequence.rbegin(); sit != sequence.rend(); sit++)
{
(*sit)->traverse(it);
if(visit && it->inVisit)
{
if(*sit != sequence.front())
{
visit = it->visitAggregate(InVisit, this);
}
}
}
}
else
{
for(TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++)
{
(*sit)->traverse(it);
if(visit && it->inVisit)
{
if(*sit != sequence.back())
{
visit = it->visitAggregate(InVisit, this);
}
}
}
}
it->decrementDepth();
}
if(visit && it->postVisit)
{
it->visitAggregate(PostVisit, this);
}
}
//
// Traverse a selection node. Same comments in binary node apply here.
//
void TIntermSelection::traverse(TIntermTraverser* it)
{
bool visit = true;
if (it->preVisit)
visit = it->visitSelection(PreVisit, this);
if (visit) {
it->incrementDepth();
if (it->rightToLeft) {
if (falseBlock)
falseBlock->traverse(it);
if (trueBlock)
trueBlock->traverse(it);
condition->traverse(it);
} else {
condition->traverse(it);
if (trueBlock)
trueBlock->traverse(it);
if (falseBlock)
falseBlock->traverse(it);
}
it->decrementDepth();
}
if (visit && it->postVisit)
it->visitSelection(PostVisit, this);
}
//
// Traverse a loop node. Same comments in binary node apply here.
//
void TIntermLoop::traverse(TIntermTraverser* it)
{
bool visit = true;
if(it->preVisit)
{
visit = it->visitLoop(PreVisit, this);
}
if(visit)
{
it->incrementDepth();
if(it->rightToLeft)
{
if(expr)
{
expr->traverse(it);
}
if(body)
{
body->traverse(it);
}
if(cond)
{
cond->traverse(it);
}
}
else
{
if(cond)
{
cond->traverse(it);
}
if(body)
{
body->traverse(it);
}
if(expr)
{
expr->traverse(it);
}
}
it->decrementDepth();
}
if(visit && it->postVisit)
{
it->visitLoop(PostVisit, this);
}
}
//
// Traverse a branch node. Same comments in binary node apply here.
//
void TIntermBranch::traverse(TIntermTraverser* it)
{
bool visit = true;
if (it->preVisit)
visit = it->visitBranch(PreVisit, this);
if (visit && expression) {
it->incrementDepth();
expression->traverse(it);
it->decrementDepth();
}
if (visit && it->postVisit)
it->visitBranch(PostVisit, this);
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _MMAP_INCLUDED_
#define _MMAP_INCLUDED_
//
// Encapsulate memory mapped files
//
class TMMap {
public:
TMMap(const char* fileName) :
fSize(-1), // -1 is the error value returned by GetFileSize()
fp(NULL),
fBuff(0) // 0 is the error value returned by MapViewOfFile()
{
if ((fp = fopen(fileName, "r")) == NULL)
return;
char c = getc(fp);
fSize = 0;
while (c != EOF) {
fSize++;
c = getc(fp);
}
if (c == EOF)
fSize++;
rewind(fp);
fBuff = (char*)malloc(sizeof(char) * fSize);
int count = 0;
c = getc(fp);
while (c != EOF) {
fBuff[count++] = c;
c = getc(fp);
}
fBuff[count++] = c;
}
char* getData() { return fBuff; }
int getSize() { return fSize; }
~TMMap() {
if (fp != NULL)
fclose(fp);
}
private:
int fSize; // size of file to map in
FILE *fp;
char* fBuff; // the actual data;
};
#endif // _MMAP_INCLUDED_
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2013 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef COMPILER_OUTPUTASM_H_
#define COMPILER_OUTPUTASM_H_
#include "intermediate.h"
#include "ParseHelper.h"
#include "Shader/PixelShader.hpp"
#include "Shader/VertexShader.hpp"
#define GL_APICALL
#include <GLES2/gl2.h>
#include <list>
#include <set>
#include <map>
namespace es2
{
class Shader;
}
namespace sh
{
struct Uniform
{
Uniform(GLenum type, GLenum precision, const std::string &name, int arraySize, int registerIndex);
GLenum type;
GLenum precision;
std::string name;
int arraySize;
int registerIndex;
};
typedef std::vector<Uniform> ActiveUniforms;
struct Attribute
{
Attribute();
Attribute(GLenum type, const std::string &name, int arraySize, int registerIndex);
GLenum type;
std::string name;
int arraySize;
int registerIndex;
};
struct Function
{
Function(int label, const char *name, TIntermSequence *arg, TIntermTyped *ret) : label(label), name(name), arg(arg), ret(ret)
{
}
Function(int label, const TString &name, TIntermSequence *arg, TIntermTyped *ret) : label(label), name(name), arg(arg), ret(ret)
{
}
int label;
TString name;
TIntermSequence *arg;
TIntermTyped *ret;
};
typedef sw::Shader::Instruction Instruction;
typedef std::vector<Attribute> ActiveAttributes;
class Temporary;
class OutputASM : public TIntermTraverser
{
public:
explicit OutputASM(TParseContext &context, es2::Shader *shaderObject);
~OutputASM();
void output();
void freeTemporary(Temporary *temporary);
private:
enum Scope
{
GLOBAL,
FUNCTION
};
void emitShader(Scope scope);
// Visit AST nodes and output their code to the body stream
virtual void visitSymbol(TIntermSymbol*);
virtual bool visitBinary(Visit visit, TIntermBinary*);
virtual bool visitUnary(Visit visit, TIntermUnary*);
virtual bool visitSelection(Visit visit, TIntermSelection*);
virtual bool visitAggregate(Visit visit, TIntermAggregate*);
virtual bool visitLoop(Visit visit, TIntermLoop*);
virtual bool visitBranch(Visit visit, TIntermBranch*);
Instruction *emit(sw::Shader::Opcode op, TIntermTyped *dst = 0, TIntermNode *src0 = 0, TIntermNode *src1 = 0, TIntermNode *src2 = 0, int index = 0);
Instruction *emitCast(TIntermTyped *dst, TIntermTyped *src);
void emitBinary(sw::Shader::Opcode op, TIntermTyped *dst = 0, TIntermNode *src0 = 0, TIntermNode *src1 = 0, TIntermNode *src2 = 0);
void emitAssign(sw::Shader::Opcode op, TIntermTyped *result, TIntermTyped *lhs, TIntermTyped *src0, TIntermTyped *src1 = 0);
void emitCmp(sw::Shader::Control cmpOp, TIntermTyped *dst, TIntermNode *left, TIntermNode *right, int index = 0);
void argument(sw::Shader::SourceParameter &parameter, TIntermNode *argument, int index = 0);
void copy(TIntermTyped *dst, TIntermNode *src, int offset = 0);
void assignLvalue(TIntermTyped *dst, TIntermNode *src);
int lvalue(sw::Shader::DestinationParameter &dst, Temporary &address, TIntermTyped *node);
sw::Shader::ParameterType registerType(TIntermTyped *operand);
int registerIndex(TIntermTyped *operand);
int writeMask(TIntermTyped *destination, int index = 0);
int readSwizzle(TIntermTyped *argument, int size);
bool trivial(TIntermTyped *expression, int budget); // Fast to compute and no side effects
int cost(TIntermNode *expression, int budget);
const Function *findFunction(const TString &name);
int temporaryRegister(TIntermTyped *temporary);
int varyingRegister(TIntermTyped *varying);
void declareVarying(TIntermTyped *varying, int reg);
int uniformRegister(TIntermTyped *uniform);
int attributeRegister(TIntermTyped *attribute);
int samplerRegister(TIntermTyped *sampler);
typedef std::vector<TIntermTyped*> VariableArray;
int lookup(VariableArray &list, TIntermTyped *variable);
int allocate(VariableArray &list, TIntermTyped *variable);
void free(VariableArray &list, TIntermTyped *variable);
void declareUniform(const TType &type, const TString &name, int index);
GLenum glVariableType(const TType &type);
GLenum glVariablePrecision(const TType &type);
static int dim(TIntermNode *v);
static int dim2(TIntermNode *m);
static unsigned int loopCount(TIntermLoop *node);
es2::Shader *const shaderObject;
sw::Shader *shader;
sw::PixelShader *pixelShader;
sw::VertexShader *vertexShader;
VariableArray temporaries;
VariableArray uniforms;
VariableArray varyings;
VariableArray attributes;
VariableArray samplers;
Scope emitScope;
Scope currentScope;
int currentFunction;
std::vector<Function> functionArray;
TParseContext &mContext;
};
// Checks whether a loop can run for a variable number of iterations
class DetectLoopDiscontinuity : public TIntermTraverser
{
public:
bool traverse(TIntermNode *node);
private:
bool visitBranch(Visit visit, TIntermBranch *node);
bool visitLoop(Visit visit, TIntermLoop *loop);
bool visitAggregate(Visit visit, TIntermAggregate *node);
int loopDepth;
bool loopDiscontinuity;
};
}
#endif // COMPILER_OUTPUTASM_H_
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _PARSER_HELPER_INCLUDED_
#define _PARSER_HELPER_INCLUDED_
#include "compiler/Diagnostics.h"
#include "compiler/DirectiveHandler.h"
#include "compiler/localintermediate.h"
#include "compiler/preprocessor/Preprocessor.h"
#include "compiler/ShHandle.h"
#include "compiler/SymbolTable.h"
struct TMatrixFields {
bool wholeRow;
bool wholeCol;
int row;
int col;
};
//
// The following are extra variables needed during parsing, grouped together so
// they can be passed to the parser without needing a global.
//
struct TParseContext {
TParseContext(TSymbolTable& symt, TExtensionBehavior& ext, TIntermediate& interm, ShShaderType type, ShShaderSpec spec, int options, bool checksPrecErrors, const char* sourcePath, TInfoSink& is) :
intermediate(interm),
symbolTable(symt),
shaderType(type),
shaderSpec(spec),
compileOptions(options),
sourcePath(sourcePath),
treeRoot(0),
lexAfterType(false),
loopNestingLevel(0),
structNestingLevel(0),
inTypeParen(false),
currentFunctionType(NULL),
functionReturnsValue(false),
checksPrecisionErrors(checksPrecErrors),
diagnostics(is),
directiveHandler(ext, diagnostics),
preprocessor(&diagnostics, &directiveHandler),
scanner(NULL) { }
TIntermediate& intermediate; // to hold and build a parse tree
TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed
ShShaderType shaderType; // vertex or fragment language (future: pack or unpack)
ShShaderSpec shaderSpec; // The language specification compiler conforms to - GLES2 or WebGL.
int compileOptions;
const char* sourcePath; // Path of source file or NULL.
TIntermNode* treeRoot; // root of parse tree being created
bool lexAfterType; // true if we've recognized a type, so can only be looking for an identifier
int loopNestingLevel; // 0 if outside all loops
int structNestingLevel; // incremented while parsing a struct declaration
bool inTypeParen; // true if in parentheses, looking only for an identifier
const TType* currentFunctionType; // the return type of the function that's currently being parsed
bool functionReturnsValue; // true if a non-void function has a return
bool checksPrecisionErrors; // true if an error will be generated when a variable is declared without precision, explicit or implicit.
TString HashErrMsg;
bool AfterEOF;
TDiagnostics diagnostics;
TDirectiveHandler directiveHandler;
pp::Preprocessor preprocessor;
void* scanner;
int numErrors() const { return diagnostics.numErrors(); }
TInfoSink& infoSink() { return diagnostics.infoSink(); }
void error(TSourceLoc loc, const char *reason, const char* token,
const char* extraInfo="");
void warning(TSourceLoc loc, const char* reason, const char* token,
const char* extraInfo="");
void trace(const char* str);
void recover();
bool parseVectorFields(const TString&, int vecSize, TVectorFields&, int line);
bool parseMatrixFields(const TString&, int matSize, TMatrixFields&, int line);
bool reservedErrorCheck(int line, const TString& identifier);
void assignError(int line, const char* op, TString left, TString right);
void unaryOpError(int line, const char* op, TString operand);
void binaryOpError(int line, const char* op, TString left, TString right);
bool precisionErrorCheck(int line, TPrecision precision, TBasicType type);
bool lValueErrorCheck(int line, const char* op, TIntermTyped*);
bool constErrorCheck(TIntermTyped* node);
bool integerErrorCheck(TIntermTyped* node, const char* token);
bool globalErrorCheck(int line, bool global, const char* token);
bool constructorErrorCheck(int line, TIntermNode*, TFunction&, TOperator, TType*);
bool arraySizeErrorCheck(int line, TIntermTyped* expr, int& size);
bool arrayQualifierErrorCheck(int line, TPublicType type);
bool arrayTypeErrorCheck(int line, TPublicType type);
bool arrayErrorCheck(int line, TString& identifier, TPublicType type, TVariable*& variable);
bool voidErrorCheck(int, const TString&, const TPublicType&);
bool boolErrorCheck(int, const TIntermTyped*);
bool boolErrorCheck(int, const TPublicType&);
bool samplerErrorCheck(int line, const TPublicType& pType, const char* reason);
bool structQualifierErrorCheck(int line, const TPublicType& pType);
bool parameterSamplerErrorCheck(int line, TQualifier qualifier, const TType& type);
bool nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type, bool array);
bool nonInitErrorCheck(int line, TString& identifier, TPublicType& type, TVariable*& variable);
bool paramErrorCheck(int line, TQualifier qualifier, TQualifier paramQualifier, TType* type);
bool extensionErrorCheck(int line, const TString&);
const TExtensionBehavior& extensionBehavior() const { return directiveHandler.extensionBehavior(); }
bool supportsExtension(const char* extension);
void handleExtensionDirective(int line, const char* extName, const char* behavior);
const TPragma& pragma() const { return directiveHandler.pragma(); }
void handlePragmaDirective(int line, const char* name, const char* value);
bool containsSampler(TType& type);
bool areAllChildConst(TIntermAggregate* aggrNode);
const TFunction* findFunction(int line, TFunction* pfnCall, bool *builtIn = 0);
bool executeInitializer(TSourceLoc line, TString& identifier, TPublicType& pType,
TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
bool arraySetMaxSize(TIntermSymbol*, TType*, int, bool, TSourceLoc);
TIntermTyped* addConstructor(TIntermNode*, const TType*, TOperator, TFunction*, TSourceLoc);
TIntermTyped* foldConstConstructor(TIntermAggregate* aggrNode, const TType& type);
TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc);
TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc);
TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line);
TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc);
// Performs an error check for embedded struct declarations.
// Returns true if an error was raised due to the declaration of
// this struct.
bool enterStructDeclaration(TSourceLoc line, const TString& identifier);
void exitStructDeclaration();
bool structNestingErrorCheck(TSourceLoc line, const TType& fieldType);
};
int PaParseStrings(int count, const char* const string[], const int length[],
TParseContext* context);
#endif // _PARSER_HELPER_INCLUDED_
//
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/PoolAlloc.h"
#ifndef _MSC_VER
#include <stdint.h>
#endif
#include <stdio.h>
#include "compiler/InitializeGlobals.h"
#include "compiler/osinclude.h"
OS_TLSIndex PoolIndex = OS_INVALID_TLS_INDEX;
void InitializeGlobalPools()
{
TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
if (globalPools)
return;
TThreadGlobalPools* threadData = new TThreadGlobalPools();
threadData->globalPoolAllocator = 0;
OS_SetTLSValue(PoolIndex, threadData);
}
void FreeGlobalPools()
{
// Release the allocated memory for this thread.
TThreadGlobalPools* globalPools= static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
if (!globalPools)
return;
delete globalPools;
}
bool InitializePoolIndex()
{
// Allocate a TLS index.
if ((PoolIndex = OS_AllocTLSIndex()) == OS_INVALID_TLS_INDEX)
return false;
return true;
}
void FreePoolIndex()
{
// Release the TLS index.
OS_FreeTLSIndex(PoolIndex);
}
TPoolAllocator& GetGlobalPoolAllocator()
{
TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
return *threadData->globalPoolAllocator;
}
void SetGlobalPoolAllocator(TPoolAllocator* poolAllocator)
{
TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
threadData->globalPoolAllocator = poolAllocator;
}
//
// Implement the functionality of the TPoolAllocator class, which
// is documented in PoolAlloc.h.
//
TPoolAllocator::TPoolAllocator(int growthIncrement, int allocationAlignment) :
pageSize(growthIncrement),
alignment(allocationAlignment),
freeList(0),
inUseList(0),
numCalls(0),
totalBytes(0)
{
//
// Don't allow page sizes we know are smaller than all common
// OS page sizes.
//
if (pageSize < 4*1024)
pageSize = 4*1024;
//
// A large currentPageOffset indicates a new page needs to
// be obtained to allocate memory.
//
currentPageOffset = pageSize;
//
// Adjust alignment to be at least pointer aligned and
// power of 2.
//
size_t minAlign = sizeof(void*);
alignment &= ~(minAlign - 1);
if (alignment < minAlign)
alignment = minAlign;
size_t a = 1;
while (a < alignment)
a <<= 1;
alignment = a;
alignmentMask = a - 1;
//
// Align header skip
//
headerSkip = minAlign;
if (headerSkip < sizeof(tHeader)) {
headerSkip = (sizeof(tHeader) + alignmentMask) & ~alignmentMask;
}
}
TPoolAllocator::~TPoolAllocator()
{
while (inUseList) {
tHeader* next = inUseList->nextPage;
inUseList->~tHeader();
delete [] reinterpret_cast<char*>(inUseList);
inUseList = next;
}
// We should not check the guard blocks
// here, because we did it already when the block was
// placed into the free list.
//
while (freeList) {
tHeader* next = freeList->nextPage;
delete [] reinterpret_cast<char*>(freeList);
freeList = next;
}
}
// Support MSVC++ 6.0
const unsigned char TAllocation::guardBlockBeginVal = 0xfb;
const unsigned char TAllocation::guardBlockEndVal = 0xfe;
const unsigned char TAllocation::userDataFill = 0xcd;
#ifdef GUARD_BLOCKS
const size_t TAllocation::guardBlockSize = 16;
#else
const size_t TAllocation::guardBlockSize = 0;
#endif
//
// Check a single guard block for damage
//
void TAllocation::checkGuardBlock(unsigned char* blockMem, unsigned char val, const char* locText) const
{
#ifdef GUARD_BLOCKS
for (size_t x = 0; x < guardBlockSize; x++) {
if (blockMem[x] != val) {
char assertMsg[80];
// We don't print the assert message. It's here just to be helpful.
#if defined(_MSC_VER)
_snprintf(assertMsg, sizeof(assertMsg), "PoolAlloc: Damage %s %Iu byte allocation at 0x%p\n",
locText, size, data());
#else
snprintf(assertMsg, sizeof(assertMsg), "PoolAlloc: Damage %s %zu byte allocation at 0x%p\n",
locText, size, data());
#endif
assert(0 && "PoolAlloc: Damage in guard block");
}
}
#endif
}
void TPoolAllocator::push()
{
tAllocState state = { currentPageOffset, inUseList };
stack.push_back(state);
//
// Indicate there is no current page to allocate from.
//
currentPageOffset = pageSize;
}
//
// Do a mass-deallocation of all the individual allocations
// that have occurred since the last push(), or since the
// last pop(), or since the object's creation.
//
// The deallocated pages are saved for future allocations.
//
void TPoolAllocator::pop()
{
if (stack.size() < 1)
return;
tHeader* page = stack.back().page;
currentPageOffset = stack.back().offset;
while (inUseList != page) {
// invoke destructor to free allocation list
inUseList->~tHeader();
tHeader* nextInUse = inUseList->nextPage;
if (inUseList->pageCount > 1)
delete [] reinterpret_cast<char*>(inUseList);
else {
inUseList->nextPage = freeList;
freeList = inUseList;
}
inUseList = nextInUse;
}
stack.pop_back();
}
//
// Do a mass-deallocation of all the individual allocations
// that have occurred.
//
void TPoolAllocator::popAll()
{
while (stack.size() > 0)
pop();
}
void* TPoolAllocator::allocate(size_t numBytes)
{
// If we are using guard blocks, all allocations are bracketed by
// them: [guardblock][allocation][guardblock]. numBytes is how
// much memory the caller asked for. allocationSize is the total
// size including guard blocks. In release build,
// guardBlockSize=0 and this all gets optimized away.
size_t allocationSize = TAllocation::allocationSize(numBytes);
//
// Just keep some interesting statistics.
//
++numCalls;
totalBytes += numBytes;
//
// Do the allocation, most likely case first, for efficiency.
// This step could be moved to be inline sometime.
//
if (currentPageOffset + allocationSize <= pageSize) {
//
// Safe to allocate from currentPageOffset.
//
unsigned char* memory = reinterpret_cast<unsigned char *>(inUseList) + currentPageOffset;
currentPageOffset += allocationSize;
currentPageOffset = (currentPageOffset + alignmentMask) & ~alignmentMask;
return initializeAllocation(inUseList, memory, numBytes);
}
if (allocationSize + headerSkip > pageSize) {
//
// Do a multi-page allocation. Don't mix these with the others.
// The OS is efficient and allocating and free-ing multiple pages.
//
size_t numBytesToAlloc = allocationSize + headerSkip;
tHeader* memory = reinterpret_cast<tHeader*>(::new char[numBytesToAlloc]);
if (memory == 0)
return 0;
// Use placement-new to initialize header
new(memory) tHeader(inUseList, (numBytesToAlloc + pageSize - 1) / pageSize);
inUseList = memory;
currentPageOffset = pageSize; // make next allocation come from a new page
// No guard blocks for multi-page allocations (yet)
return reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(memory) + headerSkip);
}
//
// Need a simple page to allocate from.
//
tHeader* memory;
if (freeList) {
memory = freeList;
freeList = freeList->nextPage;
} else {
memory = reinterpret_cast<tHeader*>(::new char[pageSize]);
if (memory == 0)
return 0;
}
// Use placement-new to initialize header
new(memory) tHeader(inUseList, 1);
inUseList = memory;
unsigned char* ret = reinterpret_cast<unsigned char *>(inUseList) + headerSkip;
currentPageOffset = (headerSkip + allocationSize + alignmentMask) & ~alignmentMask;
return initializeAllocation(inUseList, ret, numBytes);
}
//
// Check all allocations in a list for damage by calling check on each.
//
void TAllocation::checkAllocList() const
{
for (const TAllocation* alloc = this; alloc != 0; alloc = alloc->prevAlloc)
alloc->check();
}
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_PRAGMA_H_
#define COMPILER_PRAGMA_H_
struct TPragma {
// By default optimization is turned on and debug is turned off.
TPragma() : optimize(true), debug(false) { }
TPragma(bool o, bool d) : optimize(o), debug(d) { }
bool optimize;
bool debug;
};
#endif // COMPILER_PRAGMA_H_
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/intermediate.h"
#include "compiler/RemoveTree.h"
//
// Code to recursively delete the intermediate tree.
//
class RemoveTree : public TIntermTraverser
{
public:
RemoveTree() : TIntermTraverser(false, false, true)
{
}
protected:
void visitSymbol(TIntermSymbol*);
void visitConstantUnion(TIntermConstantUnion*);
bool visitBinary(Visit visit, TIntermBinary*);
bool visitUnary(Visit visit, TIntermUnary*);
bool visitSelection(Visit visit, TIntermSelection*);
bool visitAggregate(Visit visit, TIntermAggregate*);
};
void RemoveTree::visitSymbol(TIntermSymbol* node)
{
delete node;
}
bool RemoveTree::visitBinary(Visit visit, TIntermBinary* node)
{
delete node;
return true;
}
bool RemoveTree::visitUnary(Visit visit, TIntermUnary* node)
{
delete node;
return true;
}
bool RemoveTree::visitAggregate(Visit visit, TIntermAggregate* node)
{
delete node;
return true;
}
bool RemoveTree::visitSelection(Visit visit, TIntermSelection* node)
{
delete node;
return true;
}
void RemoveTree::visitConstantUnion(TIntermConstantUnion* node)
{
delete node;
}
//
// Entry point.
//
void RemoveAllTreeNodes(TIntermNode* root)
{
RemoveTree it;
root->traverse(&it);
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
void RemoveAllTreeNodes(TIntermNode*);
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#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.
//
#include "GLSLANG/ShaderLang.h"
#include "compiler/ExtensionBehavior.h"
#include "compiler/InfoSink.h"
#include "compiler/SymbolTable.h"
class TCompiler;
//
// The base class used to back handles returned to the driver.
//
class TShHandleBase {
public:
TShHandleBase();
virtual ~TShHandleBase();
virtual TCompiler* getAsCompiler() { return 0; }
protected:
// Memory allocator. Allocates and tracks memory required by the compiler.
// Deallocates all memory when compiler is destructed.
TPoolAllocator allocator;
};
//
// The base class for the machine dependent compiler to derive from
// for managing object code from the compile.
//
class TCompiler : public TShHandleBase {
public:
TCompiler(ShShaderType type, ShShaderSpec spec);
virtual ~TCompiler();
virtual TCompiler* getAsCompiler() { return this; }
bool Init(const ShBuiltInResources& resources);
bool compile(const char* const shaderStrings[],
const int numStrings,
int compileOptions);
// Get results of the last compilation.
TInfoSink& getInfoSink() { return infoSink; }
protected:
ShShaderType getShaderType() const { return shaderType; }
ShShaderSpec getShaderSpec() const { return shaderSpec; }
// Initialize symbol-table with built-in symbols.
bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
// Clears the results from the previous compilation.
void clearResults();
// Return true if function recursion is detected or call depth exceeded.
bool validateCallDepth(TIntermNode *root, TInfoSink &infoSink);
// Returns true if the given shader does not exceed the minimum
// functionality mandated in GLSL 1.0 spec Appendix A.
bool validateLimitations(TIntermNode *root);
// Translate to object code.
virtual bool translate(TIntermNode *root) = 0;
// Get built-in extensions with default behavior.
const TExtensionBehavior& getExtensionBehavior() const;
private:
ShShaderType shaderType;
ShShaderSpec shaderSpec;
unsigned int maxCallStackDepth;
// Built-in symbol table for the given language, spec, and resources.
// It is preserved from compile-to-compile.
TSymbolTable symbolTable;
// Built-in extensions with default behavior.
TExtensionBehavior extensionBehavior;
// Results of compilation.
TInfoSink infoSink; // Output sink.
};
//
// 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(ShShaderType type, ShShaderSpec spec);
void DeleteCompiler(TCompiler*);
#endif // _SHHANDLE_INCLUDED_
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//
// Implement the top-level of interface to the compiler,
// as defined in ShaderLang.h
//
#include "GLSLANG/ShaderLang.h"
#include "compiler/InitializeDll.h"
#include "compiler/preprocessor/length_limits.h"
#include "compiler/ShHandle.h"
#include <limits.h>
//
// Driver must call this first, once, before doing any other
// compiler operations.
//
int ShInitialize()
{
if (!InitProcess())
return 0;
return 1;
}
//
// Cleanup symbol tables
//
int ShFinalize()
{
if (!DetachProcess())
return 0;
return 1;
}
//
// Initialize built-in resources with minimum expected values.
//
void ShInitBuiltInResources(ShBuiltInResources* resources)
{
// Constants.
resources->MaxVertexAttribs = 8;
resources->MaxVertexUniformVectors = 128;
resources->MaxVaryingVectors = 8;
resources->MaxVertexTextureImageUnits = 0;
resources->MaxCombinedTextureImageUnits = 8;
resources->MaxTextureImageUnits = 8;
resources->MaxFragmentUniformVectors = 16;
resources->MaxDrawBuffers = 1;
// Extensions.
resources->OES_standard_derivatives = 0;
resources->OES_fragment_precision_high = 0;
resources->OES_EGL_image_external = 0;
resources->MaxCallStackDepth = UINT_MAX;
}
//
// Driver calls these to create and destroy compiler objects.
//
ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources* resources)
{
if (!InitThread())
return 0;
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(type, spec));
TCompiler* compiler = base->getAsCompiler();
if (compiler == 0)
return 0;
// Generate built-in symbol table.
if (!compiler->Init(*resources)) {
ShDestruct(base);
return 0;
}
return reinterpret_cast<void*>(base);
}
void ShDestruct(ShHandle handle)
{
if (handle == 0)
return;
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
if (base->getAsCompiler())
DeleteCompiler(base->getAsCompiler());
}
//
// Do an actual compile on the given strings. The result is left
// in the given compile object.
//
// Return: The return value of ShCompile is really boolean, indicating
// success or failure.
//
int ShCompile(
const ShHandle handle,
const char* const shaderStrings[],
const int numStrings,
int compileOptions)
{
if (!InitThread())
return 0;
if (handle == 0)
return 0;
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (compiler == 0)
return 0;
bool success = compiler->compile(shaderStrings, numStrings, compileOptions);
return success ? 1 : 0;
}
void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params)
{
if (!handle || !params)
return;
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
switch(pname)
{
case SH_INFO_LOG_LENGTH:
*params = compiler->getInfoSink().info.size() + 1;
break;
case SH_OBJECT_CODE_LENGTH:
*params = compiler->getInfoSink().obj.size() + 1;
break;
case SH_ACTIVE_UNIFORM_MAX_LENGTH:
*params = 1 + MAX_SYMBOL_NAME_LEN;
break;
case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
*params = 1 + MAX_SYMBOL_NAME_LEN;
break;
default: UNREACHABLE();
}
}
//
// Return any compiler log of messages for the application.
//
void ShGetInfoLog(const ShHandle handle, char* infoLog)
{
if (!handle || !infoLog)
return;
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
TInfoSink& infoSink = compiler->getInfoSink();
strcpy(infoLog, infoSink.info.c_str());
}
//
// Return any object code.
//
void ShGetObjectCode(const ShHandle handle, char* objCode)
{
if (!handle || !objCode)
return;
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
TInfoSink& infoSink = compiler->getInfoSink();
strcpy(objCode, infoSink.obj.c_str());
}
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//
// Symbol table for parsing. Most functionaliy and main ideas
// are documented in the header file.
//
#if defined(_MSC_VER)
#pragma warning(disable: 4718)
#endif
#include "compiler/SymbolTable.h"
#include <stdio.h>
#include <algorithm>
#if defined(_MSC_VER)
#define snprintf _snprintf
#endif
int TSymbolTableLevel::uniqueId = 0;
TType::TType(const TPublicType &p) :
type(p.type), precision(p.precision), qualifier(p.qualifier), size(p.size), matrix(p.matrix), array(p.array), arraySize(p.arraySize),
maxArraySize(0), arrayInformationType(0), structure(0), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0), typeName(0)
{
if (p.userDef)
{
structure = p.userDef->getStruct();
typeName = NewPoolTString(p.userDef->getTypeName().c_str());
computeDeepestStructNesting();
}
}
//
// Recursively generate mangled names.
//
void TType::buildMangledName(TString& mangledName)
{
if (isMatrix())
mangledName += 'm';
else if (isVector())
mangledName += 'v';
switch (type) {
case EbtFloat: mangledName += 'f'; break;
case EbtInt: mangledName += 'i'; break;
case EbtBool: mangledName += 'b'; break;
case EbtSampler2D: mangledName += "s2"; break;
case EbtSamplerCube: mangledName += "sC"; break;
case EbtSamplerExternalOES: mangledName += "sE"; break;
case EbtStruct:
mangledName += "struct-";
if (typeName)
mangledName += *typeName;
{// support MSVC++6.0
for (unsigned int i = 0; i < structure->size(); ++i) {
mangledName += '-';
(*structure)[i].type->buildMangledName(mangledName);
}
}
default:
break;
}
mangledName += static_cast<char>('0' + getNominalSize());
if (isArray()) {
char buf[20];
snprintf(buf, sizeof(buf), "%d", arraySize);
mangledName += '[';
mangledName += buf;
mangledName += ']';
}
}
int TType::getStructSize() const
{
if (!getStruct()) {
assert(false && "Not a struct");
return 0;
}
if (structureSize == 0)
for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++)
structureSize += ((*tl).type)->getObjectSize();
return structureSize;
}
void TType::computeDeepestStructNesting()
{
if (!structure)
{
return;
}
int maxNesting = 0;
for (TTypeList::const_iterator tl = structure->begin(); tl != structure->end(); tl++)
{
maxNesting = std::max(maxNesting, ((*tl).type)->getDeepestStructNesting());
}
deepestStructNesting = 1 + maxNesting;
}
bool TType::isStructureContainingArrays() const
{
if (!structure)
{
return false;
}
for (TTypeList::const_iterator member = structure->begin(); member != structure->end(); member++)
{
if (member->type->isArray() ||
member->type->isStructureContainingArrays())
{
return true;
}
}
return false;
}
//
// Functions have buried pointers to delete.
//
TFunction::~TFunction()
{
for (TParamList::iterator i = parameters.begin(); i != parameters.end(); ++i)
delete (*i).type;
}
//
// Symbol table levels are a map of pointers to symbols that have to be deleted.
//
TSymbolTableLevel::~TSymbolTableLevel()
{
for (tLevel::iterator it = level.begin(); it != level.end(); ++it)
delete (*it).second;
}
//
// Change all function entries in the table with the non-mangled name
// to be related to the provided built-in operation. This is a low
// performance operation, and only intended for symbol tables that
// live across a large number of compiles.
//
void TSymbolTableLevel::relateToOperator(const char* name, TOperator op)
{
tLevel::iterator it;
for (it = level.begin(); it != level.end(); ++it) {
if ((*it).second->isFunction()) {
TFunction* function = static_cast<TFunction*>((*it).second);
if (function->getName() == name)
function->relateToOperator(op);
}
}
}
//
// Change all function entries in the table with the non-mangled name
// to be related to the provided built-in extension. This is a low
// performance operation, and only intended for symbol tables that
// live across a large number of compiles.
//
void TSymbolTableLevel::relateToExtension(const char* name, const TString& ext)
{
for (tLevel::iterator it = level.begin(); it != level.end(); ++it) {
if (it->second->isFunction()) {
TFunction* function = static_cast<TFunction*>(it->second);
if (function->getName() == name)
function->relateToExtension(ext);
}
}
}
TSymbol::TSymbol(const TSymbol& copyOf)
{
name = NewPoolTString(copyOf.name->c_str());
}
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2012 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#include "TranslatorASM.h"
#include "InitializeParseContext.h"
TranslatorASM::TranslatorASM(es2::Shader *shaderObject, ShShaderType type, ShShaderSpec spec) : TCompiler(type, spec), shaderObject(shaderObject)
{
}
bool TranslatorASM::translate(TIntermNode* root)
{
TParseContext& parseContext = *GetGlobalParseContext();
sh::OutputASM outputASM(parseContext, shaderObject);
outputASM.output();
return parseContext.numErrors() == 0;
}
//
// This function must be provided to create the actual
// compile object used by higher level code. It returns
// a subclass of TCompiler.
//
TCompiler* ConstructCompiler(ShShaderType type, ShShaderSpec spec)
{
return new TranslatorASM(0, type, spec);
}
//
// Delete the compiler made by ConstructCompiler
//
void DeleteCompiler(TCompiler* compiler)
{
delete compiler;
}
\ No newline at end of file
// SwiftShader Software Renderer
//
// Copyright(c) 2005-2012 TransGaming Inc.
//
// All rights reserved. No part of this software may be copied, distributed, transmitted,
// transcribed, stored in a retrieval system, translated into any human or computer
// language by any means, or disclosed to third parties without the explicit written
// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express
// or implied, including but not limited to any patent rights, are granted to you.
//
#ifndef COMPILER_TRANSLATORASM_H_
#define COMPILER_TRANSLATORASM_H_
#include "ShHandle.h"
#include "OutputASM.h"
#include "Shader/PixelShader.hpp"
#include "Shader/VertexShader.hpp"
namespace es2
{
class Shader;
}
class TranslatorASM : public TCompiler
{
public:
TranslatorASM(es2::Shader *shaderObject, ShShaderType type, ShShaderSpec spec);
protected:
virtual bool translate(TIntermNode* root);
private:
es2::Shader *const shaderObject;
};
#endif // COMPILER_TRANSLATORASM_H_
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _TYPES_INCLUDED
#define _TYPES_INCLUDED
#include "compiler/BaseTypes.h"
#include "compiler/Common.h"
#include "compiler/debug.h"
#include <algorithm>
class TType;
struct TPublicType;
//
// Need to have association of line numbers to types in a list for building structs.
//
struct TTypeLine {
TType* type;
int line;
};
typedef TVector<TTypeLine> TTypeList;
inline TTypeList* NewPoolTTypeList()
{
void* memory = GlobalPoolAllocator.allocate(sizeof(TTypeList));
return new(memory) TTypeList;
}
//
// Base class for things that have a type.
//
class TType
{
public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
TType() {}
TType(TBasicType t, TPrecision p, TQualifier q = EvqTemporary, int s = 1, bool m = false, bool a = false) :
type(t), precision(p), qualifier(q), size(s), matrix(m), array(a), arraySize(0),
maxArraySize(0), arrayInformationType(0), structure(0), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0), typeName(0)
{
}
explicit TType(const TPublicType &p);
TType(TTypeList* userDef, const TString& n, TPrecision p = EbpUndefined) :
type(EbtStruct), precision(p), qualifier(EvqTemporary), size(1), matrix(false), array(false), arraySize(0),
maxArraySize(0), arrayInformationType(0), structure(userDef), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0)
{
typeName = NewPoolTString(n.c_str());
}
TBasicType getBasicType() const { return type; }
void setBasicType(TBasicType t) { type = t; }
TPrecision getPrecision() const { return precision; }
void setPrecision(TPrecision p) { precision = p; }
TQualifier getQualifier() const { return qualifier; }
void setQualifier(TQualifier q) { qualifier = q; }
// One-dimensional size of single instance type
int getNominalSize() const { return size; }
void setNominalSize(int s) { size = s; }
// Full size of single instance of type
int getObjectSize() const
{
if(isArray())
{
return getElementSize() * std::max(getArraySize(), getMaxArraySize());
}
else
{
return getElementSize();
}
}
int getElementSize() const
{
if(getBasicType() == EbtStruct)
{
return getStructSize();
}
else if(matrix)
{
return size * size;
}
else // Vector or scalar
{
return size;
}
}
int elementRegisterCount() const
{
TTypeList *structure = getStruct();
if(structure)
{
int registerCount = 0;
for(size_t i = 0; i < structure->size(); i++)
{
registerCount += (*structure)[i].type->totalRegisterCount();
}
return registerCount;
}
else if(isMatrix())
{
return getNominalSize();
}
else
{
return 1;
}
}
int totalRegisterCount() const
{
if(array)
{
return arraySize * elementRegisterCount();
}
else
{
return elementRegisterCount();
}
}
bool isMatrix() const { return matrix ? true : false; }
void setMatrix(bool m) { matrix = m; }
bool isArray() const { return array ? true : false; }
int getArraySize() const { return arraySize; }
void setArraySize(int s) { array = true; arraySize = s; }
int getMaxArraySize () const { return maxArraySize; }
void setMaxArraySize (int s) { maxArraySize = s; }
void clearArrayness() { array = false; arraySize = 0; maxArraySize = 0; }
void setArrayInformationType(TType* t) { arrayInformationType = t; }
TType* getArrayInformationType() const { return arrayInformationType; }
bool isVector() const { return size > 1 && !matrix; }
bool isScalar() const { return size == 1 && !matrix && !structure; }
bool isRegister() const { return !matrix && !structure && !array; } // Fits in a 4-element register
bool isStruct() const { return structure != 0; }
TTypeList* getStruct() const { return structure; }
void setStruct(TTypeList* s) { structure = s; computeDeepestStructNesting(); }
const TString& getTypeName() const
{
assert(typeName);
return *typeName;
}
void setTypeName(const TString& n)
{
typeName = NewPoolTString(n.c_str());
}
bool isField() const { return fieldName != 0; }
const TString& getFieldName() const
{
assert(fieldName);
return *fieldName;
}
void setFieldName(const TString& n)
{
fieldName = NewPoolTString(n.c_str());
}
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);
}
bool operator<(const TType& right) const {
if (type != right.type) return type < right.type;
if (size != right.size) return size < right.size;
if (matrix != right.matrix) return matrix < right.matrix;
if (array != right.array) return array < right.array;
if (arraySize != right.arraySize) return arraySize < right.arraySize;
if (structure != right.structure) return structure < right.structure;
return false;
}
const char* getBasicString() const { return ::getBasicString(type); }
const char* getPrecisionString() const { return ::getPrecisionString(precision); }
const char* getQualifierString() const { return ::getQualifierString(qualifier); }
TString getCompleteString() const;
// If this type is a struct, returns the deepest struct nesting of
// any field in the struct. For example:
// struct nesting1 {
// vec4 position;
// };
// struct nesting2 {
// nesting1 field1;
// vec4 field2;
// };
// For type "nesting2", this method would return 2 -- the number
// of structures through which indirection must occur to reach the
// deepest field (nesting2.field1.position).
int getDeepestStructNesting() const { return deepestStructNesting; }
bool isStructureContainingArrays() const;
protected:
void buildMangledName(TString&);
int getStructSize() const;
void computeDeepestStructNesting();
TBasicType type : 6;
TPrecision precision;
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;
int maxArraySize;
TType* arrayInformationType;
TTypeList* structure; // 0 unless this is a struct
mutable int structureSize;
int deepestStructNesting;
TString *fieldName; // for structure field names
TString *mangled;
TString *typeName; // for structure field type name
};
//
// 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.
//
struct TPublicType
{
TBasicType type;
TQualifier qualifier;
TPrecision precision;
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;
precision = EbpUndefined;
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;
}
bool isStructureContainingArrays() const
{
if (!userDef)
{
return false;
}
return userDef->isStructureContainingArrays();
}
};
#endif // _TYPES_INCLUDED_
//
// Copyright (c) 2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "GLSLANG/ShaderLang.h"
#include "compiler/intermediate.h"
class TInfoSinkBase;
struct TLoopInfo {
struct TIndex {
int id; // symbol id.
} index;
TIntermLoop* loop;
};
typedef TVector<TLoopInfo> TLoopStack;
// Traverses intermediate tree to ensure that the shader does not exceed the
// minimum functionality mandated in GLSL 1.0 spec, Appendix A.
class ValidateLimitations : public TIntermTraverser {
public:
ValidateLimitations(ShShaderType shaderType, TInfoSinkBase& sink);
int numErrors() const { return mNumErrors; }
virtual bool visitBinary(Visit, TIntermBinary*);
virtual bool visitUnary(Visit, TIntermUnary*);
virtual bool visitAggregate(Visit, TIntermAggregate*);
virtual bool visitLoop(Visit, TIntermLoop*);
private:
void error(TSourceLoc loc, const char *reason, const char* token);
bool withinLoopBody() const;
bool isLoopIndex(const TIntermSymbol* symbol) const;
bool validateLoopType(TIntermLoop* node);
bool validateForLoopHeader(TIntermLoop* node, TLoopInfo* info);
bool validateForLoopInit(TIntermLoop* node, TLoopInfo* info);
bool validateForLoopCond(TIntermLoop* node, TLoopInfo* info);
bool validateForLoopExpr(TIntermLoop* node, TLoopInfo* info);
// Returns true if none of the loop indices is used as the argument to
// the given function out or inout parameter.
bool validateFunctionCall(TIntermAggregate* node);
bool validateOperation(TIntermOperator* node, TIntermNode* operand);
// Returns true if indexing does not exceed the minimum functionality
// mandated in GLSL 1.0 spec, Appendix A, Section 5.
bool isConstExpr(TIntermNode* node);
bool isConstIndexExpr(TIntermNode* node);
bool validateIndexing(TIntermBinary* node);
ShShaderType mShaderType;
TInfoSinkBase& mSink;
int mNumErrors;
TLoopStack mLoopStack;
};
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// debug.cpp: Debugging utilities.
#include "compiler/debug.h"
#include <stdarg.h>
#include <stdio.h>
#include "compiler/InitializeParseContext.h"
#include "compiler/ParseHelper.h"
static const int kTraceBufferLen = 1024;
#ifdef TRACE_ENABLED
extern "C" {
void Trace(const char *format, ...) {
if (!format) return;
TParseContext* parseContext = GetGlobalParseContext();
if (parseContext) {
char buf[kTraceBufferLen];
va_list args;
va_start(args, format);
vsnprintf(buf, kTraceBufferLen, format, args);
va_end(args);
parseContext->trace(buf);
}
}
} // extern "C"
#endif // TRACE_ENABLED
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// debug.h: Debugging utilities.
#ifndef COMPILER_DEBUG_H_
#define COMPILER_DEBUG_H_
#include <assert.h>
#ifdef _DEBUG
#define TRACE_ENABLED // define to enable debug message tracing
#endif // _DEBUG
// Outputs text to the debug log
#ifdef TRACE_ENABLED
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void Trace(const char* format, ...);
#ifdef __cplusplus
}
#endif // __cplusplus
#else // TRACE_ENABLED
#define Trace(...) ((void)0)
#endif // TRACE_ENABLED
// A macro asserting a condition and outputting failures to the debug log
#define ASSERT(expression) do { \
if(!(expression)) \
Trace("Assert failed: %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
assert(expression); \
} while(0)
#define UNIMPLEMENTED() do { \
Trace("Unimplemented invoked: %s(%d)\n", __FUNCTION__, __LINE__); \
assert(false); \
} while(0)
#define UNREACHABLE() do { \
Trace("Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \
assert(false); \
} while(0)
#endif // COMPILER_DEBUG_H_
#!/bin/bash
# Copyright (c) 2010 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Generates GLSL ES parser - glslang_lex.cpp, glslang_tab.h, and glslang_tab.cpp
run_flex()
{
input_file=$script_dir/$1.l
output_source=$script_dir/$1_lex.cpp
flex --noline --nounistd --outfile=$output_source $input_file
}
run_bison()
{
input_file=$script_dir/$1.y
output_header=$script_dir/$1_tab.h
output_source=$script_dir/$1_tab.cpp
bison --no-lines --skeleton=yacc.c --defines=$output_header --output=$output_source $input_file
}
script_dir=$(dirname $0)
# Generate Parser
run_flex glslang
run_bison glslang
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
struct TParseContext;
extern int glslang_initialize(TParseContext* context);
extern int glslang_finalize(TParseContext* context);
extern int glslang_scan(int count,
const char* const string[],
const int length[],
TParseContext* context);
extern int glslang_parse(TParseContext* context);
This source diff could not be displayed because it is too large. You can view the blob instead.
/* A Bison parser, made by GNU Bison 2.4.1. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
INVARIANT = 258,
HIGH_PRECISION = 259,
MEDIUM_PRECISION = 260,
LOW_PRECISION = 261,
PRECISION = 262,
ATTRIBUTE = 263,
CONST_QUAL = 264,
BOOL_TYPE = 265,
FLOAT_TYPE = 266,
INT_TYPE = 267,
BREAK = 268,
CONTINUE = 269,
DO = 270,
ELSE = 271,
FOR = 272,
IF = 273,
DISCARD = 274,
RETURN = 275,
BVEC2 = 276,
BVEC3 = 277,
BVEC4 = 278,
IVEC2 = 279,
IVEC3 = 280,
IVEC4 = 281,
VEC2 = 282,
VEC3 = 283,
VEC4 = 284,
MATRIX2 = 285,
MATRIX3 = 286,
MATRIX4 = 287,
IN_QUAL = 288,
OUT_QUAL = 289,
INOUT_QUAL = 290,
UNIFORM = 291,
VARYING = 292,
STRUCT = 293,
VOID_TYPE = 294,
WHILE = 295,
SAMPLER2D = 296,
SAMPLERCUBE = 297,
SAMPLER_EXTERNAL_OES = 298,
IDENTIFIER = 299,
TYPE_NAME = 300,
FLOATCONSTANT = 301,
INTCONSTANT = 302,
BOOLCONSTANT = 303,
FIELD_SELECTION = 304,
LEFT_OP = 305,
RIGHT_OP = 306,
INC_OP = 307,
DEC_OP = 308,
LE_OP = 309,
GE_OP = 310,
EQ_OP = 311,
NE_OP = 312,
AND_OP = 313,
OR_OP = 314,
XOR_OP = 315,
MUL_ASSIGN = 316,
DIV_ASSIGN = 317,
ADD_ASSIGN = 318,
MOD_ASSIGN = 319,
LEFT_ASSIGN = 320,
RIGHT_ASSIGN = 321,
AND_ASSIGN = 322,
XOR_ASSIGN = 323,
OR_ASSIGN = 324,
SUB_ASSIGN = 325,
LEFT_PAREN = 326,
RIGHT_PAREN = 327,
LEFT_BRACKET = 328,
RIGHT_BRACKET = 329,
LEFT_BRACE = 330,
RIGHT_BRACE = 331,
DOT = 332,
COMMA = 333,
COLON = 334,
EQUAL = 335,
SEMICOLON = 336,
BANG = 337,
DASH = 338,
TILDE = 339,
PLUS = 340,
STAR = 341,
SLASH = 342,
PERCENT = 343,
LEFT_ANGLE = 344,
RIGHT_ANGLE = 345,
VERTICAL_BAR = 346,
CARET = 347,
AMPERSAND = 348,
QUESTION = 349
};
#endif
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
struct {
TSourceLoc line;
union {
TString *string;
float f;
int i;
bool b;
};
TSymbol* symbol;
} lex;
struct {
TSourceLoc line;
TOperator op;
union {
TIntermNode* intermNode;
TIntermNodePair nodePair;
TIntermTyped* intermTypedNode;
TIntermAggregate* intermAggregate;
};
union {
TPublicType type;
TPrecision precision;
TQualifier qualifier;
TFunction* function;
TParameter param;
TTypeLine typeLine;
TTypeList* typeList;
};
} interm;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _LOCAL_INTERMEDIATE_INCLUDED_
#define _LOCAL_INTERMEDIATE_INCLUDED_
#include "GLSLANG/ShaderLang.h"
#include "compiler/intermediate.h"
struct TVectorFields {
int offsets[4];
int num;
};
//
// Set of helper functions to help parse and build the tree.
//
class TInfoSink;
class TIntermediate {
public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
TIntermediate(TInfoSink& i) : infoSink(i) { }
TIntermSymbol* addSymbol(int Id, const TString&, const TType&, TSourceLoc);
TIntermTyped* addBinaryMath(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc);
TIntermTyped* addAssign(TOperator op, TIntermTyped* left, TIntermTyped* right, TSourceLoc);
TIntermTyped* addIndex(TOperator op, TIntermTyped* base, TIntermTyped* index, TSourceLoc);
TIntermTyped* addUnaryMath(TOperator op, TIntermNode* child, TSourceLoc);
TIntermAggregate* growAggregate(TIntermNode* left, TIntermNode* right, TSourceLoc);
TIntermAggregate* makeAggregate(TIntermNode* node, TSourceLoc);
TIntermAggregate* setAggregateOperator(TIntermNode*, TOperator, TSourceLoc);
TIntermNode* addSelection(TIntermTyped* cond, TIntermNodePair code, TSourceLoc);
TIntermTyped* addSelection(TIntermTyped* cond, TIntermTyped* trueBlock, TIntermTyped* falseBlock, TSourceLoc);
TIntermTyped* addComma(TIntermTyped* left, TIntermTyped* right, TSourceLoc);
TIntermConstantUnion* addConstantUnion(ConstantUnion*, const TType&, TSourceLoc);
TIntermTyped* promoteConstantUnion(TBasicType, TIntermConstantUnion*);
bool parseConstTree(TSourceLoc, TIntermNode*, ConstantUnion*, TOperator, TType, bool singleConstantParam = false);
TIntermNode* addLoop(TLoopType, TIntermNode*, TIntermTyped*, TIntermTyped*, TIntermNode*, TSourceLoc);
TIntermBranch* addBranch(TOperator, TSourceLoc);
TIntermBranch* addBranch(TOperator, TIntermTyped*, TSourceLoc);
TIntermTyped* addSwizzle(TVectorFields&, TSourceLoc);
bool postProcess(TIntermNode*);
void remove(TIntermNode*);
void outputTree(TIntermNode*);
protected:
TInfoSink& infoSink;
private:
void operator=(TIntermediate&); // prevent assignments
};
#endif // _LOCAL_INTERMEDIATE_INCLUDED_
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef __OSINCLUDE_H
#define __OSINCLUDE_H
//
// This file contains contains os-specific datatypes and
// declares any os-specific functions.
//
#if defined(_WIN32) || defined(_WIN64)
#define ANGLE_OS_WIN
#elif defined(__APPLE__) || defined(__linux__) || \
defined(__FreeBSD__) || defined(__OpenBSD__) || \
defined(__sun) || defined(ANDROID) || \
defined(__GLIBC__) || defined(__GNU__) || \
defined(__QNX__)
#define ANGLE_OS_POSIX
#else
#error Unsupported platform.
#endif
#if defined(ANGLE_OS_WIN)
#define STRICT
#define VC_EXTRALEAN 1
#include <windows.h>
#elif defined(ANGLE_OS_POSIX)
#include <pthread.h>
#include <semaphore.h>
#include <errno.h>
#endif // ANGLE_OS_WIN
#include "compiler/debug.h"
//
// Thread Local Storage Operations
//
#if defined(ANGLE_OS_WIN)
typedef DWORD OS_TLSIndex;
#define OS_INVALID_TLS_INDEX (TLS_OUT_OF_INDEXES)
#elif defined(ANGLE_OS_POSIX)
typedef pthread_key_t OS_TLSIndex;
#define OS_INVALID_TLS_INDEX (static_cast<OS_TLSIndex>(-1))
#endif // ANGLE_OS_WIN
OS_TLSIndex OS_AllocTLSIndex();
bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue);
bool OS_FreeTLSIndex(OS_TLSIndex nIndex);
inline void* OS_GetTLSValue(OS_TLSIndex nIndex)
{
ASSERT(nIndex != OS_INVALID_TLS_INDEX);
#if defined(ANGLE_OS_WIN)
return TlsGetValue(nIndex);
#elif defined(ANGLE_OS_POSIX)
return pthread_getspecific(nIndex);
#endif // ANGLE_OS_WIN
}
#endif // __OSINCLUDE_H
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//
// This file contains the posix specific functions
//
#include "compiler/osinclude.h"
#if !defined(ANGLE_OS_POSIX)
#error Trying to build a posix specific file in a non-posix build.
#endif
//
// Thread Local Storage Operations
//
OS_TLSIndex OS_AllocTLSIndex()
{
pthread_key_t pPoolIndex;
//
// Create global pool key.
//
if ((pthread_key_create(&pPoolIndex, NULL)) != 0) {
assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");
return false;
}
else {
return pPoolIndex;
}
}
bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)
{
if (nIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
return false;
}
if (pthread_setspecific(nIndex, lpvValue) == 0)
return true;
else
return false;
}
bool OS_FreeTLSIndex(OS_TLSIndex nIndex)
{
if (nIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
return false;
}
//
// Delete the global pool key.
//
if (pthread_key_delete(nIndex) == 0)
return true;
else
return false;
}
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/osinclude.h"
//
// This file contains contains the window's specific functions
//
#if !defined(ANGLE_OS_WIN)
#error Trying to build a windows specific file in a non windows build.
#endif
//
// Thread Local Storage Operations
//
OS_TLSIndex OS_AllocTLSIndex()
{
DWORD dwIndex = TlsAlloc();
if (dwIndex == TLS_OUT_OF_INDEXES) {
assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");
return OS_INVALID_TLS_INDEX;
}
return dwIndex;
}
bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)
{
if (nIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
return false;
}
if (TlsSetValue(nIndex, lpvValue))
return true;
else
return false;
}
bool OS_FreeTLSIndex(OS_TLSIndex nIndex)
{
if (nIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
return false;
}
if (TlsFree(nIndex))
return true;
else
return false;
}
//
// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/ParseHelper.h"
//
// Use this class to carry along data from node to node in
// the traversal
//
class TConstTraverser : public TIntermTraverser {
public:
TConstTraverser(ConstantUnion* cUnion, bool singleConstParam, TOperator constructType, TInfoSink& sink, TType& t)
: error(false),
index(0),
unionArray(cUnion),
type(t),
constructorType(constructType),
singleConstantParam(singleConstParam),
infoSink(sink),
size(0),
isMatrix(false),
matrixSize(0) {
}
bool error;
protected:
void visitSymbol(TIntermSymbol*);
void visitConstantUnion(TIntermConstantUnion*);
bool visitBinary(Visit visit, TIntermBinary*);
bool visitUnary(Visit visit, TIntermUnary*);
bool visitSelection(Visit visit, TIntermSelection*);
bool visitAggregate(Visit visit, TIntermAggregate*);
bool visitLoop(Visit visit, TIntermLoop*);
bool visitBranch(Visit visit, TIntermBranch*);
int index;
ConstantUnion *unionArray;
TType type;
TOperator constructorType;
bool singleConstantParam;
TInfoSink& infoSink;
int size; // size of the constructor ( 4 for vec4)
bool isMatrix;
int matrixSize; // dimension of the matrix (nominal size and not the instance size)
};
//
// The rest of the file are the traversal functions. The last one
// is the one that starts the traversal.
//
// Return true from interior nodes to have the external traversal
// continue on to children. If you process children yourself,
// return false.
//
void TConstTraverser::visitSymbol(TIntermSymbol* node)
{
infoSink.info.message(EPrefixInternalError, "Symbol Node found in constant constructor", node->getLine());
return;
}
bool TConstTraverser::visitBinary(Visit visit, TIntermBinary* node)
{
TQualifier qualifier = node->getType().getQualifier();
if (qualifier != EvqConst) {
TString buf;
buf.append("'constructor' : assigning non-constant to ");
buf.append(type.getCompleteString());
infoSink.info.message(EPrefixError, buf.c_str(), node->getLine());
error = true;
return false;
}
infoSink.info.message(EPrefixInternalError, "Binary Node found in constant constructor", node->getLine());
return false;
}
bool TConstTraverser::visitUnary(Visit visit, TIntermUnary* node)
{
TString buf;
buf.append("'constructor' : assigning non-constant to ");
buf.append(type.getCompleteString());
infoSink.info.message(EPrefixError, buf.c_str(), node->getLine());
error = true;
return false;
}
bool TConstTraverser::visitAggregate(Visit visit, TIntermAggregate* node)
{
if (!node->isConstructor() && node->getOp() != EOpComma) {
TString buf;
buf.append("'constructor' : assigning non-constant to ");
buf.append(type.getCompleteString());
infoSink.info.message(EPrefixError, buf.c_str(), node->getLine());
error = true;
return false;
}
if (node->getSequence().size() == 0) {
error = true;
return false;
}
bool flag = node->getSequence().size() == 1 && node->getSequence()[0]->getAsTyped()->getAsConstantUnion();
if (flag)
{
singleConstantParam = true;
constructorType = node->getOp();
size = node->getType().getObjectSize();
if (node->getType().isMatrix()) {
isMatrix = true;
matrixSize = node->getType().getNominalSize();
}
}
for (TIntermSequence::iterator p = node->getSequence().begin();
p != node->getSequence().end(); p++) {
if (node->getOp() == EOpComma)
index = 0;
(*p)->traverse(this);
}
if (flag)
{
singleConstantParam = false;
constructorType = EOpNull;
size = 0;
isMatrix = false;
matrixSize = 0;
}
return false;
}
bool TConstTraverser::visitSelection(Visit visit, TIntermSelection* node)
{
infoSink.info.message(EPrefixInternalError, "Selection Node found in constant constructor", node->getLine());
error = true;
return false;
}
void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
{
ConstantUnion* leftUnionArray = unionArray;
int instanceSize = type.getObjectSize();
TBasicType basicType = type.getBasicType();
if (index >= instanceSize)
return;
if (!singleConstantParam) {
int size = node->getType().getObjectSize();
ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
for (int i=0; i < size; i++) {
if (index >= instanceSize)
return;
leftUnionArray[index].cast(basicType, rightUnionArray[i]);
(index)++;
}
} else {
int totalSize = index + size;
ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
if (!isMatrix) {
int count = 0;
for (int i = index; i < totalSize; i++) {
if (i >= instanceSize)
return;
leftUnionArray[i].cast(basicType, rightUnionArray[count]);
(index)++;
if (node->getType().getObjectSize() > 1)
count++;
}
} else { // for matrix constructors
int count = 0;
int element = index;
for (int i = index; i < totalSize; i++) {
if (i >= instanceSize)
return;
if (element - i == 0 || (i - element) % (matrixSize + 1) == 0 )
leftUnionArray[i].cast(basicType, rightUnionArray[0]);
else
leftUnionArray[i].setFConst(0.0f);
(index)++;
if (node->getType().getObjectSize() > 1)
count++;
}
}
}
}
bool TConstTraverser::visitLoop(Visit visit, TIntermLoop* node)
{
infoSink.info.message(EPrefixInternalError, "Loop Node found in constant constructor", node->getLine());
error = true;
return false;
}
bool TConstTraverser::visitBranch(Visit visit, TIntermBranch* node)
{
infoSink.info.message(EPrefixInternalError, "Branch Node found in constant constructor", node->getLine());
error = true;
return false;
}
//
// This function is the one to call externally to start the traversal.
// Individual functions can be initialized to 0 to skip processing of that
// type of node. It's children will still be processed.
//
bool TIntermediate::parseConstTree(TSourceLoc line, TIntermNode* root, ConstantUnion* unionArray, TOperator constructorType, TType t, bool singleConstantParam)
{
if (root == 0)
return false;
TConstTraverser it(unionArray, singleConstantParam, constructorType, infoSink, t);
root->traverse(&it);
if (it.error)
return true;
else
return false;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment