diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-09-20 17:51:04 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2015-09-20 17:51:04 -0400 |
commit | 540bf5283639fc5a08505a891ac8db16ea4cc0f3 (patch) | |
tree | f2de439dab88f6287183cec0e097f0d0fce154f1 /lisc/emit.c | |
parent | 9fcad221d074f09bde0ff7da9a49558d2ab067c7 (diff) | |
download | roux-540bf5283639fc5a08505a891ac8db16ea4cc0f3.tar.gz |
simplify two loops with a pointer
Diffstat (limited to 'lisc/emit.c')
-rw-r--r-- | lisc/emit.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/lisc/emit.c b/lisc/emit.c index 116d0d2..fb4bc8d 100644 --- a/lisc/emit.c +++ b/lisc/emit.c @@ -306,7 +306,7 @@ emitfn(Fn *fn, FILE *f) { Blk *b, *s; Ins *i; - int r, j, c, fs; + int *r, c, fs; fprintf(f, ".text\n" @@ -320,11 +320,9 @@ emitfn(Fn *fn, FILE *f) fs = framesz(fn); if (fs) fprintf(f, "\tsub $%d, %%rsp\n", fs); - for (j=0; j<NRClob; j++) { - r = rclob[j]; - if (fn->reg & BIT(r)) - emitf(fn, f, "\tpush%w %R\n", 1, TMP(r)); - } + for (r=rclob; r-rclob < NRClob; r++) + if (fn->reg & BIT(*r)) + emitf(fn, f, "\tpush%w %R\n", 1, TMP(*r)); for (b=fn->start; b; b=b->link) { fprintf(f, ".L%s:\n", b->name); @@ -332,11 +330,9 @@ emitfn(Fn *fn, FILE *f) eins(*i, fn, f); switch (b->jmp.type) { case JRet: - for (j=NRClob; j>=0; j--) { - r = rclob[j]; - if (fn->reg & BIT(r)) - emitf(fn, f, "\tpop%w %R\n", 1, TMP(r)); - } + for (r=&rclob[NRClob]; r>rclob;) + if (fn->reg & BIT(*--r)) + emitf(fn, f, "\tpop%w %R\n", 1, TMP(*r)); fprintf(f, "\tleave\n" "\tret\n" |