diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2017-02-27 10:34:22 -0500 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2017-02-27 10:34:29 -0500 |
commit | e80252a52bf25f762bc986ce6e4e0d17fbb130d0 (patch) | |
tree | 06b476558944a83d6c3e11ecc322a568caf1fe94 /emit.c | |
parent | 3aecf460f5ab60c96ba90042ffd1cd7df41eeca5 (diff) | |
download | roux-e80252a52bf25f762bc986ce6e4e0d17fbb130d0.tar.gz |
scrub assembly output
Notably, this adds a new pass to get rid of jumps on jumps.
Diffstat (limited to 'emit.c')
-rw-r--r-- | emit.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/emit.c b/emit.c index c3a274b..138bc1d 100644 --- a/emit.c +++ b/emit.c @@ -505,7 +505,7 @@ emitfn(Fn *fn, FILE *f) static int id0; Blk *b, *s; Ins *i, itmp; - int *r, c, fs, o, n; + int *r, c, fs, o, n, lbl; fprintf(f, ".text\n"); if (fn->export) @@ -532,11 +532,12 @@ emitfn(Fn *fn, FILE *f) emitf("pushq %L0", &itmp, fn, f); } - for (b=fn->start; b; b=b->link) { - fprintf(f, "%sbb%d:\n", locprefix, id0+b->id); - fprintf(f, "/* @%s */\n", b->name); + for (lbl=0, b=fn->start; b; b=b->link) { + if (lbl || b->npred > 1) + fprintf(f, "%sbb%d:\n", locprefix, id0+b->id); for (i=b->ins; i!=&b->ins[b->nins]; i++) emitins(*i, fn, f); + lbl = 1; switch (b->jmp.type) { case Jret0: for (r=&rclob[NRClob]; r>rclob;) @@ -554,6 +555,8 @@ emitfn(Fn *fn, FILE *f) if (b->s1 != b->link) fprintf(f, "\tjmp %sbb%d\n", locprefix, id0+b->s1->id); + else + lbl = 0; break; default: c = b->jmp.type - Jxjc; |