6/simp.c
/*
 * Turns a deeply nested function body into a flatter
 * and simpler representation, which maps easily and
 * directly to assembly instructions.
 */
Turns a deeply nested function body into a flatter
and simpler representation, which maps easily and
directly to assembly instructions.
Turns a deeply nested function body into a flatter and simpler representation which maps easily and directly to assembly instructions .
static void flatten(Simp *s, Node *f)
{
    Node *dcl;
    Type *ty;
    size_t i;
    assert(f->type == Nfunc);
    s->nstmts = 0;
    s->stmts = NULL;
    s->endlbl = genlbl(f->loc);
    s->ret = NULL;
    ty = f->func.type->sub[0];
    if (isstacktype(ty)) {
        s->isbigret = 1;
        s->ret = gentemp(s, f->loc, mktyptr(f->loc, ty), &dcl);
        declarearg(s, dcl);
    } else if (ty->type != Tyvoid) {
        s->isbigret = 0;
        s->ret = gentemp(s, f->loc, ty, &dcl);
    }
    for (i = 0; i < f->func.nargs; i++) {
      declarearg(s, f->func.args[i]);
    }
    simp(s, f->func.body);
    append(s, s->endlbl);
}
static void flatten ( Simp * s , Node * f ) { Node * dcl ; Type * ty ; size_t i ; assert ( f -> type == Nfunc ) ; s -> nstmts = 0 ; s -> stmts = NULL ; s -> endlbl = genlbl ( f -> loc ) ; s -> ret = NULL ; ty = f -> func . type -> sub [ 0 ] ; if ( isstacktype ( ty ) ) { s -> isbigret = 1 ; s -> ret = gentemp ( s , f -> loc , mktyptr ( f -> loc , ty ) , & dcl ) ; declarearg ( s , dcl ) ; } else if ( ty -> type != Tyvoid ) { s -> isbigret = 0 ; s -> ret = gentemp ( s , f -> loc , ty , & dcl ) ; } for ( i = 0 ; i < f -> func . nargs ; i ++ ) { declarearg ( s , f -> func . args [ i ] ) ; } simp ( s , f -> func . body ) ; append ( s , s -> endlbl ) ; }
Turns a deeply nested function body into a flatter
 and simpler representation, which maps easily and
 directly to assembly instructions.
Turns a deeply nested function body into a flatter and simpler representation which maps easily and directly to assembly instructions .
/* make a temp for the return type */