ptx_parser/parser/instruction/
mapa.rs

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