Skip to content

Commit 701f7f5

Browse files
committed
added public methods to iterate all blocks of a local function
1 parent 9d6c9de commit 701f7f5

File tree

1 file changed

+11
-0
lines changed
  • src/module/functions/local_function

1 file changed

+11
-0
lines changed

src/module/functions/local_function/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::ir::*;
1010
use crate::map::{IdHashMap, IdHashSet};
1111
use crate::parse::IndicesToIds;
1212
use crate::{Data, DataId, FunctionBuilder, FunctionId, MemoryId, Module, Result, TypeId, ValType};
13+
use id_arena::Id;
1314
use std::collections::BTreeMap;
1415
use wasmparser::{FuncValidator, Operator, ValidatorResources};
1516

@@ -104,6 +105,16 @@ impl LocalFunction {
104105
&self.builder.arena[id]
105106
}
106107

108+
/// Iterate over all the blocks in the function
109+
pub fn blocks(&self) -> impl Iterator<Item = (Id<InstrSeq>, &InstrSeq)> {
110+
self.builder.arena.iter()
111+
}
112+
113+
/// Mutably iterate over all the blocks in the function
114+
pub fn blocks_mut(&mut self) -> impl Iterator<Item = (Id<InstrSeq>, &mut InstrSeq)> {
115+
self.builder.arena.iter_mut()
116+
}
117+
107118
/// Get the block associated with the given id.
108119
pub fn block_mut(&mut self, id: InstrSeqId) -> &mut InstrSeq {
109120
&mut self.builder.arena[id]

0 commit comments

Comments
 (0)