Commit 8cf3a7ec by Nicolas Capens Committed by Shannon Woods

Initialize the symbol table without invoking the parser.

TRAC #23368 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens
parent 45494d46
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -27,52 +27,6 @@ bool isWebGLBasedSpec(ShShaderSpec spec) ...@@ -27,52 +27,6 @@ bool isWebGLBasedSpec(ShShaderSpec spec)
} }
namespace { namespace {
bool InitializeSymbolTable(
const TBuiltInStrings& builtInStrings,
ShShaderType type, ShShaderSpec spec, const ShBuiltInResources& resources,
TInfoSink& infoSink, TSymbolTable& symbolTable)
{
TIntermediate intermediate(infoSink);
TExtensionBehavior extBehavior;
InitExtensionBehavior(resources, extBehavior);
// The builtins deliberately don't specify precisions for the function
// arguments and return types. For that reason we don't try to check them.
TParseContext parseContext(symbolTable, extBehavior, intermediate, type, spec, 0, false, NULL, infoSink);
parseContext.fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
GlobalParseContext = &parseContext;
assert(symbolTable.isEmpty());
//
// Parse the built-ins. This should only happen once per
// language symbol table.
//
// 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();
for (TBuiltInStrings::const_iterator i = builtInStrings.begin(); i != builtInStrings.end(); ++i)
{
const char* builtInShaders = i->c_str();
int builtInLengths = static_cast<int>(i->size());
if (builtInLengths <= 0)
continue;
if (PaParseStrings(1, &builtInShaders, &builtInLengths, &parseContext) != 0)
{
infoSink.info.prefix(EPrefixInternalError);
infoSink.info << "Unable to parse built-ins";
return false;
}
}
IdentifyBuiltIns(type, spec, resources, symbolTable);
return true;
}
class TScopedPoolAllocator { class TScopedPoolAllocator {
public: public:
TScopedPoolAllocator(TPoolAllocator* allocator, bool pushPop) TScopedPoolAllocator(TPoolAllocator* allocator, bool pushPop)
...@@ -252,14 +206,42 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -252,14 +206,42 @@ bool TCompiler::compile(const char* const shaderStrings[],
return success; return success;
} }
bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources& resources) bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
{ {
TBuiltIns builtIns;
compileResources = resources; compileResources = resources;
builtIns.initialize(shaderType, shaderSpec, resources, extensionBehavior);
return InitializeSymbolTable(builtIns.getBuiltInStrings(), assert(symbolTable.isEmpty());
shaderType, shaderSpec, resources, infoSink, symbolTable); 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, shaderSpec, resources, extensionBehavior, symbolTable);
IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
return true;
} }
void TCompiler::clearResults() void TCompiler::clearResults()
......
// //
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. // 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -11,20 +11,8 @@ ...@@ -11,20 +11,8 @@
#include "compiler/ShHandle.h" #include "compiler/ShHandle.h"
#include "compiler/SymbolTable.h" #include "compiler/SymbolTable.h"
typedef TVector<TString> TBuiltInStrings; void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources,
const TExtensionBehavior &extensionBehavior, TSymbolTable &table);
class TBuiltIns {
public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
void initialize(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources,
const TExtensionBehavior& extensionBehavior);
const TBuiltInStrings& getBuiltInStrings() { return builtInStrings; }
protected:
TBuiltInStrings builtInStrings;
};
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources, const ShBuiltInResources& resources,
......
// //
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. // 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -273,6 +273,35 @@ public: ...@@ -273,6 +273,35 @@ public:
return table[currentLevel()]->insert(symbol); return table[currentLevel()]->insert(symbol);
} }
bool insertConstInt(const char *name, int value)
{
TVariable *constant = new TVariable(NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1));
constant->getConstPointer()->setIConst(value);
return insert(*constant);
}
bool insertBuiltIn(TType *rvalue, const char *name, TType *ptype1, const char *pname1, TType *ptype2 = 0, const char *pname2 = 0, TType *ptype3 = 0, const char *pname3 = 0)
{
TFunction *function = new TFunction(NewPoolTString(name), *rvalue);
TParameter param1 = {NewPoolTString(pname1), ptype1};
function->addParameter(param1);
if (pname2)
{
TParameter param2 = {NewPoolTString(pname2), ptype2};
function->addParameter(param2);
}
if (pname3)
{
TParameter param3 = {NewPoolTString(pname3), ptype3};
function->addParameter(param3);
}
return insert(*function);
}
TSymbol* find(const TString& name, bool* builtIn = 0, bool *sameScope = 0) TSymbol* find(const TString& name, bool* builtIn = 0, bool *sameScope = 0)
{ {
int level = currentLevel(); int level = currentLevel();
......
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