diff --git a/.gitignore b/.gitignore index 9050e80..c0e0ed1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ config.h *~ .direnv result -.cache \ No newline at end of file +.cache +.fuse_hidden* diff --git a/all.h b/all.h index 5d352b6..078c1a0 100644 --- a/all.h +++ b/all.h @@ -159,13 +159,12 @@ enum J { #define JMPS(X) \ X(retw) X(retl) X(rets) X(retd) \ X(retsb) X(retub) X(retsh) X(retuh) \ - X(retc) X(ret0) X(jmp) X(jnz) \ - X(tail) \ + X(retc) X(ret0) X(jmp) X(jnz) \ X(jfieq) X(jfine) X(jfisge) X(jfisgt) \ X(jfisle) X(jfislt) X(jfiuge) X(jfiugt) \ X(jfiule) X(jfiult) X(jffeq) X(jffge) \ X(jffgt) X(jffle) X(jfflt) X(jffne) \ - X(jffo) X(jffuo) X(hlt) + X(jffo) X(jffuo) X(hlt) X(tail) #define X(j) J##j, JMPS(X) #undef X diff --git a/amd64/isel.c b/amd64/isel.c index 379244a..7201b09 100644 --- a/amd64/isel.c +++ b/amd64/isel.c @@ -602,7 +602,8 @@ seljmp(Blk *b, Fn *fn) if (b->jmp.type == Jret0 || b->jmp.type == Jjmp - || b->jmp.type == Jhlt) + || b->jmp.type == Jhlt + || b->jmp.type == Jtail) return; assert(b->jmp.type == Jjnz); r = b->jmp.arg; diff --git a/amd64/sysv.c b/amd64/sysv.c index 68f548c..da78cd9 100644 --- a/amd64/sysv.c +++ b/amd64/sysv.c @@ -167,7 +167,7 @@ argsclass(Ins *i0, Ins *i1, AClass *ac, int op, AClass *aret, Ref *env) nsse = 8; varc = 0; envc = 0; - for (i=i0, a=ac; iop - op + Oarg) { case Oarg: if (KBASE(i->cls) == 0) @@ -211,8 +211,9 @@ argsclass(Ins *i0, Ins *i1, AClass *ac, int op, AClass *aret, Ref *env) varc = 1; break; default: - die("unreachable"); + die("218 unreachable"); } + } if (varc && envc) err("sysv abi does not support variadic env calls"); @@ -686,7 +687,7 @@ amd64_sysv_abi(Fn *fn) continue; curi = &insb[NIns]; selret(b, fn); - for (i=&b->ins[b->nins]; i!=b->ins;) + for (i=&b->ins[b->nins]; i!=b->ins;) { switch ((--i)->op) { default: emiti(*i); @@ -706,8 +707,13 @@ amd64_sysv_abi(Fn *fn) break; case Oarg: case Oargc: - die("unreachable"); + if (b->jmp.type != Jtail) { + die("710 unreachable"); + } else { + + } } + } if (b == fn->start) for (; ral; ral=ral->link) emiti(ral->i); diff --git a/dump-enums.c b/dump-enums.c new file mode 100644 index 0000000..e69de29 diff --git a/flake.nix b/flake.nix index d8ff59a..992e1e4 100644 --- a/flake.nix +++ b/flake.nix @@ -34,12 +34,8 @@ gcc clang-analyzer clang-tools + gdbgui ]; - # shellHook = '' - # [[ ! -z "$LD_LIBRARY_PATH" ]] \ - # && export LD_LIBRARY_PATH=:$LD_LIBRARY_PATH - # export LD_LIBRARY_PATH="${self.packages.${system}.default.libllvm.lib}/lib$LD_LIBRARY_PATH" - # ''; }; }); }; diff --git a/main.c b/main.c index b611667..1afdfec 100644 --- a/main.c +++ b/main.c @@ -17,6 +17,7 @@ char debug['Z'+1] = { ['L'] = 0, /* liveness */ ['S'] = 0, /* spilling */ ['R'] = 0, /* reg. allocation */ + ['E'] = 0, /* enums */ }; extern Target T_amd64_sysv; @@ -60,7 +61,6 @@ func(Fn *fn) if (debug['P']) { fprintf(stderr, "\n> After parsing:\n"); printfn(fn, stderr); - exit (1); } T.abi0(fn); fillcfg(fn); diff --git a/parse.c b/parse.c index a099ef0..799c427 100644 --- a/parse.c +++ b/parse.c @@ -1446,7 +1446,7 @@ printfn(Fn *fn, FILE *f) case Jtail: fprintf (f, "\ttail "); printref (b->jmp.arg, fn, f); - fprintf (f, "%d (%d)", i->op, Oarg); + fprintf (f, "\n"); break; default: fprintf(f, "\t%s ", jtoa[b->jmp.type]); diff --git a/test/call-factorial.ssa b/test/call-factorial.ssa new file mode 100644 index 0000000..70c3598 --- /dev/null +++ b/test/call-factorial.ssa @@ -0,0 +1,11 @@ +function w $factorial (w %n, w %acc) { +@start + jnz %n, @nz, @z +@z + ret %acc +@nz + %n_next =w sub %n, 1 + %acc_next =w mul %n, %acc + %r =w call $factorial (w %n_next, w %acc) + ret %r +} \ No newline at end of file diff --git a/test/tail.ssa b/test/tail.ssa index 17d254b..44c6b6b 100644 --- a/test/tail.ssa +++ b/test/tail.ssa @@ -1,6 +1,6 @@ function w $factorial (w %n, w %acc) { @start - jnz %n, @z, @nz + jnz %n, @nz, @z @z ret %acc @nz diff --git a/util.c b/util.c index 00bd92b..8ba30d0 100644 --- a/util.c +++ b/util.c @@ -261,6 +261,7 @@ igroup(Blk *b, Ins *i, Ins **i0, Ins **i1) ib = b->ins; ie = ib + b->nins; + switch (i->op) { case Oblit0: *i0 = i; @@ -285,8 +286,12 @@ igroup(Blk *b, Ins *i, Ins **i0, Ins **i1) *i0 = i; for (; iop != Ocall; i++) ; - assert(i < ie); - *i1 = i + 1; + if (b->jmp.type == Jtail) { + *i1 = ie; + } else { + assert(i < ie); + *i1 = i + 1; + } return; case Osel1: for (; i>ib && (i-1)->op == Osel1; i--)