(&mut self, item: RuntimeItem)
| 582 | } |
| 583 | |
| 584 | fn emit_runtime_item(&mut self, item: RuntimeItem) { |
| 585 | match item { |
| 586 | RuntimeItem::AllocCrate => { |
| 587 | uwriteln!(self.src, "extern crate alloc as alloc_crate;"); |
| 588 | } |
| 589 | RuntimeItem::StdAllocModule => { |
| 590 | self.rt_module.insert(RuntimeItem::AllocCrate); |
| 591 | uwriteln!(self.src, "pub use alloc_crate::alloc;"); |
| 592 | } |
| 593 | RuntimeItem::StringType => { |
| 594 | self.rt_module.insert(RuntimeItem::AllocCrate); |
| 595 | uwriteln!(self.src, "pub use alloc_crate::string::String;"); |
| 596 | } |
| 597 | RuntimeItem::BoxType => { |
| 598 | self.rt_module.insert(RuntimeItem::AllocCrate); |
| 599 | uwriteln!(self.src, "pub use alloc_crate::boxed::Box;"); |
| 600 | } |
| 601 | RuntimeItem::VecType => { |
| 602 | self.rt_module.insert(RuntimeItem::AllocCrate); |
| 603 | uwriteln!(self.src, "pub use alloc_crate::vec::Vec;"); |
| 604 | } |
| 605 | RuntimeItem::CabiDealloc => { |
| 606 | self.rt_module.insert(RuntimeItem::StdAllocModule); |
| 607 | self.src.push_str( |
| 608 | "\ |
| 609 | pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { |
| 610 | if size == 0 { |
| 611 | return; |
| 612 | } |
| 613 | unsafe { |
| 614 | let layout = alloc::Layout::from_size_align_unchecked(size, align); |
| 615 | alloc::dealloc(ptr, layout); |
| 616 | } |
| 617 | } |
| 618 | ", |
| 619 | ); |
| 620 | } |
| 621 | |
| 622 | RuntimeItem::StringLift => { |
| 623 | self.rt_module.insert(RuntimeItem::StringType); |
| 624 | self.src.push_str( |
| 625 | "\ |
| 626 | pub unsafe fn string_lift(bytes: Vec<u8>) -> String { |
| 627 | if cfg!(debug_assertions) { |
| 628 | String::from_utf8(bytes).unwrap() |
| 629 | } else { |
| 630 | unsafe { String::from_utf8_unchecked(bytes) } |
| 631 | } |
| 632 | } |
| 633 | ", |
| 634 | ); |
| 635 | } |
| 636 | |
| 637 | RuntimeItem::InvalidEnumDiscriminant => { |
| 638 | self.src.push_str( |
| 639 | "\ |
| 640 | pub unsafe fn invalid_enum_discriminant<T>() -> T { |
| 641 | if cfg!(debug_assertions) { |
no test coverage detected