Reecriture de certaines boucles avec sortie par catch...exit.
Introduction de main.c commun a tous les tests. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@38 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
ba79d4bd1f
commit
30ef39841f
|
@ -0,0 +1,42 @@
|
|||
ARCH=alpha
|
||||
|
||||
CODEGEN=../codegen
|
||||
ASFLAGS=-O
|
||||
CFLAGS=-g
|
||||
|
||||
PROGS=fib tak quicksort quicksort2 soli integr
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
fib: main.c fib.o $(ARCH).o
|
||||
$(CC) $(CFLAGS) -o fib -DINT_INT -DFUN=fib main.c fib.o $(ARCH).o
|
||||
|
||||
tak: main.c tak.o $(ARCH).o
|
||||
$(CC) $(CFLAGS) -o tak -DUNIT_INT -DFUN=takmain main.c tak.o $(ARCH).o
|
||||
|
||||
quicksort: main.c quicksort.o $(ARCH).o
|
||||
$(CC) $(CFLAGS) -o quicksort -DSORT -DFUN=quicksort main.c quicksort.o $(ARCH).o
|
||||
|
||||
quicksort2: main.c quicksort2.o $(ARCH).o
|
||||
$(CC) $(CFLAGS) -o quicksort2 -DSORT -DFUN=quicksort main.c quicksort2.o $(ARCH).o
|
||||
|
||||
soli: main.c soli.o $(ARCH).o
|
||||
$(CC) $(CFLAGS) -o soli -DUNIT_INT -DFUN=solitaire main.c soli.o $(ARCH).o
|
||||
|
||||
integr: main.c integr.o $(ARCH).o
|
||||
$(CC) $(CFLAGS) -o integr -DINT_FLOAT -DFUN=test main.c integr.o $(ARCH).o
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .cmm .c .o .asm
|
||||
|
||||
.cmm.o:
|
||||
cslrun $(CODEGEN) $*.cmm > $*.s
|
||||
$(AS) $(ASFLAGS) -o $*.o $*.s
|
||||
|
||||
.asm.o:
|
||||
$(AS) $(ASFLAGS) -o $*.o $*.asm
|
||||
|
||||
clean:
|
||||
rm -f *.s *.o *~ $(PROGS)
|
||||
|
||||
fib.o tak.o quicksort.o quicksort2.o integr.o soli.o: $(CODEGEN)
|
|
@ -0,0 +1,68 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#ifdef SORT
|
||||
|
||||
long cmpint(i, j)
|
||||
long * i, * j;
|
||||
{
|
||||
return *i - *j;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char ** argv;
|
||||
{
|
||||
#ifdef UNIT_INT
|
||||
{ extern int FUN();
|
||||
extern int call_gen_code();
|
||||
printf("%d\n", call_gen_code(FUN));
|
||||
}
|
||||
#else
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s [int arg]\n", argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
#ifdef INT_INT
|
||||
{ extern int FUN();
|
||||
extern int call_gen_code();
|
||||
printf("%d\n", call_gen_code(FUN, atoi(argv[1])));
|
||||
}
|
||||
#endif
|
||||
#ifdef INT_FLOAT
|
||||
{ extern double FUN();
|
||||
extern double call_gen_code();
|
||||
printf("%f\n", call_gen_code(FUN, atoi(argv[1])));
|
||||
}
|
||||
#endif
|
||||
#ifdef SORT
|
||||
{ extern void FUN();
|
||||
extern void call_gen_code();
|
||||
long n;
|
||||
long * a, * b;
|
||||
long i;
|
||||
|
||||
srandom(argc >= 3 ? atoi(argv[2]) : time((char *) 0));
|
||||
n = atoi(argv[1]);
|
||||
a = (long *) malloc(n * sizeof(long));
|
||||
for (i = 0 ; i < n; i++) a[i] = random() & 0xFFF;
|
||||
#ifdef DEBUG
|
||||
for (i = 0; i < n; i++) printf("%d ", a[i]); printf("\n");
|
||||
#endif
|
||||
b = (long *) malloc(n * sizeof(long));
|
||||
for (i = 0; i < n; i++) b[i] = a[i];
|
||||
call_gen_code(FUN, 0, n-1, a);
|
||||
#ifdef DEBUG
|
||||
for (i = 0; i < n; i++) printf("%d ", a[i]); printf("\n");
|
||||
#endif
|
||||
qsort(b, n, sizeof(long), cmpint);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (a[i] != b[i]) { printf("Bug!\n"); return 2; }
|
||||
}
|
||||
printf("OK\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
|
@ -4,10 +4,18 @@
|
|||
j hi
|
||||
pivot (addraref a hi))
|
||||
(while (< i j)
|
||||
(while (if (< i hi) (<= (addraref a i) pivot) 0)
|
||||
(assign i (+ i 1)))
|
||||
(while (if (> j lo) (>= (addraref a j) pivot) 0)
|
||||
(assign j (- j 1)))
|
||||
(catch
|
||||
(while 1
|
||||
(if (>= i hi) exit [])
|
||||
(if (> (addraref a i) pivot) exit [])
|
||||
(assign i (+ i 1)))
|
||||
with [])
|
||||
(catch
|
||||
(while 1
|
||||
(if (<= j lo) exit [])
|
||||
(if (< (addraref a j) pivot) exit [])
|
||||
(assign j (- j 1)))
|
||||
with [])
|
||||
(if (< i j)
|
||||
(let temp (addraref a i)
|
||||
(addraset a i (addraref a j))
|
||||
|
|
|
@ -7,10 +7,18 @@
|
|||
j hi
|
||||
pivot (addraref a hi))
|
||||
(while (< i j)
|
||||
(while (if (< i hi) (<= (app cmp [(addraref a i) pivot] int) 0) 0)
|
||||
(assign i (+ i 1)))
|
||||
(while (if (> j lo) (>= (app cmp [(addraref a j) pivot] int) 0) 0)
|
||||
(assign j (- j 1)))
|
||||
(catch
|
||||
(while 1
|
||||
(if (>= i hi) exit [])
|
||||
(if (> (app cmp [(addraref a i) pivot] int) 0) exit [])
|
||||
(assign i (+ i 1)))
|
||||
with [])
|
||||
(catch
|
||||
(while 1
|
||||
(if (<= j lo) exit [])
|
||||
(if (< (app cmp [(addraref a j) pivot] int) 0) exit [])
|
||||
(assign j (- j 1)))
|
||||
with [])
|
||||
(if (< i j)
|
||||
(let temp (addraref a i)
|
||||
(addraset a i (addraref a j))
|
||||
|
|
Loading…
Reference in New Issue