pub fn fixup(target: &Target, calls: &mut [Call]) {
    let mut cnt = 0;
    let mut res_map: HashMap<ResValueId, ResValueId> = HashMap::default();
    let mut allocator = Allocator::new(target.page_sz() * target.page_num());

    for call in calls {
        let mut grs: HashMap<ResKind, HashSet<ResValueId>> = HashMap::new();
        let mut urs: HashMap<ResKind, HashSet<ResValueId>> = HashMap::new();

        foreach_call_arg_mut(call, |val| {
            use ResValueKind::*;

            // fixup ptr address
            if let Some(val) = val.as_ptr_mut() {
                if let Some(pointee) = val.pointee.as_mut() {
                    let addr = allocator.alloc(pointee.layout(target));
                    val.addr = addr;
                }
            }

            if val.kind() != ValueKind::Res {
                return;
            }

            // remap res id
            let val = val.checked_as_res_mut();
            match &mut val.kind {
                Own(id) => {
                    let entry = res_map.entry(*id).or_insert_with(|| {
                        let new_id = cnt;
                        cnt += 1;
                        new_id
                    });
                    *id = *entry;
                }
                Ref(id) => {
                    if let Some(new_id) = res_map.get(id) {
                        *id = *new_id;
                    } else {
                        debug_warn!("fixup: res-{} missing", id);
                        let dir = val.dir();
                        *val = ResValue::new_null(val.ty_id(), dir, 0);
                    }
                }
                _ => (),
            }

            let ty = val.ty(target).checked_as_res();
            if let Some(id) = val.res_val_id() {
                if val.own_res() {
                    if !grs.contains_key(ty.res_name()) {
                        grs.insert(ty.res_name().clone(), HashSet::new());
                    }
                    grs.get_mut(ty.res_name()).unwrap().insert(id);
                } else {
                    if !urs.contains_key(ty.res_name()) {
                        urs.insert(ty.res_name().clone(), HashSet::new());
                    }
                    urs.get_mut(ty.res_name()).unwrap().insert(id);
                }
            }
        });
        call.generated_res = grs
            .into_iter()
            .map(|(k, v)| (k, v.into_iter().collect()))
            .collect();
        call.used_res = urs
            .into_iter()
            .map(|(k, v)| (k, v.into_iter().collect()))
            .collect();
    }
}
/// Fixup the addr of ptr value, re-order res id and re-collect generated res and used res of calls.
Fixup the addr of ptr value, re-order res id and re-collect generated res and used res of calls.
Fixup the addr of ptr value re - order res id and re - collect generated res and used res of calls .
pub fn fixup(target: &Target, calls: &mut [Call]) {
    let mut cnt = 0;
    let mut res_map: HashMap<ResValueId, ResValueId> = HashMap::default();
    let mut allocator = Allocator::new(target.page_sz() * target.page_num());
    for call in calls {
        let mut grs: HashMap<ResKind, HashSet<ResValueId>> = HashMap::new();
        let mut urs: HashMap<ResKind, HashSet<ResValueId>> = HashMap::new();
        foreach_call_arg_mut(call, |val| {
            use ResValueKind::*;
            // fixup ptr address
            if let Some(val) = val.as_ptr_mut() {
                if let Some(pointee) = val.pointee.as_mut() {
                    let addr = allocator.alloc(pointee.layout(target));
                    val.addr = addr;
                }
            }
            if val.kind() != ValueKind::Res {
                return;
            }
            // remap res id
            let val = val.checked_as_res_mut();
            match &mut val.kind {
                Own(id) => {
                    let entry = res_map.entry(*id).or_insert_with(|| {
                        let new_id = cnt;
                        cnt += 1;
                        new_id
                    });
                    *id = *entry;
                }
                Ref(id) => {
                    if let Some(new_id) = res_map.get(id) {
                        *id = *new_id;
                    } else {
                        debug_warn!("fixup: res-{} missing", id);
                        let dir = val.dir();
                        *val = ResValue::new_null(val.ty_id(), dir, 0);
                    }
                }
                _ => (),
            }
            let ty = val.ty(target).checked_as_res();
            if let Some(id) = val.res_val_id() {
                if val.own_res() {
                    if !grs.contains_key(ty.res_name()) {
                        grs.insert(ty.res_name().clone(), HashSet::new());
                    }
                    grs.get_mut(ty.res_name()).unwrap().insert(id);
                } else {
                    if !urs.contains_key(ty.res_name()) {
                        urs.insert(ty.res_name().clone(), HashSet::new());
                    }
                    urs.get_mut(ty.res_name()).unwrap().insert(id);
                }
            }
        });
        call.generated_res = grs
            .into_iter()
            .map(|(k, v)| (k, v.into_iter().collect()))
            .collect();
        call.used_res = urs
            .into_iter()
            .map(|(k, v)| (k, v.into_iter().collect()))
            .collect();
    }
}
pub fn fixup ( target : & Target , calls : & mut [ Call ] ) { let mut cnt = 0 ; let mut res_map : HashMap < ResValueId , ResValueId > = HashMap :: default ( ) ; let mut allocator = Allocator :: new ( target . page_sz ( ) * target . page_num ( ) ) ; for call in calls { let mut grs : HashMap < ResKind , HashSet < ResValueId > > = HashMap :: new ( ) ; let mut urs : HashMap < ResKind , HashSet < ResValueId > > = HashMap :: new ( ) ; foreach_call_arg_mut ( call , | val | { use ResValueKind :: * ; // fixup ptr address if let Some ( val ) = val . as_ptr_mut ( ) { if let Some ( pointee ) = val . pointee . as_mut ( ) { let addr = allocator . alloc ( pointee . layout ( target ) ) ; val . addr = addr ; } } if val . kind ( ) != ValueKind :: Res { return ; } // remap res id let val = val . checked_as_res_mut ( ) ; match & mut val . kind { Own ( id ) => { let entry = res_map . entry ( * id ) . or_insert_with ( | | { let new_id = cnt ; cnt += 1 ; new_id } ) ; * id = * entry ; } Ref ( id ) => { if let Some ( new_id ) = res_map . get ( id ) { * id = * new_id ; } else { debug_warn ! ( " " id ) ; let dir = val . dir ( ) ; * val = ResValue :: new_null ( val . ty_id ( ) , dir , 0 ) ; } } _ => ( ) , } let ty = val . ty ( target ) . checked_as_res ( ) ; if let Some ( id ) = val . res_val_id ( ) { if val . own_res ( ) { if ! grs . contains_key ( ty . res_name ( ) ) { grs . insert ( ty . res_name ( ) . clone ( ) , HashSet :: new ( ) ) ; } grs . get_mut ( ty . res_name ( ) ) . unwrap ( ) . insert ( id ) ; } else { if ! urs . contains_key ( ty . res_name ( ) ) { urs . insert ( ty . res_name ( ) . clone ( ) , HashSet :: new ( ) ) ; } urs . get_mut ( ty . res_name ( ) ) . unwrap ( ) . insert ( id ) ; } } } ) ; call . generated_res = grs . into_iter ( ) . map ( | ( k , v ) | ( k , v . into_iter ( ) . collect ( ) ) ) . collect ( ) ; call . used_res = urs . into_iter ( ) . map ( | ( k , v ) | ( k , v . into_iter ( ) . collect ( ) ) ) . collect ( ) ; } }
Fixup the addr of ptr value, re-order res id and re-collect generated res and used res of calls.
Fixup the addr of ptr value re - order res id and re - collect generated res and used res of calls .
target
&Target
calls
&mut [Call]
target
&Target
calls
&mut [Call]