Commit a240a2f9 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 407c6a53
# Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. # Copyright (c) 2012-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.
...@@ -64,8 +64,6 @@ ...@@ -64,8 +64,6 @@
'COMPILER_IMPLEMENTATION', 'COMPILER_IMPLEMENTATION',
], ],
'sources': [ 'sources': [
'compiler/builtin_symbol_table.h',
'compiler/builtin_symbol_table.cpp',
'compiler/BaseTypes.h', 'compiler/BaseTypes.h',
'compiler/BuiltInFunctionEmulator.cpp', 'compiler/BuiltInFunctionEmulator.cpp',
'compiler/BuiltInFunctionEmulator.h', 'compiler/BuiltInFunctionEmulator.h',
......
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 2250 #define BUILD_REVISION 2251
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
// //
// 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.
// //
#include "compiler/builtin_symbol_table.h"
#include "compiler/BuiltInFunctionEmulator.h" #include "compiler/BuiltInFunctionEmulator.h"
#include "compiler/DetectCallDepth.h" #include "compiler/DetectCallDepth.h"
#include "compiler/ForLoopUnroll.h" #include "compiler/ForLoopUnroll.h"
...@@ -28,66 +27,6 @@ bool isWebGLBasedSpec(ShShaderSpec spec) ...@@ -28,66 +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;
}
}
switch (type) {
case SH_FRAGMENT_SHADER:
InsertBuiltInFunctionsCommon(resources, &symbolTable);
break;
case SH_VERTEX_SHADER:
InsertBuiltInFunctionsCommon(resources, &symbolTable);
InsertBuiltInFunctionsVertex(resources, &symbolTable);
break;
default: assert(false && "Language not supported");
}
IdentifyBuiltIns(type, spec, resources, symbolTable);
return true;
}
class TScopedPoolAllocator { class TScopedPoolAllocator {
public: public:
TScopedPoolAllocator(TPoolAllocator* allocator, bool pushPop) TScopedPoolAllocator(TPoolAllocator* allocator, bool pushPop)
...@@ -268,13 +207,40 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -268,13 +207,40 @@ 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; assert(symbolTable.isEmpty());
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;
builtIns.initialize(shaderType, shaderSpec, resources); switch(shaderType)
return InitializeSymbolTable(builtIns.getBuiltInStrings(), {
shaderType, shaderSpec, resources, infoSink, symbolTable); 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,19 +11,8 @@ ...@@ -11,19 +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 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();
......
//
// 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 _BUILTIN_SYMBOL_TABLE_INCLUDED_
#define _BUILTIN_SYMBOL_TABLE_INCLUDED_
#include "GLSLANG/ShaderLang.h"
class TSymbolTable;
extern void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable* t);
extern void InsertBuiltInFunctionsVertex(const ShBuiltInResources& resources, TSymbolTable* t);
#endif // _BUILTIN_SYMBOL_TABLE_INCLUDED_
#!/usr/bin/python
# Copyright (c) 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.
import json
# This file contains the definitions for all the builtin in JSON format.
json_data = open('builtin_symbols.json')
builtin = json.load(json_data)
# This maps the shader language's types and how to create the TTypes in the symbol table.
ttypeMap = builtin["ttypemap"]
# This is the output that we are going to generate.
output = open('builtin_symbol_table.cpp', 'w');
# The header part of the file.
header = """// 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.
// *************************************************************
// This file is generated by generate_builtin_symbol_table.py.
// * DO NOT HAND MODIFY *
// *************************************************************
#include "compiler/builtin_symbol_table.h"
#include "compiler/SymbolTable.h"
"""
output.write(header)
registerfunc = """
static void builtin1(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1)
{
TFunction* f = new TFunction(new TString(name), *rvalue);
TParameter param = {new TString(pname1), ptype1};
f->addParameter(param);
t->insert(*f);
}
static void builtin2(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1, TType* ptype2, const char* pname2)
{
TFunction* f = new TFunction(new TString(name), *rvalue);
TParameter param1 = {new TString(pname1), ptype1};
f->addParameter(param1);
TParameter param2 = {new TString(pname2), ptype2};
f->addParameter(param2);
t->insert(*f);
}
static void builtin3(TSymbolTable* t, TType* rvalue, const char* name, TType* ptype1, const char* pname1, TType* ptype2, const char* pname2, TType* ptype3, const char* pname3)
{
TFunction* f = new TFunction(new TString(name), *rvalue);
TParameter param1 = {new TString(pname1), ptype1};
f->addParameter(param1);
TParameter param2 = {new TString(pname2), ptype2};
f->addParameter(param2);
TParameter param3 = {new TString(pname3), ptype3};
f->addParameter(param3);
t->insert(*f);
}
"""
output.write(registerfunc)
# A function that parses the JSON representation of a list of builtin functions.
def parseBuiltin(name):
for func in builtin[name]:
out = ""
indent = " ";
size = len(func['parameter'])
if 'condition' in func:
out += indent + "if (" + func['condition'] + ") {\n"
indent += indent;
out += indent + "builtin" + str(size) + "(t, "
out += ttypeMap[func['return_type']]
out += ", \"" + func['name'] + "\""
paramlist = func['parameter']
paramdef = "";
for param in paramlist:
paramdef += ", "
paramdef += ttypeMap[param['type']]
paramdef += ", \"" + param['name'] + "\""
out += paramdef + ");\n"
if 'condition' in func:
out += " }\n"
output.write(out)
commonHeader = "void InsertBuiltInFunctionsCommon(const ShBuiltInResources& resources, TSymbolTable* t) {\n"
output.write(commonHeader)
parseBuiltin("common")
output.write("}\n\n")
vertexHeader = "void InsertBuiltInFunctionsVertex(const ShBuiltInResources& resources, TSymbolTable* t) {\n"
output.write(vertexHeader)
parseBuiltin("vertex")
output.write("}\n\n")
json_data.close()
output.close()
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