ptx_parser/unparser/
mod.rs1pub(crate) mod common;
2pub(crate) mod function;
3pub(crate) mod instruction;
4pub(crate) mod module;
5pub(crate) mod variable;
6
7use crate::lexer::PtxToken;
8
9#[allow(unused_imports)]
10pub(crate) use common::{
11 push_decimal, push_directive, push_identifier, push_opcode, push_register, push_token_from_str,
12};
13
14pub(crate) fn push_space(tokens: &mut Vec<PtxToken>, spaced: bool) {
15 if spaced {
16 tokens.push(PtxToken::Space);
17 }
18}
19
20pub(crate) fn push_newline(tokens: &mut Vec<PtxToken>, spaced: bool) {
21 if spaced {
22 tokens.push(PtxToken::Newline);
23 }
24}
25
26pub trait PtxUnparser {
29 fn unparse_tokens(&self, tokens: &mut Vec<PtxToken>);
31
32 fn unparse_tokens_mode(&self, tokens: &mut Vec<PtxToken>, spaced: bool) {
34 let _ = spaced;
35 self.unparse_tokens(tokens);
36 }
37
38 fn to_tokens(&self) -> Vec<PtxToken> {
40 let mut tokens = Vec::new();
41 self.unparse_tokens_mode(&mut tokens, false);
42 tokens
43 }
44
45 fn to_tokens_spaced(&self) -> Vec<PtxToken> {
48 let mut tokens = Vec::new();
49 self.unparse_tokens_mode(&mut tokens, true);
50 tokens
51 }
52}