(glslang) Use string append

This commit is contained in:
LibretroAdmin 2022-07-31 22:48:30 +02:00
parent e602f8762b
commit 4b8d3ab8a0
8 changed files with 921 additions and 886 deletions

View File

@ -54,7 +54,13 @@ void C_DECL TParseContextBase::error(const TSourceLoc& loc, const char* szReason
safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args);
infoSink.info.append("ERROR: ");
infoSink.info.location(loc);
infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n";
infoSink.info.append("'");
infoSink.info << szToken;
infoSink.info.append("' : ");
infoSink.info << szReason;
infoSink.info.append(" ");
infoSink.info << szExtraInfo;
infoSink.info.append("\n");
++numErrors;
va_end(args);
@ -74,7 +80,13 @@ void C_DECL TParseContextBase::warn(const TSourceLoc& loc, const char* szReason,
safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args);
infoSink.info.append("WARNING: ");
infoSink.info.location(loc);
infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n";
infoSink.info.append("'");
infoSink.info << szToken;
infoSink.info.append("' : ");
infoSink.info << szReason;
infoSink.info.append(" ");
infoSink.info << szExtraInfo;
infoSink.info.append("\n");
va_end(args);
}
@ -88,7 +100,13 @@ void C_DECL TParseContextBase::ppError(const TSourceLoc& loc, const char* szReas
safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args);
infoSink.info.append("ERROR: ");
infoSink.info.location(loc);
infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n";
infoSink.info.append("'");
infoSink.info << szToken;
infoSink.info.append("' : ");
infoSink.info << szReason;
infoSink.info.append(" ");
infoSink.info << szExtraInfo;
infoSink.info.append("\n");
++numErrors;
va_end(args);
@ -106,7 +124,13 @@ void C_DECL TParseContextBase::ppWarn(const TSourceLoc& loc, const char* szReaso
safe_vsprintf(szExtraInfo, maxSize, szExtraInfoFormat, args);
infoSink.info.append("WARNING: ");
infoSink.info.location(loc);
infoSink.info << "'" << szToken << "' : " << szReason << " " << szExtraInfo << "\n";
infoSink.info.append("'");
infoSink.info << szToken;
infoSink.info.append("' : ");
infoSink.info << szReason;
infoSink.info.append(" ");
infoSink.info << szExtraInfo;
infoSink.info.append("\n");
va_end(args);
}

View File

@ -82,9 +82,7 @@ static TBuiltInParseables* CreateBuiltInParseables(TInfoSink& infoSink, EShSourc
#endif
default:
infoSink.info.append("INTERNAL ERROR: ");
infoSink.info.append("Unable to determine source language");
infoSink.info.append("\n");
infoSink.info.append("INTERNAL ERROR: Unable to determine source language\n");
return nullptr;
}
}
@ -110,9 +108,7 @@ static TParseContextBase* CreateParseContext(TSymbolTable& symbolTable, TInterme
language, infoSink, sourceEntryPointName.c_str(), forwardCompatible, messages);
#endif
default:
infoSink.info.append("INTERNAL ERROR: ");
infoSink.info.append("Unable to determine source language");
infoSink.info.append("\n");
infoSink.info.append("INTERNAL ERROR: Unable to determine source language\n");
return nullptr;
}
}
@ -256,9 +252,7 @@ static bool InitializeSymbolTable(const TString& builtIns, int version, EProfile
TInputScanner input(1, builtInShaders, builtInLengths);
if (! _parseContext->parseShaderStrings(ppContext, input) != 0)
{
infoSink.info.append("INTERNAL ERROR: ");
infoSink.info.append("Unable to parse built-ins");
infoSink.info.append("\n");
infoSink.info.append("INTERNAL ERROR: Unable to parse built-ins\n");
return false;
}
@ -453,9 +447,7 @@ static bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool ve
if (profile == ENoProfile) {
if (version == 300 || version == 310 || version == 320) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: versions 300, 310, and 320 require specifying the 'es' profile");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: versions 300, 310, and 320 require specifying the 'es' profile\n");
profile = EEsProfile;
} else if (version == 100)
profile = EEsProfile;
@ -467,9 +459,7 @@ static bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool ve
// a profile was provided...
if (version < 150) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: versions before 150 do not allow a profile token");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: versions before 150 do not allow a profile token\n");
if (version == 100)
profile = EEsProfile;
else
@ -477,17 +467,13 @@ static bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool ve
} else if (version == 300 || version == 310 || version == 320) {
if (profile != EEsProfile) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: versions 300, 310, and 320 support only the es profile");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: versions 300, 310, and 320 support only the es profile\n");
}
profile = EEsProfile;
} else {
if (profile == EEsProfile) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: only version 300, 310, and 320 support the es profile");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: only version 300, 310, and 320 support the es profile\n");
if (version >= FirstProfileVersion)
profile = ECoreProfile;
else
@ -523,9 +509,7 @@ static bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool ve
// unknown version
default:
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("version not supported");
infoSink.info.append("\n");
infoSink.info.append("ERROR: version not supported\n");
if (profile == EEsProfile)
version = 310;
else {
@ -541,9 +525,7 @@ static bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool ve
if ((profile == EEsProfile && version < 310) ||
(profile != EEsProfile && version < 150)) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: geometry shaders require es profile with version 310 or non-es profile with version 150 or above");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: geometry shaders require es profile with version 310 or non-es profile with version 150 or above\n");
version = (profile == EEsProfile) ? 310 : 150;
if (profile == EEsProfile || profile == ENoProfile)
profile = ECoreProfile;
@ -554,9 +536,7 @@ static bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool ve
if ((profile == EEsProfile && version < 310) ||
(profile != EEsProfile && version < 150)) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: tessellation shaders require es profile with version 310 or non-es profile with version 150 or above");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: tessellation shaders require es profile with version 310 or non-es profile with version 150 or above\n");
version = (profile == EEsProfile) ? 310 : 400; // 150 supports the extension, correction is to 400 which does not
if (profile == EEsProfile || profile == ENoProfile)
profile = ECoreProfile;
@ -566,9 +546,7 @@ static bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool ve
if ((profile == EEsProfile && version < 310) ||
(profile != EEsProfile && version < 420)) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: compute shaders require es profile with version 310 or above, or non-es profile with version 420 or above");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: compute shaders require es profile with version 310 or above, or non-es profile with version 420 or above\n");
version = profile == EEsProfile ? 310 : 420;
}
break;
@ -578,9 +556,7 @@ static bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool ve
if (profile == EEsProfile && version >= 300 && versionNotFirst) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: statement must appear first in es-profile shader; before comments or newlines");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: statement must appear first in es-profile shader; before comments or newlines\n");
}
// Check for SPIR-V compatibility
@ -589,37 +565,27 @@ static bool DeduceVersionProfile(TInfoSink& infoSink, EShLanguage stage, bool ve
case EEsProfile:
if (spvVersion.vulkan > 0 && version < 310) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: ES shaders for Vulkan SPIR-V require version 310 or higher");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: ES shaders for Vulkan SPIR-V require version 310 or higher\n");
version = 310;
}
if (spvVersion.openGl >= 100) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: ES shaders for OpenGL SPIR-V are not supported");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: ES shaders for OpenGL SPIR-V are not supported\n");
version = 310;
}
break;
case ECompatibilityProfile:
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: compilation for SPIR-V does not support the compatibility profile");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: compilation for SPIR-V does not support the compatibility profile\n");
break;
default:
if (spvVersion.vulkan > 0 && version < 140) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: Desktop shaders for Vulkan SPIR-V require version 140 or higher");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: Desktop shaders for Vulkan SPIR-V require version 140 or higher\n");
version = 140;
}
if (spvVersion.openGl >= 100 && version < 330) {
correct = false;
infoSink.info.append("ERROR: ");
infoSink.info.append("#version: Desktop shaders for OpenGL SPIR-V require version 330 or higher");
infoSink.info.append("\n");
infoSink.info.append("ERROR: #version: Desktop shaders for OpenGL SPIR-V require version 330 or higher\n");
version = 330;
}
break;
@ -1112,9 +1078,7 @@ struct DoFullParse{
if (success && intermediate.getTreeRoot()) {
if (optLevel == EShOptNoGeneration)
{
_parseContext.infoSink.info.append("ERROR: ");
_parseContext.infoSink.info.append("No errors. No code generation or linking was requested.");
_parseContext.infoSink.info.append("\n");
_parseContext.infoSink.info.append("ERROR: No errors. No code generation or linking was requested.\n");
}
else
success = intermediate.postProcess(intermediate.getTreeRoot(), _parseContext.getLanguage());
@ -1448,14 +1412,10 @@ bool TProgram::linkStage(EShLanguage stage, EShMessages messages)
}
if (numEsShaders > 0 && numNonEsShaders > 0) {
infoSink->info.append("ERROR: ");
infoSink->info.append("Cannot mix ES profile with non-ES profile shaders");
infoSink->info.append("\n");
infoSink->info.append("ERROR: Cannot mix ES profile with non-ES profile shaders\n");
return false;
} else if (numEsShaders > 1) {
infoSink->info.append("ERROR: ");
infoSink->info.append("Cannot attach multiple ES shaders of the same type to a single program");
infoSink->info.append("\n");
infoSink->info.append("ERROR: Cannot attach multiple ES shaders of the same type to a single program\n");
return false;
}

View File

@ -172,21 +172,33 @@ void TType::buildMangledName(TString& mangledName) const
void TVariable::dump(TInfoSink& infoSink) const
{
infoSink.debug << getName().c_str() << ": " << type.getStorageQualifierString() << " " << type.getBasicTypeString();
if (type.isArray()) {
infoSink.debug << "[0]";
}
infoSink.debug << "\n";
infoSink.debug << getName().c_str();
infoSink.debug.append(": ");
infoSink.debug << type.getStorageQualifierString();
infoSink.debug.append(" ");
infoSink.debug << type.getBasicTypeString();
if (type.isArray())
infoSink.debug.append("[0]");
infoSink.debug.append("\n");
}
void TFunction::dump(TInfoSink& infoSink) const
{
infoSink.debug << getName().c_str() << ": " << returnType.getBasicTypeString() << " " << getMangledName().c_str() << "\n";
infoSink.debug << getName().c_str();
infoSink.debug.append(": ");
infoSink.debug << returnType.getBasicTypeString();
infoSink.debug.append(" ");
infoSink.debug << getMangledName().c_str();
infoSink.debug.append("\n");
}
void TAnonMember::dump(TInfoSink& TInfoSink) const
{
TInfoSink.debug << "anonymous member " << getMemberNumber() << " of " << getAnonContainer().getName().c_str() << "\n";
TInfoSink.debug.append("anonymous member ");
TInfoSink.debug << getMemberNumber();
TInfoSink.debug.append(" of ");
TInfoSink.debug << getAnonContainer().getName().c_str();
TInfoSink.debug.append("\n");
}
void TSymbolTableLevel::dump(TInfoSink &infoSink) const
@ -199,7 +211,9 @@ void TSymbolTableLevel::dump(TInfoSink &infoSink) const
void TSymbolTable::dump(TInfoSink &infoSink) const
{
for (int level = currentLevel(); level >= 0; --level) {
infoSink.debug << "LEVEL " << level << "\n";
infoSink.debug.append("LEVEL ");
infoSink.debug << level;
infoSink.debug.append("\n");
table[level]->dump(infoSink);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -55,8 +55,11 @@ namespace glslang {
//
void TIntermediate::error(TInfoSink& infoSink, const char* message)
{
infoSink.info.append("ERROR: ");
infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n";
infoSink.info.append("ERROR: Linking");
infoSink.info << StageName(language);
infoSink.info.append(" stage: ");
infoSink.info << message;
infoSink.info.append("\n");
++numErrors;
}
@ -64,8 +67,11 @@ void TIntermediate::error(TInfoSink& infoSink, const char* message)
// Link-time warning.
void TIntermediate::warn(TInfoSink& infoSink, const char* message)
{
infoSink.info.append("WARNING: ");
infoSink.info << "Linking " << StageName(language) << " stage: " << message << "\n";
infoSink.info.append("WARNING: Linking");
infoSink.info << StageName(language);
infoSink.info.append(" stage: ");
infoSink.info << message;
infoSink.info.append("\n");
}
// TODO: 4.4 offset/align: "Two blocks linked together in the same program with the same block
@ -215,7 +221,9 @@ void TIntermediate::mergeBodies(TInfoSink& infoSink, TIntermSequence& globals, c
TIntermAggregate* unitBody = unitGlobals[unitChild]->getAsAggregate();
if (body && unitBody && body->getOp() == EOpFunction && unitBody->getOp() == EOpFunction && body->getName() == unitBody->getName()) {
error(infoSink, "Multiple function bodies in multiple compilation units for the same signature in the same stage:");
infoSink.info << " " << globals[child]->getAsAggregate()->getName() << "\n";
infoSink.info.append(" ");
infoSink.info << globals[child]->getAsAggregate()->getName();
infoSink.info.append("\n");
}
}
}
@ -373,14 +381,23 @@ void TIntermediate::mergeErrorCheck(TInfoSink& infoSink, const TIntermSymbol& sy
if (! symbol.getConstArray().empty() && ! unitSymbol.getConstArray().empty()) {
if (symbol.getConstArray() != unitSymbol.getConstArray()) {
error(infoSink, "Initializers must match:");
infoSink.info << " " << symbol.getName() << "\n";
infoSink.info.append(" ");
infoSink.info << symbol.getName();
infoSink.info.append("\n");
}
}
}
if (writeTypeComparison)
infoSink.info << " " << symbol.getName() << ": \"" << symbol.getType().getCompleteString() << "\" versus \"" <<
unitSymbol.getType().getCompleteString() << "\"\n";
{
infoSink.info.append(" ");
infoSink.info << symbol.getName();
infoSink.info.append(": \"");
infoSink.info << symbol.getType().getCompleteString();
infoSink.info.append("\" versus \"");
infoSink.info << unitSymbol.getType().getCompleteString();
infoSink.info.append("\"\n");
}
}
//
@ -435,8 +452,8 @@ void TIntermediate::finalCheck(TInfoSink& infoSink)
// compile-time or link-time error to have different values specified for the stride for the same buffer."
if (xfbBuffers[b].stride != TQualifier::layoutXfbStrideEnd && xfbBuffers[b].implicitStride > xfbBuffers[b].stride) {
error(infoSink, "xfb_stride is too small to hold all buffer entries:");
infoSink.info.append("ERROR: ");
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << ", minimum stride needed: " << xfbBuffers[b].implicitStride << "\n";
infoSink.info.append("ERROR: xfb_buffer ");
infoSink.info << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << ", minimum stride needed: " << xfbBuffers[b].implicitStride << "\n";
}
if (xfbBuffers[b].stride == TQualifier::layoutXfbStrideEnd)
xfbBuffers[b].stride = xfbBuffers[b].implicitStride;
@ -446,20 +463,20 @@ void TIntermediate::finalCheck(TInfoSink& infoSink)
// multiple of 4, or a compile-time or link-time error results."
if (xfbBuffers[b].containsDouble && ! IsMultipleOfPow2(xfbBuffers[b].stride, 8)) {
error(infoSink, "xfb_stride must be multiple of 8 for buffer holding a double:");
infoSink.info.append("ERROR: ");
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
infoSink.info.append("ERROR: xfb_buffer ");
infoSink.info << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
} else if (! IsMultipleOfPow2(xfbBuffers[b].stride, 4)) {
error(infoSink, "xfb_stride must be multiple of 4:");
infoSink.info.append("ERROR: ");
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
infoSink.info.append("ERROR: xfb_buffer ");
infoSink.info << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
}
// "The resulting stride (implicit or explicit), when divided by 4, must be less than or equal to the
// implementation-dependent constant gl_MaxTransformFeedbackInterleavedComponents."
if (xfbBuffers[b].stride > (unsigned int)(4 * resources.maxTransformFeedbackInterleavedComponents)) {
error(infoSink, "xfb_stride is too large:");
infoSink.info.append("ERROR: ");
infoSink.info << " xfb_buffer " << (unsigned int)b << ", components (1/4 stride) needed are " << xfbBuffers[b].stride/4 << ", gl_MaxTransformFeedbackInterleavedComponents is " << resources.maxTransformFeedbackInterleavedComponents << "\n";
infoSink.info.append("ERROR: xfb_buffer ");
infoSink.info << (unsigned int)b << ", components (1/4 stride) needed are " << xfbBuffers[b].stride/4 << ", gl_MaxTransformFeedbackInterleavedComponents is " << resources.maxTransformFeedbackInterleavedComponents << "\n";
}
}
@ -587,7 +604,11 @@ void TIntermediate::checkCallGraphCycles(TInfoSink& infoSink)
// Then, we found a back edge
if (! child->errorGiven) {
error(infoSink, "Recursion detected:");
infoSink.info << " " << call->callee << " calling " << child->callee << "\n";
infoSink.info.append(" ");
infoSink.info << call->callee;
infoSink.info.append(" calling ");
infoSink.info << child->callee;
infoSink.info.append("\n");
child->errorGiven = true;
recursive = true;
}
@ -670,7 +691,9 @@ void TIntermediate::checkCallGraphBodies(TInfoSink& infoSink)
if (call->visited) {
if (call->calleeBodyPosition == -1) {
error(infoSink, "No function definition (body) found: ");
infoSink.info << " " << call->callee << "\n";
infoSink.info.append(" ");
infoSink.info << call->callee;
infoSink.info.append("\n");
} else
reachable[call->calleeBodyPosition] = true;
}

View File

@ -633,9 +633,14 @@ int TPpContext::CPPinclude(TPpToken* ppToken)
const bool forNextLine = _parseContext.lineDirectiveShouldSetNextLine();
std::ostringstream prologue;
std::ostringstream epilogue;
prologue << "#line " << forNextLine << " " << "\"" << res->headerName << "\"\n";
epilogue << (res->headerData[res->headerLength - 1] == '\n'? "" : "\n") <<
"#line " << directiveLoc.line + forNextLine << " " << directiveLoc.getStringNameOrNum() << "\n";
prologue << "#line ";
prologue << forNextLine;
prologue << " \"";
prologue << res->headerName;
prologue << "\"\n";
epilogue << (res->headerData[res->headerLength - 1] == '\n'? "" : "\n");
epilogue << "#line ";
epilogue << directiveLoc.line + forNextLine << " " << directiveLoc.getStringNameOrNum() << "\n";
pushInput(new TokenizableIncludeFile(directiveLoc, prologue.str(), res, epilogue.str(), this));
// There's no "current" location anymore.
_parseContext.setCurrentColumn(0);

View File

@ -471,8 +471,7 @@ void TBuiltInParseablesHlsl::createMatTimesMat()
// Create a mat * mat of the appropriate dimensions
AppendTypeName(s, "M", "F", retRows, retCols); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append(" mul"); // space between type and name, intrinsic name
s.append("("); // open paren
AppendTypeName(s, "M", "F", xRows, xCols); // add X input
@ -484,8 +483,7 @@ void TBuiltInParseablesHlsl::createMatTimesMat()
// Create M*V
AppendTypeName(s, "V", "F", xRows, 1); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append(" mul"); // space between type and name, intrinsic name
s.append("("); // open paren
AppendTypeName(s, "M", "F", xRows, xCols); // add X input
@ -496,8 +494,7 @@ void TBuiltInParseablesHlsl::createMatTimesMat()
// Create V*M
AppendTypeName(s, "V", "F", xCols, 1); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append(" mul"); // space between type and name, intrinsic name
s.append("("); // open paren
AppendTypeName(s, "V", "F", xRows, 1); // add Y input

View File

@ -857,8 +857,7 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier()
default:
_parseContext.infoSink.info.append("INTERNAL ERROR: ");
_parseContext.infoSink.info.location(loc);
_parseContext.infoSink.info.append("Unknown glslang keyword");
_parseContext.infoSink.info.append("\n");
_parseContext.infoSink.info.append("Unknown glslang keyword" "\n");
return EHTokNone;
}
}