ptx_parser/parser/instruction/
txq.rs

1//! Original PTX specification:
2//!
3//! txq.tquery.b32         d, [a];       // texture attributes
4//! txq.level.tlquery.b32  d, [a], lod;  // texture attributes
5//! txq.squery.b32         d, [a];       // sampler attributes
6//! .tquery  = { .width, .height, .depth,
7//! .channel_data_type, .channel_order,
8//! .normalized_coords, .array_size,
9//! .num_mipmap_levels, .num_samples};
10//! .tlquery = { .width, .height, .depth };
11//! .squery  = { .force_unnormalized_coords, .filter_mode,
12//! .addr_mode_0, addr_mode_1, addr_mode_2 };
13
14#![allow(unused)]
15
16use crate::parser::{
17    PtxParseError, PtxParser, PtxTokenStream, Span,
18    util::{
19        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
20        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
21    },
22};
23use crate::r#type::common::*;
24use crate::{alt, ok, seq_n};
25
26pub mod section_0 {
27    use super::*;
28    use crate::r#type::instruction::txq::section_0::*;
29
30    // ============================================================================
31    // Generated enum parsers
32    // ============================================================================
33
34    impl PtxParser for Squery {
35        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
36            alt!(
37                map(string_p(".force_unnormalized_coords"), |_, _span| {
38                    Squery::ForceUnnormalizedCoords
39                }),
40                map(string_p(".filter_mode"), |_, _span| Squery::FilterMode),
41                map(string_p(".addr_mode_0"), |_, _span| Squery::AddrMode0),
42                map(string_p("addr_mode_1"), |_, _span| Squery::AddrMode1),
43                map(string_p("addr_mode_2"), |_, _span| Squery::AddrMode2)
44            )
45        }
46    }
47
48    impl PtxParser for Tlquery {
49        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
50            alt!(
51                map(string_p(".height"), |_, _span| Tlquery::Height),
52                map(string_p(".width"), |_, _span| Tlquery::Width),
53                map(string_p(".depth"), |_, _span| Tlquery::Depth)
54            )
55        }
56    }
57
58    impl PtxParser for Tquery {
59        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
60            alt!(
61                map(string_p(".channel_data_type"), |_, _span| {
62                    Tquery::ChannelDataType
63                }),
64                map(string_p(".normalized_coords"), |_, _span| {
65                    Tquery::NormalizedCoords
66                }),
67                map(string_p(".num_mipmap_levels"), |_, _span| {
68                    Tquery::NumMipmapLevels
69                }),
70                map(string_p(".channel_order"), |_, _span| Tquery::ChannelOrder),
71                map(string_p(".num_samples"), |_, _span| Tquery::NumSamples),
72                map(string_p(".array_size"), |_, _span| Tquery::ArraySize),
73                map(string_p(".height"), |_, _span| Tquery::Height),
74                map(string_p(".width"), |_, _span| Tquery::Width),
75                map(string_p(".depth"), |_, _span| Tquery::Depth)
76            )
77        }
78    }
79
80    impl PtxParser for TxqTqueryB32 {
81        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
82            try_map(
83                seq_n!(
84                    string_p("txq"),
85                    Tquery::parse(),
86                    string_p(".b32"),
87                    GeneralOperand::parse(),
88                    comma_p(),
89                    AddressOperand::parse(),
90                    semicolon_p()
91                ),
92                |(_, tquery, b32, d, _, a, _), span| {
93                    ok!(TxqTqueryB32 {
94                        tquery = tquery,
95                        b32 = b32,
96                        d = d,
97                        a = a,
98
99                    })
100                },
101            )
102        }
103    }
104
105    impl PtxParser for TxqLevelTlqueryB32 {
106        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
107            try_map(
108                seq_n!(
109                    string_p("txq"),
110                    string_p(".level"),
111                    Tlquery::parse(),
112                    string_p(".b32"),
113                    GeneralOperand::parse(),
114                    comma_p(),
115                    AddressOperand::parse(),
116                    comma_p(),
117                    GeneralOperand::parse(),
118                    semicolon_p()
119                ),
120                |(_, level, tlquery, b32, d, _, a, _, lod, _), span| {
121                    ok!(TxqLevelTlqueryB32 {
122                        level = level,
123                        tlquery = tlquery,
124                        b32 = b32,
125                        d = d,
126                        a = a,
127                        lod = lod,
128
129                    })
130                },
131            )
132        }
133    }
134
135    impl PtxParser for TxqSqueryB32 {
136        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
137            try_map(
138                seq_n!(
139                    string_p("txq"),
140                    Squery::parse(),
141                    string_p(".b32"),
142                    GeneralOperand::parse(),
143                    comma_p(),
144                    AddressOperand::parse(),
145                    semicolon_p()
146                ),
147                |(_, squery, b32, d, _, a, _), span| {
148                    ok!(TxqSqueryB32 {
149                        squery = squery,
150                        b32 = b32,
151                        d = d,
152                        a = a,
153
154                    })
155                },
156            )
157        }
158    }
159}