cubecl_core/frontend/
debug.rs1use alloc::{string::String, vec::Vec};
2use cubecl_ir::{dialect::general::PrintfOp, pliron::value::Value};
3
4use crate::ir::Scope;
5
6use super::CubeDebug;
7
8#[track_caller]
10pub fn debug_call_expand<C>(
11 scope: &Scope,
12 _line: u32,
13 _col: u32,
14 call: impl FnOnce(&Scope) -> C,
15) -> C {
16 let ret = call(scope);
21 ret
24}
25
26#[track_caller]
28pub fn debug_source_expand(
29 _scope: &Scope,
30 _name: &'static str,
31 _file: &'static str,
32 _source_text: &'static str,
33 _line: u32,
34 _column: u32,
35) {
36 }
45
46#[track_caller]
48pub fn debug_var_expand<E: CubeDebug>(scope: &Scope, name: &'static str, expand: E) -> E {
49 expand.set_debug_name(scope, name);
50 expand
51}
52
53pub fn printf_expand(scope: &Scope, format_string: impl Into<String>, args: Vec<Value>) {
55 scope.register(&PrintfOp::new(scope.ctx_mut(), format_string.into(), args));
56}
57
58#[macro_export]
61macro_rules! debug_print {
62 ($format:literal, $($args:expr),*) => {
63 {
64 let _ = $format;
65 $(let _ = $args;)*
66 }
67 };
68 ($format:literal, $($args:expr,)*) => {
69 $crate::debug_print!($format, $($args),*);
70 };
71}
72
73#[macro_export]
76macro_rules! __expand_debug_print {
77 ($scope:expr, $format:expr, $($args:expr),*) => {
78 {
79 let args = $crate::__private::vec![$($crate::ir::ExpandValue::from($args).read_value($scope)),*];
80 $crate::frontend::printf_expand($scope, $format, args);
81 }
82 };
83 ($format:literal, $($args:expr,)*) => {
84 $crate::__expand_debug_print!($format, $($args),*)
85 };
86}
87
88pub mod cube_comment {
89 use alloc::string::ToString;
90
91 use cubecl_ir::{Scope, dialect::general::CommentOp};
92
93 pub fn expand(scope: &Scope, content: &str) {
94 scope.register(&CommentOp::new(scope.ctx_mut(), content.to_string()));
95 }
96}