ptx_parser/type/
module.rs

1use super::common::*;
2use super::function::{DwarfDirective, SectionDirective};
3use super::variable::ModuleVariableDirective;
4use crate::Spanned;
5use crate::parser::Span;
6use crate::r#type::{AliasFunctionDirective, EntryFunctionDirective, FuncFunctionDirective};
7
8/// A full PTX module containing directives and function definitions.
9#[derive(Debug, Clone, PartialEq, Spanned, Default)]
10pub struct Module {
11    pub directives: Vec<ModuleDirective>,
12    pub span: Span,
13}
14
15/// Module-level directives recognised by the parser.
16#[derive(Debug, Clone, PartialEq, Spanned)]
17pub enum ModuleDirective {
18    ModuleVariable {
19        linkage: Option<DataLinkage>,
20        directive: ModuleVariableDirective,
21        span: Span,
22    },
23    EntryFunction {
24        linkage: Option<CodeLinkage>,
25        directive: EntryFunctionDirective,
26        span: Span,
27    },
28    FuncFunction {
29        linkage: Option<CodeLinkage>,
30        directive: FuncFunctionDirective,
31        span: Span,
32    },
33    AliasFunction {
34        directive: AliasFunctionDirective,
35        span: Span,
36    },
37    ModuleInfo {
38        directive: ModuleInfoDirectiveKind,
39        span: Span,
40    },
41    Debug {
42        directive: ModuleDebugDirective,
43        span: Span,
44    },
45}
46
47/// Directives that apply to the PTX module as a whole.
48#[derive(Debug, Clone, PartialEq, Spanned)]
49pub enum ModuleInfoDirectiveKind {
50    Version {
51        directive: VersionDirective,
52        span: Span,
53    },
54    Target {
55        directive: TargetDirective,
56        span: Span,
57    },
58    AddressSize {
59        directive: AddressSizeDirective,
60        span: Span,
61    },
62}
63
64/// Structured representation of the `.version` directive.
65///
66/// Syntax:
67/// .version  major.minor    // major, minor are integers
68///
69/// Example:
70/// .version 3.1
71/// .version 3.0
72/// .version 2.3
73#[derive(Debug, Clone, PartialEq, Spanned)]
74pub struct VersionDirective {
75    pub major: u32,
76    pub minor: u32,
77    pub span: Span,
78}
79
80/// Structured representation of the `.target` directive.
81///
82/// Syntax:
83/// .target stringlist         // comma separated list of target specifiers
84/// string = { sm_120a, sm_120f, sm_120,          // sm_12x target architectures
85/// sm_121a, sm_121f, sm_121,          // sm_12x target architectures
86/// sm_110a, sm_110f, sm_110,          // sm_11x target architectures
87/// sm_100a, sm_100f, sm_100,          // sm_10x target architectures
88/// sm_101a, sm_101f, sm_101,          // sm_10x target architectures
89/// sm_103a, sm_103f, sm_103           // sm_10x target architectures
90/// sm_90a, sm_90,                     // sm_9x target architectures
91/// sm_80, sm_86, sm_87, sm_88, sm_89, // sm_8x target architectures
92/// sm_70, sm_72, sm_75,               // sm_7x target architectures
93/// sm_60, sm_61, sm_62,               // sm_6x target architectures
94/// sm_50, sm_52, sm_53,               // sm_5x target architectures
95/// sm_30, sm_32, sm_35, sm_37,        // sm_3x target architectures
96/// sm_20,                             // sm_2x target architectures
97/// sm_10, sm_11, sm_12, sm_13,        // sm_1x target architectures
98/// texmode_unified, texmode_independent,   // texturing mode
99/// debug,                                  // platform option
100/// map_f64_to_f32 };                       // platform option
101///
102/// Example:
103/// .target sm_10       // baseline target architecture
104/// .target sm_13       // supports double-precision
105/// .target sm_20, texmode_independent
106/// .target sm_90       // baseline target architecture
107/// .target sm_90a      // PTX using architecture-specific features
108/// .target sm_100f     // PTX using family-specific features
109#[derive(Debug, Clone, PartialEq, Spanned)]
110pub struct TargetDirective {
111    pub entries: Vec<TargetString>,
112    pub span: Span,
113}
114
115/// Structured representation of the `.address_size` directive.
116///
117/// Syntax:
118/// .address_size  address-size
119/// address-size = { 32, 64 };
120///
121/// Example:
122/// .address_size 64
123#[derive(Debug, Clone, PartialEq, Spanned)]
124pub struct AddressSizeDirective {
125    pub size: AddressSize,
126    pub span: Span,
127}
128
129/// Debugging directives defined by the PTX ISA.
130#[derive(Debug, Clone, PartialEq, Spanned)]
131pub enum ModuleDebugDirective {
132    File {
133        directive: FileDirective,
134        span: Span,
135    },
136    Section {
137        directive: SectionDirective,
138        span: Span,
139    },
140    Dwarf {
141        directive: DwarfDirective,
142        span: Span,
143    },
144}
145
146/// Structured representation of the `.file` directive.
147///
148/// Syntax:
149/// .file file_index "filename" {, timestamp, file_size}
150///
151/// Example:
152/// .file 1 "example.cu"
153/// .file 2 "kernel.cu"
154/// .file 1 "kernel.cu", 1339013327, 64118
155#[derive(Debug, Clone, PartialEq, Spanned)]
156pub struct FileDirective {
157    pub index: u32,
158    pub path: String,
159    pub timestamp: Option<u64>,
160    pub file_size: Option<u64>,
161    pub span: Span,
162}
163
164/// Target specifiers used in the `.target` directive.
165#[derive(Debug, Clone, PartialEq, Spanned)]
166pub enum TargetString {
167    Sm120a { span: Span },
168    Sm120f { span: Span },
169    Sm120 { span: Span },
170    Sm121a { span: Span },
171    Sm121f { span: Span },
172    Sm121 { span: Span },
173    Sm110a { span: Span },
174    Sm110f { span: Span },
175    Sm110 { span: Span },
176    Sm100a { span: Span },
177    Sm100f { span: Span },
178    Sm100 { span: Span },
179    Sm101a { span: Span },
180    Sm101f { span: Span },
181    Sm101 { span: Span },
182    Sm103a { span: Span },
183    Sm103f { span: Span },
184    Sm103 { span: Span },
185    Sm90a { span: Span },
186    Sm90 { span: Span },
187    Sm80 { span: Span },
188    Sm86 { span: Span },
189    Sm87 { span: Span },
190    Sm88 { span: Span },
191    Sm89 { span: Span },
192    Sm70 { span: Span },
193    Sm72 { span: Span },
194    Sm75 { span: Span },
195    Sm60 { span: Span },
196    Sm61 { span: Span },
197    Sm62 { span: Span },
198    Sm50 { span: Span },
199    Sm52 { span: Span },
200    Sm53 { span: Span },
201    Sm30 { span: Span },
202    Sm32 { span: Span },
203    Sm35 { span: Span },
204    Sm37 { span: Span },
205    Sm20 { span: Span },
206    Sm10 { span: Span },
207    Sm11 { span: Span },
208    Sm12 { span: Span },
209    Sm13 { span: Span },
210    TexmodeUnified { span: Span },
211    TexmodeIndependent { span: Span },
212    Debug { span: Span },
213    MapF64ToF32 { span: Span },
214}
215
216/// Address size options for the `.address_size` directive.
217#[derive(Debug, Clone, PartialEq, Spanned)]
218pub enum AddressSize {
219    Size32 { span: Span },
220    Size64 { span: Span },
221}