Skip to main content

ptx_parser/parser/instruction/
match_sync.rs

1//! Original PTX specification:
2//!
3//! match.any.sync.type  d, a, membermask;
4//! match.all.sync.type  d{|p}, a, membermask;
5//! .type = { .b32, .b64 };
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::match_sync::section_0::*;
22
23    // ============================================================================
24    // Generated enum parsers
25    // ============================================================================
26
27    impl PtxParser for Type {
28        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
29            alt!(
30                map(string_p(".b32"), |_, _span| Type::B32),
31                map(string_p(".b64"), |_, _span| Type::B64)
32            )
33        }
34    }
35
36    impl PtxParser for MatchAnySyncType {
37        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
38            try_map(
39                seq_n!(
40                    string_p("match"),
41                    string_p(".any"),
42                    string_p(".sync"),
43                    Type::parse(),
44                    GeneralOperand::parse(),
45                    comma_p(),
46                    GeneralOperand::parse(),
47                    comma_p(),
48                    GeneralOperand::parse(),
49                    semicolon_p()
50                ),
51                |(_, any, sync, type_, d, _, a, _, membermask, _), span| {
52                    ok!(MatchAnySyncType {
53                        any = any,
54                        sync = sync,
55                        type_ = type_,
56                        d = d,
57                        a = a,
58                        membermask = membermask,
59
60                    })
61                },
62            )
63        }
64    }
65
66    impl PtxParser for MatchAllSyncType {
67        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
68            try_map(
69                seq_n!(
70                    string_p("match"),
71                    string_p(".all"),
72                    string_p(".sync"),
73                    Type::parse(),
74                    GeneralOperand::parse(),
75                    map(
76                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
77                        |value, _| value.map(|(_, operand)| operand)
78                    ),
79                    comma_p(),
80                    GeneralOperand::parse(),
81                    comma_p(),
82                    GeneralOperand::parse(),
83                    semicolon_p()
84                ),
85                |(_, all, sync, type_, d, p, _, a, _, membermask, _), span| {
86                    ok!(MatchAllSyncType {
87                        all = all,
88                        sync = sync,
89                        type_ = type_,
90                        d = d,
91                        p = p,
92                        a = a,
93                        membermask = membermask,
94
95                    })
96                },
97            )
98        }
99    }
100}