MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / visit_memory_grow

Method visit_memory_grow

winch/codegen/src/visitor.rs:1777–1804  ·  view source on GitHub ↗
(&mut self, mem: u32)

Source from the content-addressed store, hash-verified

1775 }
1776
1777 fn visit_memory_grow(&mut self, mem: u32) -> Self::Output {
1778 let at = self.context.stack.ensure_index_at(1)?;
1779 let mem = MemoryIndex::from_u32(mem);
1780 // The stack at this point contains: [ delta ]
1781 // The desired state is
1782 // [ vmctx, delta, index ]
1783 let builtin = self.env.builtins.memory_grow::<M::ABI>()?;
1784 let builtin = self.prepare_builtin_defined_memory_arg(mem, at + 1, builtin)?;
1785
1786 let heap = self.env.resolve_heap(mem);
1787 FnCall::emit::<M>(&mut self.env, self.masm, &mut self.context, builtin)?;
1788
1789 // The memory32_grow builtin returns a pointer type, therefore we must
1790 // ensure that the return type is representative of the address space of
1791 // the heap type.
1792 match (self.env.ptr_type(), heap.index_type()) {
1793 (WasmValType::I64, WasmValType::I64) => Ok(()),
1794 // When the heap type is smaller than the pointer type, we adjust
1795 // the result of the memory32_grow builtin.
1796 (WasmValType::I64, WasmValType::I32) => {
1797 let top: Reg = self.context.pop_to_reg(self.masm, None)?.into();
1798 self.masm.wrap(writable!(top), top)?;
1799 self.context.stack.push(TypedReg::i32(top).into());
1800 Ok(())
1801 }
1802 _ => Err(format_err!(CodeGenError::unsupported_32_bit_platform())),
1803 }
1804 }
1805
1806 fn visit_data_drop(&mut self, data_index: u32) -> Self::Output {
1807 self.emit_data_drop(DataIndex::from_u32(data_index))

Callers

nothing calls this directly

Calls 9

OkFunction · 0.85
ensure_index_atMethod · 0.80
resolve_heapMethod · 0.80
pop_to_regMethod · 0.80
ptr_typeMethod · 0.45
index_typeMethod · 0.45
wrapMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected