ptx_parser/parser/instruction/
ldu.rs

1//! Original PTX specification:
2//!
3//! ldu{.ss}.type      d, [a];       // load from address
4//! ldu{.ss}.vec.type  d, [a];       // vec load from address
5//! .ss   = { .global };             // state space
6//! .vec  = { .v2, .v4 };
7//! .type = { .b8, .b16, .b32, .b64, .b128,
8//! .u8, .u16, .u32, .u64,
9//! .s8, .s16, .s32, .s64,
10//! .f32, .f64 };
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::ldu::section_0::*;
27
28    // ============================================================================
29    // Generated enum parsers
30    // ============================================================================
31
32    impl PtxParser for Ss {
33        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
34            alt!(map(string_p(".global"), |_, _span| Ss::Global))
35        }
36    }
37
38    impl PtxParser for Type {
39        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
40            alt!(
41                map(string_p(".b128"), |_, _span| Type::B128),
42                map(string_p(".b16"), |_, _span| Type::B16),
43                map(string_p(".b32"), |_, _span| Type::B32),
44                map(string_p(".b64"), |_, _span| Type::B64),
45                map(string_p(".u16"), |_, _span| Type::U16),
46                map(string_p(".u32"), |_, _span| Type::U32),
47                map(string_p(".u64"), |_, _span| Type::U64),
48                map(string_p(".s16"), |_, _span| Type::S16),
49                map(string_p(".s32"), |_, _span| Type::S32),
50                map(string_p(".s64"), |_, _span| Type::S64),
51                map(string_p(".f32"), |_, _span| Type::F32),
52                map(string_p(".f64"), |_, _span| Type::F64),
53                map(string_p(".b8"), |_, _span| Type::B8),
54                map(string_p(".u8"), |_, _span| Type::U8),
55                map(string_p(".s8"), |_, _span| Type::S8)
56            )
57        }
58    }
59
60    impl PtxParser for Vec {
61        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
62            alt!(
63                map(string_p(".v2"), |_, _span| Vec::V2),
64                map(string_p(".v4"), |_, _span| Vec::V4)
65            )
66        }
67    }
68
69    impl PtxParser for LduSsType {
70        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
71            try_map(
72                seq_n!(
73                    string_p("ldu"),
74                    optional(Ss::parse()),
75                    Type::parse(),
76                    GeneralOperand::parse(),
77                    comma_p(),
78                    AddressOperand::parse(),
79                    semicolon_p()
80                ),
81                |(_, ss, type_, d, _, a, _), span| {
82                    ok!(LduSsType {
83                        ss = ss,
84                        type_ = type_,
85                        d = d,
86                        a = a,
87
88                    })
89                },
90            )
91        }
92    }
93
94    impl PtxParser for LduSsVecType {
95        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
96            try_map(
97                seq_n!(
98                    string_p("ldu"),
99                    optional(Ss::parse()),
100                    Vec::parse(),
101                    Type::parse(),
102                    GeneralOperand::parse(),
103                    comma_p(),
104                    AddressOperand::parse(),
105                    semicolon_p()
106                ),
107                |(_, ss, vec, type_, d, _, a, _), span| {
108                    ok!(LduSsVecType {
109                        ss = ss,
110                        vec = vec,
111                        type_ = type_,
112                        d = d,
113                        a = a,
114
115                    })
116                },
117            )
118        }
119    }
120}