mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-09 12:00:05 +00:00
Support suffixes for floats and doubles (none were supported in 110).
Add preprocessor support for parsing doubles. Add double support to the flex stage. Put in some of the basic double supported needed in the front end. Add generic support for version numbers in the preprocessor, and the core, compatibility, and es profiles. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@19949 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
e95ecc54fa
commit
5d3e2e35b6
@ -41,6 +41,7 @@
|
||||
enum TBasicType {
|
||||
EbtVoid,
|
||||
EbtFloat,
|
||||
EbtDouble,
|
||||
EbtInt,
|
||||
EbtBool,
|
||||
EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
|
||||
|
@ -42,13 +42,16 @@ public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
|
||||
void setIConst(int i) {iConst = i; type = EbtInt; }
|
||||
void setFConst(float f) {fConst = f; type = EbtFloat; }
|
||||
void setDConst(double d) {dConst = d; type = EbtDouble; }
|
||||
void setBConst(bool b) {bConst = b; type = EbtBool; }
|
||||
|
||||
int getIConst() { return iConst; }
|
||||
float getFConst() { return fConst; }
|
||||
double getDConst() { return dConst; }
|
||||
bool getBConst() { return bConst; }
|
||||
int getIConst() const { return iConst; }
|
||||
float getFConst() const { return fConst; }
|
||||
double getDConst() const { return dConst; }
|
||||
bool getBConst() const { return bConst; }
|
||||
|
||||
bool operator==(const int i) const
|
||||
@ -67,6 +70,14 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const double d) const
|
||||
{
|
||||
if (d == dConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator==(const bool b) const
|
||||
{
|
||||
if (b == bConst)
|
||||
@ -90,6 +101,11 @@ public:
|
||||
if (constant.fConst == fConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtDouble:
|
||||
if (constant.dConst == dConst)
|
||||
return true;
|
||||
|
||||
break;
|
||||
case EbtBool:
|
||||
if (constant.bConst == bConst)
|
||||
@ -134,6 +150,11 @@ public:
|
||||
if (fConst > constant.fConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtDouble:
|
||||
if (dConst > constant.dConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
@ -156,6 +177,11 @@ public:
|
||||
if (fConst < constant.fConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
case EbtDouble:
|
||||
if (dConst < constant.dConst)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
default:
|
||||
assert(false && "Default missing");
|
||||
@ -172,6 +198,7 @@ public:
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
|
||||
case EbtFloat: returnValue.setFConst(fConst + constant.fConst); break;
|
||||
case EbtDouble: returnValue.setDConst(dConst + constant.dConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
@ -185,6 +212,7 @@ public:
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
|
||||
case EbtFloat: returnValue.setFConst(fConst - constant.fConst); break;
|
||||
case EbtDouble: returnValue.setDConst(dConst - constant.dConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
@ -198,6 +226,7 @@ public:
|
||||
switch (type) {
|
||||
case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
|
||||
case EbtFloat: returnValue.setFConst(fConst * constant.fConst); break;
|
||||
case EbtDouble: returnValue.setDConst(dConst * constant.dConst); break;
|
||||
default: assert(false && "Default missing");
|
||||
}
|
||||
|
||||
@ -307,6 +336,7 @@ private:
|
||||
int iConst; // used for ivec, scalar ints
|
||||
bool bConst; // used for bvec, scalar bools
|
||||
float fConst; // used for vec, mat, scalar floats
|
||||
double dConst; // used for dvec, dmat, scalar doubles
|
||||
} ;
|
||||
|
||||
TBasicType type;
|
||||
|
@ -235,6 +235,7 @@ public:
|
||||
switch (t) {
|
||||
case EbtVoid: return "void"; break;
|
||||
case EbtFloat: return "float"; break;
|
||||
case EbtDouble: return "double"; break;
|
||||
case EbtInt: return "int"; break;
|
||||
case EbtBool: return "bool"; break;
|
||||
case EbtSampler1D: return "sampler1D"; break;
|
||||
|
@ -187,6 +187,7 @@ enum TOperator {
|
||||
EOpConstructInt,
|
||||
EOpConstructBool,
|
||||
EOpConstructFloat,
|
||||
EOpConstructDouble,
|
||||
EOpConstructVec2,
|
||||
EOpConstructVec3,
|
||||
EOpConstructVec4,
|
||||
|
@ -243,9 +243,10 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode,
|
||||
//
|
||||
TBasicType newType = EbtVoid;
|
||||
switch (op) {
|
||||
case EOpConstructInt: newType = EbtInt; break;
|
||||
case EOpConstructBool: newType = EbtBool; break;
|
||||
case EOpConstructFloat: newType = EbtFloat; break;
|
||||
case EOpConstructInt: newType = EbtInt; break;
|
||||
case EOpConstructBool: newType = EbtBool; break;
|
||||
case EOpConstructFloat: newType = EbtFloat; break;
|
||||
case EOpConstructDouble: newType = EbtDouble; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,7 @@ void TType::buildMangledName(TString& mangledName)
|
||||
|
||||
switch (type) {
|
||||
case EbtFloat: mangledName += 'f'; break;
|
||||
case EbtDouble: mangledName += 'd'; break;
|
||||
case EbtInt: mangledName += 'i'; break;
|
||||
case EbtBool: mangledName += 'b'; break;
|
||||
case EbtSampler1D: mangledName += "s1"; break;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -93,6 +93,7 @@ Jutta Degener, 1995
|
||||
float f;
|
||||
int i;
|
||||
bool b;
|
||||
double d;
|
||||
};
|
||||
TSymbol* symbol;
|
||||
} lex;
|
||||
@ -278,8 +279,8 @@ primary_expression
|
||||
}
|
||||
| DOUBLECONSTANT {
|
||||
constUnion *unionArray = new constUnion[1];
|
||||
unionArray->setFConst($1.f);
|
||||
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtFloat, EvqConst), $1.line);
|
||||
unionArray->setDConst($1.d);
|
||||
$$ = parseContext.intermediate.addConstantUnion(unionArray, TType(EbtDouble, EvqConst), $1.line);
|
||||
}
|
||||
| BOOLCONSTANT {
|
||||
constUnion *unionArray = new constUnion[1];
|
||||
@ -1825,7 +1826,7 @@ type_specifier_nonarray
|
||||
| DOUBLE {
|
||||
TQualifier qual = parseContext.symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
|
||||
// TODO: implement EbtDouble, check all float types
|
||||
$$.setBasic(EbtFloat, qual, $1.line);
|
||||
$$.setBasic(EbtDouble, qual, $1.line);
|
||||
}
|
||||
| INT {
|
||||
// TODO: implement EbtUint, check all int types
|
||||
|
@ -380,6 +380,15 @@ void OutputConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
|
||||
out.debug << buf << "\n";
|
||||
}
|
||||
break;
|
||||
case EbtDouble:
|
||||
{
|
||||
const int maxSize = 300;
|
||||
char buf[maxSize];
|
||||
sprintf_s(buf, maxSize, "%f (%s)", node->getUnionArrayPointer()[i].getDConst(), "const double");
|
||||
|
||||
out.debug << buf << "\n";
|
||||
}
|
||||
break;
|
||||
case EbtInt:
|
||||
{
|
||||
const int maxSize = 300;
|
||||
|
@ -127,6 +127,10 @@ struct CPPStruct_Rec {
|
||||
int PaArgc; // count of strings in the array
|
||||
char** PaArgv; // our array of strings to parse
|
||||
unsigned int tokensBeforeEOF : 1;
|
||||
|
||||
// Declared version of the shader
|
||||
int version;
|
||||
int profileAtom;
|
||||
};
|
||||
|
||||
#endif // !defined(__COMPILE_H)
|
||||
|
@ -115,6 +115,9 @@ static int __LINE__Atom = 0;
|
||||
static int __FILE__Atom = 0;
|
||||
static int __VERSION__Atom = 0;
|
||||
static int versionAtom = 0;
|
||||
static int coreAtom = 0;
|
||||
static int compatibilityAtom = 0;
|
||||
static int esAtom = 0;
|
||||
static int extensionAtom = 0;
|
||||
|
||||
static Scope *macros = 0;
|
||||
@ -149,6 +152,9 @@ int InitCPP(void)
|
||||
__FILE__Atom = LookUpAddString(atable, "__FILE__");
|
||||
__VERSION__Atom = LookUpAddString(atable, "__VERSION__");
|
||||
versionAtom = LookUpAddString(atable, "version");
|
||||
coreAtom = LookUpAddString(atable, "core");
|
||||
compatibilityAtom = LookUpAddString(atable, "compatibility");
|
||||
esAtom = LookUpAddString(atable, "es");
|
||||
extensionAtom = LookUpAddString(atable, "extension");
|
||||
macros = NewScopeInPool(mem_CreatePool(0, 0));
|
||||
strcpy(buffer, "PROFILE_");
|
||||
@ -660,8 +666,6 @@ static int CPPpragma(yystypepp * yylvalpp)
|
||||
return token;
|
||||
} // CPPpragma
|
||||
|
||||
#define GL2_VERSION_NUMBER 110
|
||||
|
||||
static int CPPversion(yystypepp * yylvalpp)
|
||||
{
|
||||
|
||||
@ -680,10 +684,8 @@ static int CPPversion(yystypepp * yylvalpp)
|
||||
CPPErrorToInfoLog("#version");
|
||||
|
||||
yylvalpp->sc_int=atoi(yylvalpp->symbol_name);
|
||||
//SetVersionNumber(yylvalpp->sc_int);
|
||||
|
||||
if (yylvalpp->sc_int != GL2_VERSION_NUMBER)
|
||||
CPPShInfoLogMsg("Version number not supported by GL2");
|
||||
|
||||
cpp->version = yylvalpp->sc_int;
|
||||
|
||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||
|
||||
@ -691,8 +693,20 @@ static int CPPversion(yystypepp * yylvalpp)
|
||||
return token;
|
||||
}
|
||||
else{
|
||||
CPPErrorToInfoLog("#version");
|
||||
cpp->profileAtom = yylvalpp->sc_ident;
|
||||
if (cpp->profileAtom != coreAtom &&
|
||||
cpp->profileAtom != compatibilityAtom &&
|
||||
cpp->profileAtom != esAtom)
|
||||
CPPErrorToInfoLog("#version profile name");
|
||||
|
||||
token = cpp->currentInput->scan(cpp->currentInput, yylvalpp);
|
||||
|
||||
if (token == '\n')
|
||||
return token;
|
||||
else
|
||||
CPPErrorToInfoLog("#version");
|
||||
}
|
||||
|
||||
return token;
|
||||
} // CPPversion
|
||||
|
||||
|
@ -132,6 +132,8 @@ int ResetPreprocessor(void)
|
||||
cpp->elsedepth[cpp->elsetracker]=0;
|
||||
cpp->elsetracker=0;
|
||||
cpp->tokensBeforeEOF = 0;
|
||||
cpp->version = 110;
|
||||
cpp->profileAtom = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
typedef struct {
|
||||
int sc_int;
|
||||
float sc_fval;
|
||||
double sc_dval;
|
||||
int sc_ident;
|
||||
char symbol_name[MAX_SYMBOL_NAME_LEN+1];
|
||||
} yystypepp;
|
||||
|
@ -225,47 +225,9 @@ int ScanFromString(char *s)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////// Floating point constants: /////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* lBuildFloatValue() - Quick and dirty conversion to floating point. Since all
|
||||
* we need is single precision this should be quite precise.
|
||||
*/
|
||||
|
||||
static float lBuildFloatValue(const char *str, int len, int exp)
|
||||
{
|
||||
double val, expval, ten;
|
||||
int ii, llen, absexp;
|
||||
float rv;
|
||||
|
||||
val = 0.0;
|
||||
llen = len;
|
||||
for (ii = 0; ii < len; ii++)
|
||||
val = val*10.0 + (str[ii] - '0');
|
||||
if (exp != 0) {
|
||||
absexp = exp > 0 ? exp : -exp;
|
||||
expval = 1.0f;
|
||||
ten = 10.0;
|
||||
while (absexp) {
|
||||
if (absexp & 1)
|
||||
expval *= ten;
|
||||
ten *= ten;
|
||||
absexp >>= 1;
|
||||
}
|
||||
if (exp >= 0) {
|
||||
val *= expval;
|
||||
} else {
|
||||
val /= expval;
|
||||
}
|
||||
}
|
||||
rv = (float)val;
|
||||
if (isinff(rv)) {
|
||||
CPPErrorToInfoLog(" ERROR___FP_CONST_OVERFLOW");
|
||||
}
|
||||
return rv;
|
||||
} // lBuildFloatValue
|
||||
|
||||
|
||||
/*
|
||||
* lFloatConst() - Scan a floating point constant. Assumes that the scanner
|
||||
* lFloatConst() - Scan a single- or double-precision floating point constant. Assumes that the scanner
|
||||
* has seen at least one digit, followed by either a decimal '.' or the
|
||||
* letter 'e'.
|
||||
*/
|
||||
@ -274,7 +236,6 @@ static int lFloatConst(char *str, int len, int ch, yystypepp * yylvalpp)
|
||||
{
|
||||
int HasDecimal, declen, exp, ExpSign;
|
||||
int str_len;
|
||||
float lval;
|
||||
|
||||
HasDecimal = 0;
|
||||
declen = 0;
|
||||
@ -303,41 +264,76 @@ static int lFloatConst(char *str, int len, int ch, yystypepp * yylvalpp)
|
||||
// Exponent:
|
||||
|
||||
if (ch == 'e' || ch == 'E') {
|
||||
ExpSign = 1;
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
if (ch == '+') {
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
} else if (ch == '-') {
|
||||
ExpSign = -1;
|
||||
str[len++]=ch;
|
||||
if (len >= MAX_SYMBOL_NAME_LEN) {
|
||||
CPPErrorToInfoLog("ERROR___FP_CONST_TOO_LONG");
|
||||
len = 1,str_len=1;
|
||||
} else {
|
||||
ExpSign = 1;
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
}
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
while (ch >= '0' && ch <= '9') {
|
||||
exp = exp*10 + ch - '0';
|
||||
str[len++]=ch;
|
||||
if (ch == '+') {
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
} else if (ch == '-') {
|
||||
ExpSign = -1;
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
}
|
||||
} else {
|
||||
CPPErrorToInfoLog("ERROR___ERROR_IN_EXPONENT");
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
while (ch >= '0' && ch <= '9') {
|
||||
if (len < MAX_SYMBOL_NAME_LEN) {
|
||||
exp = exp*10 + ch - '0';
|
||||
str[len++]=ch;
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
} else {
|
||||
CPPErrorToInfoLog("ERROR___FP_CONST_TOO_LONG");
|
||||
len = 1,str_len=1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CPPErrorToInfoLog("ERROR___ERROR_IN_EXPONENT");
|
||||
}
|
||||
exp *= ExpSign;
|
||||
}
|
||||
exp *= ExpSign;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
lval = 0.0f;
|
||||
yylvalpp->sc_fval = 0.0f;
|
||||
yylvalpp->sc_dval = 0.0;
|
||||
strcpy(str,"0.0");
|
||||
} else {
|
||||
if (ch == 'l' || ch == 'L') {
|
||||
int ch2 = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
if (ch2 != 'f' && ch2 != 'F') {
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch2, yylvalpp);
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
} else {
|
||||
if (len < MAX_SYMBOL_NAME_LEN-1) {
|
||||
str[len++] = ch;
|
||||
str[len++] = ch2;
|
||||
} else {
|
||||
CPPErrorToInfoLog("ERROR___FP_CONST_TOO_LONG");
|
||||
len = 1,str_len=1;
|
||||
}
|
||||
}
|
||||
} else if (ch == 'f' || ch == 'F') {
|
||||
if (len < MAX_SYMBOL_NAME_LEN)
|
||||
str[len++] = ch;
|
||||
else {
|
||||
CPPErrorToInfoLog("ERROR___FP_CONST_TOO_LONG");
|
||||
len = 1,str_len=1;
|
||||
}
|
||||
} else
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
|
||||
str[len]='\0';
|
||||
lval = lBuildFloatValue(str, str_len, exp - declen);
|
||||
|
||||
yylvalpp->sc_dval = strtod(str, 0);
|
||||
yylvalpp->sc_fval = (float)yylvalpp->sc_dval;
|
||||
}
|
||||
// Suffix:
|
||||
|
||||
yylvalpp->sc_fval = lval;
|
||||
strcpy(yylvalpp->symbol_name,str);
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
|
||||
return CPP_FLOATCONSTANT;
|
||||
} // lFloatConst
|
||||
|
||||
@ -454,7 +450,7 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
||||
}
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
} while (ch >= '0' && ch <= '7');
|
||||
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E')
|
||||
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L')
|
||||
return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);
|
||||
yylvalpp->symbol_name[len] = '\0';
|
||||
cpp->currentInput->ungetch(cpp->currentInput, ch, yylvalpp);
|
||||
@ -476,7 +472,7 @@ static int byte_scan(InputSrc *in, yystypepp * yylvalpp)
|
||||
ch = cpp->currentInput->getch(cpp->currentInput, yylvalpp);
|
||||
}
|
||||
} while (ch >= '0' && ch <= '9');
|
||||
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E') {
|
||||
if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'h' || ch == 'x'|| ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L') {
|
||||
return lFloatConst(yylvalpp->symbol_name, len, ch, yylvalpp);
|
||||
} else {
|
||||
yylvalpp->symbol_name[len] = '\0';
|
||||
|
@ -83,6 +83,8 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
typedef struct CPPStruct_Rec CPPStruct;
|
||||
|
||||
// Multi-threading note: The existence of this global makes
|
||||
// this preprocessing single-threaded only.
|
||||
extern CPPStruct *cpp;
|
||||
|
||||
#undef CPPC_DEBUG_THE_COMPILER
|
||||
|
Loading…
Reference in New Issue
Block a user