Commit ad771eb2 by alokp@chromium.org

Added mechanism to predefine associated macros for extensions. Also refactored…

Added mechanism to predefine associated macros for extensions. Also refactored the way extension behavior is initialized and updated. Please note that I still need to add validation that appropriate extensions are enabled before using an extension function. BUG=25 Review URL: http://codereview.appspot.com/2139042 git-svn-id: https://angleproject.googlecode.com/svn/trunk@413 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 8f0f24a0
...@@ -71,6 +71,4 @@ public: ...@@ -71,6 +71,4 @@ public:
TMap(const tAllocator& a) : std::map<K, D, CMP, tAllocator>(std::map<K, D, CMP, tAllocator>::key_compare(), a) {} TMap(const tAllocator& a) : std::map<K, D, CMP, tAllocator>(std::map<K, D, CMP, tAllocator>::key_compare(), a) {}
}; };
typedef TMap<TString, TString> TPragmaTable;
#endif // _COMMON_INCLUDED_ #endif // _COMMON_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 _EXTENSION_BEHAVIOR_INCLUDED_
#define _EXTENSION_BEHAVIOR_INCLUDED_
#include "compiler/Common.h"
typedef enum {
EBhRequire,
EBhEnable,
EBhWarn,
EBhDisable
} TBehavior;
typedef TMap<TString, TBehavior> TExtensionBehavior;
#endif // _EXTENSION_TABLE_INCLUDED_
...@@ -619,3 +619,9 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource ...@@ -619,3 +619,9 @@ void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource
} }
} }
void InitExtensionBehavior(const TBuiltInResource& resources,
TExtensionBehavior& extBehavior)
{
if (resources.OES_standard_derivatives)
extBehavior["GL_OES_standard_derivatives"] = EBhDisable;
}
...@@ -27,7 +27,11 @@ protected: ...@@ -27,7 +27,11 @@ protected:
void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource& resources, void IdentifyBuiltIns(EShLanguage language, EShSpec spec, const TBuiltInResource& resources,
TSymbolTable& symbolTable); TSymbolTable& symbolTable);
void InitExtensionBehavior(const TBuiltInResource& resources,
TExtensionBehavior& extensionBehavior);
extern "C" int InitPreprocessor(void); extern "C" int InitPreprocessor(void);
extern "C" int FinalizePreprocessor(void); extern "C" int FinalizePreprocessor(void);
extern "C" void PredefineIntMacro(const char *name, int value);
#endif // _INITIALIZE_INCLUDED_ #endif // _INITIALIZE_INCLUDED_
...@@ -1375,17 +1375,6 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n ...@@ -1375,17 +1375,6 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n
return typedNode; return typedNode;
} }
//
// Initialize all supported extensions to disable
//
void TParseContext::initializeExtensionBehavior()
{
//
// example code: extensionBehavior["test"] = EBhDisable; // where "test" is the name of
// supported extension
//
}
OS_TLSIndex GlobalParseContextIndex = OS_INVALID_TLS_INDEX; OS_TLSIndex GlobalParseContextIndex = OS_INVALID_TLS_INDEX;
bool InitializeParseContextIndex() bool InitializeParseContextIndex()
......
...@@ -6,9 +6,10 @@ ...@@ -6,9 +6,10 @@
#ifndef _PARSER_HELPER_INCLUDED_ #ifndef _PARSER_HELPER_INCLUDED_
#define _PARSER_HELPER_INCLUDED_ #define _PARSER_HELPER_INCLUDED_
#include "compiler/ExtensionBehavior.h"
#include "compiler/localintermediate.h"
#include "compiler/ShHandle.h" #include "compiler/ShHandle.h"
#include "compiler/SymbolTable.h" #include "compiler/SymbolTable.h"
#include "compiler/localintermediate.h"
struct TMatrixFields { struct TMatrixFields {
bool wholeRow; bool wholeRow;
...@@ -17,13 +18,6 @@ struct TMatrixFields { ...@@ -17,13 +18,6 @@ struct TMatrixFields {
int col; int col;
}; };
typedef enum {
EBhRequire,
EBhEnable,
EBhWarn,
EBhDisable
} TBehavior;
struct TPragma { struct TPragma {
TPragma(bool o, bool d) : optimize(o), debug(d) { } TPragma(bool o, bool d) : optimize(o), debug(d) { }
bool optimize; bool optimize;
...@@ -36,12 +30,13 @@ struct TPragma { ...@@ -36,12 +30,13 @@ struct TPragma {
// they can be passed to the parser without needing a global. // they can be passed to the parser without needing a global.
// //
struct TParseContext { struct TParseContext {
TParseContext(TSymbolTable& symt, TIntermediate& interm, EShLanguage l, EShSpec s, TInfoSink& is) : TParseContext(TSymbolTable& symt, const TExtensionBehavior& ext, TIntermediate& interm, EShLanguage l, EShSpec s, TInfoSink& is) :
intermediate(interm), symbolTable(symt), infoSink(is), language(l), spec(s), treeRoot(0), intermediate(interm), symbolTable(symt), extensionBehavior(ext), infoSink(is), language(l), spec(s), treeRoot(0),
recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0), recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0),
inTypeParen(false), contextPragma(true, false) { } inTypeParen(false), contextPragma(true, false) { }
TIntermediate& intermediate; // to hold and build a parse tree TIntermediate& intermediate; // to hold and build a parse tree
TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed
TExtensionBehavior extensionBehavior; // mapping between supported extensions and current behavior.
TInfoSink& infoSink; TInfoSink& infoSink;
EShLanguage language; // vertex or fragment language (future: pack or unpack) EShLanguage language; // vertex or fragment language (future: pack or unpack)
EShSpec spec; // The language specification compiler conforms to - GLES2 or WebGL. EShSpec spec; // The language specification compiler conforms to - GLES2 or WebGL.
...@@ -53,8 +48,6 @@ struct TParseContext { ...@@ -53,8 +48,6 @@ struct TParseContext {
bool inTypeParen; // true if in parentheses, looking only for an identifier 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 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 functionReturnsValue; // true if a non-void function has a return
TMap<TString, TBehavior> extensionBehavior;
void initializeExtensionBehavior();
void error(TSourceLoc, const char *szReason, const char *szToken, void error(TSourceLoc, const char *szReason, const char *szToken,
const char *szExtraInfoFormat, ...); const char *szExtraInfoFormat, ...);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "compiler/ExtensionBehavior.h"
#include "compiler/InfoSink.h" #include "compiler/InfoSink.h"
#include "compiler/SymbolTable.h" #include "compiler/SymbolTable.h"
...@@ -44,6 +45,7 @@ public: ...@@ -44,6 +45,7 @@ public:
EShLanguage getLanguage() const { return language; } EShLanguage getLanguage() const { return language; }
EShSpec getSpec() const { return spec; } EShSpec getSpec() const { return spec; }
TSymbolTable& getSymbolTable() { return symbolTable; } TSymbolTable& getSymbolTable() { return symbolTable; }
TExtensionBehavior& getExtensionBehavior() { return extensionBehavior; }
TInfoSink& getInfoSink() { return infoSink; } TInfoSink& getInfoSink() { return infoSink; }
virtual bool compile(TIntermNode* root) = 0; virtual bool compile(TIntermNode* root) = 0;
...@@ -57,6 +59,8 @@ protected: ...@@ -57,6 +59,8 @@ protected:
// Built-in symbol table for the given language, spec, and resources. // Built-in symbol table for the given language, spec, and resources.
// It is preserved from compile-to-compile. // It is preserved from compile-to-compile.
TSymbolTable symbolTable; TSymbolTable symbolTable;
// Built-in extensions with default behavior.
TExtensionBehavior extensionBehavior;
// Output sink. // Output sink.
TInfoSink infoSink; TInfoSink infoSink;
}; };
......
...@@ -23,7 +23,8 @@ static bool InitializeSymbolTable( ...@@ -23,7 +23,8 @@ static bool InitializeSymbolTable(
TInfoSink& infoSink, TSymbolTable& symbolTable) TInfoSink& infoSink, TSymbolTable& symbolTable)
{ {
TIntermediate intermediate(infoSink); TIntermediate intermediate(infoSink);
TParseContext parseContext(symbolTable, intermediate, language, spec, infoSink); TExtensionBehavior extBehavior;
TParseContext parseContext(symbolTable, extBehavior, intermediate, language, spec, infoSink);
GlobalParseContext = &parseContext; GlobalParseContext = &parseContext;
...@@ -79,6 +80,14 @@ static bool GenerateBuiltInSymbolTable( ...@@ -79,6 +80,14 @@ static bool GenerateBuiltInSymbolTable(
return InitializeSymbolTable(builtIns.getBuiltInStrings(), language, spec, resources, infoSink, symbolTable); return InitializeSymbolTable(builtIns.getBuiltInStrings(), language, spec, resources, infoSink, symbolTable);
} }
static void DefineExtensionMacros(const TExtensionBehavior& extBehavior)
{
for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
iter != extBehavior.end(); ++iter) {
PredefineIntMacro(iter->first.c_str(), 1);
}
}
// //
// This is the platform independent interface between an OGL driver // This is the platform independent interface between an OGL driver
// and the shading language compiler. // and the shading language compiler.
...@@ -144,6 +153,7 @@ ShHandle ShConstructCompiler(EShLanguage language, EShSpec spec, const TBuiltInR ...@@ -144,6 +153,7 @@ ShHandle ShConstructCompiler(EShLanguage language, EShSpec spec, const TBuiltInR
ShDestruct(base); ShDestruct(base);
return 0; return 0;
} }
InitExtensionBehavior(*resources, compiler->getExtensionBehavior());
return reinterpret_cast<void*>(base); return reinterpret_cast<void*>(base);
} }
...@@ -196,14 +206,16 @@ int ShCompile( ...@@ -196,14 +206,16 @@ int ShCompile(
TIntermediate intermediate(infoSink); TIntermediate intermediate(infoSink);
TSymbolTable& symbolTable = compiler->getSymbolTable(); TSymbolTable& symbolTable = compiler->getSymbolTable();
const TExtensionBehavior& extBehavior = compiler->getExtensionBehavior();
TParseContext parseContext(symbolTable, intermediate, compiler->getLanguage(), compiler->getSpec(), infoSink); TParseContext parseContext(symbolTable, extBehavior, intermediate,
parseContext.initializeExtensionBehavior(); compiler->getLanguage(), compiler->getSpec(), infoSink);
GlobalParseContext = &parseContext; GlobalParseContext = &parseContext;
setInitialState(); setInitialState();
InitPreprocessor(); InitPreprocessor();
DefineExtensionMacros(extBehavior);
// //
// Parse the application's shaders. All the following symbol table // Parse the application's shaders. All the following symbol table
// work will be throw-away, so push a new allocation scope that can // work will be throw-away, so push a new allocation scope that can
......
...@@ -404,6 +404,7 @@ protected: ...@@ -404,6 +404,7 @@ protected:
typedef TVector<TIntermNode*> TIntermSequence; typedef TVector<TIntermNode*> TIntermSequence;
typedef TVector<int> TQualifierList; typedef TVector<int> TQualifierList;
typedef TMap<TString, TString> TPragmaTable;
// //
// Nodes that operate on an arbitrary sized set of children. // Nodes that operate on an arbitrary sized set of children.
// //
......
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