1// Copyright (C) 2019 Google Inc. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Generated by {{GenerateArguments}} 16// Do not modify this file directly. 17 18package schema 19 20// Opcode holds information about a specific SPIR-V opcode. 21type Opcode struct { 22 Opname string 23 Class string 24 Opcode int 25 Operands []Operand 26} 27 28// Operand contains information about a logical operand for an instruction. 29type Operand struct { 30 Kind *OperandKind 31 Name string 32 Quantifier Quantifier 33} 34 35// OperandKind contains information about a specific operand kind. 36type OperandKind struct { 37 Category OperandCategory 38 Kind string 39 Enumerants []Enumerant 40 Bases []*OperandKind 41} 42 43// Enumerant contains information about an enumerant in an enum. 44type Enumerant struct { 45 Enumerant string 46 Value interface{} 47 Capabilities []string 48 Parameters []Parameter 49 Version string 50} 51 52// Parameter contains information about a logical parameter for an enumerant. 53type Parameter struct { 54 Kind *OperandKind 55 Name string 56} 57 58// Quantifier indicates the number of times the quantified term may appear. 59type Quantifier string 60 61const ( 62 // Once indicates the quantified term may appear exactly once. 63 Once Quantifier = "" 64 65 // ZeroOrOnce indicates the quantified term may appear zero or one 66 // time; an optional term. 67 ZeroOrOnce Quantifier = "?" 68 69 // ZeroOrMany indicates the quantified term may appear any number of 70 // times. 71 ZeroOrMany Quantifier = "*" 72) 73 74// OperandCategory is an enumerator that groups operand kinds. 75type OperandCategory string 76 77const ( 78 // OperandCategoryBitEnum describes an operand kind where its value is a 79 // mask, which is formed by combining the bits specified as enumerants in an 80 // enum. 81 OperandCategoryBitEnum = "BitEnum" 82 83 // OperandCategoryValueEnum describes an operand kind where its value is an 84 // enumerant from an enum. 85 OperandCategoryValueEnum = "ValueEnum" 86 87 // OperandCategoryID describes and operand kind where its value is an <id> 88 // definition or reference. 89 OperandCategoryID = "Id" 90 91 // OperandCategoryLiteral describes and operand kind where its value is an 92 // literal number or string. 93 OperandCategoryLiteral = "Literal" 94 95 // OperandCategoryComposite describes and operand kind where its value is 96 // composed from operand values from the above categories. 97 OperandCategoryComposite = "Composite" 98) 99 100// OpcodeMap is a map of opcode name to Opcode type. 101type OpcodeMap map[string]*Opcode 102 103var ( 104 // Opcodes is a map of opcode name to Opcode description. 105 Opcodes = OpcodeMap {•{{range $i := .SPIRV.Instructions}} 106 "{{$i.Opname}}": {{Title $i.Opname}},{{end}} 107 } 108 109 // ExtOpcodes is a map of extension name to Opcode description list. 110 ExtOpcodes = map[string]OpcodeMap {•{{range $ext := .Extensions}} 111 "{{$ext.Name}}": {•{{range $i := $ext.Instructions}} 112 "{{$i.Opname}}": {{Global $ext.Name}}_{{$i.Opname}},{{end}} 113 },{{end}} 114 } 115 116{{range $i := .SPIRV.Instructions}} {{Title $i.Opname}} = &Opcode { 117 Opname: "{{$i.Opname}}", 118 Class: "{{$i.Class}}", 119 Opcode: {{$i.Opcode}}, 120 Operands: []Operand {•{{range $i := $i.Operands}} 121 Operand { 122 Kind: OperandKind{{$i.Kind}}, 123 Name: "{{Replace $i.Name "\n" " "}}", 124 Quantifier: "{{$i.Quantifier}}", 125 }, {{end}} 126 }, 127 } 128{{end}} 129{{range $ext := .Extensions}}{{range $i := $ext.Instructions}} {{Global $ext.Name}}_{{$i.Opname}} = &Opcode { 130 Opname: "{{$i.Opname}}", 131 Operands: []Operand {•{{range $i := $i.Operands}} 132 Operand { 133 Kind: OperandKind{{$i.Kind}}, 134 Name: "{{Replace $i.Name "\n" " "}}", 135 Quantifier: "{{$i.Quantifier}}", 136 }, {{end}} 137 }, 138 } 139{{end}}{{end}} 140 141{{range $o := .All.OperandKinds}} OperandKind{{$o.Kind}} = &OperandKind { 142 Kind: "{{$o.Kind}}", 143 Category: "{{$o.Category}}", 144 Enumerants: []Enumerant {•{{range $e := $o.Enumerants}} 145 Enumerant{ 146 Enumerant: "{{$e.Enumerant}}", 147 Value: {{$e.Value}}, 148 Capabilities: []string{•{{range $c := $e.Capabilities}}"{{$c}}",{{end}}•}, 149 Parameters: []Parameter{•{{range $p := $e.Parameters}}{•OperandKind{{$p.Kind}}, "{{$p.Name}}"•},{{end}}•}, 150 Version: "{{$e.Version}}", 151 },{{end}} 152 }, 153 Bases: []*OperandKind {•{{range $b := $o.Bases}}OperandKind{{$b}},{{end}}•}, 154 } 155{{end}} 156) 157