RetroArch
parseVersions.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2016 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 //
56 public:
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 #ifdef AMD_EXTENSIONS
83  virtual void float16OpaqueCheck(const TSourceLoc&, const char* op, bool builtIn = false);
84 #endif
85  virtual void int64Check(const TSourceLoc&, const char* op, bool builtIn = false);
86  virtual void explicitInt8Check(const TSourceLoc&, const char* op, bool builtIn = false);
87  virtual void explicitInt16Check(const TSourceLoc&, const char* op, bool builtIn = false);
88  virtual void explicitInt32Check(const TSourceLoc&, const char* op, bool builtIn = false);
89  virtual void explicitFloat32Check(const TSourceLoc&, const char* op, bool builtIn = false);
90  virtual void explicitFloat64Check(const TSourceLoc&, const char* op, bool builtIn = false);
91  virtual void spvRemoved(const TSourceLoc&, const char* op);
92  virtual void vulkanRemoved(const TSourceLoc&, const char* op);
93  virtual void requireVulkan(const TSourceLoc&, const char* op);
94  virtual void requireSpv(const TSourceLoc&, const char* op);
95  virtual bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc);
96  virtual void updateExtensionBehavior(const char* const extension, TExtensionBehavior);
97 
98  virtual void C_DECL error(const TSourceLoc&, const char* szReason, const char* szToken,
99  const char* szExtraInfoFormat, ...) = 0;
100  virtual void C_DECL warn(const TSourceLoc&, const char* szReason, const char* szToken,
101  const char* szExtraInfoFormat, ...) = 0;
102  virtual void C_DECL ppError(const TSourceLoc&, const char* szReason, const char* szToken,
103  const char* szExtraInfoFormat, ...) = 0;
104  virtual void C_DECL ppWarn(const TSourceLoc&, const char* szReason, const char* szToken,
105  const char* szExtraInfoFormat, ...) = 0;
106 
107  void addError() { ++numErrors; }
108  int getNumErrors() const { return numErrors; }
109 
110  void setScanner(TInputScanner* scanner) { currentScanner = scanner; }
112  const TSourceLoc& getCurrentLoc() const { return currentScanner->getSourceLoc(); }
113  void setCurrentLine(int line) { currentScanner->setLine(line); }
116  void setCurrentString(int string) { currentScanner->setString(string); }
117 
118  void getPreamble(std::string&);
119  bool relaxedErrors() const { return (messages & EShMsgRelaxedErrors) != 0; }
120  bool suppressWarnings() const { return (messages & EShMsgSuppressWarnings) != 0; }
121  bool isReadingHLSL() const { return (messages & EShMsgReadHlsl) == EShMsgReadHlsl; }
122  bool hlslEnable16BitTypes() const { return (messages & EShMsgHlslEnable16BitTypes) != 0; }
123 
125 
126  // compilation mode
127  int version; // version, updated by #version in the shader
128  EProfile profile; // the declared profile in the shader (core by default)
129  EShLanguage language; // really the stage
131  bool forwardCompatible; // true if errors are to be given for use of deprecated features
132  TIntermediate& intermediate; // helper for making and hooking up pieces of the parse tree
133 
134 protected:
135  TMap<TString, TExtensionBehavior> extensionBehavior; // for each extension string, what its current behavior is set to
136  EShMessages messages; // errors/warnings/rule-sets
137  int numErrors; // number of compile-time errors encountered
139 
140 private:
141  explicit TParseVersions(const TParseVersions&);
143 };
144 
145 } // end namespace glslang
146 
147 #endif // _PARSE_VERSIONS_INCLUDED_
Definition: parseVersions.h:55
bool forwardCompatible
Definition: parseVersions.h:131
GLuint const GLchar * name
Definition: glext.h:6671
virtual void C_DECL ppWarn(const TSourceLoc &, const char *szReason, const char *szToken, const char *szExtraInfoFormat,...)=0
virtual bool checkExtensionsRequested(const TSourceLoc &, int numExtensions, const char *const extensions[], const char *featureDesc)
Definition: Versions.cpp:594
int version
Definition: parseVersions.h:127
set set set set set set set macro pixldst1 op
Definition: pixman-arm-neon-asm.h:54
Definition: InfoSink.h:138
Definition: Versions.h:83
EShLanguage
Definition: ShaderLang.h:90
Definition: Common.h:231
virtual void spvRemoved(const TSourceLoc &, const char *op)
Definition: Versions.cpp:937
virtual void fullIntegerCheck(const TSourceLoc &, const char *op)
Definition: Versions.cpp:804
virtual void requireNotRemoved(const TSourceLoc &, int queryProfiles, int removedVersion, const char *featureDesc)
Definition: Versions.cpp:575
void addError()
Definition: parseVersions.h:107
TMap< TString, TExtensionBehavior > extensionBehavior
Definition: parseVersions.h:135
Definition: localintermediate.h:210
EShLanguageMask
Definition: ShaderLang.h:100
virtual void C_DECL ppError(const TSourceLoc &, const char *szReason, const char *szToken, const char *szExtraInfoFormat,...)=0
EShLanguage language
Definition: parseVersions.h:129
GLsizei const GLchar *const * string
Definition: glext.h:6699
TExtensionBehavior
Definition: Versions.h:94
virtual void vulkanRemoved(const TSourceLoc &, const char *op)
Definition: Versions.cpp:944
virtual void doubleCheck(const TSourceLoc &, const char *op)
Definition: Versions.cpp:811
void setCurrentLine(int line)
Definition: parseVersions.h:113
virtual void requireSpv(const TSourceLoc &, const char *op)
Definition: Versions.cpp:958
const TSourceLoc & getCurrentLoc() const
Definition: parseVersions.h:112
Definition: ShaderLang.h:207
virtual void C_DECL error(const TSourceLoc &, const char *szReason, const char *szToken, const char *szExtraInfoFormat,...)=0
void setString(int newString)
Definition: Scan.h:185
void setColumn(int col)
Definition: Scan.h:194
virtual void int64Check(const TSourceLoc &, const char *op, bool builtIn=false)
Definition: Versions.cpp:923
EProfile
Definition: Versions.h:51
virtual void explicitFloat64Check(const TSourceLoc &, const char *op, bool builtIn=false)
Definition: Versions.cpp:852
virtual void requireStage(const TSourceLoc &, EShLanguageMask, const char *featureDesc)
Definition: Versions.cpp:541
int getNumErrors() const
Definition: parseVersions.h:108
EProfile profile
Definition: parseVersions.h:128
TInputScanner * getScanner() const
Definition: parseVersions.h:111
virtual TExtensionBehavior getExtensionBehavior(const char *)
Definition: Versions.cpp:659
void setScanner(TInputScanner *scanner)
Definition: parseVersions.h:110
virtual void explicitInt32Check(const TSourceLoc &, const char *op, bool builtIn=false)
Definition: Versions.cpp:910
int numErrors
Definition: parseVersions.h:137
virtual void requireProfile(const TSourceLoc &, int queryProfiles, const char *featureDesc)
Definition: Versions.cpp:465
virtual void C_DECL warn(const TSourceLoc &, const char *szReason, const char *szToken, const char *szExtraInfoFormat,...)=0
Definition: ShaderLang.h:212
TInputScanner * currentScanner
Definition: parseVersions.h:138
TInfoSink & infoSink
Definition: parseVersions.h:124
Definition: arrays.h:46
virtual void initializeExtensionBehavior()
Definition: Versions.cpp:152
virtual void requireVulkan(const TSourceLoc &, const char *op)
Definition: Versions.cpp:951
virtual void explicitFloat32Check(const TSourceLoc &, const char *op, bool builtIn=false)
Definition: Versions.cpp:839
virtual void explicitInt16Check(const TSourceLoc &, const char *op, bool builtIn=false)
Definition: Versions.cpp:891
bool suppressWarnings() const
Definition: parseVersions.h:120
Definition: ShaderLang.h:217
void setLine(int newLine)
Definition: Scan.h:164
virtual void checkDeprecated(const TSourceLoc &, int queryProfiles, int depVersion, const char *featureDesc)
Definition: Versions.cpp:558
virtual void explicitInt8Check(const TSourceLoc &, const char *op, bool builtIn=false)
Definition: Versions.cpp:865
const TSourceLoc & getSourceLoc() const
Definition: Scan.h:208
u32 col
Definition: gx_regdef.h:5093
void setCurrentString(int string)
Definition: parseVersions.h:116
bool hlslEnable16BitTypes() const
Definition: parseVersions.h:122
#define C_DECL
Definition: ShaderLang.h:58
virtual void unimplemented(const TSourceLoc &, const char *featureDesc)
Definition: Versions.cpp:587
Definition: ShaderLang.h:206
TParseVersions(TIntermediate &interm, int version, EProfile profile, const SpvVersion &spvVersion, EShLanguage language, TInfoSink &infoSink, bool forwardCompatible, EShMessages messages)
Definition: parseVersions.h:57
virtual ~TParseVersions()
Definition: parseVersions.h:63
virtual void profileRequires(const TSourceLoc &, int queryProfiles, int minVersion, int numExtensions, const char *const extensions[], const char *featureDesc)
Definition: Versions.cpp:504
void setCurrentSourceName(const char *name)
Definition: parseVersions.h:115
bool relaxedErrors() const
Definition: parseVersions.h:119
bool isReadingHLSL() const
Definition: parseVersions.h:121
virtual void ppRequireExtensions(const TSourceLoc &, int numExtensions, const char *const extensions[], const char *featureDesc)
Definition: Versions.cpp:644
virtual void requireExtensions(const TSourceLoc &, int numExtensions, const char *const extensions[], const char *featureDesc)
Definition: Versions.cpp:625
virtual void updateExtensionBehavior(int line, const char *const extension, const char *behavior)
Definition: Versions.cpp:694
virtual bool extensionTurnedOn(const char *const extension)
Definition: Versions.cpp:669
EShMessages
Definition: ShaderLang.h:204
TParseVersions & operator=(const TParseVersions &)
virtual void float16Check(const TSourceLoc &, const char *op, bool builtIn=false)
Definition: Versions.cpp:819
void getPreamble(std::string &)
Definition: Versions.cpp:282
const char * extension
Definition: civetweb.c:4908
virtual bool extensionsTurnedOn(int numExtensions, const char *const extensions[])
Definition: Versions.cpp:682
EShMessages messages
Definition: parseVersions.h:136
Definition: Scan.h:52
void setCurrentColumn(int col)
Definition: parseVersions.h:114
SpvVersion spvVersion
Definition: parseVersions.h:130
TIntermediate & intermediate
Definition: parseVersions.h:132
void setFile(const char *filename)
Definition: Scan.h:171