From 6684d32db1f5693bcfb4971558cb30e855cd3bad Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 5 Mar 2020 10:59:54 -0500 Subject: Feature/glslang spirv version (#1256) * WIP add support for __spirv_version . * Added IRRequireSPIRVVersionDecoration * SPIR-V version passed to glslang. Enable VK wave tests. Split ExtensionTracker out, so can be cast and used externally to emit. Added SourceResult. * Fix warning on Clang. * Missing hlsl.meta.h * Refactor communication/parsing of __spirv_version with glslang. * Fix some debug typos. Be more precise in handling of substring handling. * Make glslang forwards and backwards binary compatible. * Small comment improvements. * Added slang-spirv-target-info.h/cpp * Fix for major/minor on gcc. * Another fix for gcc/clang. * VS projects include slang-spirv-target-info.h/cpp * Removed SPIRVTargetInfo Added SemanticVersion. Don't bother with passing a target to glslang. Should be separate from 'version'. * Renamed slang-emit-glsl-extension-tracker.cpp/.h -> slang-glsl-extension-tracker.cpp/.h Fixed some VS project issues. * Fix a comment. * Added slang-semantic-version.cpp/.h * Added slang-glsl-extension-tracker.cpp/.h * Added split that can check for input has all been parsed. * Fix problem on x86 win build. --- source/slang/slang-parser.cpp | 74 ++++++++++--------------------------------- 1 file changed, 17 insertions(+), 57 deletions(-) (limited to 'source/slang/slang-parser.cpp') diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index 9dfe7ddc6..94ab58c07 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -7,6 +7,8 @@ #include "slang-lookup.h" #include "slang-visitor.h" +#include "../core/slang-semantic-version.h" + namespace Slang { // pre-declare @@ -4752,81 +4754,39 @@ namespace Slang auto modifier = new RequiredSPIRVVersionModifier(); parser->ReadToken(TokenType::LParent); + Token token = parser->ReadToken(); + parser->ReadToken(TokenType::RParent); - UnownedStringSlice typeName; - UnownedStringSlice majorVersionText; - UnownedStringSlice minorVersionText; - - // There is a legitimate question about how the version should be handled here. - switch (parser->tokenReader.peekTokenType()) + UnownedStringSlice content = token.Content; + // We allow specified as major.minor or as a string (in quotes) + switch (token.type) { case TokenType::FloatingPointLiteral: { - modifier->token = parser->ReadToken(TokenType::FloatingPointLiteral); - - List split; - StringUtil::split(modifier->token.Content, '.', split); - - if (split.getCount() != 2) - { - parser->sink->diagnose(modifier->token, Diagnostics::invalidSPIRVVersion); - return RefPtr(); - } - - majorVersionText = split[0]; - minorVersionText = split[1]; break; } - case TokenType::Identifier: + case TokenType::StringLiteral: { - modifier->token = parser->ReadToken(TokenType::Identifier); - - List split; - StringUtil::split(modifier->token.Content, '_', split); - - if (split.getCount() != 3) - { - parser->sink->diagnose(modifier->token, Diagnostics::invalidSPIRVVersion); - return RefPtr(); - } - - typeName = split[0]; - majorVersionText = split[1]; - minorVersionText = split[2]; + // We need to trim quotes if needed + SLANG_ASSERT(content.getLength() >= 2 && content[0] == '"' && content[content.getLength() -1] == '"'); + content = UnownedStringSlice(content.begin() + 1, content.end() - 1); break; - } default: { - parser->sink->diagnose(modifier->token, Diagnostics::invalidSPIRVVersion); + parser->sink->diagnose(token, Diagnostics::invalidSPIRVVersion); return RefPtr(); } } - - parser->ReadToken(TokenType::RParent); - - // Currently we only support 'spirv' or no typename - if (!(typeName == UnownedStringSlice::fromLiteral("spirv") || typeName.getLength() == 0)) - { - parser->sink->diagnose(modifier->token, Diagnostics::invalidSPIRVVersion); - return RefPtr(); - } - - Token intToken = modifier->token; - intToken.type = TokenType::IntegerLiteral; - intToken.Content = majorVersionText; - - auto majorValue = getIntegerLiteralValue(intToken); - intToken.Content = minorVersionText; - auto minorValue = getIntegerLiteralValue(intToken); - - if (minorValue < 0 || minorValue > 0xff || majorValue < 0) + + SemanticVersion version; + if (SLANG_FAILED(SemanticVersion::parse(content, modifier->version))) { - parser->sink->diagnose(modifier->token, Diagnostics::invalidSPIRVVersion); + // Unable to parse the error so fail + parser->sink->diagnose(token, Diagnostics::invalidSPIRVVersion); return RefPtr(); } - modifier->spirvVersion = makeSPIRVVersion(int(majorValue), int(minorValue)); return modifier; } -- cgit v1.2.3