Add compilation mode flags for forward-compatible contexts and relaxed error checking. These initiate as arguments to ShCompile() and both default to being off.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@20817 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-03-08 18:49:22 +00:00
parent 9500dff05e
commit 4055816bc9
8 changed files with 42 additions and 23 deletions

View File

@ -259,7 +259,7 @@ bool CompileFile(const char *fileName, ShHandle compiler, int debugOptions, cons
for (int i = 0; i < 1000; ++i) {
for (int j = 0; j < 100; ++j)
#endif
ret = ShCompile(compiler, data, OutputMultipleStrings, EShOptNone, resources, debugOptions, 100);
ret = ShCompile(compiler, data, OutputMultipleStrings, EShOptNone, resources, debugOptions, 100, false, false);
#ifdef MEASURE_MEMORY
GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters));

View File

@ -178,7 +178,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
switch (getType().getBasicType()) {
case EbtFloat:
if (rightUnionArray[i] == 0.0f) {
infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
newConstArray[i].setFConst(FLT_MAX);
} else
newConstArray[i].setFConst(unionArray[i].getFConst() / rightUnionArray[i].getFConst());
@ -186,7 +185,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EbtInt:
if (rightUnionArray[i] == 0) {
infoSink.info.message(EPrefixWarning, "Divide by zero error during constant folding", getLine());
newConstArray[i].setIConst(0xEFFFFFFF);
} else
newConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst());

View File

@ -39,11 +39,12 @@
#include "osinclude.h"
#include <stdarg.h>
TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, int v, EProfile p, EShLanguage L, TInfoSink& is) :
TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, int v, EProfile p, EShLanguage L, TInfoSink& is,
bool fc, bool rc) :
intermediate(interm), symbolTable(symt), infoSink(is), language(L), treeRoot(0),
recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0),
switchNestingLevel(0), inTypeParen(false),
version(v), profile(p), futureCompatibility(false),
version(v), profile(p), forwardCompatible(fc), relaxedChecking(rc),
contextPragma(true, false)
{
for (int type = 0; type < EbtNumTypes; ++type)
@ -438,6 +439,7 @@ bool TParseContext::reservedErrorCheck(int line, const TString& identifier)
if (identifier.find("__") != TString::npos) {
//error(line, "Two consecutive underscores are reserved for future use.", identifier.c_str(), "", "");
//return true;
// TODO: make this an error
infoSink.info.message(EPrefixWarning, "Two consecutive underscores are reserved for future use.", line);
return false;
}

View File

@ -67,7 +67,8 @@ struct TPragma {
// they can be passed to the parser without needing a global.
//
struct TParseContext {
TParseContext(TSymbolTable&, TIntermediate&, int version, EProfile, EShLanguage, TInfoSink&);
TParseContext(TSymbolTable&, TIntermediate&, int version, EProfile, EShLanguage, TInfoSink&,
bool forwardCompatible = false, bool relaxedChecking = false);
TIntermediate& intermediate; // to hold and build a parse tree
TSymbolTable& symbolTable; // symbol table that goes with the current language, version, and profile
TInfoSink& infoSink;
@ -82,8 +83,10 @@ struct TParseContext {
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
int version; // the declared version in the shader (110 by default)
int version; // version, updated by #version in the shader
EProfile profile; // the declared profile in the shader (core by default)
bool forwardCompatible; // true if errors are to be given for use of deprecated features
bool relaxedChecking; // suppress warnings and reduce error checking
bool futureCompatibility; // true if requesting errors for future compatibility (false by default)
TMap<TString, TBehavior> extensionBehavior; // for each extension string, what it's current enablement is

View File

@ -482,7 +482,9 @@ int ShCompile(
const EShOptimizationLevel optLevel,
const TBuiltInResource* resources,
int debugOptions,
int defaultVersion
int defaultVersion, // use 100 for ES environment, 110 for desktop
bool forwardCompatible, // give errors for use of deprecated features
bool relaxedChecking // no warnings, reduced errors
)
{
if (!InitThread())
@ -520,7 +522,7 @@ int ShCompile(
// they get popped again further down.
AddContextSpecificSymbols(resources, compiler->infoSink, &symbolTable, version, profile, compiler->getLanguage());
TParseContext parseContext(symbolTable, intermediate, version, profile, compiler->getLanguage(), compiler->infoSink);
TParseContext parseContext(symbolTable, intermediate, version, profile, compiler->getLanguage(), compiler->infoSink, forwardCompatible, relaxedChecking);
if (! goodProfile)
parseContext.error(1, "incorrect", "#version", "");

View File

@ -132,10 +132,10 @@ void TParseContext::checkDeprecated(int line, EProfile callingProfile, int depVe
{
if (profile == callingProfile) {
if (version >= depVersion) {
if (futureCompatibility) {
if (forwardCompatible) {
error(line, "deprecated, may be removed in future release", featureDesc, "");
recover();
} else {
} else if (! relaxedChecking) {
infoSink.info.message(EPrefixWarning, (TString(featureDesc) + " deprecated in version " +
String(depVersion) + "; may be removed in future release").c_str(), line);
}

View File

@ -572,8 +572,10 @@ int PaIdentOrReserved(bool reserved, TParseContext& pc, int line, const char* te
pyylval->lex.line = line;
pyylval->lex.string = NewPoolTString(text);
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "using future reserved keyword", yylineno);
if (pc.futureCompatibility) {
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "using future reserved keyword", yylineno);
}
return PaIdentOrType(*pyylval->lex.string, pc, pyylval->lex.symbol);
}
@ -584,8 +586,10 @@ int PaES30ReservedFromGLSL(int version, TParseContext& pc, int line, const char*
pc.profile != EEsProfile && pc.version < version) {
pyylval->lex.line = yylineno;
pyylval->lex.string = NewPoolTString(yytext);
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "future reserved word in ES 300 and keyword in GLSL", yylineno);
if (pc.futureCompatibility) {
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "future reserved word in ES 300 and keyword in GLSL", yylineno);
}
return PaIdentOrType(*pyylval->lex.string, pc, pyylval->lex.symbol);
} else if (pc.profile == EEsProfile && pc.version >= 300)
@ -605,8 +609,10 @@ int PaPrecisionKeyword(TParseContext& pc, int line, const char* text, YYSTYPE* p
pyylval->lex.line = line;
pyylval->lex.string = NewPoolTString(text);
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "using ES precision qualifier keyword", yylineno);
if (pc.futureCompatibility) {
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "using ES precision qualifier keyword", yylineno);
}
return PaIdentOrType(*pyylval->lex.string, pc, pyylval->lex.symbol);
}
@ -618,8 +624,10 @@ int PaMatNxM(TParseContext& pc, int line, const char* text, YYSTYPE* pyylval, in
pyylval->lex.line = line;
pyylval->lex.string = NewPoolTString(text);
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "using future non-square matrix type keyword", yylineno);
if (pc.futureCompatibility) {
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "using future non-square matrix type keyword", yylineno);
}
return PaIdentOrType(*pyylval->lex.string, pc, pyylval->lex.symbol);
}
@ -636,8 +644,10 @@ int PaDMat(TParseContext& pc, int line, const char* text, YYSTYPE* pyylval, int
pyylval->lex.line = line;
pyylval->lex.string = NewPoolTString(text);
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "using future type keyword", yylineno);
if (pc.futureCompatibility) {
pc.infoSink.info.message(EPrefixWarning, pyylval->lex.string->c_str(), yylineno);
pc.infoSink.info.message(EPrefixWarning, "using future type keyword", yylineno);
}
return PaIdentOrType(*pyylval->lex.string, pc, pyylval->lex.symbol);
}
@ -685,7 +695,8 @@ void CPPWarningToInfoLog(const char *msg)
{
TParseContext& pc = *((TParseContext *)cpp->pC);
pc.infoSink.info.message(EPrefixWarning, msg, yylineno);
if (! pc.relaxedChecking)
pc.infoSink.info.message(EPrefixWarning, msg, yylineno);
}
void CPPShInfoLogMsg(const char *msg)
@ -910,6 +921,7 @@ void updateExtensionBehavior(const char* extName, const char* behavior)
pc.infoSink.info.message(EPrefixWarning, msg.c_str(), yylineno);
break;
}
return;
} else
iter->second = behaviorVal;

View File

@ -155,7 +155,9 @@ SH_IMPORT_EXPORT int ShCompile(
const EShOptimizationLevel,
const TBuiltInResource *resources,
int debugOptions,
int defaultVersion = 110 // use 100 for ES environment
int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader
bool forwardCompatible = false, // give errors for use of deprecated features
bool relaxedChecking = false // no warnings, reduced errors
);