1 // 2 // Copyright (C) 2016 LunarG, Inc. 3 // 4 // All rights reserved. 5 // 6 // Redistribution and use in source and binary forms, with or without 7 // modification, are permitted provided that the following conditions 8 // are met: 9 // 10 // Redistributions of source code must retain the above copyright 11 // notice, this list of conditions and the following disclaimer. 12 // 13 // Redistributions in binary form must reproduce the above 14 // copyright notice, this list of conditions and the following 15 // disclaimer in the documentation and/or other materials provided 16 // with the distribution. 17 // 18 // Neither the name of Google, Inc., nor the names of its 19 // contributors may be used to endorse or promote products derived 20 // from this software without specific prior written permission. 21 // 22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 // POSSIBILITY OF SUCH DAMAGE. 34 // 35 36 #ifndef HLSLATTRIBUTES_H_ 37 #define HLSLATTRIBUTES_H_ 38 39 #include <unordered_map> 40 #include <functional> 41 #include "hlslScanContext.h" 42 #include "../glslang/Include/Common.h" 43 44 namespace glslang { 45 enum TAttributeType { 46 EatNone, 47 EatAllow_uav_condition, 48 EatBranch, 49 EatCall, 50 EatDomain, 51 EatEarlyDepthStencil, 52 EatFastOpt, 53 EatFlatten, 54 EatForceCase, 55 EatInstance, 56 EatMaxTessFactor, 57 EatNumThreads, 58 EatMaxVertexCount, 59 EatOutputControlPoints, 60 EatOutputTopology, 61 EatPartitioning, 62 EatPatchConstantFunc, 63 EatPatchSize, 64 EatUnroll, 65 EatLoop, 66 }; 67 } 68 69 namespace std { 70 // Allow use of TAttributeType enum in hash_map without calling code having to cast. 71 template <> struct hash<glslang::TAttributeType> { 72 std::size_t operator()(glslang::TAttributeType attr) const { 73 return std::hash<int>()(int(attr)); 74 } 75 }; 76 } // end namespace std 77 78 namespace glslang { 79 class TIntermAggregate; 80 81 class TAttributeMap { 82 public: 83 // Search for and potentially add the attribute into the map. Return the 84 // attribute type enum for it, if found, else EatNone. 85 TAttributeType setAttribute(const TString* name, TIntermAggregate* value); 86 87 // Const lookup: search for (but do not modify) the attribute in the map. 88 const TIntermAggregate* operator[](TAttributeType) const; 89 90 // True if entry exists in map (even if value is nullptr) 91 bool contains(TAttributeType) const; 92 93 protected: 94 // Find an attribute enum given its name. 95 static TAttributeType attributeFromName(const TString&); 96 97 std::unordered_map<TAttributeType, TIntermAggregate*> attributes; 98 }; 99 100 class TFunctionDeclarator { 101 public: 102 TFunctionDeclarator() : function(nullptr), body(nullptr) { } 103 TSourceLoc loc; 104 TFunction* function; 105 TAttributeMap attributes; 106 TVector<HlslToken>* body; 107 }; 108 109 } // end namespace glslang 110 111 112 #endif // HLSLATTRIBUTES_H_ 113