Skip to content

Commit 7d8f214

Browse files
committed
add docs
1 parent 6037413 commit 7d8f214

File tree

1 file changed

+40
-0
lines changed
  • crates/wasmi/src/engine/translator/stack2

1 file changed

+40
-0
lines changed

crates/wasmi/src/engine/translator/stack2/mod.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ use core::num::NonZeroUsize;
88

99
#[derive(Debug, Clone)]
1010
pub struct ValueStack {
11+
/// The Wasm value stack during translation from Wasm to Wasmi bytecode.
12+
/// The stack of operands.
1113
operands: Vec<StackOperand>,
14+
/// All function local constants.
1215
consts: ConstRegistry,
16+
/// All function parameters and locals and their types.
1317
locals: LocalsRegistry,
18+
/// The index of the first [`StackOperand::Local`] on the [`Stack`].
1419
first_local: Option<OperandIdx>,
20+
/// The index of the last [`StackOperand::Local`] on the [`Stack`].
1521
last_local: Option<OperandIdx>,
22+
/// The maximum size of the [`Stack`].
1623
max_stack_height: usize,
1724
}
1825

@@ -34,41 +41,61 @@ impl From<usize> for OperandIdx {
3441
}
3542
}
3643

44+
/// An [`Operand`] on the [`Stack`].
45+
///
46+
/// This is the internal version of [`Operand`] with information that shall remain
47+
/// hidden to the outside.
3748
#[derive(Debug, Copy, Clone)]
3849
enum StackOperand {
50+
/// A local variable.
3951
Local {
52+
/// The index of the local variable.
4053
index: LocalIdx,
54+
/// The previous [`StackOperand::Local`] on the [`Stack`].
4155
prev_local: Option<OperandIdx>,
56+
/// The next [`StackOperand::Local`] on the [`Stack`].
4257
next_local: Option<OperandIdx>,
4358
},
59+
/// A temporary value on the [`Stack`].
4460
Temp {
61+
/// The type of the temporary value.
4562
ty: ValType,
4663
},
64+
/// An immediate value on the [`Stack`].
4765
Immediate {
66+
/// The value (and type) of the immediate value.
4867
val: TypedVal,
4968
},
5069
}
5170

71+
/// An operand on the [`Stack`].
5272
#[derive(Debug, Copy, Clone)]
5373
pub enum Operand {
74+
/// A local variable operand.
5475
Local(LocalOperand),
76+
/// A temporary operand.
5577
Temp(TempOperand),
78+
/// An immediate value operand.
5679
Immediate(ImmediateOperand),
5780
}
5881

5982
impl Operand {
83+
/// Returns `true` if `self` is an [`Operand::Local`].
6084
pub fn is_local(self) -> bool {
6185
matches!(self, Self::Local(_))
6286
}
6387

88+
/// Returns `true` if `self` is an [`Operand::Temp`].
6489
pub fn is_temp(self) -> bool {
6590
matches!(self, Self::Temp(_))
6691
}
6792

93+
/// Returns `true` if `self` is an [`Operand::Immediate`].
6894
pub fn is_immediate(self) -> bool {
6995
matches!(self, Self::Immediate(_))
7096
}
7197

98+
/// Returns the type of the [`Operand`].
7299
pub fn ty(self) -> ValType {
73100
match self {
74101
Self::Local(local_operand) => local_operand.ty(),
@@ -78,47 +105,60 @@ impl Operand {
78105
}
79106
}
80107

108+
/// A local variable on the [`Stack`].
81109
#[derive(Debug, Copy, Clone)]
82110
pub struct LocalOperand {
111+
/// The index of the local variable.
83112
index: LocalIdx,
113+
/// The type of the local variable.
84114
ty: ValType,
85115
}
86116

87117
impl LocalOperand {
118+
/// Returns the index of the local variable.
88119
pub fn index(self) -> LocalIdx {
89120
self.index
90121
}
91122

123+
/// Returns the type of the local variable.
92124
pub fn ty(self) -> ValType {
93125
self.ty
94126
}
95127
}
96128

129+
/// A temporary on the [`Stack`].
97130
#[derive(Debug, Copy, Clone)]
98131
pub struct TempOperand {
132+
/// The type of the temporary.
99133
ty: ValType,
100134
}
101135

102136
impl TempOperand {
137+
/// Returns the type of the temporary.
103138
pub fn ty(self) -> ValType {
104139
self.ty
105140
}
106141
}
107142

143+
/// An immediate value on the [`Stack`].
108144
#[derive(Debug, Copy, Clone)]
109145
pub struct ImmediateOperand {
146+
/// The value and type of the immediate value.
110147
val: TypedVal,
111148
}
112149

113150
impl ImmediateOperand {
151+
/// Returns the value (and type) of the immediate value.
114152
pub fn val(self) -> TypedVal {
115153
self.val
116154
}
117155

156+
/// Returns the type of the immediate value.
118157
pub fn ty(self) -> ValType {
119158
self.val.ty()
120159
}
121160
}
122161

162+
/// A local variable index.
123163
#[derive(Debug, Copy, Clone)]
124164
pub struct LocalIdx(usize);

0 commit comments

Comments
 (0)