MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / emit

Method emit

crates/rust/src/bindgen.rs:270–1405  ·  view source on GitHub ↗
(
        &mut self,
        resolve: &Resolve,
        inst: &Instruction<'_>,
        operands: &mut Vec<String>,
        results: &mut Vec<String>,
    )

Source from the content-addressed store, hash-verified

268 }
269
270 fn emit(
271 &mut self,
272 resolve: &Resolve,
273 inst: &Instruction<'_>,
274 operands: &mut Vec<String>,
275 results: &mut Vec<String>,
276 ) {
277 let mut top_as = |cvt: &str| {
278 let mut s = operands.pop().unwrap();
279 s.push_str(" as ");
280 s.push_str(cvt);
281 results.push(s);
282 };
283
284 match inst {
285 Instruction::GetArg { nth } => results.push(self.params[*nth].clone()),
286 Instruction::I32Const { val } => results.push(format!("{val}i32")),
287 Instruction::ConstZero { tys } => {
288 for ty in tys.iter() {
289 match ty {
290 WasmType::I32 => results.push("0i32".to_string()),
291 WasmType::I64 => results.push("0i64".to_string()),
292 WasmType::F32 => results.push("0.0f32".to_string()),
293 WasmType::F64 => results.push("0.0f64".to_string()),
294 WasmType::Pointer => results.push("::core::ptr::null_mut()".to_string()),
295 WasmType::PointerOrI64 => {
296 results.push("::core::mem::MaybeUninit::<u64>::zeroed()".to_string())
297 }
298 WasmType::Length => results.push("0usize".to_string()),
299 }
300 }
301 }
302
303 Instruction::I64FromU64 | Instruction::I64FromS64 => {
304 let s = operands.pop().unwrap();
305 results.push(format!("{}({s})", self.r#gen.path_to_as_i64()));
306 }
307 Instruction::I32FromChar
308 | Instruction::I32FromU8
309 | Instruction::I32FromS8
310 | Instruction::I32FromU16
311 | Instruction::I32FromS16
312 | Instruction::I32FromU32
313 | Instruction::I32FromS32 => {
314 let s = operands.pop().unwrap();
315 results.push(format!("{}({s})", self.r#gen.path_to_as_i32()));
316 }
317
318 Instruction::CoreF32FromF32 => {
319 let s = operands.pop().unwrap();
320 results.push(format!("{}({s})", self.r#gen.path_to_as_f32()));
321 }
322 Instruction::CoreF64FromF64 => {
323 let s = operands.pop().unwrap();
324 results.push(format!("{}({s})", self.r#gen.path_to_as_f64()));
325 }
326 Instruction::F32FromCoreF32
327 | Instruction::F64FromCoreF64

Callers

nothing calls this directly

Calls 15

bitcastFunction · 0.85
newFunction · 0.85
type_pathMethod · 0.80
is_exported_resourceMethod · 0.80
async_support_pathMethod · 0.80
type_name_ownedMethod · 0.80
path_to_rootMethod · 0.80
record_lowerMethod · 0.80
record_liftMethod · 0.80
tuple_lowerMethod · 0.80
tuple_liftMethod · 0.80

Tested by

no test coverage detected