Skip to main content

singe_ptx/ast/
mod.rs

1mod common;
2mod directive;
3mod function;
4mod instruction;
5mod operand;
6
7pub use self::{common::*, directive::*, function::*, instruction::*, operand::*};
8
9#[derive(Debug, Clone, PartialEq)]
10pub struct Module {
11    pub span: Span,
12    pub version: VersionDirective,
13    pub target: TargetDirective,
14    pub address_size: AddressSize,
15    pub items: Vec<TopLevelItem>,
16}
17
18#[derive(Debug, Clone, PartialEq)]
19pub struct VersionDirective {
20    pub span: Span,
21    pub major: u32,
22    pub minor: u32,
23}
24
25#[derive(Debug, Clone, PartialEq)]
26pub struct TargetDirective {
27    pub span: Span,
28    pub specifiers: Vec<String>,
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum AddressSize {
33    Bits32,
34    Bits64,
35}
36
37#[derive(Debug, Clone, PartialEq)]
38pub enum TopLevelItem {
39    Function(Function),
40    Variable(VariableDecl),
41    Pragma {
42        span: Span,
43        value: String,
44    },
45    File {
46        span: Span,
47        index: u32,
48        name: String,
49        timestamp: Option<u64>,
50        file_size: Option<u64>,
51    },
52    Alias {
53        span: Span,
54        alias: String,
55        target: String,
56    },
57    Section(SectionDirective),
58}
59
60#[derive(Debug, Clone, PartialEq)]
61pub struct SectionDirective {
62    pub span: Span,
63    pub name: String,
64    pub lines: Vec<SectionLine>,
65}
66
67#[derive(Debug, Clone, PartialEq)]
68pub enum SectionLine {
69    Label {
70        span: Span,
71        name: String,
72    },
73    Data {
74        span: Span,
75        width: SectionDataWidth,
76        values: Vec<SectionValue>,
77    },
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Eq)]
81pub enum SectionDataWidth {
82    B8,
83    B16,
84    B32,
85    B64,
86}
87
88#[derive(Debug, Clone, PartialEq)]
89pub enum SectionValue {
90    Integer {
91        span: Span,
92        value: i64,
93    },
94    UnsignedInteger {
95        span: Span,
96        value: u64,
97    },
98    Label {
99        span: Span,
100        name: String,
101    },
102    LabelOffset {
103        span: Span,
104        label: String,
105        offset: i64,
106    },
107    LabelDifference {
108        span: Span,
109        left: String,
110        right: String,
111    },
112}