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$ */
|
|
|
|
|
2000-06-29 04:45:24 -07:00
|
|
|
#include <stddef.h>
|
1995-06-15 09:09:45 -07:00
|
|
|
#include <stdio.h>
|
2000-06-29 04:45:24 -07:00
|
|
|
#include <stdlib.h>
|
1995-06-15 09:09:45 -07:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-06-30 01:28:48 -07:00
|
|
|
void print_string(char * s)
|
|
|
|
{
|
|
|
|
fputs(s, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void printf_int(char * fmt, int arg)
|
|
|
|
{
|
|
|
|
printf(fmt, arg);
|
|
|
|
}
|
|
|
|
|
1995-06-15 09:09:45 -07:00
|
|
|
#ifdef SORT
|
|
|
|
|
2000-06-29 04:45:24 -07:00
|
|
|
int cmpint(const void * i, const void * j)
|
1995-06-15 09:09:45 -07:00
|
|
|
{
|
2000-06-29 04:45:24 -07:00
|
|
|
long vi = *((long *) i);
|
|
|
|
long vj = *((long *) j);
|
|
|
|
if (vi == vj) return 0;
|
|
|
|
if (vi < vj) return -1;
|
|
|
|
return 1;
|
1995-06-15 09:09:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#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
|
2000-06-29 04:45:24 -07:00
|
|
|
for (i = 0; i < n; i++) printf("%ld ", a[i]); printf("\n");
|
1995-06-15 09:09:45 -07:00
|
|
|
#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
|
2000-06-29 04:45:24 -07:00
|
|
|
for (i = 0; i < n; i++) printf("%ld ", a[i]); printf("\n");
|
1995-06-15 09:09:45 -07:00
|
|
|
#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;
|
|
|
|
}
|