ptx_parser/parser/instruction/
mov.rs

1//! Original PTX specification:
2//!
3//! mov.type  d, a;
4//! // mov.type  d, sreg;
5//! // mov.type  d, avar;       // get address of variable
6//! // mov.type  d, avar+imm;   // get address of variable with offset
7//! mov.u32   d, fname;      // get address of device function
8//! mov.u64   d, fname;      // get address of device function
9//! mov.u32   d, kernel;     // get address of entry function
10//! mov.u64   d, kernel;     // get address of entry function
11//! .type = { .pred,
12//! .b16, .b32, .b64,
13//! .u16, .u32, .u64,
14//! .s16, .s32, .s64,
15//! .f32, .f64 };
16//! ----------------------------------------------
17//! mov.type  d, a;
18//! .type = { .b16, .b32, .b64, .b128 };
19
20#![allow(unused)]
21
22use crate::parser::{
23    PtxParseError, PtxParser, PtxTokenStream, Span,
24    util::{
25        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
26        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
27    },
28};
29use crate::r#type::common::*;
30use crate::{alt, ok, seq_n};
31
32pub mod section_0 {
33    use super::*;
34    use crate::r#type::instruction::mov::section_0::*;
35
36    // ============================================================================
37    // Generated enum parsers
38    // ============================================================================
39
40    impl PtxParser for Type {
41        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
42            alt!(
43                map(string_p(".pred"), |_, _span| Type::Pred),
44                map(string_p(".b16"), |_, _span| Type::B16),
45                map(string_p(".b32"), |_, _span| Type::B32),
46                map(string_p(".b64"), |_, _span| Type::B64),
47                map(string_p(".u16"), |_, _span| Type::U16),
48                map(string_p(".u32"), |_, _span| Type::U32),
49                map(string_p(".u64"), |_, _span| Type::U64),
50                map(string_p(".s16"), |_, _span| Type::S16),
51                map(string_p(".s32"), |_, _span| Type::S32),
52                map(string_p(".s64"), |_, _span| Type::S64),
53                map(string_p(".f32"), |_, _span| Type::F32),
54                map(string_p(".f64"), |_, _span| Type::F64)
55            )
56        }
57    }
58
59    impl PtxParser for MovType {
60        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
61            try_map(
62                seq_n!(
63                    string_p("mov"),
64                    Type::parse(),
65                    GeneralOperand::parse(),
66                    comma_p(),
67                    GeneralOperand::parse(),
68                    semicolon_p()
69                ),
70                |(_, type_, d, _, a, _), span| {
71                    ok!(MovType {
72                        type_ = type_,
73                        d = d,
74                        a = a,
75
76                    })
77                },
78            )
79        }
80    }
81
82    impl PtxParser for MovU32 {
83        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
84            try_map(
85                seq_n!(
86                    string_p("mov"),
87                    string_p(".u32"),
88                    GeneralOperand::parse(),
89                    comma_p(),
90                    GeneralOperand::parse(),
91                    semicolon_p()
92                ),
93                |(_, u32, d, _, fname, _), span| {
94                    ok!(MovU32 {
95                        u32 = u32,
96                        d = d,
97                        fname = fname,
98
99                    })
100                },
101            )
102        }
103    }
104
105    impl PtxParser for MovU64 {
106        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
107            try_map(
108                seq_n!(
109                    string_p("mov"),
110                    string_p(".u64"),
111                    GeneralOperand::parse(),
112                    comma_p(),
113                    GeneralOperand::parse(),
114                    semicolon_p()
115                ),
116                |(_, u64, d, _, fname, _), span| {
117                    ok!(MovU64 {
118                        u64 = u64,
119                        d = d,
120                        fname = fname,
121
122                    })
123                },
124            )
125        }
126    }
127
128    impl PtxParser for MovU321 {
129        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
130            try_map(
131                seq_n!(
132                    string_p("mov"),
133                    string_p(".u32"),
134                    GeneralOperand::parse(),
135                    comma_p(),
136                    GeneralOperand::parse(),
137                    semicolon_p()
138                ),
139                |(_, u32, d, _, kernel, _), span| {
140                    ok!(MovU321 {
141                        u32 = u32,
142                        d = d,
143                        kernel = kernel,
144
145                    })
146                },
147            )
148        }
149    }
150
151    impl PtxParser for MovU641 {
152        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
153            try_map(
154                seq_n!(
155                    string_p("mov"),
156                    string_p(".u64"),
157                    GeneralOperand::parse(),
158                    comma_p(),
159                    GeneralOperand::parse(),
160                    semicolon_p()
161                ),
162                |(_, u64, d, _, kernel, _), span| {
163                    ok!(MovU641 {
164                        u64 = u64,
165                        d = d,
166                        kernel = kernel,
167
168                    })
169                },
170            )
171        }
172    }
173}
174
175pub mod section_1 {
176    use super::*;
177    use crate::r#type::instruction::mov::section_1::*;
178
179    // ============================================================================
180    // Generated enum parsers
181    // ============================================================================
182
183    impl PtxParser for Type {
184        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
185            alt!(
186                map(string_p(".b128"), |_, _span| Type::B128),
187                map(string_p(".b16"), |_, _span| Type::B16),
188                map(string_p(".b32"), |_, _span| Type::B32),
189                map(string_p(".b64"), |_, _span| Type::B64)
190            )
191        }
192    }
193
194    impl PtxParser for MovType1 {
195        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
196            try_map(
197                seq_n!(
198                    string_p("mov"),
199                    Type::parse(),
200                    GeneralOperand::parse(),
201                    comma_p(),
202                    GeneralOperand::parse(),
203                    semicolon_p()
204                ),
205                |(_, type_, d, _, a, _), span| {
206                    ok!(MovType1 {
207                        type_ = type_,
208                        d = d,
209                        a = a,
210
211                    })
212                },
213            )
214        }
215    }
216}