1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
|
|
|
/* under the terms of the Q Public License version 1.0. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-06-15 09:09:45 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
1998-11-18 10:10:53 -08:00
|
|
|
void caml_array_bound_error(void)
|
1995-12-05 05:09:19 -08:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Fatal error: out-of-bound access in array or string\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
1995-06-15 09:09:45 -07:00
|
|
|
#ifdef SORT
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
long cmpint(long * i, long * j)
|
1995-06-15 09:09:45 -07:00
|
|
|
{
|
|
|
|
return *i - *j;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
int main(int argc, char **argv)
|
1995-06-15 09:09:45 -07:00
|
|
|
{
|
|
|
|
#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();
|
1996-10-24 09:16:11 -07:00
|
|
|
#ifdef __mc68020__
|
|
|
|
#define call_gen_code call_gen_code_float
|
|
|
|
#endif
|
1995-06-15 09:09:45 -07:00
|
|
|
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;
|
|
|
|
|
1995-11-26 06:38:29 -08:00
|
|
|
srand(argc >= 3 ? atoi(argv[2]) : time((char *) 0));
|
1995-06-15 09:09:45 -07:00
|
|
|
n = atoi(argv[1]);
|
|
|
|
a = (long *) malloc(n * sizeof(long));
|
1995-11-26 06:38:29 -08:00
|
|
|
for (i = 0 ; i < n; i++) a[i] = rand() & 0xFFF;
|
1995-06-15 09:09:45 -07:00
|
|
|
#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
|
1995-12-05 01:16:53 -08:00
|
|
|
#endif
|
|
|
|
#ifdef CHECKBOUND
|
|
|
|
{ extern void checkbound1(), checkbound2();
|
|
|
|
extern void call_gen_code();
|
|
|
|
long x, y;
|
|
|
|
x = atoi(argv[1]);
|
|
|
|
if (argc >= 3) {
|
|
|
|
y = atoi(argv[2]);
|
|
|
|
if ((unsigned long) x < (unsigned long) y)
|
|
|
|
printf("Should not trap\n");
|
|
|
|
else
|
|
|
|
printf("Should trap\n");
|
|
|
|
call_gen_code(checkbound2, y, x);
|
|
|
|
} else {
|
|
|
|
if (2 < (unsigned long) x)
|
|
|
|
printf("Should not trap\n");
|
|
|
|
else
|
|
|
|
printf("Should trap\n");
|
|
|
|
call_gen_code(checkbound1, x);
|
|
|
|
}
|
|
|
|
printf("OK\n");
|
|
|
|
}
|
1995-06-15 09:09:45 -07:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|