FictionTools/z88dk/src/sccz80/codegen.c
/*
 * \brief Generate the leave state for a function
 *
 * \param vartype The type of variable we're leaving with
 * \param type 1=c, 2=nc, 0=no carry state
 * \param incritical - We're in a critical section, restore interrupts 
 */
\brief Generate the leave state for a function
\param vartype The type of variable we're leaving with
\param type 1=c, 2=nc, 0=no carry state
\param incritical - We're in a critical section, restore interrupts
\ brief Generate the leave state for a function \ param vartype The type of variable we ' re leaving with \ param type 1 = c 2 = nc 0 = no carry state \ param incritical - We ' re in a critical section restore interrupts
void leave(Kind vartype, char type, int incritical)
{
    int savesp;
    Kind save = vartype;
    int callee_cleanup = (currfn->ctype->flags & CALLEE) && (stackargs > 2);
    if ( (currfn->flags & NAKED) == NAKED ) {
        return;
    }
    if (vartype == KIND_CPTR) 
        vartype = KIND_LONG;
    else if ( vartype == KIND_DOUBLE ) {
        if ( c_fp_size == 4 ) {
            vartype = KIND_LONG;
        } else {
            vartype = KIND_NONE;
            save = NO;
        }
    }
    modstk(0, save, NO,YES);
    if (callee_cleanup) {
        int bcused = 0;
        savesp = Zsp;
        Zsp = -stackargs;
        if ( c_notaltreg && ( vartype != KIND_NONE && vartype != KIND_DOUBLE) && abs(Zsp) >= 11 ) {
            savehl();
            mainpop();
        } else {
            zpopbc();
            bcused = 1;
        }
        if ( Zsp > 0 ) {
            errorfmt("Internal error: Cannot cleanup function by lowering sp: Zsp=%d",1,Zsp);
        }
        modstk(0, save, NO, !bcused);
        if ( bcused ) {
            ol("push\tbc");
            Zsp -= 2;
        } else {
            zpush();
            restorehl();
        }
    }
    popframe(); 
    if ( (currfn->flags & CRITICAL) == CRITICAL || incritical) {
        zleavecritical();
    }
    if (type)
        setcond(type);
    zret(); 
}
void leave ( Kind vartype , char type , int incritical ) { int savesp ; Kind save = vartype ; int callee_cleanup = ( currfn -> ctype -> flags & CALLEE ) && ( stackargs > 2 ) ; if ( ( currfn -> flags & NAKED ) == NAKED ) { return ; } if ( vartype == KIND_CPTR ) vartype = KIND_LONG ; else if ( vartype == KIND_DOUBLE ) { if ( c_fp_size == 4 ) { vartype = KIND_LONG ; } else { vartype = KIND_NONE ; save = NO ; } } modstk ( 0 , save , NO , YES ) ; if ( callee_cleanup ) { int bcused = 0 ; savesp = Zsp ; Zsp = - stackargs ; if ( c_notaltreg && ( vartype != KIND_NONE && vartype != KIND_DOUBLE ) && abs ( Zsp ) >= 11 ) { savehl ( ) ; mainpop ( ) ; } else { zpopbc ( ) ; bcused = 1 ; } if ( Zsp > 0 ) { errorfmt ( " " , 1 , Zsp ) ; } modstk ( 0 , save , NO , ! bcused ) ; if ( bcused ) { ol ( " \t " ) ; Zsp -= 2 ; } else { zpush ( ) ; restorehl ( ) ; } } popframe ( ) ; if ( ( currfn -> flags & CRITICAL ) == CRITICAL || incritical ) { zleavecritical ( ) ; } if ( type ) setcond ( type ) ; zret ( ) ; }
\brief Generate the leave state for a function
 \param vartype The type of variable we're leaving with
 \param type 1=c, 2=nc, 0=no carry state
 \param incritical - We're in a critical section, restore interrupts
\ brief Generate the leave state for a function \ param vartype The type of variable we ' re leaving with \ param type 1 = c 2 = nc 0 = no carry state \ param incritical - We ' re in a critical section restore interrupts
/* they are the same in any case! */ // 8080, save hl, pop return int hl // Pop return address into bc /* Restore previous frame pointer */ /* Naked has already returned */ /* and exit function */