ptx_parser/parser/instruction/
cvta.rs

1//! Original PTX specification:
2//!
3//! // convert const, global, local, or shared address to generic address
4//! cvta.space.size  p, a;        // source address in register a
5//! // cvta.space.size  p, var;      // get generic address of var
6//! // cvta.space.size  p, var+imm;  // generic address of var+offset
7//! // convert generic address to const, global, local, or shared address
8//! cvta.to.space.size  p, a;
9//! .space = { .const, .global, .local, .shared, .shared::cta, .shared::cluster, .param, .param::entry };
10//! .size  = { .u32, .u64 };
11
12#![allow(unused)]
13
14use crate::parser::{
15    PtxParseError, PtxParser, PtxTokenStream, Span,
16    util::{
17        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
18        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
19    },
20};
21use crate::r#type::common::*;
22use crate::{alt, ok, seq_n};
23
24pub mod section_0 {
25    use super::*;
26    use crate::r#type::instruction::cvta::section_0::*;
27
28    // ============================================================================
29    // Generated enum parsers
30    // ============================================================================
31
32    impl PtxParser for Size {
33        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
34            alt!(
35                map(string_p(".u32"), |_, _span| Size::U32),
36                map(string_p(".u64"), |_, _span| Size::U64)
37            )
38        }
39    }
40
41    impl PtxParser for Space {
42        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
43            alt!(
44                map(string_p(".shared::cluster"), |_, _span| {
45                    Space::SharedCluster
46                }),
47                map(string_p(".param::entry"), |_, _span| Space::ParamEntry),
48                map(string_p(".shared::cta"), |_, _span| Space::SharedCta),
49                map(string_p(".global"), |_, _span| Space::Global),
50                map(string_p(".shared"), |_, _span| Space::Shared),
51                map(string_p(".const"), |_, _span| Space::Const),
52                map(string_p(".local"), |_, _span| Space::Local),
53                map(string_p(".param"), |_, _span| Space::Param)
54            )
55        }
56    }
57
58    impl PtxParser for CvtaSpaceSize {
59        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
60            try_map(
61                seq_n!(
62                    string_p("cvta"),
63                    Space::parse(),
64                    Size::parse(),
65                    GeneralOperand::parse(),
66                    comma_p(),
67                    GeneralOperand::parse(),
68                    semicolon_p()
69                ),
70                |(_, space, size, p, _, a, _), span| {
71                    ok!(CvtaSpaceSize {
72                        space = space,
73                        size = size,
74                        p = p,
75                        a = a,
76
77                    })
78                },
79            )
80        }
81    }
82
83    impl PtxParser for CvtaToSpaceSize {
84        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
85            try_map(
86                seq_n!(
87                    string_p("cvta"),
88                    string_p(".to"),
89                    Space::parse(),
90                    Size::parse(),
91                    GeneralOperand::parse(),
92                    comma_p(),
93                    GeneralOperand::parse(),
94                    semicolon_p()
95                ),
96                |(_, to, space, size, p, _, a, _), span| {
97                    ok!(CvtaToSpaceSize {
98                        to = to,
99                        space = space,
100                        size = size,
101                        p = p,
102                        a = a,
103
104                    })
105                },
106            )
107        }
108    }
109}