1use crate::r#type::function::*;
4use super::{TreeDisplay, TreeFormatter};
5
6impl TreeDisplay for AliasFunctionDirective {
7 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
8 f.root(&format!("AliasFunctionDirective [{}]", f.format_raw(self.span, source)))?;
9 f.field(false, "alias", &self.alias.val)?;
10 f.field(true, "target", &self.target.val)
11 }
12}
13
14impl TreeDisplay for FuncFunctionDirective {
15 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
16 f.root(&format!("FuncFunctionDirective [{}]", f.format_raw(self.span, source)))?;
17 f.field_vec(false, "attributes", &self.attributes, source)?;
18 f.field_option(false, "return_param", &self.return_param, source)?;
19 f.field(false, "name", &self.name.val)?;
20 f.field_vec(false, "params", &self.params, source)?;
21 f.field_vec(false, "directives", &self.directives, source)?;
22 f.field_option(true, "body", &self.body, source)
23 }
24}
25
26impl TreeDisplay for EntryFunctionDirective {
27 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
28 f.root(&format!("EntryFunctionDirective [{}]", f.format_raw(self.span, source)))?;
29 f.field(false, "name", &self.name.val)?;
30 f.field_vec(false, "params", &self.params, source)?;
31 f.field_vec(false, "directives", &self.directives, source)?;
32 f.field_option(true, "body", &self.body, source)
33 }
34}
35
36impl TreeDisplay for FuncFunctionHeaderDirective {
37 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
38 match self {
39 FuncFunctionHeaderDirective::NoReturn { span } => {
40 f.root(&format!("FuncFunctionHeaderDirective::NoReturn [{}]", f.format_raw(*span, source)))
41 }
42 FuncFunctionHeaderDirective::Pragma { args, span } => {
43 f.root(&format!("FuncFunctionHeaderDirective::Pragma [{}]", f.format_raw(*span, source)))?;
44 f.field_vec(true, "args", args, source)
45 }
46 FuncFunctionHeaderDirective::AbiPreserve { value, span } => {
47 f.root(&format!("FuncFunctionHeaderDirective::AbiPreserve [{}]", f.format_raw(*span, source)))?;
48 f.field(true, "value", &value.to_string())
49 }
50 FuncFunctionHeaderDirective::AbiPreserveControl { value, span } => {
51 f.root(&format!("FuncFunctionHeaderDirective::AbiPreserveControl [{}]", f.format_raw(*span, source)))?;
52 f.field(true, "value", &value.to_string())
53 }
54 }
55 }
56}
57
58impl TreeDisplay for EntryFunctionHeaderDirective {
59 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
60 match self {
61 EntryFunctionHeaderDirective::MaxNReg { value, span } => {
62 f.root(&format!("EntryFunctionHeaderDirective::MaxNReg [{}]", f.format_raw(*span, source)))?;
63 f.field(true, "value", &value.to_string())
64 }
65 EntryFunctionHeaderDirective::MaxNTid { dim, span } => {
66 f.root(&format!("EntryFunctionHeaderDirective::MaxNTid [{}]", f.format_raw(*span, source)))?;
67 f.field_with_child(true, "dim", dim, source)
68 }
69 EntryFunctionHeaderDirective::ReqNTid { dim, span } => {
70 f.root(&format!("EntryFunctionHeaderDirective::ReqNTid [{}]", f.format_raw(*span, source)))?;
71 f.field_with_child(true, "dim", dim, source)
72 }
73 EntryFunctionHeaderDirective::MinNCtaPerSm { value, span } => {
74 f.root(&format!("EntryFunctionHeaderDirective::MinNCtaPerSm [{}]", f.format_raw(*span, source)))?;
75 f.field(true, "value", &value.to_string())
76 }
77 EntryFunctionHeaderDirective::MaxNCtaPerSm { value, span } => {
78 f.root(&format!("EntryFunctionHeaderDirective::MaxNCtaPerSm [{}]", f.format_raw(*span, source)))?;
79 f.field(true, "value", &value.to_string())
80 }
81 EntryFunctionHeaderDirective::Pragma { args, span } => {
82 f.root(&format!("EntryFunctionHeaderDirective::Pragma [{}]", f.format_raw(*span, source)))?;
83 f.field_vec(true, "args", args, source)
84 }
85 EntryFunctionHeaderDirective::ReqNctaPerCluster { dim, span } => {
86 f.root(&format!("EntryFunctionHeaderDirective::ReqNctaPerCluster [{}]", f.format_raw(*span, source)))?;
87 f.field_with_child(true, "dim", dim, source)
88 }
89 EntryFunctionHeaderDirective::ExplicitCluster { span } => {
90 f.root(&format!("EntryFunctionHeaderDirective::ExplicitCluster [{}]", f.format_raw(*span, source)))
91 }
92 EntryFunctionHeaderDirective::MaxClusterRank { value, span } => {
93 f.root(&format!("EntryFunctionHeaderDirective::MaxClusterRank [{}]", f.format_raw(*span, source)))?;
94 f.field(true, "value", &value.to_string())
95 }
96 EntryFunctionHeaderDirective::BlocksAreClusters { span } => {
97 f.root(&format!("EntryFunctionHeaderDirective::BlocksAreClusters [{}]", f.format_raw(*span, source)))
98 }
99 }
100 }
101}
102
103impl TreeDisplay for FunctionBody {
104 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
105 f.root(&format!("FunctionBody [{}]", f.format_raw(self.span, source)))?;
106 f.field_vec(true, "statements", &self.statements, source)
107 }
108}
109
110impl TreeDisplay for FunctionStatement {
111 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
112 match self {
113 FunctionStatement::Label { label, span } => {
114 f.root(&format!("FunctionStatement::Label [{}]", f.format_raw(*span, source)))?;
115 f.field_with_child(true, "label", label, source)
116 }
117 FunctionStatement::Directive { directive, span } => {
118 f.root(&format!("FunctionStatement::Directive [{}]", f.format_raw(*span, source)))?;
119 f.field_with_child(true, "directive", directive, source)
120 }
121 FunctionStatement::Instruction { instruction, span: _ } => {
122 instruction.tree_display(f, source)
124 }
125 FunctionStatement::Block { statements, span } => {
126 f.root(&format!("FunctionStatement::Block [{}]", f.format_raw(*span, source)))?;
127 f.field_vec(true, "statements", statements, source)
128 }
129 }
130 }
131}
132
133impl TreeDisplay for RegisterDirective {
134 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
135 f.root(&format!("RegisterDirective [{}]", f.format_raw(self.span, source)))?;
136 f.field_with_child(false, "ty", &self.ty, source)?;
137 f.field_vec(true, "registers", &self.registers, source)
138 }
139}
140
141impl TreeDisplay for RegisterTarget {
142 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
143 f.root(&format!(
144 "RegisterTarget [{}]",
145 f.format_raw(self.span, source)
146 ))?;
147 f.field(false, "name", &self.name.val)?;
148 match self.range {
149 Some(r) => f.field(true, "range", &format!("Some({})", r))?,
150 None => f.field(true, "range", "None")?,
151 };
152 Ok(())
153 }
154}
155
156impl TreeDisplay for StatementDirective {
157 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
158 match self {
159 StatementDirective::Loc { directive, span } => {
160 f.root(&format!("StatementDirective::Loc [{}]", f.format_raw(*span, source)))?;
161 f.field_with_child(true, "directive", directive, source)
162 }
163 StatementDirective::Pragma { directive, span } => {
164 f.root(&format!("StatementDirective::Pragma [{}]", f.format_raw(*span, source)))?;
165 f.field_with_child(true, "directive", directive, source)
166 }
167 StatementDirective::Section { directive, span } => {
168 f.root(&format!("StatementDirective::Section [{}]", f.format_raw(*span, source)))?;
169 f.field_with_child(true, "directive", directive, source)
170 }
171 StatementDirective::Reg { directive, span } => {
172 f.root(&format!("StatementDirective::Reg [{}]", f.format_raw(*span, source)))?;
173 f.field_with_child(true, "directive", directive, source)
174 }
175 StatementDirective::Local { directive, span } => {
176 f.root(&format!("StatementDirective::Local [{}]", f.format_raw(*span, source)))?;
177 f.field_with_child(true, "directive", directive, source)
178 }
179 StatementDirective::Param { directive, span } => {
180 f.root(&format!("StatementDirective::Param [{}]", f.format_raw(*span, source)))?;
181 f.field_with_child(true, "directive", directive, source)
182 }
183 StatementDirective::Shared { directive, span } => {
184 f.root(&format!("StatementDirective::Shared [{}]", f.format_raw(*span, source)))?;
185 f.field_with_child(true, "directive", directive, source)
186 }
187 StatementDirective::Dwarf { directive, span } => {
188 f.root(&format!("StatementDirective::Dwarf [{}]", f.format_raw(*span, source)))?;
189 f.field_with_child(true, "directive", directive, source)
190 }
191 StatementDirective::BranchTargets { directive, span } => {
192 f.root(&format!("StatementDirective::BranchTargets [{}]", f.format_raw(*span, source)))?;
193 f.field_with_child(true, "directive", directive, source)
194 }
195 StatementDirective::CallTargets { directive, span } => {
196 f.root(&format!("StatementDirective::CallTargets [{}]", f.format_raw(*span, source)))?;
197 f.field_with_child(true, "directive", directive, source)
198 }
199 StatementDirective::CallPrototype { directive, span } => {
200 f.root(&format!("StatementDirective::CallPrototype [{}]", f.format_raw(*span, source)))?;
201 f.field_with_child(true, "directive", directive, source)
202 }
203 }
204 }
205}
206
207impl TreeDisplay for DwarfDirective {
208 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
209 f.root(&format!("DwarfDirective [{}]", f.format_raw(self.span, source)))?;
210 f.field(true, "kind", &format!("{:?}", self.kind))
211 }
212}
213
214impl TreeDisplay for SectionDirective {
215 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
216 f.root(&format!("SectionDirective [{}]", f.format_raw(self.span, source)))?;
217 f.field(false, "name", &format!("\"{}\"", self.name))?;
218 f.field(true, "entries", &format!("<{} entries>", self.entries.len()))
219 }
220}
221
222impl TreeDisplay for LocationDirective {
223 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
224 f.root(&format!("LocationDirective [{}]", f.format_raw(self.span, source)))?;
225 f.field(false, "file_index", &self.file_index.to_string())?;
226 f.field(false, "line", &self.line.to_string())?;
227 f.field(false, "column", &self.column.to_string())?;
228 f.field_option(true, "inlined_at", &self.inlined_at, source)
229 }
230}
231
232impl TreeDisplay for LocationInlinedAt {
233 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
234 f.root(&format!("LocationInlinedAt [{}]", f.format_raw(self.span, source)))?;
235 f.field(false, "file_index", &self.file_index.to_string())?;
236 f.field(false, "line", &self.line.to_string())?;
237 f.field(false, "column", &self.column.to_string())?;
238 f.field(false, "function_name", &self.function_name.val)?;
239 f.field_with_child(false, "label", &self.label, source)?;
240 match self.label_offset {
241 Some(offset) => f.field(true, "label_offset", &format!("Some({})", offset)),
242 None => f.field(true, "label_offset", "None"),
243 }
244 }
245}
246
247impl TreeDisplay for PragmaDirective {
248 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
249 f.root(&format!("PragmaDirective [{}]", f.format_raw(self.span, source)))?;
250 f.field(true, "kind", &format!("{:?}", self.kind))
251 }
252}
253
254impl TreeDisplay for BranchTargetsDirective {
255 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
256 f.root(&format!("BranchTargetsDirective [{}]", f.format_raw(self.span, source)))?;
257 f.field_vec(true, "labels", &self.labels, source)
258 }
259}
260
261impl TreeDisplay for CallTargetsDirective {
262 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
263 f.root(&format!("CallTargetsDirective [{}]", f.format_raw(self.span, source)))?;
264 let targets: Vec<String> = self.targets.iter().map(|t| t.val.clone()).collect();
265 f.field_vec(true, "targets", &targets, source)
266 }
267}
268
269impl TreeDisplay for CallPrototypeDirective {
270 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
271 f.root(&format!("CallPrototypeDirective [{}]", f.format_raw(self.span, source)))?;
272 f.field_option(false, "return_param", &self.return_param, source)?;
273 f.field_vec(false, "params", &self.params, source)?;
274 f.field(false, "noreturn", &self.noreturn.to_string())?;
275 match self.abi_preserve {
276 Some(v) => f.field(false, "abi_preserve", &format!("Some({})", v))?,
277 None => f.field(false, "abi_preserve", "None")?,
278 }
279 match self.abi_preserve_control {
280 Some(v) => f.field(true, "abi_preserve_control", &format!("Some({})", v)),
281 None => f.field(true, "abi_preserve_control", "None"),
282 }
283 }
284}
285
286impl TreeDisplay for FunctionDim {
287 fn tree_display(&self, f: &mut TreeFormatter, source: &str) -> std::fmt::Result {
288 match self {
289 FunctionDim::X { x, span } => {
290 f.root(&format!("FunctionDim::X [{}]", f.format_raw(*span, source)))?;
291 f.field(true, "x", &x.to_string())
292 }
293 FunctionDim::XY { x, y, span } => {
294 f.root(&format!("FunctionDim::XY [{}]", f.format_raw(*span, source)))?;
295 f.field(false, "x", &x.to_string())?;
296 f.field(true, "y", &y.to_string())
297 }
298 FunctionDim::XYZ { x, y, z, span } => {
299 f.root(&format!("FunctionDim::XYZ [{}]", f.format_raw(*span, source)))?;
300 f.field(false, "x", &x.to_string())?;
301 f.field(false, "y", &y.to_string())?;
302 f.field(true, "z", &z.to_string())
303 }
304 }
305 }
306}