1use crate::ast::{Attribute, LinkingDirective, ScalarType, Span, StateSpace};
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct Function {
5 pub span: Span,
6 pub linkage: Option<LinkingDirective>,
7 pub entry: bool,
8 pub name: String,
9 pub attributes: Vec<Attribute>,
10 pub directives: Vec<FunctionDirective>,
11 pub params: Vec<Parameter>,
12 pub return_params: Vec<Parameter>,
13 pub body: Option<Vec<Statement>>,
14}
15
16#[derive(Debug, Clone, PartialEq)]
17pub struct Parameter {
18 pub span: Span,
19 pub name: String,
20 pub ty: ScalarType,
21 pub state_space: Option<StateSpace>,
22 pub alignment: Option<u32>,
23 pub array_bounds: Vec<Option<u32>>,
24 pub ptr: bool,
25}
26
27#[derive(Debug, Clone, PartialEq)]
28pub enum Statement {
29 Label {
30 span: Span,
31 name: String,
32 },
33 Instruction(super::Instruction),
34 Variable(super::VariableDecl),
35 Directive(DirectiveStatement),
36 Block {
37 span: Span,
38 statements: Vec<Statement>,
39 },
40}
41
42#[derive(Debug, Clone, PartialEq)]
43pub enum FunctionDirective {
44 NoReturn { span: Span },
45 MaxNReg { span: Span, value: u32 },
46 MaxNTid { span: Span, values: Vec<u32> },
47 ReqNTid { span: Span, values: Vec<u32> },
48 MinNCtaPerSm { span: Span, value: u32 },
49 AbiPreserve { span: Span, value: u32 },
50 AbiPreserveControl { span: Span, value: u32 },
51 Pragma { span: Span, value: String },
52}
53
54#[derive(Debug, Clone, PartialEq)]
55pub enum DirectiveStatement {
56 Pragma {
57 span: Span,
58 value: String,
59 },
60 Loc(LocDirective),
61 BranchTargets {
62 span: Span,
63 labels: Vec<LabelPattern>,
64 },
65 CallTargets {
66 span: Span,
67 targets: Vec<String>,
68 },
69 CallPrototype {
70 span: Span,
71 prototype: CallPrototype,
72 },
73}
74
75#[derive(Debug, Clone, PartialEq)]
76pub struct LocDirective {
77 pub span: Span,
78 pub file: u32,
79 pub line: u32,
80 pub column: u32,
81 pub function_name: Option<LocFunctionName>,
82 pub inlined_at: Option<LocInlineSite>,
83}
84
85#[derive(Debug, Clone, PartialEq)]
86pub enum LocFunctionName {
87 Label {
88 span: Span,
89 label: String,
90 },
91 LabelOffset {
92 span: Span,
93 label: String,
94 offset: i64,
95 },
96}
97
98#[derive(Debug, Clone, PartialEq)]
99pub struct LocInlineSite {
100 pub span: Span,
101 pub file: u32,
102 pub line: u32,
103 pub column: u32,
104}
105
106#[derive(Debug, Clone, PartialEq)]
107pub enum LabelPattern {
108 Name {
109 span: Span,
110 name: String,
111 },
112 Range {
113 span: Span,
114 prefix: String,
115 count: u32,
116 },
117}
118
119#[derive(Debug, Clone, PartialEq)]
120pub struct CallPrototype {
121 pub span: Span,
122 pub return_params: Vec<Parameter>,
123 pub placeholder: String,
124 pub params: Vec<Parameter>,
125 pub directives: Vec<FunctionDirective>,
126}