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

Method emit

crates/cpp/src/lib.rs:2451–3552  ·  view source on GitHub ↗
(
        &mut self,
        _resolve: &Resolve,
        inst: &wit_bindgen_core::abi::Instruction<'_>,
        operands: &mut Vec<Self::Operand>,
        results: &mut Vec<Self::Operand>,
    )

Source from the content-addressed store, hash-verified

2449 type Operand = String;
2450
2451 fn emit(
2452 &mut self,
2453 _resolve: &Resolve,
2454 inst: &wit_bindgen_core::abi::Instruction<'_>,
2455 operands: &mut Vec<Self::Operand>,
2456 results: &mut Vec<Self::Operand>,
2457 ) {
2458 let mut top_as = |cvt: &str| {
2459 results.push(format!("({cvt}({}))", operands.pop().unwrap()));
2460 };
2461
2462 match inst {
2463 abi::Instruction::GetArg { nth } => {
2464 if *nth == 0 && self.params[0].as_str() == "self" {
2465 if self.r#gen.in_guest_import {
2466 results.push("(*this)".to_string());
2467 } else {
2468 results.push("(*lookup_resource(self))".to_string());
2469 }
2470 } else {
2471 results.push(self.params[*nth].clone());
2472 }
2473 }
2474 abi::Instruction::I32Const { val } => results.push(format!("(int32_t({val}))")),
2475 abi::Instruction::Bitcasts { casts } => {
2476 for (cast, op) in casts.iter().zip(operands) {
2477 // let op = op;
2478 results.push(self.r#gen.r#gen.perform_cast(op, cast));
2479 }
2480 }
2481 abi::Instruction::ConstZero { tys } => {
2482 for ty in tys.iter() {
2483 match ty {
2484 WasmType::I32 => results.push("int32_t(0)".to_string()),
2485 WasmType::I64 => results.push("int64_t(0)".to_string()),
2486 WasmType::F32 => results.push("0.0f".to_string()),
2487 WasmType::F64 => results.push("0.0".to_string()),
2488 WasmType::Length => results.push("size_t(0)".to_string()),
2489 WasmType::Pointer => results.push("nullptr".to_string()),
2490 WasmType::PointerOrI64 => results.push("int64_t(0)".to_string()),
2491 }
2492 }
2493 }
2494 abi::Instruction::I32Load { offset } => {
2495 let tmp = self.tmp();
2496 uwriteln!(
2497 self.src,
2498 "int32_t l{tmp} = *((int32_t const*)({} + {offset}));",
2499 operands[0],
2500 offset = offset.format(POINTER_SIZE_EXPRESSION)
2501 );
2502 results.push(format!("l{tmp}"));
2503 }
2504 abi::Instruction::I32Load8U { offset } => {
2505 self.load_ext("uint8_t", *offset, operands, results)
2506 }
2507 abi::Instruction::I32Load8S { offset } => {
2508 self.load_ext("int8_t", *offset, operands, results)

Callers

nothing calls this directly

Calls 15

move_if_necessaryFunction · 0.85
to_c_identFunction · 0.85
newFunction · 0.85
as_strMethod · 0.80
ptr_typeMethod · 0.80
is_exported_typeMethod · 0.80
tempnameMethod · 0.80
joinMethod · 0.80
mapMethod · 0.80
optional_type_nameMethod · 0.80
func_namespace_nameMethod · 0.80
removeMethod · 0.80

Tested by

no test coverage detected