File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
crates/wasmi/src/engine/translator/func2 Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,35 @@ impl InstrEncoder {
107
107
Ok ( instr)
108
108
}
109
109
110
+ /// Replaces `instr` with `new_instr` in `self`.
111
+ ///
112
+ /// - Returns `Ok(true)` if replacement was successful.
113
+ /// - Returns `Ok(false)` if replacement was unsuccessful.
114
+ ///
115
+ /// # Panics (Debug)
116
+ ///
117
+ /// If `instr` or `new_instr` are [`Instruction`] parameters.
118
+ pub fn try_replace_instr (
119
+ & mut self ,
120
+ instr : Instr ,
121
+ new_instr : Instruction ,
122
+ ) -> Result < bool , Error > {
123
+ debug_assert ! (
124
+ !new_instr. is_instruction_parameter( ) ,
125
+ "parameter: {new_instr:?}"
126
+ ) ;
127
+ let Some ( last_instr) = self . last_instr else {
128
+ return Ok ( false ) ;
129
+ } ;
130
+ let replace = self . get_mut ( instr) ;
131
+ debug_assert ! ( !replace. is_instruction_parameter( ) , "parameter: {instr:?}" ) ;
132
+ if instr != last_instr {
133
+ return Ok ( false ) ;
134
+ }
135
+ * replace = new_instr;
136
+ Ok ( true )
137
+ }
138
+
110
139
/// Pushes an [`Instruction`] parameter to the [`InstrEncoder`].
111
140
///
112
141
/// The parameter is associated to the last pushed [`Instruction`].
You can’t perform that action at this time.
0 commit comments