summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2012-06-06 01:07:32 -0400
committerOri Bernstein <ori@eigenstate.org>2012-06-06 01:07:32 -0400
commitf4d54a5bc70ba219402c1b20a16423bce1704ed9 (patch)
tree10e7a048dac2a5e93f2eb8de379f6523f8aa45ff
parent3065ee64d255b9eca94efd48269cd291960d6c4e (diff)
downloadmc-f4d54a5bc70ba219402c1b20a16423bce1704ed9.tar.gz
Add loop generation test.
-rw-r--r--8/asm.h1
-rw-r--r--8/insns.def12
-rw-r--r--8/isel.c12
-rw-r--r--8/reduce.c2
-rwxr-xr-xtest/build.sh1
-rw-r--r--test/fib.myr4
-rwxr-xr-xtest/test.sh1
7 files changed, 19 insertions, 14 deletions
diff --git a/8/asm.h b/8/asm.h
index b431cf0..530f09f 100644
--- a/8/asm.h
+++ b/8/asm.h
@@ -89,3 +89,4 @@ Loc *loclit(Loc *l, long val);
/* useful functions */
size_t size(Node *n);
+void breakhere();
diff --git a/8/insns.def b/8/insns.def
index dc2435f..20e95cf 100644
--- a/8/insns.def
+++ b/8/insns.def
@@ -35,12 +35,12 @@ Insn(Ipush, "\tpush%t %r\n", 0)
Insn(Ipop, "\tpop%t %r\n", 0)
/* branch instructions */
-Insn(Isetz, "\tsetz\n", 0)
-Insn(Isetnz, "\tsetnz\n", 0)
-Insn(Isetlt, "\tsetlt\n", 0)
-Insn(Isetle, "\tsetle\n", 0)
-Insn(Isetgt, "\tsetgt\n", 0)
-Insn(Isetge, "\tsetge\n", 0)
+Insn(Isetz, "\tsetz %v\n", 0)
+Insn(Isetnz, "\tsetnz %v\n", 0)
+Insn(Isetlt, "\tsetlt %v\n", 0)
+Insn(Isetle, "\tsetle %v\n", 0)
+Insn(Isetgt, "\tsetgt %v\n", 0)
+Insn(Isetge, "\tsetge %v\n", 0)
/* branch instructions */
Insn(Icall, "\tcall %v\n", 0)
diff --git a/8/isel.c b/8/isel.c
index b6d922c..7556d64 100644
--- a/8/isel.c
+++ b/8/isel.c
@@ -152,7 +152,7 @@ Loc loc(Isel *s, Node *n)
case Ovar:
if (hthas(s->locs, (void*)n->expr.did)) {
stkoff = (size_t)htget(s->locs, (void*)n->expr.did);
- locmem(&l, stkoff, Resp, Rnone, ModeL);
+ locmem(&l, -stkoff, Resp, Rnone, ModeL);
} else if (hthas(s->globls, (void*)n->expr.did)) {
locstrlbl(&l, htget(s->globls, (void*)n->expr.did));
} else {
@@ -269,6 +269,8 @@ Insn *mkinsnv(AsmOp op, va_list ap)
n = 0;
i = malloc(sizeof(Insn));
i->op = op;
+ if (op == Isetnz)
+ breakhere();
while ((l = va_arg(ap, Loc*)) != NULL)
i->args[n++] = *l;
i->narg = n;
@@ -429,7 +431,7 @@ static Loc memloc(Isel *s, Node *e, Mode m)
Loc gencall(Isel *s, Node *n)
{
- int argsz;
+ int argsz, argoff;
int i;
Loc eax, esp; /* hard-coded registers */
Loc stkbump; /* calculated stack offset */
@@ -451,13 +453,13 @@ Loc gencall(Isel *s, Node *n)
g(s, Isub, &stkbump, &esp, NULL);
/* Now, we can evaluate the arguments */
- argsz = 0;
+ argoff = 0;
for (i = 1; i < n->expr.nargs; i++) {
- argsz += size(n->expr.args[i]);
arg = selexpr(s, n->expr.args[i]);
arg = inri(s, arg);
- locmem(&dst, argsz, Resp, Rnone, arg.mode);
+ locmem(&dst, argoff, Resp, Rnone, arg.mode);
stor(s, &arg, &dst);
+ argsz += size(n->expr.args[i]);
}
fn = selexpr(s, n->expr.args[0]);
g(s, Icall, &fn, NULL);
diff --git a/8/reduce.c b/8/reduce.c
index 311ec45..c7a0736 100644
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -452,7 +452,7 @@ void declarearg(Simp *s, Node *n)
{
assert(n->type == Ndecl);
if (debug)
- printf("DECLARE %s(%ld) at %zd\n", declname(n), n->decl.sym->id, -s->argsz);
+ printf("DECLARE %s(%ld) at %zd\n", declname(n), n->decl.sym->id, -(s->argsz + 8));
htput(s->locs, (void*)n->decl.sym->id, (void*)-s->argsz);
s->argsz += size(n);
}
diff --git a/test/build.sh b/test/build.sh
index 5710c30..8a406f9 100755
--- a/test/build.sh
+++ b/test/build.sh
@@ -16,6 +16,7 @@ build struct_oneval
build struct
build array
build call
+build loop
build fib
exit 0
diff --git a/test/fib.myr b/test/fib.myr
index 6eb4b44..f744a27 100644
--- a/test/fib.myr
+++ b/test/fib.myr
@@ -1,5 +1,5 @@
const fib = {n
- if n == 0
+ if n <= 0
-> 0
elif n == 1
-> 1
@@ -9,6 +9,6 @@ const fib = {n
}
const main = {
- -> fib(4)
+ -> fib(2)
}
diff --git a/test/test.sh b/test/test.sh
index 006855d..6d0f61d 100755
--- a/test/test.sh
+++ b/test/test.sh
@@ -24,4 +24,5 @@ returns struct_oneval 12
returns struct 42
returns array 7
returns call 42
+returns loop 45
returns fib 8