Skip to main content

ptx_parser/parser/instruction/
alloca.rs

1//! Original PTX specification:
2//!
3//! alloca.type  ptr, size{, immAlign};
4//! .type = { .u32, .u64 };
5
6#![allow(unused)]
7
8use crate::parser::{
9    PtxParseError, PtxParser, PtxTokenStream, Span,
10    util::{
11        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
12        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
13    },
14};
15use crate::r#type::common::*;
16use crate::{alt, ok, seq_n};
17
18pub mod section_0 {
19    use super::*;
20    use crate::r#type::instruction::alloca::section_0::*;
21
22    // ============================================================================
23    // Generated enum parsers
24    // ============================================================================
25
26    impl PtxParser for Type {
27        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
28            alt!(
29                map(string_p(".u32"), |_, _span| Type::U32),
30                map(string_p(".u64"), |_, _span| Type::U64)
31            )
32        }
33    }
34
35    impl PtxParser for AllocaType {
36        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
37            try_map(
38                seq_n!(
39                    string_p("alloca"),
40                    Type::parse(),
41                    GeneralOperand::parse(),
42                    comma_p(),
43                    GeneralOperand::parse(),
44                    map(
45                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
46                        |value, _| value.map(|(_, operand)| operand)
47                    ),
48                    semicolon_p()
49                ),
50                |(_, type_, ptr, _, size, immalign, _), span| {
51                    ok!(AllocaType {
52                        type_ = type_,
53                        ptr = ptr,
54                        size = size,
55                        immalign = immalign,
56
57                    })
58                },
59            )
60        }
61    }
62}