Skip to main content

ptx_parser/parser/instruction/
testp.rs

1//! Original PTX specification:
2//!
3//! testp.op.type  p, a;  // result is .pred
4//! .op   = { .finite, .infinite,
5//! .number, .notanumber,
6//! .normal, .subnormal };
7//! .type = { .f32, .f64 };
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::testp::section_0::*;
24
25    // ============================================================================
26    // Generated enum parsers
27    // ============================================================================
28
29    impl PtxParser for Op {
30        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
31            alt!(
32                map(string_p(".notanumber"), |_, _span| Op::Notanumber),
33                map(string_p(".subnormal"), |_, _span| Op::Subnormal),
34                map(string_p(".infinite"), |_, _span| Op::Infinite),
35                map(string_p(".finite"), |_, _span| Op::Finite),
36                map(string_p(".number"), |_, _span| Op::Number),
37                map(string_p(".normal"), |_, _span| Op::Normal)
38            )
39        }
40    }
41
42    impl PtxParser for Type {
43        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
44            alt!(
45                map(string_p(".f32"), |_, _span| Type::F32),
46                map(string_p(".f64"), |_, _span| Type::F64)
47            )
48        }
49    }
50
51    impl PtxParser for TestpOpType {
52        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
53            try_map(
54                seq_n!(
55                    string_p("testp"),
56                    Op::parse(),
57                    Type::parse(),
58                    GeneralOperand::parse(),
59                    comma_p(),
60                    GeneralOperand::parse(),
61                    semicolon_p()
62                ),
63                |(_, op, type_, p, _, a, _), span| {
64                    ok!(TestpOpType {
65                        op = op,
66                        type_ = type_,
67                        p = p,
68                        a = a,
69
70                    })
71                },
72            )
73        }
74    }
75}