aboutsummaryrefslogtreecommitdiff
path: root/autogen/spirv_grammar.rs
blob: 3087672cf7a9bf9a17ccfa81ede09c774703399a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2021 The Vulkano developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or https://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.

use serde::Deserialize;
use serde_json::Value;
use std::{
    fs::File,
    io::{BufReader, Read},
    path::Path,
};

#[derive(Clone, Debug, Deserialize)]
pub struct SpirvGrammar {
    pub major_version: u16,
    pub minor_version: u16,
    pub revision: u16,
    pub instructions: Vec<SpirvInstruction>,
    pub operand_kinds: Vec<SpirvOperandKind>,
}

impl SpirvGrammar {
    pub fn new<P: AsRef<Path> + ?Sized>(path: &P) -> Self {
        let mut reader = BufReader::new(File::open(path).unwrap());
        let mut json = String::new();
        reader.read_to_string(&mut json).unwrap();
        serde_json::from_str(&json).unwrap()
    }
}

#[derive(Clone, Debug, Deserialize)]
pub struct SpirvInstruction {
    pub opname: String,
    pub class: String,
    pub opcode: u16,
    #[serde(default)]
    pub operands: Vec<SpirvOperand>,
    #[serde(default)]
    pub capabilities: Vec<String>,
    #[serde(default)]
    pub extensions: Vec<String>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct SpirvOperand {
    pub kind: String,
    pub quantifier: Option<char>,
    pub name: Option<String>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct SpirvOperandKind {
    pub category: String,
    pub kind: String,
    #[serde(default)]
    pub enumerants: Vec<SpirvKindEnumerant>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct SpirvKindEnumerant {
    pub enumerant: String,
    pub value: Value,
    #[serde(default)]
    pub parameters: Vec<SpirvParameter>,
    #[serde(default)]
    pub capabilities: Vec<String>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct SpirvParameter {
    pub kind: String,
    pub name: Option<String>,
}