MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / alloc_slot_for_alloc

Method alloc_slot_for_alloc

crates/ir-to-asm/src/compiler/function_context.rs:84–98  ·  view source on GitHub ↗

Allocate a stack slot for an `Alloc` (`stack_alloc`) instruction. Uses the actual inner type size rather than pointer size so structs get enough space.

(
        &mut self,
        reg: &IrRegister,
        ty: &IrType,
        count: Option<usize>,
    )

Source from the content-addressed store, hash-verified

82 ) -> usize {
83 let elem_size = self.frame.type_size(ty, &self.type_aliases);
84 let total_size = (elem_size * count.unwrap_or(1)).max(8);
85 let alignment = self.frame.type_alignment(ty, &self.type_aliases).max(8);
86 let slot = self.frame.alloc_slot(total_size, alignment);
87 self.reg_slots.insert(reg.clone(), slot);
88 self.reg_types
89 .insert(reg.clone(), IrType::Pointer(Box::new(ty.clone())));
90 slot
91 }
92
93 /// Reserve space for saving `ra`.
94 pub fn save_ra(&mut self) {
95 self.frame.save_ra();
96 }
97
98 /// Reserve space for saving a callee-saved register.
99 pub fn save_reg(&mut self, reg: u8) {
100 self.frame.save_reg(reg);
101 }

Calls 5

type_alignmentMethod · 0.80
alloc_slotMethod · 0.80
type_sizeMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45