ptx_parser/type/
module.rs

1use super::common::*;
2use super::function::{DwarfDirective, FunctionKernelDirective};
3use super::variable::ModuleVariableDirective;
4
5/// A full PTX module containing directives and function definitions.
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct Module {
8    pub directives: Vec<ModuleDirective>,
9}
10
11/// Module-level directives recognised by the parser.
12#[derive(Debug, Clone, PartialEq)]
13pub enum ModuleDirective {
14    ModuleVariable(ModuleVariableDirective),
15    FunctionKernel(FunctionKernelDirective),
16    ModuleInfo(ModuleInfoDirectiveKind),
17    Debug(ModuleDebugDirective),
18    Linking(LinkingDirective),
19}
20
21/// Directives that apply to the PTX module as a whole.
22#[derive(Debug, Clone, PartialEq)]
23pub enum ModuleInfoDirectiveKind {
24    Version(VersionDirective),
25    Target(TargetDirective),
26    AddressSize(AddressSizeDirective),
27}
28
29/// Structured representation of the `.version` directive.
30#[derive(Debug, Clone, PartialEq)]
31pub struct VersionDirective {
32    pub major: u32,
33    pub minor: u32,
34}
35
36/// Structured representation of the `.target` directive.
37#[derive(Debug, Clone, PartialEq)]
38pub struct TargetDirective {
39    pub entries: Vec<String>,
40    pub raw: String,
41}
42
43/// Structured representation of the `.address_size` directive.
44#[derive(Debug, Clone, PartialEq)]
45pub struct AddressSizeDirective {
46    pub size: u32,
47}
48
49/// Debugging directives defined by the PTX ISA.
50#[derive(Debug, Clone, PartialEq)]
51pub enum ModuleDebugDirective {
52    File(FileDirective),
53    Section(SectionDirective),
54    Dwarf(DwarfDirective),
55}
56
57/// Structured representation of the `.file` directive.
58#[derive(Debug, Clone, PartialEq)]
59pub struct FileDirective {
60    pub index: u32,
61    pub path: String,
62}
63
64/// Structured representation of the `.section` directive.
65#[derive(Debug, Clone, PartialEq)]
66pub struct SectionDirective {
67    pub name: String,
68    pub attributes: Vec<String>,
69}
70
71/// Linking directives that influence symbol visibility. TODO: further parse the
72/// prototype, which should be a function signature.
73#[derive(Debug, Clone, PartialEq)]
74pub struct LinkingDirective {
75    pub kind: CodeOrDataLinkage,
76    pub prototype: String,
77    pub raw: String,
78}