ptx_parser/parser/instruction/
mad24.rs

1//! Original PTX specification:
2//!
3//! mad24.mode.type  d, a, b, c;
4//! mad24.hi.sat.s32 d, a, b, c;
5//! .mode = { .hi, .lo };
6//! .type = { .u32, .s32 };
7
8#![allow(unused)]
9
10use crate::parser::{
11    PtxParseError, PtxParser, PtxTokenStream, Span,
12    util::{
13        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
14        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
15    },
16};
17use crate::r#type::common::*;
18use crate::{alt, ok, seq_n};
19
20pub mod section_0 {
21    use super::*;
22    use crate::r#type::instruction::mad24::section_0::*;
23
24    // ============================================================================
25    // Generated enum parsers
26    // ============================================================================
27
28    impl PtxParser for Mode {
29        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
30            alt!(
31                map(string_p(".hi"), |_, _span| Mode::Hi),
32                map(string_p(".lo"), |_, _span| Mode::Lo)
33            )
34        }
35    }
36
37    impl PtxParser for Type {
38        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
39            alt!(
40                map(string_p(".u32"), |_, _span| Type::U32),
41                map(string_p(".s32"), |_, _span| Type::S32)
42            )
43        }
44    }
45
46    impl PtxParser for Mad24ModeType {
47        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
48            try_map(
49                seq_n!(
50                    string_p("mad24"),
51                    Mode::parse(),
52                    Type::parse(),
53                    GeneralOperand::parse(),
54                    comma_p(),
55                    GeneralOperand::parse(),
56                    comma_p(),
57                    GeneralOperand::parse(),
58                    comma_p(),
59                    GeneralOperand::parse(),
60                    semicolon_p()
61                ),
62                |(_, mode, type_, d, _, a, _, b, _, c, _), span| {
63                    ok!(Mad24ModeType {
64                        mode = mode,
65                        type_ = type_,
66                        d = d,
67                        a = a,
68                        b = b,
69                        c = c,
70
71                    })
72                },
73            )
74        }
75    }
76
77    impl PtxParser for Mad24HiSatS32 {
78        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
79            try_map(
80                seq_n!(
81                    string_p("mad24"),
82                    string_p(".hi"),
83                    string_p(".sat"),
84                    string_p(".s32"),
85                    GeneralOperand::parse(),
86                    comma_p(),
87                    GeneralOperand::parse(),
88                    comma_p(),
89                    GeneralOperand::parse(),
90                    comma_p(),
91                    GeneralOperand::parse(),
92                    semicolon_p()
93                ),
94                |(_, hi, sat, s32, d, _, a, _, b, _, c, _), span| {
95                    ok!(Mad24HiSatS32 {
96                        hi = hi,
97                        sat = sat,
98                        s32 = s32,
99                        d = d,
100                        a = a,
101                        b = b,
102                        c = c,
103
104                    })
105                },
106            )
107        }
108    }
109}