1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Canonical node kinds for the Performance Graph (PG) layout.
/// Canonical node kinds for the Performance Graph (PG) layout.
/// Shared between surgec and vyre as the definitive source of truth.
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Deserialize, serde::Serialize)]
#[non_exhaustive]
pub enum PgNodeKind {
/// Variable declaration node.
VariableDecl = 1,
/// Variable usage node.
VariableUse = 2,
/// Assignment statement node.
Assignment = 3,
/// Binary operation node.
Binary = 4,
/// Comparison operation node.
Comparison = 5,
/// Function call node.
FunctionCall = 6,
/// Function definition node.
FunctionDef = 7,
/// If statement node.
IfStmt = 8,
/// For loop node.
ForStmt = 9,
/// While loop node.
WhileStmt = 10,
/// Return statement node.
ReturnStmt = 11,
/// Pointer dereference node.
Deref = 12,
/// Address-of node.
AddrOf = 13,
/// Type cast node.
Cast = 14,
/// Member access node.
MemberAccess = 15,
/// Array access node.
ArrayAccess = 16,
/// Struct declaration node.
StructDecl = 17,
/// Integer literal node.
LiteralInt = 18,
/// String literal node.
LiteralStr = 19,
/// Floating point literal node.
LiteralFloat = 20,
}
impl PgNodeKind {
/// Converts a u32 into a `PgNodeKind` if it is valid.
#[must_use]
pub const fn from_u32(value: u32) -> Option<Self> {
match value {
1 => Some(Self::VariableDecl),
2 => Some(Self::VariableUse),
3 => Some(Self::Assignment),
4 => Some(Self::Binary),
5 => Some(Self::Comparison),
6 => Some(Self::FunctionCall),
7 => Some(Self::FunctionDef),
8 => Some(Self::IfStmt),
9 => Some(Self::ForStmt),
10 => Some(Self::WhileStmt),
11 => Some(Self::ReturnStmt),
12 => Some(Self::Deref),
13 => Some(Self::AddrOf),
14 => Some(Self::Cast),
15 => Some(Self::MemberAccess),
16 => Some(Self::ArrayAccess),
17 => Some(Self::StructDecl),
18 => Some(Self::LiteralInt),
19 => Some(Self::LiteralStr),
20 => Some(Self::LiteralFloat),
_ => None,
}
}
}