cubecl_ir/
non_semantic.rs1use core::fmt::Display;
2
3use alloc::{borrow::Cow, string::String, vec::Vec};
4
5use crate::TypeHash;
6
7use crate::{OperationCode, OperationReflect, fmt_vararg};
8
9use super::Variable;
10
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16#[derive(Debug, Clone, TypeHash, PartialEq, Eq, Hash, OperationCode)]
17#[operation(opcode_name = NonSemanticOpCode)]
18pub enum NonSemantic {
19 EnterDebugScope,
22 ExitDebugScope,
24 Print {
28 format_string: String,
29 args: Vec<Variable>,
30 },
31 Comment { content: String },
33}
34
35impl OperationReflect for NonSemantic {
36 type OpCode = NonSemanticOpCode;
37
38 fn op_code(&self) -> Self::OpCode {
39 self.__match_opcode()
40 }
41}
42
43impl Display for NonSemantic {
44 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
45 match self {
46 NonSemantic::Print {
47 format_string,
48 args,
49 } => {
50 write!(f, "print({format_string}, {})", fmt_vararg(args))
51 }
52 NonSemantic::Comment { content } => write!(f, "//{content}"),
53 _ => Ok(()),
55 }
56 }
57}
58
59#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
61#[derive(Debug, Clone, PartialEq, Eq, Hash, TypeHash)]
62pub struct SourceLoc {
63 pub line: u32,
64 pub column: u32,
65 pub source: CubeFnSource,
66}
67
68#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
70#[derive(Debug, Clone, PartialEq, Eq, Hash, TypeHash)]
71pub struct CubeFnSource {
72 pub function_name: Cow<'static, str>,
73 pub file: Cow<'static, str>,
74 pub source_text: Cow<'static, str>,
75 pub line: u32,
76 pub column: u32,
77}