fn encode_elems(&self, module: &mut wasm_encoder::Module) { ifself.elems.is_empty() { return;
} letmut elems = wasm_encoder::ElementSection::new(); for el in &self.elems { let elements = match &el.items {
Elements::Expressions(es) => wasm_encoder::Elements::Expressions(el.ty, es.into()),
Elements::Functions(fs) => {
assert_eq!(el.ty, RefType::FUNCREF);
wasm_encoder::Elements::Functions(fs.into())
}
}; match &el.kind {
ElementKind::Active { table, offset } => { let offset = match *offset {
Offset::Const32(n) => ConstExpr::i32_const(n),
Offset::Const64(n) => ConstExpr::i64_const(n),
Offset::Global(g) => ConstExpr::global_get(g),
};
elems.active(*table, &offset, elements);
}
ElementKind::Passive => {
elems.passive(elements);
}
ElementKind::Declared => {
elems.declared(elements);
}
}
}
module.section(&elems);
}
fn encode_data_count(&self, module: &mut wasm_encoder::Module) { // Without bulk memory there's no need for a data count section, if !self.config.bulk_memory_enabled { return;
} // ... and also if there's no data no need for a data count section. ifself.data.is_empty() { return;
}
module.section(&wasm_encoder::DataCountSection {
count: u32::try_from(self.data.len()).unwrap(),
});
}
fn encode_code(&self, module: &mut wasm_encoder::Module) { ifself.code.is_empty() { return;
} letmut code = wasm_encoder::CodeSection::new(); for c in &self.code { // Skip the run-length encoding because it is a little // annoying to compute; use a length of one for every local. letmut func = wasm_encoder::Function::new(c.locals.iter().map(|l| (1, *l))); match &c.instructions {
Instructions::Generated(instrs) => { for instr in instrs {
func.instruction(instr);
}
func.instruction(&wasm_encoder::Instruction::End);
}
Instructions::Arbitrary(body) => {
func.raw(body.iter().copied());
}
}
code.function(&func);
}
module.section(&code);
}
fn encode_data(&self, module: &mut wasm_encoder::Module) { ifself.data.is_empty() { return;
} letmut data = wasm_encoder::DataSection::new(); for seg in &self.data { match &seg.kind {
DataSegmentKind::Active {
memory_index,
offset,
} => { let offset = match *offset {
Offset::Const32(n) => ConstExpr::i32_const(n),
Offset::Const64(n) => ConstExpr::i64_const(n),
Offset::Global(g) => ConstExpr::global_get(g),
};
data.active(*memory_index, &offset, seg.init.iter().copied());
}
DataSegmentKind::Passive => {
data.passive(seg.init.iter().copied());
}
}
}
module.section(&data);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.