Skip to main content

ptx_parser/parser/instruction/
tld4.rs

1//! Original PTX specification:
2//!
3//! tld4.comp.2d.v4.dtype.f32    d{|p}, [a, c] {, e} {, f};
4//! tld4.comp.geom.v4.dtype.f32  d{|p}, [a, b, c] {, e} {, f};  // explicit sampler
5//! .comp  = { .r, .g, .b, .a };
6//! .geom  = { .2d, .a2d, .cube, .acube };
7//! .dtype = { .u32, .s32, .f32 };
8
9#![allow(unused)]
10
11use crate::parser::{
12    PtxParseError, PtxParser, PtxTokenStream, Span,
13    util::{
14        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
15        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
16    },
17};
18use crate::r#type::common::*;
19use crate::{alt, ok, seq_n};
20
21pub mod section_0 {
22    use super::*;
23    use crate::r#type::instruction::tld4::section_0::*;
24
25    // ============================================================================
26    // Generated enum parsers
27    // ============================================================================
28
29    impl PtxParser for Comp {
30        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
31            alt!(
32                map(string_p(".r"), |_, _span| Comp::R),
33                map(string_p(".g"), |_, _span| Comp::G),
34                map(string_p(".b"), |_, _span| Comp::B),
35                map(string_p(".a"), |_, _span| Comp::A)
36            )
37        }
38    }
39
40    impl PtxParser for Dtype {
41        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
42            alt!(
43                map(string_p(".u32"), |_, _span| Dtype::U32),
44                map(string_p(".s32"), |_, _span| Dtype::S32),
45                map(string_p(".f32"), |_, _span| Dtype::F32)
46            )
47        }
48    }
49
50    impl PtxParser for Geom {
51        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
52            alt!(
53                map(string_p(".acube"), |_, _span| Geom::Acube),
54                map(string_p(".cube"), |_, _span| Geom::Cube),
55                map(string_p(".a2d"), |_, _span| Geom::A2d),
56                map(string_p(".2d"), |_, _span| Geom::_2d)
57            )
58        }
59    }
60
61    impl PtxParser for Tld4Comp2dV4DtypeF32 {
62        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
63            try_map(
64                seq_n!(
65                    string_p("tld4"),
66                    Comp::parse(),
67                    string_p(".2d"),
68                    string_p(".v4"),
69                    Dtype::parse(),
70                    string_p(".f32"),
71                    GeneralOperand::parse(),
72                    map(
73                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
74                        |value, _| value.map(|(_, operand)| operand)
75                    ),
76                    comma_p(),
77                    TexHandler2::parse(),
78                    map(
79                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
80                        |value, _| value.map(|(_, operand)| operand)
81                    ),
82                    map(
83                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
84                        |value, _| value.map(|(_, operand)| operand)
85                    ),
86                    semicolon_p()
87                ),
88                |(_, comp, _2d, v4, dtype, f32, d, p, _, a, e, f, _), span| {
89                    ok!(Tld4Comp2dV4DtypeF32 {
90                        comp = comp,
91                        _2d = _2d,
92                        v4 = v4,
93                        dtype = dtype,
94                        f32 = f32,
95                        d = d,
96                        p = p,
97                        a = a,
98                        e = e,
99                        f = f,
100
101                    })
102                },
103            )
104        }
105    }
106
107    impl PtxParser for Tld4CompGeomV4DtypeF32 {
108        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
109            try_map(
110                seq_n!(
111                    string_p("tld4"),
112                    Comp::parse(),
113                    Geom::parse(),
114                    string_p(".v4"),
115                    Dtype::parse(),
116                    string_p(".f32"),
117                    GeneralOperand::parse(),
118                    map(
119                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
120                        |value, _| value.map(|(_, operand)| operand)
121                    ),
122                    comma_p(),
123                    TexHandler3::parse(),
124                    map(
125                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
126                        |value, _| value.map(|(_, operand)| operand)
127                    ),
128                    map(
129                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
130                        |value, _| value.map(|(_, operand)| operand)
131                    ),
132                    semicolon_p()
133                ),
134                |(_, comp, geom, v4, dtype, f32, d, p, _, a, e, f, _), span| {
135                    ok!(Tld4CompGeomV4DtypeF32 {
136                        comp = comp,
137                        geom = geom,
138                        v4 = v4,
139                        dtype = dtype,
140                        f32 = f32,
141                        d = d,
142                        p = p,
143                        a = a,
144                        e = e,
145                        f = f,
146
147                    })
148                },
149            )
150        }
151    }
152}