• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
108     virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
109         const char* szExtraInfoFormat, ...) = 0;
110     virtual void C_DECL  warn(const TSourceLoc&, const char* szReason, const char* szToken,
111         const char* szExtraInfoFormat, ...) = 0;
112     virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
113         const char* szExtraInfoFormat, ...) = 0;
114     virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
115         const char* szExtraInfoFormat, ...) = 0;
116 
addError()117     void addError() { ++numErrors; }
getNumErrors()118     int getNumErrors() const { return numErrors; }
119 
setScanner(TInputScanner * scanner)120     void setScanner(TInputScanner* scanner) { currentScanner = scanner; }
getScanner()121     TInputScanner* getScanner() const { return currentScanner; }
getCurrentLoc()122     const TSourceLoc& getCurrentLoc() const { return currentScanner->getSourceLoc(); }
setCurrentLine(int line)123     void setCurrentLine(int line) { currentScanner->setLine(line); }
setCurrentColumn(int col)124     void setCurrentColumn(int col) { currentScanner->setColumn(col); }
setCurrentSourceName(const char * name)125     void setCurrentSourceName(const char* name) { currentScanner->setFile(name); }
setCurrentString(int string)126     void setCurrentString(int string) { currentScanner->setString(string); }
127 
128     void getPreamble(std::string&);
relaxedErrors()129     bool relaxedErrors()    const { return (messages & EShMsgRelaxedErrors) != 0; }
suppressWarnings()130     bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; }
isReadingHLSL()131     bool isReadingHLSL()    const { return (messages & EShMsgReadHlsl) == EShMsgReadHlsl; }
hlslEnable16BitTypes()132     bool hlslEnable16BitTypes() const { return (messages & EShMsgHlslEnable16BitTypes) != 0; }
hlslDX9Compatible()133     bool hlslDX9Compatible() const { return (messages & EShMsgHlslDX9Compatible) != 0; }
134 
135     TInfoSink& infoSink;
136 
137     // compilation mode
138     int version;                 // version, updated by #version in the shader
139     EProfile profile;            // the declared profile in the shader (core by default)
140     EShLanguage language;        // really the stage
141     SpvVersion spvVersion;
142     bool forwardCompatible;      // true if errors are to be given for use of deprecated features
143     TIntermediate& intermediate; // helper for making and hooking up pieces of the parse tree
144 
145 protected:
146     TMap<TString, TExtensionBehavior> extensionBehavior;    // for each extension string, what its current behavior is set to
147     EShMessages messages;        // errors/warnings/rule-sets
148     int numErrors;               // number of compile-time errors encountered
149     TInputScanner* currentScanner;
150 
151 private:
152     explicit TParseVersions(const TParseVersions&);
153     TParseVersions& operator=(const TParseVersions&);
154 };
155 
156 } // end namespace glslang
157 
158 #endif // _PARSE_VERSIONS_INCLUDED_
159