Retrieves the size of the memory, pushing the result to the value stack.
(&mut self, heap_data: &HeapData)
| 1523 | |
| 1524 | /// Retrieves the size of the memory, pushing the result to the value stack. |
| 1525 | pub fn emit_compute_memory_size(&mut self, heap_data: &HeapData) -> Result<()> { |
| 1526 | let size_reg = self.context.any_gpr(self.masm)?; |
| 1527 | self.load_memory_length(heap_data, size_reg)?; |
| 1528 | |
| 1529 | // Emit a shift to get the size in pages rather than in bytes. |
| 1530 | let dst = TypedReg::new(heap_data.index_type(), size_reg); |
| 1531 | let pow = heap_data.memory.page_size_log2; |
| 1532 | self.masm.shift_ir( |
| 1533 | writable!(dst.reg), |
| 1534 | Imm::i32(pow as i32), |
| 1535 | dst.into(), |
| 1536 | ShiftKind::ShrU, |
| 1537 | self.env.ptr_type().try_into()?, |
| 1538 | )?; |
| 1539 | self.context.stack.push(dst.into()); |
| 1540 | Ok(()) |
| 1541 | } |
| 1542 | |
| 1543 | /// Emit a bounds check for `ptr+len` and put the native address for this |
| 1544 | /// wasm address into `dst`. |
no test coverage detected