1#![allow(unused)]
24
25use crate::parser::{
26 PtxParseError, PtxParser, PtxTokenStream, Span,
27 util::{
28 between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
29 pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
30 },
31};
32use crate::r#type::common::*;
33use crate::{alt, ok, seq_n};
34
35pub mod section_0 {
36 use super::*;
37 use crate::r#type::instruction::st::section_0::*;
38
39 impl PtxParser for Cop {
44 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
45 alt!(
46 map(string_p(".wb"), |_, _span| Cop::Wb),
47 map(string_p(".cg"), |_, _span| Cop::Cg),
48 map(string_p(".cs"), |_, _span| Cop::Cs),
49 map(string_p(".wt"), |_, _span| Cop::Wt)
50 )
51 }
52 }
53
54 impl PtxParser for Level1EvictionPriority {
55 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
56 alt!(
57 map(string_p(".L1::evict_unchanged"), |_, _span| {
58 Level1EvictionPriority::L1EvictUnchanged
59 }),
60 map(string_p(".L1::evict_normal"), |_, _span| {
61 Level1EvictionPriority::L1EvictNormal
62 }),
63 map(string_p(".L1::evict_first"), |_, _span| {
64 Level1EvictionPriority::L1EvictFirst
65 }),
66 map(string_p(".L1::no_allocate"), |_, _span| {
67 Level1EvictionPriority::L1NoAllocate
68 }),
69 map(string_p(".L1::evict_last"), |_, _span| {
70 Level1EvictionPriority::L1EvictLast
71 })
72 )
73 }
74 }
75
76 impl PtxParser for Level2EvictionPriority {
77 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
78 alt!(
79 map(string_p(".L2::evict_normal"), |_, _span| {
80 Level2EvictionPriority::L2EvictNormal
81 }),
82 map(string_p(".L2::evict_first"), |_, _span| {
83 Level2EvictionPriority::L2EvictFirst
84 }),
85 map(string_p(".L2::evict_last"), |_, _span| {
86 Level2EvictionPriority::L2EvictLast
87 })
88 )
89 }
90 }
91
92 impl PtxParser for LevelCacheHint {
93 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
94 alt!(map(string_p(".L2::cache_hint"), |_, _span| {
95 LevelCacheHint::L2CacheHint
96 }))
97 }
98 }
99
100 impl PtxParser for Scope {
101 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
102 alt!(
103 map(string_p(".cluster"), |_, _span| Scope::Cluster),
104 map(string_p(".cta"), |_, _span| Scope::Cta),
105 map(string_p(".gpu"), |_, _span| Scope::Gpu),
106 map(string_p(".sys"), |_, _span| Scope::Sys)
107 )
108 }
109 }
110
111 impl PtxParser for Ss {
112 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
113 alt!(
114 map(string_p(".shared::cluster"), |_, _span| Ss::SharedCluster),
115 map(string_p(".param::func"), |_, _span| Ss::ParamFunc),
116 map(string_p(".shared::cta"), |_, _span| Ss::SharedCta),
117 map(string_p(".global"), |_, _span| Ss::Global),
118 map(string_p(".shared"), |_, _span| Ss::Shared),
119 map(string_p(".local"), |_, _span| Ss::Local),
120 map(string_p(".param"), |_, _span| Ss::Param)
121 )
122 }
123 }
124
125 impl PtxParser for Type {
126 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
127 alt!(
128 map(string_p(".b128"), |_, _span| Type::B128),
129 map(string_p(".b16"), |_, _span| Type::B16),
130 map(string_p(".b32"), |_, _span| Type::B32),
131 map(string_p(".b64"), |_, _span| Type::B64),
132 map(string_p(".u16"), |_, _span| Type::U16),
133 map(string_p(".u32"), |_, _span| Type::U32),
134 map(string_p(".u64"), |_, _span| Type::U64),
135 map(string_p(".s16"), |_, _span| Type::S16),
136 map(string_p(".s32"), |_, _span| Type::S32),
137 map(string_p(".s64"), |_, _span| Type::S64),
138 map(string_p(".f32"), |_, _span| Type::F32),
139 map(string_p(".f64"), |_, _span| Type::F64),
140 map(string_p(".b8"), |_, _span| Type::B8),
141 map(string_p(".u8"), |_, _span| Type::U8),
142 map(string_p(".s8"), |_, _span| Type::S8)
143 )
144 }
145 }
146
147 impl PtxParser for Vec {
148 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
149 alt!(
150 map(string_p(".v2"), |_, _span| Vec::V2),
151 map(string_p(".v4"), |_, _span| Vec::V4),
152 map(string_p(".v8"), |_, _span| Vec::V8)
153 )
154 }
155 }
156
157 impl PtxParser for StWeakSsCopLevelCacheHintVecType {
158 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
159 try_map(
160 seq_n!(
161 string_p("st"),
162 map(optional(string_p(".weak")), |value, _| value.is_some()),
163 optional(Ss::parse()),
164 optional(Cop::parse()),
165 optional(LevelCacheHint::parse()),
166 optional(Vec::parse()),
167 Type::parse(),
168 AddressOperand::parse(),
169 comma_p(),
170 GeneralOperand::parse(),
171 map(
172 optional(seq_n!(comma_p(), GeneralOperand::parse())),
173 |value, _| value.map(|(_, operand)| operand)
174 ),
175 semicolon_p()
176 ),
177 |(_, weak, ss, cop, level_cache_hint, vec, type_, a, _, b, cache_policy, _),
178 span| {
179 ok!(StWeakSsCopLevelCacheHintVecType {
180 weak = weak,
181 ss = ss,
182 cop = cop,
183 level_cache_hint = level_cache_hint,
184 vec = vec,
185 type_ = type_,
186 a = a,
187 b = b,
188 cache_policy = cache_policy,
189
190 })
191 },
192 )
193 }
194 }
195
196 impl PtxParser for StWeakSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintVecType {
197 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
198 try_map(
199 seq_n!(
200 string_p("st"),
201 map(optional(string_p(".weak")), |value, _| value.is_some()),
202 optional(Ss::parse()),
203 optional(Level1EvictionPriority::parse()),
204 optional(Level2EvictionPriority::parse()),
205 optional(LevelCacheHint::parse()),
206 optional(Vec::parse()),
207 Type::parse(),
208 AddressOperand::parse(),
209 comma_p(),
210 GeneralOperand::parse(),
211 map(
212 optional(seq_n!(comma_p(), GeneralOperand::parse())),
213 |value, _| value.map(|(_, operand)| operand)
214 ),
215 semicolon_p()
216 ),
217 |(
218 _,
219 weak,
220 ss,
221 level1_eviction_priority,
222 level2_eviction_priority,
223 level_cache_hint,
224 vec,
225 type_,
226 a,
227 _,
228 b,
229 cache_policy,
230 _,
231 ),
232 span| {
233 ok!(StWeakSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintVecType {
234 weak = weak,
235 ss = ss,
236 level1_eviction_priority = level1_eviction_priority,
237 level2_eviction_priority = level2_eviction_priority,
238 level_cache_hint = level_cache_hint,
239 vec = vec,
240 type_ = type_,
241 a = a,
242 b = b,
243 cache_policy = cache_policy,
244
245 })
246 },
247 )
248 }
249 }
250
251 impl PtxParser for StVolatileSsVecType {
252 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
253 try_map(
254 seq_n!(
255 string_p("st"),
256 string_p(".volatile"),
257 optional(Ss::parse()),
258 optional(Vec::parse()),
259 Type::parse(),
260 AddressOperand::parse(),
261 comma_p(),
262 GeneralOperand::parse(),
263 semicolon_p()
264 ),
265 |(_, volatile, ss, vec, type_, a, _, b, _), span| {
266 ok!(StVolatileSsVecType {
267 volatile = volatile,
268 ss = ss,
269 vec = vec,
270 type_ = type_,
271 a = a,
272 b = b,
273
274 })
275 },
276 )
277 }
278 }
279
280 impl PtxParser
281 for StRelaxedScopeSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintVecType
282 {
283 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
284 try_map(
285 seq_n!(
286 string_p("st"),
287 string_p(".relaxed"),
288 Scope::parse(),
289 optional(Ss::parse()),
290 optional(Level1EvictionPriority::parse()),
291 optional(Level2EvictionPriority::parse()),
292 optional(LevelCacheHint::parse()),
293 optional(Vec::parse()),
294 Type::parse(),
295 AddressOperand::parse(),
296 comma_p(),
297 GeneralOperand::parse(),
298 map(
299 optional(seq_n!(comma_p(), GeneralOperand::parse())),
300 |value, _| value.map(|(_, operand)| operand)
301 ),
302 semicolon_p()
303 ),
304 |(
305 _,
306 relaxed,
307 scope,
308 ss,
309 level1_eviction_priority,
310 level2_eviction_priority,
311 level_cache_hint,
312 vec,
313 type_,
314 a,
315 _,
316 b,
317 cache_policy,
318 _,
319 ),
320 span| {
321 ok!(StRelaxedScopeSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintVecType {
322 relaxed = relaxed,
323 scope = scope,
324 ss = ss,
325 level1_eviction_priority = level1_eviction_priority,
326 level2_eviction_priority = level2_eviction_priority,
327 level_cache_hint = level_cache_hint,
328 vec = vec,
329 type_ = type_,
330 a = a,
331 b = b,
332 cache_policy = cache_policy,
333
334 })
335 },
336 )
337 }
338 }
339
340 impl PtxParser
341 for StReleaseScopeSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintVecType
342 {
343 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
344 try_map(
345 seq_n!(
346 string_p("st"),
347 string_p(".release"),
348 Scope::parse(),
349 optional(Ss::parse()),
350 optional(Level1EvictionPriority::parse()),
351 optional(Level2EvictionPriority::parse()),
352 optional(LevelCacheHint::parse()),
353 optional(Vec::parse()),
354 Type::parse(),
355 AddressOperand::parse(),
356 comma_p(),
357 GeneralOperand::parse(),
358 map(
359 optional(seq_n!(comma_p(), GeneralOperand::parse())),
360 |value, _| value.map(|(_, operand)| operand)
361 ),
362 semicolon_p()
363 ),
364 |(
365 _,
366 release,
367 scope,
368 ss,
369 level1_eviction_priority,
370 level2_eviction_priority,
371 level_cache_hint,
372 vec,
373 type_,
374 a,
375 _,
376 b,
377 cache_policy,
378 _,
379 ),
380 span| {
381 ok!(StReleaseScopeSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintVecType {
382 release = release,
383 scope = scope,
384 ss = ss,
385 level1_eviction_priority = level1_eviction_priority,
386 level2_eviction_priority = level2_eviction_priority,
387 level_cache_hint = level_cache_hint,
388 vec = vec,
389 type_ = type_,
390 a = a,
391 b = b,
392 cache_policy = cache_policy,
393
394 })
395 },
396 )
397 }
398 }
399
400 impl PtxParser for StMmioRelaxedSysGlobalType {
401 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
402 try_map(
403 seq_n!(
404 string_p("st"),
405 string_p(".mmio"),
406 string_p(".relaxed"),
407 string_p(".sys"),
408 map(optional(string_p(".global")), |value, _| value.is_some()),
409 Type::parse(),
410 AddressOperand::parse(),
411 comma_p(),
412 GeneralOperand::parse(),
413 semicolon_p()
414 ),
415 |(_, mmio, relaxed, sys, global, type_, a, _, b, _), span| {
416 ok!(StMmioRelaxedSysGlobalType {
417 mmio = mmio,
418 relaxed = relaxed,
419 sys = sys,
420 global = global,
421 type_ = type_,
422 a = a,
423 b = b,
424
425 })
426 },
427 )
428 }
429 }
430}