MCPcopy Index your code
hub / github.com/RustPython/RustPython / convert_pseudo_ops

Function convert_pseudo_ops

crates/codegen/src/ir.rs:3053–3093  ·  view source on GitHub ↗

Convert remaining pseudo ops to real instructions or NOP. flowgraph.c convert_pseudo_ops

(blocks: &mut [Block], cellfixedoffsets: &[u32])

Source from the content-addressed store, hash-verified

3051/// Convert remaining pseudo ops to real instructions or NOP.
3052/// flowgraph.c convert_pseudo_ops
3053pub(crate) fn convert_pseudo_ops(blocks: &mut [Block], cellfixedoffsets: &[u32]) {
3054 for block in blocks.iter_mut() {
3055 for info in &mut block.instructions {
3056 let Some(pseudo) = info.instr.pseudo() else {
3057 continue;
3058 };
3059 match pseudo {
3060 // Block push pseudo ops → NOP
3061 PseudoInstruction::SetupCleanup { .. }
3062 | PseudoInstruction::SetupFinally { .. }
3063 | PseudoInstruction::SetupWith { .. } => {
3064 info.instr = Instruction::Nop.into();
3065 }
3066 // PopBlock in reachable blocks is converted to NOP by
3067 // label_exception_targets. Dead blocks may still have them.
3068 PseudoInstruction::PopBlock => {
3069 info.instr = Instruction::Nop.into();
3070 }
3071 // LOAD_CLOSURE → LOAD_FAST (using cellfixedoffsets for merged layout)
3072 PseudoInstruction::LoadClosure { i } => {
3073 let cell_relative = i.get(info.arg) as usize;
3074 let new_idx = cellfixedoffsets[cell_relative];
3075 info.arg = OpArg::new(new_idx);
3076 info.instr = Instruction::LoadFast {
3077 var_num: Arg::marker(),
3078 }
3079 .into();
3080 }
3081 // Jump pseudo ops are resolved during block linearization
3082 PseudoInstruction::Jump { .. } | PseudoInstruction::JumpNoInterrupt { .. } => {}
3083 // These should have been resolved earlier
3084 PseudoInstruction::AnnotationsPlaceholder
3085 | PseudoInstruction::JumpIfFalse { .. }
3086 | PseudoInstruction::JumpIfTrue { .. }
3087 | PseudoInstruction::StoreFastMaybeNull { .. } => {
3088 unreachable!("Unexpected pseudo instruction in convert_pseudo_ops: {pseudo:?}")
3089 }
3090 }
3091 }
3092 }
3093}
3094
3095/// Build cellfixedoffsets mapping: cell/free index -> localsplus index.
3096/// Merged cells (cellvar also in varnames) get the local slot index.

Callers 1

finalize_codeMethod · 0.85

Calls 4

newFunction · 0.85
pseudoMethod · 0.80
iter_mutMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected