ptx_parser/parser/instruction/
sust.rs

1//! Original PTX specification:
2//!
3//! sust.b.dim{.cop}.vec.ctype{.mode} [a, b], c;  // unformatted
4//! sust.p.dim.vec.b32{.mode}       [a, b], c;  // formatted
5//! sust.b.adim{.cop}.vec.ctype{.mode}   [a, b], c;  // unformatted
6//! .cop   = { .wb, .cg, .cs, .wt };                     // cache operation
7//! .vec   = { none, .v2, .v4 };
8//! .ctype = { .b8 , .b16, .b32, .b64 };
9//! .mode  = { .trap, .clamp, .zero };
10//! .dim   = { .1d, .2d, .3d };
11//! .adim  = { .a1d, .a2d };
12
13#![allow(unused)]
14
15use crate::parser::{
16    PtxParseError, PtxParser, PtxTokenStream, Span,
17    util::{
18        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
19        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
20    },
21};
22use crate::r#type::common::*;
23use crate::{alt, ok, seq_n};
24
25pub mod section_0 {
26    use super::*;
27    use crate::r#type::instruction::sust::section_0::*;
28
29    // ============================================================================
30    // Generated enum parsers
31    // ============================================================================
32
33    impl PtxParser for Adim {
34        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
35            alt!(
36                map(string_p(".a1d"), |_, _span| Adim::A1d),
37                map(string_p(".a2d"), |_, _span| Adim::A2d)
38            )
39        }
40    }
41
42    impl PtxParser for Cop {
43        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
44            alt!(
45                map(string_p(".wb"), |_, _span| Cop::Wb),
46                map(string_p(".cg"), |_, _span| Cop::Cg),
47                map(string_p(".cs"), |_, _span| Cop::Cs),
48                map(string_p(".wt"), |_, _span| Cop::Wt)
49            )
50        }
51    }
52
53    impl PtxParser for Ctype {
54        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
55            alt!(
56                map(string_p(".b16"), |_, _span| Ctype::B16),
57                map(string_p(".b32"), |_, _span| Ctype::B32),
58                map(string_p(".b64"), |_, _span| Ctype::B64),
59                map(string_p(".b8"), |_, _span| Ctype::B8)
60            )
61        }
62    }
63
64    impl PtxParser for Dim {
65        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
66            alt!(
67                map(string_p(".1d"), |_, _span| Dim::_1d),
68                map(string_p(".2d"), |_, _span| Dim::_2d),
69                map(string_p(".3d"), |_, _span| Dim::_3d)
70            )
71        }
72    }
73
74    impl PtxParser for Mode {
75        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
76            alt!(
77                map(string_p(".clamp"), |_, _span| Mode::Clamp),
78                map(string_p(".trap"), |_, _span| Mode::Trap),
79                map(string_p(".zero"), |_, _span| Mode::Zero)
80            )
81        }
82    }
83
84    impl PtxParser for Vec {
85        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
86            alt!(
87                map(string_p("none"), |_, _span| Vec::None),
88                map(string_p(".v2"), |_, _span| Vec::V2),
89                map(string_p(".v4"), |_, _span| Vec::V4)
90            )
91        }
92    }
93
94    impl PtxParser for SustBDimCopVecCtypeMode {
95        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
96            try_map(
97                seq_n!(
98                    string_p("sust"),
99                    string_p(".b"),
100                    Dim::parse(),
101                    optional(Cop::parse()),
102                    Vec::parse(),
103                    Ctype::parse(),
104                    optional(Mode::parse()),
105                    TexHandler2::parse(),
106                    comma_p(),
107                    GeneralOperand::parse(),
108                    semicolon_p()
109                ),
110                |(_, b, dim, cop, vec, ctype, mode, a, _, c, _), span| {
111                    ok!(SustBDimCopVecCtypeMode {
112                        b = b,
113                        dim = dim,
114                        cop = cop,
115                        vec = vec,
116                        ctype = ctype,
117                        mode = mode,
118                        a = a,
119                        c = c,
120
121                    })
122                },
123            )
124        }
125    }
126
127    impl PtxParser for SustPDimVecB32Mode {
128        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
129            try_map(
130                seq_n!(
131                    string_p("sust"),
132                    string_p(".p"),
133                    Dim::parse(),
134                    Vec::parse(),
135                    string_p(".b32"),
136                    optional(Mode::parse()),
137                    TexHandler2::parse(),
138                    comma_p(),
139                    GeneralOperand::parse(),
140                    semicolon_p()
141                ),
142                |(_, p, dim, vec, b32, mode, a, _, c, _), span| {
143                    ok!(SustPDimVecB32Mode {
144                        p = p,
145                        dim = dim,
146                        vec = vec,
147                        b32 = b32,
148                        mode = mode,
149                        a = a,
150                        c = c,
151
152                    })
153                },
154            )
155        }
156    }
157
158    impl PtxParser for SustBAdimCopVecCtypeMode {
159        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
160            try_map(
161                seq_n!(
162                    string_p("sust"),
163                    string_p(".b"),
164                    Adim::parse(),
165                    optional(Cop::parse()),
166                    Vec::parse(),
167                    Ctype::parse(),
168                    optional(Mode::parse()),
169                    TexHandler2::parse(),
170                    comma_p(),
171                    GeneralOperand::parse(),
172                    semicolon_p()
173                ),
174                |(_, b, adim, cop, vec, ctype, mode, a, _, c, _), span| {
175                    ok!(SustBAdimCopVecCtypeMode {
176                        b = b,
177                        adim = adim,
178                        cop = cop,
179                        vec = vec,
180                        ctype = ctype,
181                        mode = mode,
182                        a = a,
183                        c = c,
184
185                    })
186                },
187            )
188        }
189    }
190}