1 // 2 // Copyright (C) 2015-2018 Google, Inc. 3 // Copyright (C) 2017 ARM Limited. 4 // 5 // All rights reserved. 6 // 7 // Redistribution and use in source and binary forms, with or without 8 // modification, are permitted provided that the following conditions 9 // are met: 10 // 11 // Redistributions of source code must retain the above copyright 12 // notice, this list of conditions and the following disclaimer. 13 // 14 // Redistributions in binary form must reproduce the above 15 // copyright notice, this list of conditions and the following 16 // disclaimer in the documentation and/or other materials provided 17 // with the distribution. 18 // 19 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its 20 // contributors may be used to endorse or promote products derived 21 // from this software without specific prior written permission. 22 // 23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 29 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 33 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 // POSSIBILITY OF SUCH DAMAGE. 35 // 36 37 // This is implemented in Versions.cpp 38 39 #ifndef _PARSE_VERSIONS_INCLUDED_ 40 #define _PARSE_VERSIONS_INCLUDED_ 41 42 #include "../Public/ShaderLang.h" 43 #include "../Include/InfoSink.h" 44 #include "Scan.h" 45 46 #include <map> 47 48 namespace glslang { 49 50 // 51 // Base class for parse helpers. 52 // This just has version-related information and checking. 53 // This class should be sufficient for preprocessing. 54 // 55 class TParseVersions { 56 public: TParseVersions(TIntermediate & interm,int version,EProfile profile,const SpvVersion & spvVersion,EShLanguage language,TInfoSink & infoSink,bool forwardCompatible,EShMessages messages)57 TParseVersions(TIntermediate& interm, int version, EProfile profile, 58 const SpvVersion& spvVersion, EShLanguage language, TInfoSink& infoSink, 59 bool forwardCompatible, EShMessages messages) 60 : infoSink(infoSink), version(version), profile(profile), language(language), 61 spvVersion(spvVersion), forwardCompatible(forwardCompatible), 62 intermediate(interm), messages(messages), numErrors(0), currentScanner(0) { } ~TParseVersions()63 virtual ~TParseVersions() { } 64 virtual void initializeExtensionBehavior(); 65 virtual void requireProfile(const TSourceLoc&, int queryProfiles, const char* featureDesc); 66 virtual void profileRequires(const TSourceLoc&, int queryProfiles, int minVersion, int numExtensions, const char* const extensions[], const char* featureDesc); 67 virtual void profileRequires(const TSourceLoc&, int queryProfiles, int minVersion, const char* const extension, const char* featureDesc); 68 virtual void requireStage(const TSourceLoc&, EShLanguageMask, const char* featureDesc); 69 virtual void requireStage(const TSourceLoc&, EShLanguage, const char* featureDesc); 70 virtual void checkDeprecated(const TSourceLoc&, int queryProfiles, int depVersion, const char* featureDesc); 71 virtual void requireNotRemoved(const TSourceLoc&, int queryProfiles, int removedVersion, const char* featureDesc); 72 virtual void unimplemented(const TSourceLoc&, const char* featureDesc); 73 virtual void requireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc); 74 virtual void ppRequireExtensions(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc); 75 virtual TExtensionBehavior getExtensionBehavior(const char*); 76 virtual bool extensionTurnedOn(const char* const extension); 77 virtual bool extensionsTurnedOn(int numExtensions, const char* const extensions[]); 78 virtual void updateExtensionBehavior(int line, const char* const extension, const char* behavior); 79 virtual void fullIntegerCheck(const TSourceLoc&, const char* op); 80 virtual void doubleCheck(const TSourceLoc&, const char* op); 81 virtual void float16Check(const TSourceLoc&, const char* op, bool builtIn = false); 82 virtual void float16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false); 83 virtual bool float16Arithmetic(); 84 virtual void requireFloat16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc); 85 virtual void int16ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false); 86 virtual bool int16Arithmetic(); 87 virtual void requireInt16Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc); 88 virtual void int8ScalarVectorCheck(const TSourceLoc&, const char* op, bool builtIn = false); 89 virtual bool int8Arithmetic(); 90 virtual void requireInt8Arithmetic(const TSourceLoc& loc, const char* op, const char* featureDesc); 91 #ifdef AMD_EXTENSIONS 92 virtual void float16OpaqueCheck(const TSourceLoc&, const char* op, bool builtIn = false); 93 #endif 94 virtual void int64Check(const TSourceLoc&, const char* op, bool builtIn = false); 95 virtual void explicitInt8Check(const TSourceLoc&, const char* op, bool builtIn = false); 96 virtual void explicitInt16Check(const TSourceLoc&, const char* op, bool builtIn = false); 97 virtual void explicitInt32Check(const TSourceLoc&, const char* op, bool builtIn = false); 98 virtual void explicitFloat32Check(const TSourceLoc&, const char* op, bool builtIn = false); 99 virtual void explicitFloat64Check(const TSourceLoc&, const char* op, bool builtIn = false); 100 virtual void spvRemoved(const TSourceLoc&, const char* op); 101 virtual void vulkanRemoved(const TSourceLoc&, const char* op); 102 virtual void requireVulkan(const TSourceLoc&, const char* op); 103 virtual void requireSpv(const TSourceLoc&, const char* op); 104 virtual bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc); 105 virtual void updateExtensionBehavior(const char* const extension, TExtensionBehavior); 106 virtual void checkExtensionStage(const TSourceLoc&, const char* const extension); 107 virtual void fcoopmatCheck(const TSourceLoc&, const char* op, bool builtIn = false); 108 109 virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken, 110 const char* szExtraInfoFormat, ...) = 0; 111 virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken, 112 const char* szExtraInfoFormat, ...) = 0; 113 virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken, 114 const char* szExtraInfoFormat, ...) = 0; 115 virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken, 116 const char* szExtraInfoFormat, ...) = 0; 117 addError()118 void addError() { ++numErrors; } getNumErrors()119 int getNumErrors() const { return numErrors; } 120 setScanner(TInputScanner * scanner)121 void setScanner(TInputScanner* scanner) { currentScanner = scanner; } getScanner()122 TInputScanner* getScanner() const { return currentScanner; } getCurrentLoc()123 const TSourceLoc& getCurrentLoc() const { return currentScanner->getSourceLoc(); } setCurrentLine(int line)124 void setCurrentLine(int line) { currentScanner->setLine(line); } setCurrentColumn(int col)125 void setCurrentColumn(int col) { currentScanner->setColumn(col); } setCurrentSourceName(const char * name)126 void setCurrentSourceName(const char* name) { currentScanner->setFile(name); } setCurrentString(int string)127 void setCurrentString(int string) { currentScanner->setString(string); } 128 129 void getPreamble(std::string&); relaxedErrors()130 bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; } suppressWarnings()131 bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; } isReadingHLSL()132 bool isReadingHLSL() const { return (messages & EShMsgReadHlsl) == EShMsgReadHlsl; } hlslEnable16BitTypes()133 bool hlslEnable16BitTypes() const { return (messages & EShMsgHlslEnable16BitTypes) != 0; } hlslDX9Compatible()134 bool hlslDX9Compatible() const { return (messages & EShMsgHlslDX9Compatible) != 0; } 135 136 TInfoSink& infoSink; 137 138 // compilation mode 139 int version; // version, updated by #version in the shader 140 EProfile profile; // the declared profile in the shader (core by default) 141 EShLanguage language; // really the stage 142 SpvVersion spvVersion; 143 bool forwardCompatible; // true if errors are to be given for use of deprecated features 144 TIntermediate& intermediate; // helper for making and hooking up pieces of the parse tree 145 146 protected: 147 TMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to 148 EShMessages messages; // errors/warnings/rule-sets 149 int numErrors; // number of compile-time errors encountered 150 TInputScanner* currentScanner; 151 152 private: 153 explicit TParseVersions(const TParseVersions&); 154 TParseVersions& operator=(const TParseVersions&); 155 }; 156 157 } // end namespace glslang 158 159 #endif // _PARSE_VERSIONS_INCLUDED_ 160