ptx_parser/parser/instruction/
madc.rs

1//! Original PTX specification:
2//!
3//! madc.hilo{.cc}.type  d, a, b, c;
4//! .type = { .u32, .s32, .u64, .s64 };
5//! .hilo = { .hi, .lo };
6
7#![allow(unused)]
8
9use crate::parser::{
10    PtxParseError, PtxParser, PtxTokenStream, Span,
11    util::{
12        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
13        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
14    },
15};
16use crate::r#type::common::*;
17use crate::{alt, ok, seq_n};
18
19pub mod section_0 {
20    use super::*;
21    use crate::r#type::instruction::madc::section_0::*;
22
23    // ============================================================================
24    // Generated enum parsers
25    // ============================================================================
26
27    impl PtxParser for Hilo {
28        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
29            alt!(
30                map(string_p(".hi"), |_, _span| Hilo::Hi),
31                map(string_p(".lo"), |_, _span| Hilo::Lo)
32            )
33        }
34    }
35
36    impl PtxParser for Type {
37        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
38            alt!(
39                map(string_p(".u32"), |_, _span| Type::U32),
40                map(string_p(".s32"), |_, _span| Type::S32),
41                map(string_p(".u64"), |_, _span| Type::U64),
42                map(string_p(".s64"), |_, _span| Type::S64)
43            )
44        }
45    }
46
47    impl PtxParser for MadcHiloCcType {
48        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
49            try_map(
50                seq_n!(
51                    string_p("madc"),
52                    Hilo::parse(),
53                    map(optional(string_p(".cc")), |value, _| value.is_some()),
54                    Type::parse(),
55                    GeneralOperand::parse(),
56                    comma_p(),
57                    GeneralOperand::parse(),
58                    comma_p(),
59                    GeneralOperand::parse(),
60                    comma_p(),
61                    GeneralOperand::parse(),
62                    semicolon_p()
63                ),
64                |(_, hilo, cc, type_, d, _, a, _, b, _, c, _), span| {
65                    ok!(MadcHiloCcType {
66                        hilo = hilo,
67                        cc = cc,
68                        type_ = type_,
69                        d = d,
70                        a = a,
71                        b = b,
72                        c = c,
73
74                    })
75                },
76            )
77        }
78    }
79}