ptx_parser/parser/instruction/
suld.rs

1//! Original PTX specification:
2//!
3//! suld.b.geom{.cop}.vec.dtype{.mode}  d, [a, b];  // unformatted
4//!
5//! .geom  = { .1d, .2d, .3d, .a1d, .a2d };
6//! .cop   = { .ca, .cg, .cs, .cv };               // cache operation
7//! .vec   = { none, .v2, .v4 };
8//! .dtype = { .b8 , .b16, .b32, .b64 };
9//! .mode = { .trap, .clamp, .zero };
10
11#![allow(unused)]
12
13use crate::parser::{
14    PtxParseError, PtxParser, PtxTokenStream, Span,
15    util::{
16        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
17        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
18    },
19};
20use crate::r#type::common::*;
21use crate::{alt, ok, seq_n};
22
23pub mod section_0 {
24    use super::*;
25    use crate::r#type::instruction::suld::section_0::*;
26
27    // ============================================================================
28    // Generated enum parsers
29    // ============================================================================
30
31    impl PtxParser for Cop {
32        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
33            alt!(
34                map(string_p(".ca"), |_, _span| Cop::Ca),
35                map(string_p(".cg"), |_, _span| Cop::Cg),
36                map(string_p(".cs"), |_, _span| Cop::Cs),
37                map(string_p(".cv"), |_, _span| Cop::Cv)
38            )
39        }
40    }
41
42    impl PtxParser for Dtype {
43        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
44            alt!(
45                map(string_p(".b16"), |_, _span| Dtype::B16),
46                map(string_p(".b32"), |_, _span| Dtype::B32),
47                map(string_p(".b64"), |_, _span| Dtype::B64),
48                map(string_p(".b8"), |_, _span| Dtype::B8)
49            )
50        }
51    }
52
53    impl PtxParser for Geom {
54        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
55            alt!(
56                map(string_p(".a1d"), |_, _span| Geom::A1d),
57                map(string_p(".a2d"), |_, _span| Geom::A2d),
58                map(string_p(".1d"), |_, _span| Geom::_1d),
59                map(string_p(".2d"), |_, _span| Geom::_2d),
60                map(string_p(".3d"), |_, _span| Geom::_3d)
61            )
62        }
63    }
64
65    impl PtxParser for Mode {
66        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
67            alt!(
68                map(string_p(".clamp"), |_, _span| Mode::Clamp),
69                map(string_p(".trap"), |_, _span| Mode::Trap),
70                map(string_p(".zero"), |_, _span| Mode::Zero)
71            )
72        }
73    }
74
75    impl PtxParser for Vec {
76        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
77            alt!(
78                map(string_p("none"), |_, _span| Vec::None),
79                map(string_p(".v2"), |_, _span| Vec::V2),
80                map(string_p(".v4"), |_, _span| Vec::V4)
81            )
82        }
83    }
84
85    impl PtxParser for SuldBGeomCopVecDtypeMode {
86        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
87            try_map(
88                seq_n!(
89                    string_p("suld"),
90                    string_p(".b"),
91                    Geom::parse(),
92                    optional(Cop::parse()),
93                    Vec::parse(),
94                    Dtype::parse(),
95                    optional(Mode::parse()),
96                    GeneralOperand::parse(),
97                    comma_p(),
98                    TexHandler2::parse(),
99                    semicolon_p()
100                ),
101                |(_, b, geom, cop, vec, dtype, mode, d, _, a, _), span| {
102                    ok!(SuldBGeomCopVecDtypeMode {
103                        b = b,
104                        geom = geom,
105                        cop = cop,
106                        vec = vec,
107                        dtype = dtype,
108                        mode = mode,
109                        d = d,
110                        a = a,
111
112                    })
113                },
114            )
115        }
116    }
117}