ptx_parser/parser/instruction/
setmaxnreg.rs

1//! Original PTX specification:
2//!
3//! setmaxnreg.action.sync.aligned.u32 imm-reg-count;
4//! .action = { .inc, .dec };
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::setmaxnreg::section_0::*;
15
16    // ============================================================================
17    // Generated enum parsers
18    // ============================================================================
19
20    impl PtxParser for Action {
21        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
22            // Try Inc
23            {
24                let saved_pos = stream.position();
25                if stream.expect_string(".inc").is_ok() {
26                    return Ok(Action::Inc);
27                }
28                stream.set_position(saved_pos);
29            }
30            let saved_pos = stream.position();
31            // Try Dec
32            {
33                let saved_pos = stream.position();
34                if stream.expect_string(".dec").is_ok() {
35                    return Ok(Action::Dec);
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 = &[".inc", ".dec"];
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 SetmaxnregActionSyncAlignedU32 {
54        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
55            stream.expect_string("setmaxnreg")?;
56            let action = Action::parse(stream)?;
57            stream.expect_complete()?;
58            stream.expect_string(".sync")?;
59            let sync = ();
60            stream.expect_complete()?;
61            stream.expect_string(".aligned")?;
62            let aligned = ();
63            stream.expect_complete()?;
64            stream.expect_string(".u32")?;
65            let u32 = ();
66            stream.expect_complete()?;
67            let imm_reg_count = GeneralOperand::parse(stream)?;
68            stream.expect_complete()?;
69            stream.expect_complete()?;
70            stream.expect(&PtxToken::Semicolon)?;
71            Ok(SetmaxnregActionSyncAlignedU32 {
72                action,
73                sync,
74                aligned,
75                u32,
76                imm_reg_count,
77            })
78        }
79    }
80}