exits successfully lol

This commit is contained in:
2026-06-12 13:28:10 -06:00
parent 30e73fcba1
commit c051b402dd
11 changed files with 38 additions and 19 deletions

3
.gitignore vendored
View File

@@ -6,4 +6,5 @@ config.h
*~
.direnv
result
.cache
.cache
.fuse_hidden*

5
all.h
View File

@@ -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

View File

@@ -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;

View File

@@ -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; i<i1; i++, a++)
for (i=i0, a=ac; i<i1; i++, a++) {
switch (i->op - 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);

0
dump-enums.c Normal file
View File

View File

@@ -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"
# '';
};
});
};

2
main.c
View File

@@ -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);

View File

@@ -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]);

11
test/call-factorial.ssa Normal file
View File

@@ -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
}

View File

@@ -1,6 +1,6 @@
function w $factorial (w %n, w %acc) {
@start
jnz %n, @z, @nz
jnz %n, @nz, @z
@z
ret %acc
@nz

9
util.c
View File

@@ -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 (; i<ie && i->op != 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--)