yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
f3234432
main
1// 2// Copyright (C) 2014-2015 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 3Dlabs Inc. Ltd. 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// Parameterize the SPIR-V enumerants. 37// 38 39#pragma once 40 41#include "spirv.hpp11" 42 43#include <vector> 44 45namespace spv { 46 47// Fill in all the parameters 48void Parameterize (); 49 50// Return the English names of all the enums. 51const char * SourceString (int ); 52const char * AddressingString (int ); 53const char * MemoryString (int ); 54const char * ExecutionModelString (int ); 55const char * ExecutionModeString (int ); 56const char * StorageClassString (int ); 57const char * DecorationString (int ); 58const char * BuiltInString (int ); 59const char * DimensionString (int ); 60const char * SelectControlString (int ); 61const char * LoopControlString (int ); 62const char * FunctionControlString (int ); 63const char * SamplerAddressingModeString (int ); 64const char * SamplerFilterModeString (int ); 65const char * ImageFormatString (int ); 66const char * ImageChannelOrderString (int ); 67const char * ImageChannelTypeString (int ); 68const char * ImageChannelDataTypeString (int type ); 69const char * ImageOperandsString (int format ); 70const char * ImageOperands (int ); 71const char * FPFastMathString (int ); 72const char * FPRoundingModeString (int ); 73const char * LinkageTypeString (int ); 74const char * FuncParamAttrString (int ); 75const char * AccessQualifierString (int ); 76const char * MemorySemanticsString (int ); 77const char * MemoryAccessString (int ); 78const char * ExecutionScopeString (int ); 79const char * GroupOperationString (int ); 80const char * KernelEnqueueFlagsString (int ); 81const char * KernelProfilingInfoString (int ); 82const char * CapabilityString (int ); 83const char * OpcodeString (int ); 84const char * ScopeString (int mem ); 85 86// For grouping opcodes into subsections 87enum OpcodeClass { 88OpClassMisc , 89OpClassDebug , 90OpClassAnnotate , 91OpClassExtension , 92OpClassMode , 93OpClassType , 94OpClassConstant , 95OpClassMemory , 96OpClassFunction , 97OpClassImage , 98OpClassConvert , 99OpClassComposite , 100OpClassArithmetic , 101OpClassBit , 102OpClassRelationalLogical , 103OpClassDerivative , 104OpClassFlowControl , 105OpClassAtomic , 106OpClassPrimitive , 107OpClassBarrier , 108OpClassGroup , 109OpClassDeviceSideEnqueue , 110OpClassPipe , 111 112OpClassCount , 113OpClassMissing // all instructions start out as missing 114}; 115 116// For parameterizing operands. 117enum OperandClass { 118OperandNone , 119OperandId , 120OperandVariableIds , 121OperandOptionalLiteral , 122OperandOptionalLiteralString , 123OperandVariableLiterals , 124OperandVariableIdLiteral , 125OperandVariableLiteralId , 126OperandLiteralNumber , 127OperandLiteralString , 128OperandVariableLiteralStrings , 129OperandSource , 130OperandExecutionModel , 131OperandAddressing , 132OperandMemory , 133OperandExecutionMode , 134OperandStorage , 135OperandDimensionality , 136OperandSamplerAddressingMode , 137OperandSamplerFilterMode , 138OperandSamplerImageFormat , 139OperandImageChannelOrder , 140OperandImageChannelDataType , 141OperandImageOperands , 142OperandFPFastMath , 143OperandFPRoundingMode , 144OperandLinkageType , 145OperandAccessQualifier , 146OperandFuncParamAttr , 147OperandDecoration , 148OperandBuiltIn , 149OperandSelect , 150OperandLoop , 151OperandFunction , 152OperandMemorySemantics , 153OperandMemoryAccess , 154OperandScope , 155OperandGroupOperation , 156OperandKernelEnqueueFlags , 157OperandKernelProfilingInfo , 158OperandCapability , 159OperandCooperativeMatrixOperands , 160OperandTensorAddressingOperands , 161 162OperandOpcode , 163 164OperandCount 165}; 166 167// Any specific enum can have a set of capabilities that allow it: 168typedef std ::vector < Capability > EnumCaps ; 169 170// Parameterize a set of operands with their OperandClass(es) and descriptions. 171class OperandParameters { 172public : 173OperandParameters () { } 174void push (OperandClass oc ,const char * d ,bool opt = false) 175 { 176opClass .push_back (oc ); 177desc .push_back (d ); 178optional .push_back (opt ); 179 } 180void setOptional (); 181OperandClass getClass (int op )const {return opClass [op ]; } 182const char * getDesc (int op )const {return desc [op ]; } 183bool isOptional (int op )const {return optional [op ]; } 184int getNum ()const {return (int )opClass .size (); } 185 186protected : 187std ::vector < OperandClass > opClass ; 188std ::vector < const char *> desc ; 189std ::vector < bool > optional ; 190}; 191 192// Parameterize an enumerant 193class EnumParameters { 194public : 195EnumParameters () :desc (nullptr ) { } 196const char * desc ; 197}; 198 199// Parameterize a set of enumerants that form an enum 200class EnumDefinition :public EnumParameters { 201public : 202EnumDefinition () : 203ceiling (0 ),bitmask (false),getName (nullptr ),enumParams (nullptr ),operandParams (nullptr ) { } 204void set (int ceil ,const char * (* name )(int ),EnumParameters * ep ,bool mask = false) 205 { 206ceiling = ceil ; 207getName = name ; 208bitmask = mask ; 209enumParams = ep ; 210 } 211void setOperands (OperandParameters * op ) {operandParams = op ; } 212int ceiling ;// ceiling of enumerants 213bool bitmask ;// true if these enumerants combine into a bitmask 214const char * (* getName )(int );// a function that returns the name for each enumerant value (or shift) 215EnumParameters * enumParams ;// parameters for each individual enumerant 216OperandParameters * operandParams ;// sets of operands 217}; 218 219// Parameterize an instruction's logical format, including its known set of operands, 220// per OperandParameters above. 221class InstructionParameters { 222public : 223InstructionParameters () : 224opDesc ("TBD" ), 225opClass (OpClassMissing ), 226typePresent (true),// most normal, only exceptions have to be spelled out 227resultPresent (true)// most normal, only exceptions have to be spelled out 228 { } 229 230void setResultAndType (bool r ,bool t ) 231 { 232resultPresent = r ; 233typePresent = t ; 234 } 235 236bool hasResult ()const {return resultPresent != 0 ; } 237bool hasType ()const {return typePresent != 0 ; } 238 239const char * opDesc ; 240OpcodeClass opClass ; 241OperandParameters operands ; 242 243protected : 244bool typePresent :1 ; 245bool resultPresent :1 ; 246}; 247 248// The set of objects that hold all the instruction/operand 249// parameterization information. 250extern InstructionParameters InstructionDesc []; 251 252// These hold definitions of the enumerants used for operands 253extern EnumDefinition OperandClassParams []; 254 255const char * GetOperandDesc (OperandClass operand ); 256void PrintImmediateRow (int imm ,const char * name ,const EnumParameters * enumParams ,bool caps ,bool hex = false); 257const char * AccessQualifierString (int attr ); 258 259void PrintOperands (const OperandParameters & operands ,int reservedOperands ); 260 261}// end namespace spv