• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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// Package grammar holds the JSON type definitions for the SPIR-V grammar schema.
16//
17// See https://www.khronos.org/registry/spir-v/specs/unified1/MachineReadableGrammar.html
18// for more information.
19package grammar
20
21// Root is the top-level structure of the JSON grammar.
22type Root struct {
23	MagicNumber  string        `json:"magic_number"`
24	MajorVersion int           `json:"major_version"`
25	MinorVersion int           `json:"minor_version"`
26	Revision     int           `json:"revision"`
27	Instructions []Instruction `json:"instructions"`
28	OperandKinds []OperandKind `json:"operand_kinds"`
29}
30
31// Instruction holds information about a specific SPIR-V instruction.
32type Instruction struct {
33	Opname   string    `json:"opname"`
34	Class    string    `json:"class"`
35	Opcode   int       `json:"opcode"`
36	Operands []Operand `json:"operands"`
37}
38
39// Operand contains information about a logical operand for an instruction.
40type Operand struct {
41	Kind       string     `json:"kind"`
42	Name       string     `json:"name"`
43	Quantifier Quantifier `json:"quantifier"`
44}
45
46// OperandKind contains information about a specific operand kind.
47type OperandKind struct {
48	Category   string      `json:"category"`
49	Kind       string      `json:"kind"`
50	Enumerants []Enumerant `json:"enumerants"`
51	Bases      []string    `json:"bases"`
52}
53
54// Enumerant contains information about an enumerant in an enum.
55type Enumerant struct {
56	Enumerant    string      `json:"enumerant"`
57	Value        interface{} `json:"value"`
58	Capabilities []string    `json:"capabilities"`
59	Parameters   []Parameter `json:"parameters"`
60	Version      string      `json:"version"`
61}
62
63// Parameter contains information about a logical parameter for an enumerant.
64type Parameter struct {
65	Kind string `json:"kind"`
66	Name string `json:"name"`
67}
68
69// Quantifier indicates the number of times the quantified term may appear.
70type Quantifier string
71
72const (
73	// Once indicates the quantified term may appear exactly once.
74	Once Quantifier = ""
75	// ZeroOrOnce indicates the quantified term may appear zero or one
76	// time; an optional term.
77	ZeroOrOnce Quantifier = "?"
78	// ZeroOrMany indicates the quantified term may appear any number of
79	// times.
80	ZeroOrMany Quantifier = "*"
81)
82