Skip to main content

ptx_parser/parser/instruction/
discard.rs

1//! Original PTX specification:
2//!
3//! discard{.global}.level  [a], size;
4//! .level = { .L2 };
5
6#![allow(unused)]
7
8use crate::parser::{
9    PtxParseError, PtxParser, PtxTokenStream, Span,
10    util::{
11        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
12        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
13    },
14};
15use crate::r#type::common::*;
16use crate::{alt, ok, seq_n};
17
18pub mod section_0 {
19    use super::*;
20    use crate::r#type::instruction::discard::section_0::*;
21
22    // ============================================================================
23    // Generated enum parsers
24    // ============================================================================
25
26    impl PtxParser for Level {
27        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
28            alt!(map(string_p(".L2"), |_, _span| Level::L2))
29        }
30    }
31
32    impl PtxParser for DiscardGlobalLevel {
33        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
34            try_map(
35                seq_n!(
36                    string_p("discard"),
37                    map(optional(string_p(".global")), |value, _| value.is_some()),
38                    Level::parse(),
39                    AddressOperand::parse(),
40                    comma_p(),
41                    GeneralOperand::parse(),
42                    semicolon_p()
43                ),
44                |(_, global, level, a, _, size, _), span| {
45                    ok!(DiscardGlobalLevel {
46                        global = global,
47                        level = level,
48                        a = a,
49                        size = size,
50
51                    })
52                },
53            )
54        }
55    }
56}