ptx_parser/parser/instruction/
tcgen05_shift.rs

1//! Original PTX specification:
2//!
3//! tcgen05.shift.cta_group.down  [taddr];
4//! .cta_group = { .cta_group::1, .cta_group::2 }
5
6#![allow(unused)]
7
8use crate::lexer::PtxToken;
9use crate::parser::{PtxParseError, PtxParser, PtxTokenStream, Span};
10use crate::r#type::common::*;
11
12pub mod section_0 {
13    use super::*;
14    use crate::r#type::instruction::tcgen05_shift::section_0::*;
15
16    // ============================================================================
17    // Generated enum parsers
18    // ============================================================================
19
20    impl PtxParser for CtaGroup {
21        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
22            // Try CtaGroup1
23            {
24                let saved_pos = stream.position();
25                if stream.expect_string(".cta_group::1").is_ok() {
26                    return Ok(CtaGroup::CtaGroup1);
27                }
28                stream.set_position(saved_pos);
29            }
30            let saved_pos = stream.position();
31            // Try CtaGroup2
32            {
33                let saved_pos = stream.position();
34                if stream.expect_string(".cta_group::2").is_ok() {
35                    return Ok(CtaGroup::CtaGroup2);
36                }
37                stream.set_position(saved_pos);
38            }
39            stream.set_position(saved_pos);
40            let span = stream
41                .peek()
42                .map(|(_, s)| s.clone())
43                .unwrap_or(Span { start: 0, end: 0 });
44            let expected = &[".cta_group::1", ".cta_group::2"];
45            let found = stream
46                .peek()
47                .map(|(t, _)| format!("{:?}", t))
48                .unwrap_or_else(|_| "<end of input>".to_string());
49            Err(crate::parser::unexpected_value(span, expected, found))
50        }
51    }
52
53    impl PtxParser for Tcgen05ShiftCtaGroupDown {
54        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
55            stream.expect_string("tcgen05")?;
56            stream.expect_string(".shift")?;
57            let shift = ();
58            stream.expect_complete()?;
59            let cta_group = CtaGroup::parse(stream)?;
60            stream.expect_complete()?;
61            stream.expect_string(".down")?;
62            let down = ();
63            stream.expect_complete()?;
64            let taddr = AddressOperand::parse(stream)?;
65            stream.expect_complete()?;
66            stream.expect_complete()?;
67            stream.expect(&PtxToken::Semicolon)?;
68            Ok(Tcgen05ShiftCtaGroupDown {
69                shift,
70                cta_group,
71                down,
72                taddr,
73            })
74        }
75    }
76}