@@ -8,11 +8,18 @@ use core::num::NonZeroUsize;
8
8
9
9
#[ derive( Debug , Clone ) ]
10
10
pub struct ValueStack {
11
+ /// The Wasm value stack during translation from Wasm to Wasmi bytecode.
12
+ /// The stack of operands.
11
13
operands : Vec < StackOperand > ,
14
+ /// All function local constants.
12
15
consts : ConstRegistry ,
16
+ /// All function parameters and locals and their types.
13
17
locals : LocalsRegistry ,
18
+ /// The index of the first [`StackOperand::Local`] on the [`Stack`].
14
19
first_local : Option < OperandIdx > ,
20
+ /// The index of the last [`StackOperand::Local`] on the [`Stack`].
15
21
last_local : Option < OperandIdx > ,
22
+ /// The maximum size of the [`Stack`].
16
23
max_stack_height : usize ,
17
24
}
18
25
@@ -34,41 +41,61 @@ impl From<usize> for OperandIdx {
34
41
}
35
42
}
36
43
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.
37
48
#[ derive( Debug , Copy , Clone ) ]
38
49
enum StackOperand {
50
+ /// A local variable.
39
51
Local {
52
+ /// The index of the local variable.
40
53
index : LocalIdx ,
54
+ /// The previous [`StackOperand::Local`] on the [`Stack`].
41
55
prev_local : Option < OperandIdx > ,
56
+ /// The next [`StackOperand::Local`] on the [`Stack`].
42
57
next_local : Option < OperandIdx > ,
43
58
} ,
59
+ /// A temporary value on the [`Stack`].
44
60
Temp {
61
+ /// The type of the temporary value.
45
62
ty : ValType ,
46
63
} ,
64
+ /// An immediate value on the [`Stack`].
47
65
Immediate {
66
+ /// The value (and type) of the immediate value.
48
67
val : TypedVal ,
49
68
} ,
50
69
}
51
70
71
+ /// An operand on the [`Stack`].
52
72
#[ derive( Debug , Copy , Clone ) ]
53
73
pub enum Operand {
74
+ /// A local variable operand.
54
75
Local ( LocalOperand ) ,
76
+ /// A temporary operand.
55
77
Temp ( TempOperand ) ,
78
+ /// An immediate value operand.
56
79
Immediate ( ImmediateOperand ) ,
57
80
}
58
81
59
82
impl Operand {
83
+ /// Returns `true` if `self` is an [`Operand::Local`].
60
84
pub fn is_local ( self ) -> bool {
61
85
matches ! ( self , Self :: Local ( _) )
62
86
}
63
87
88
+ /// Returns `true` if `self` is an [`Operand::Temp`].
64
89
pub fn is_temp ( self ) -> bool {
65
90
matches ! ( self , Self :: Temp ( _) )
66
91
}
67
92
93
+ /// Returns `true` if `self` is an [`Operand::Immediate`].
68
94
pub fn is_immediate ( self ) -> bool {
69
95
matches ! ( self , Self :: Immediate ( _) )
70
96
}
71
97
98
+ /// Returns the type of the [`Operand`].
72
99
pub fn ty ( self ) -> ValType {
73
100
match self {
74
101
Self :: Local ( local_operand) => local_operand. ty ( ) ,
@@ -78,47 +105,60 @@ impl Operand {
78
105
}
79
106
}
80
107
108
+ /// A local variable on the [`Stack`].
81
109
#[ derive( Debug , Copy , Clone ) ]
82
110
pub struct LocalOperand {
111
+ /// The index of the local variable.
83
112
index : LocalIdx ,
113
+ /// The type of the local variable.
84
114
ty : ValType ,
85
115
}
86
116
87
117
impl LocalOperand {
118
+ /// Returns the index of the local variable.
88
119
pub fn index ( self ) -> LocalIdx {
89
120
self . index
90
121
}
91
122
123
+ /// Returns the type of the local variable.
92
124
pub fn ty ( self ) -> ValType {
93
125
self . ty
94
126
}
95
127
}
96
128
129
+ /// A temporary on the [`Stack`].
97
130
#[ derive( Debug , Copy , Clone ) ]
98
131
pub struct TempOperand {
132
+ /// The type of the temporary.
99
133
ty : ValType ,
100
134
}
101
135
102
136
impl TempOperand {
137
+ /// Returns the type of the temporary.
103
138
pub fn ty ( self ) -> ValType {
104
139
self . ty
105
140
}
106
141
}
107
142
143
+ /// An immediate value on the [`Stack`].
108
144
#[ derive( Debug , Copy , Clone ) ]
109
145
pub struct ImmediateOperand {
146
+ /// The value and type of the immediate value.
110
147
val : TypedVal ,
111
148
}
112
149
113
150
impl ImmediateOperand {
151
+ /// Returns the value (and type) of the immediate value.
114
152
pub fn val ( self ) -> TypedVal {
115
153
self . val
116
154
}
117
155
156
+ /// Returns the type of the immediate value.
118
157
pub fn ty ( self ) -> ValType {
119
158
self . val . ty ( )
120
159
}
121
160
}
122
161
162
+ /// A local variable index.
123
163
#[ derive( Debug , Copy , Clone ) ]
124
164
pub struct LocalIdx ( usize ) ;
0 commit comments