home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-2.LHA / CLISP960530-ki.lha / ffcall / vacall / tests.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  30.3 KB  |  1,023 lines

  1. /* Some random tests for vacall. */
  2.  
  3. /*
  4.  * Copyright 1993 Bill Triggs, <bill@robots.oxford.ac.uk>,
  5.  * Copyright 1995 Bruno Haible, <haible@ma2s2.mathematik.uni-karlsruhe.de>
  6.  *
  7.  * This is free software distributed under the GNU General Public Licence
  8.  * described in the file COPYING. Contact the author if you don't have this
  9.  * or can't live with it. There is ABSOLUTELY NO WARRANTY, explicit or implied,
  10.  * on this software.
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include "vacall.h"
  16. FILE* out;
  17.  
  18. /* NB since K&R C always passes chars and shorts as ints and floats as doubles,
  19.  * unprototyped ANSI-C functions must do the same, eg:
  20.  * - foo(x) float x; { ... } passes x as a double & converts it to a float internally.
  21.  * - foo(float x) { ... } passes x as a float.
  22.  */
  23. #if defined(__STDC__) || defined(__GNUC__)
  24. #define _ ,
  25. #define _P(ARGS,TYPES) (TYPES)
  26. #define FTYPE(RETTYPE,ARGTYPES) (RETTYPE (*) ARGTYPES)
  27. #else
  28. #define _ ;
  29. #define _P(ARGS,TYPES) ARGS TYPES;
  30. #define FTYPE(RETTYPE,ARGTYPES) (RETTYPE (*) ())
  31. #endif
  32.  
  33. #if defined(__hppa__) && defined(__GNUC__)
  34. #if (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
  35. /* gcc-2.5.2 bugs prevent the T test from working. */
  36. #define SKIP_T
  37. #endif
  38. #endif
  39. #if defined(__m68k__) && defined(__GNUC__)
  40. /* "gcc-2.6.3 -freg-struct-return" returns  T = struct { char c[3]; }  (which
  41.  * has size 4 !) in memory, in contrast to  struct { char a,b,c; }  and
  42.  * struct { char c[4]; }  and  struct { char a,b,c,d; }  which have the same
  43.  * size and the same alignment but are returned in registers. I don't know why.
  44.  */
  45. #define SKIP_T
  46. #endif
  47.  
  48. #define uchar unsigned char
  49. #define ushort unsigned short
  50. #define uint unsigned int
  51. #define ulong unsigned long
  52.  
  53. typedef struct { char x; } Char;
  54. typedef struct { short x; } Short;
  55. typedef struct { int x; } Int;
  56. typedef struct { long x; } Long;
  57. typedef struct { float x; } Float;
  58. typedef struct { double x; } Double;
  59. typedef struct { char c; float f; } A;
  60. typedef struct { double d; int i[3]; } B;
  61. typedef struct { long l1; long l2; } J;
  62. typedef struct { char c[3]; } T;
  63. typedef struct { char c[33],c1; } X;
  64.  
  65. char c1='a', c2=127, c3=(char)128, c4=(char)255, c5=-1;
  66. short s1=32767, s2=(short)32768, s3=3, s4=4, s5=5, s6=6, s7=7, s8=8, s9=9;
  67. int i1=1, i2=2, i3=3, i4=4, i5=5, i6=6, i7=7, i8=8, i9=9;
  68. long l1=1, l2=2, l3=3, l4=4, l5=5, l6=6, l7=7, l8=8, l9=9;
  69. float f1=0.1, f2=0.2, f3=0.3, f4=0.4, f5=0.5, f6=0.6, f7=0.7, f8=0.8, f9=0.9;
  70. double d1=0.1, d2=0.2, d3=0.3, d4=0.4, d5=0.5, d6=0.6, d7=0.7, d8=0.8, d9=0.9;
  71.  
  72. uchar uc1='a', uc2=127, uc3=128, uc4=255, uc5=-1;
  73. ushort us1=1, us2=2, us3=3, us4=4, us5=5, us6=6, us7=7, us8=8, us9=9;
  74. uint ui1=1, ui2=2, ui3=3, ui4=4, ui5=5, ui6=6, ui7=7, ui8=8, ui9=9;
  75. ulong ul1=1, ul2=2, ul3=3, ul4=4, ul5=5, ul6=6, ul7=7, ul8=8, ul9=9;
  76.  
  77. char *str1="hello",str2[]="goodbye",*str3="still here?";
  78. Char C1={'A'}, C2={'B'}, C3={'C'}, C4={'\377'}, C5={-1};
  79. Short S1={1}, S2={2}, S3={3}, S4={4}, S5={5}, S6={6}, S7={7}, S8={8}, S9={9};
  80. Int I1={1}, I2={2}, I3={3}, I4={4}, I5={5}, I6={6}, I7={7}, I8={8}, I9={9};
  81. Float F1={0.1}, F2={0.2}, F3={0.3}, F4={0.4}, F5={0.5}, F6={0.6}, F7={0.7}, F8={0.8}, F9={0.9};
  82. Double D1={0.1}, D2={0.2}, D3={0.3}, D4={0.4}, D5={0.5}, D6={0.6}, D7={0.7}, D8={0.8}, D9={0.9};
  83.  
  84. A A1={'a',0.1},A2={'b',0.2},A3={'\377',0.3};
  85. B B1={0.1,{1,2,3}},B2={0.2,{5,4,3}};
  86. J J1={47,11},J2={73,55};
  87. T T1={"the"},T2={"fox"};
  88. X X1={"abcdefghijklmnopqrstuvwxyzABCDEF",'G'}, X2={"123",'9'}, X3={"return-return-return",'R'};
  89.  
  90. /* void tests */
  91. void v_v()
  92. {
  93.   fprintf(out,"void f(void):\n");
  94.   fflush(out);
  95. }
  96.  
  97. /* int tests */
  98. int i_v()
  99. {
  100.   int r=99;
  101.   fprintf(out,"int f(void):");
  102.   fflush(out);
  103.   return r;
  104. }
  105. int i_i _P((a), int a)
  106. {
  107.   int r=a+1;
  108.   fprintf(out,"int f(int):(%d)",a);
  109.   fflush(out);
  110.   return r;
  111. }
  112. int i_i2 _P((a,b), int a _ int b)
  113. {
  114.   int r=a+b;
  115.   fprintf(out,"int f(2*int):(%d,%d)",a,b);
  116.   fflush(out);
  117.   return r;
  118. }
  119. int i_i4 _P((a,b,c,d), int a _ int b _ int c _ int d)
  120. {
  121.   int r=a+b+c+d;
  122.   fprintf(out,"int f(4*int):(%d,%d,%d,%d)",a,b,c,d);
  123.   fflush(out);
  124.   return r;
  125. }
  126. int i_i8 _P((a,b,c,d,e,f,g,h),
  127.             int a _ int b _ int c _ int d _ int e _ int f _ int g _ int h)
  128. {
  129.   int r=a+b+c+d+e+f+g+h;
  130.   fprintf(out,"int f(8*int):(%d,%d,%d,%d,%d,%d,%d,%d)",a,b,c,d,e,f,g,h);
  131.   fflush(out);
  132.   return r;
  133. }
  134. int i_i16 _P((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p),
  135.              int a _ int b _ int c _ int d _ int e _ int f _ int g _ int h
  136.              _ int i _ int j _ int k _ int l _ int m _ int n _ int o _ int p)
  137. {
  138.   int r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
  139.   fprintf(out,"int f(16*int):(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",
  140.           a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
  141.   fflush(out);
  142.   return r;
  143. }
  144.  
  145. /* float tests */
  146. float f_f _P((a), float a)
  147. {
  148.   float r=a+1.0;
  149.   fprintf(out,"float f(float):(%g)",a);
  150.   fflush(out);
  151.   return r;
  152. }
  153. float f_f2 _P((a,b), float a _ float b)
  154. {
  155.   float r=a+b;
  156.   fprintf(out,"float f(2*float):(%g,%g)",a,b);
  157.   fflush(out);
  158.   return r;
  159. }
  160. float f_f4 _P((a,b,c,d), float a _ float b _ float c _ float d)
  161. {
  162.   float r=a+b+c+d;
  163.   fprintf(out,"float f(4*float):(%g,%g,%g,%g)",a,b,c,d);
  164.   fflush(out);
  165.   return r;
  166. }
  167. float f_f8 _P((a,b,c,d,e,f,g,h), float a _ float b _ float c _ float d _ float e _ float f
  168.               _ float g _ float h)
  169. {
  170.   float r=a+b+c+d+e+f+g+h;
  171.   fprintf(out,"float f(8*float):(%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h);
  172.   fflush(out);
  173.   return r;
  174. }
  175. float f_f16 _P((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p),
  176.                float a _ float b _ float c _ float d _ float e _ float f _ float g _ float h
  177.                _ float i _ float j _ float k _ float l _ float m _ float n _ float o _ float p)
  178. {
  179.   float r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
  180.   fprintf(out,"float f(16*float):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
  181.   fflush(out);
  182.   return r;
  183. }
  184.  
  185. /* double tests */
  186. double d_d _P((a), double a)
  187. {
  188.   double r=a+1.0;
  189.   fprintf(out,"double f(double):(%g)",a);
  190.   fflush(out);
  191.   return r;
  192. }
  193. double d_d2 _P((a,b), double a _ double b)
  194. {
  195.   double r=a+b;
  196.   fprintf(out,"double f(2*double):(%g,%g)",a,b);
  197.   fflush(out);
  198.   return r;
  199. }
  200. double d_d4 _P((a,b,c,d), double a _ double b _ double c _ double d)
  201. {
  202.   double r=a+b+c+d;
  203.   fprintf(out,"double f(4*double):(%g,%g,%g,%g)",a,b,c,d);
  204.   fflush(out);
  205.   return r;
  206. }
  207. double d_d8 _P((a,b,c,d,e,f,g,h),
  208.                double a _ double b _ double c _ double d _ double e _ double f
  209.                _ double g _ double h)
  210. {
  211.   double r=a+b+c+d+e+f+g+h;
  212.   fprintf(out,"double f(8*double):(%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h);
  213.   fflush(out);
  214.   return r;
  215. }
  216. double d_d16 _P((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p),
  217.                 double a _ double b _ double c _ double d _ double e _ double f
  218.                 _ double g _ double h _ double i _ double j _ double k _ double l
  219.                 _ double m _ double n _ double o _ double p)
  220. {
  221.   double r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
  222.   fprintf(out,"double f(16*double):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
  223.   fflush(out);
  224.   return r;
  225. }
  226.  
  227. /* pointer tests */
  228. void* vp_vpdpcpsp _P((a,b,c,d), void* a _ double* b _ char* c _ Int* d)
  229. {
  230.   void* ret = (char*)b + 1;
  231.   fprintf(out,"void* f(void*,double*,char*,Int*):(0x%lx,0x%lx,0x%lx,0x%lx)",(long)a,(long)b,(long)c,(long)d);
  232.   fflush(out);
  233.   return ret;
  234. }
  235.  
  236. /* mixed number tests */
  237. uchar uc_ucsil _P((a,b,c,d), uchar a _ ushort b _ uint c _ ulong d)
  238. {
  239.   uchar r=-1;
  240.   fprintf(out,"uchar f(uchar,ushort,uint,ulong):(%u,%u,%u,%u)",a,b,c,d);
  241.   fflush(out);
  242.   return r;
  243. }
  244. double d_iidd _P((a,b,c,d), int a _ int b _ double c _ double d)
  245. {
  246.   double r=a+b+c+d;
  247.   fprintf(out,"double f(int,int,double,double):(%d,%d,%g,%g)",a,b,c,d);
  248.   fflush(out);
  249.   return r;
  250. }
  251. double d_idid _P((a,b,c,d), int a _ double b _ int c _ double d)
  252. {
  253.   double r=a+b+c+d;
  254.   fprintf(out,"double f(int,double,int,double):(%d,%g,%d,%g)",a,b,c,d);
  255.   fflush(out);
  256.   return r;
  257. }
  258. ushort us_cdcd _P((a,b,c,d), char a _ double b _ char c _ double d)
  259. {
  260.   ushort r = (ushort)(a + b + c + d);
  261.   fprintf(out,"ushort f(char,double,char,double):('%c',%g,'%c',%g)",a,b,c,d);
  262.   fflush(out);
  263.   return r;
  264. }
  265.  
  266. /* structure tests */
  267. Int I_III _P((a,b,c), Int a _ Int b _ Int c)
  268. {
  269.   Int r;
  270.   r.x = a.x + b.x + c.x;
  271.   fprintf(out,"Int f(Int,Int,Int):({%d},{%d},{%d})",a.x,b.x,c.x);
  272.   fflush(out);
  273.   return r;
  274. }
  275. Char C_CdC _P((a,b,c), Char a _ double b _ Char c)
  276. {
  277.   Char r;
  278.   r.x = (a.x + c.x)/2;
  279.   fprintf(out,"Char f(Char,double,Char):({'%c'},%g,{'%c'})",a.x,b,c.x);
  280.   fflush(out);
  281.   return r;
  282. }
  283. Double D_fDd _P((a,b,c), float a _ Double b _ double c)
  284. {
  285.   Double r;
  286.   r.x = a + b.x + c;
  287.   fprintf(out,"Double f(float,Double,double):(%g,{%g},%g)",a,b.x,c);
  288.   fflush(out);
  289.   return r;
  290. }
  291. J J_JiJ _P((a,b,c), J a _ int b _ J c)
  292. {
  293.   J r;
  294.   r.l1 = a.l1+c.l1; r.l2 = a.l2+b+c.l2;
  295.   fprintf(out,"J f(J,int,J):({%d,%d},%d,{%d,%d})",a.l1,a.l2,b,c.l1,c.l2);
  296.   fflush(out);
  297.   return r;
  298. }
  299. T T_TcT _P((a,b,c), T a _ char b _ T c)
  300. {
  301.   T r;
  302.   r.c[0]='b'; r.c[1]=c.c[1]; r.c[2]=c.c[2];
  303.   fprintf(out,"T f(T,char,T):({\"%c%c%c\"},'%c',{\"%c%c%c\"})",a.c[0],a.c[1],a.c[2],b,c.c[0],c.c[1],c.c[2]);
  304.   fflush(out);
  305.   return r;
  306. }
  307. X X_BcdB _P((a,b,c,d), B a _ char b _ double c _ B d)
  308. {
  309.   static X xr={"return val",'R'};
  310.   X r;
  311.   r = xr;
  312.   r.c1 = b;
  313.   fprintf(out,"X f(B,char,double,B):({%g,{%d,%d,%d}},'%c',%g,{%g,{%d,%d,%d}})",
  314.           a.d,a.i[0],a.i[1],a.i[2],b,c,d.d,d.i[0],d.i[1],d.i[2]);
  315.   fflush(out);
  316.   return r;
  317. }
  318.  
  319.  
  320. void* current_function;
  321.  
  322. /* This function simulates the behaviour of current_function. */
  323. void simulator (alist)
  324.   va_alist alist;
  325. {
  326.   /* void tests */
  327.   if (current_function == (void*)&v_v)
  328.     {
  329.       va_start_void(alist);
  330.       fprintf(out,"void f(void):\n");
  331.       fflush(out);
  332.       va_return_void(alist);
  333.     }
  334.  
  335.   /* int tests */
  336.   else if (current_function == (void*)&i_v)
  337.     {
  338.       va_start_int(alist);
  339.      {int r=99;
  340.       fprintf(out,"int f(void):");
  341.       fflush(out);
  342.       va_return_int(alist, r);
  343.     }}
  344.   else if (current_function == (void*)&i_i)
  345.     {
  346.       va_start_int(alist);
  347.      {int a = va_arg_int(alist);
  348.       int r=a+1;
  349.       fprintf(out,"int f(int):(%d)",a);
  350.       fflush(out);
  351.       va_return_int(alist, r);
  352.     }}
  353.   else if (current_function == (void*)&i_i2)
  354.     {
  355.       va_start_int(alist);
  356.      {int a = va_arg_int(alist);
  357.       int b = va_arg_int(alist);
  358.       int r=a+b;
  359.       fprintf(out,"int f(2*int):(%d,%d)",a,b);
  360.       fflush(out);
  361.       va_return_int(alist, r);
  362.     }}
  363.   else if (current_function == (void*)&i_i4)
  364.     {
  365.       va_start_int(alist);
  366.      {int a = va_arg_int(alist);
  367.       int b = va_arg_int(alist);
  368.       int c = va_arg_int(alist);
  369.       int d = va_arg_int(alist);
  370.       int r=a+b+c+d;
  371.       fprintf(out,"int f(4*int):(%d,%d,%d,%d)",a,b,c,d);
  372.       fflush(out);
  373.       va_return_int(alist, r);
  374.     }}
  375.   else if (current_function == (void*)&i_i8)
  376.     {
  377.       va_start_int(alist);
  378.      {int a = va_arg_int(alist);
  379.       int b = va_arg_int(alist);
  380.       int c = va_arg_int(alist);
  381.       int d = va_arg_int(alist);
  382.       int e = va_arg_int(alist);
  383.       int f = va_arg_int(alist);
  384.       int g = va_arg_int(alist);
  385.       int h = va_arg_int(alist);
  386.       int r=a+b+c+d+e+f+g+h;
  387.       fprintf(out,"int f(8*int):(%d,%d,%d,%d,%d,%d,%d,%d)",a,b,c,d,e,f,g,h);
  388.       fflush(out);
  389.       va_return_int(alist, r);
  390.     }}
  391.   else if (current_function == (void*)&i_i16)
  392.     {
  393.       va_start_int(alist);
  394.      {int a = va_arg_int(alist);
  395.       int b = va_arg_int(alist);
  396.       int c = va_arg_int(alist);
  397.       int d = va_arg_int(alist);
  398.       int e = va_arg_int(alist);
  399.       int f = va_arg_int(alist);
  400.       int g = va_arg_int(alist);
  401.       int h = va_arg_int(alist);
  402.       int i = va_arg_int(alist);
  403.       int j = va_arg_int(alist);
  404.       int k = va_arg_int(alist);
  405.       int l = va_arg_int(alist);
  406.       int m = va_arg_int(alist);
  407.       int n = va_arg_int(alist);
  408.       int o = va_arg_int(alist);
  409.       int p = va_arg_int(alist);
  410.       int r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
  411.       fprintf(out,"int f(16*int):(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",
  412.               a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
  413.       fflush(out);
  414.       va_return_int(alist, r);
  415.     }}
  416.  
  417.   /* float tests */
  418.   else if (current_function == (void*)&f_f)
  419.     {
  420.       va_start_float(alist);
  421.      {float a = va_arg_float(alist);
  422.       float r=a+1.0;
  423.       fprintf(out,"float f(float):(%g)",a);
  424.       fflush(out);
  425.       va_return_float(alist, r);
  426.     }}
  427.   else if (current_function == (void*)&f_f2)
  428.     {
  429.       va_start_float(alist);
  430.      {float a = va_arg_float(alist);
  431.       float b = va_arg_float(alist);
  432.       float r=a+b;
  433.       fprintf(out,"float f(2*float):(%g,%g)",a,b);
  434.       fflush(out);
  435.       va_return_float(alist, r);
  436.     }}
  437.   else if (current_function == (void*)&f_f4)
  438.     {
  439.       va_start_float(alist);
  440.      {float a = va_arg_float(alist);
  441.       float b = va_arg_float(alist);
  442.       float c = va_arg_float(alist);
  443.       float d = va_arg_float(alist);
  444.       float r=a+b+c+d;
  445.       fprintf(out,"float f(4*float):(%g,%g,%g,%g)",a,b,c,d);
  446.       fflush(out);
  447.       va_return_float(alist, r);
  448.     }}
  449.   else if (current_function == (void*)&f_f8)
  450.     {
  451.       va_start_float(alist);
  452.      {float a = va_arg_float(alist);
  453.       float b = va_arg_float(alist);
  454.       float c = va_arg_float(alist);
  455.       float d = va_arg_float(alist);
  456.       float e = va_arg_float(alist);
  457.       float f = va_arg_float(alist);
  458.       float g = va_arg_float(alist);
  459.       float h = va_arg_float(alist);
  460.       float r=a+b+c+d+e+f+g+h;
  461.       fprintf(out,"float f(8*float):(%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h);
  462.       fflush(out);
  463.       va_return_float(alist, r);
  464.     }}
  465.   else if (current_function == (void*)&f_f16)
  466.     {
  467.       va_start_float(alist);
  468.      {float a = va_arg_float(alist);
  469.       float b = va_arg_float(alist);
  470.       float c = va_arg_float(alist);
  471.       float d = va_arg_float(alist);
  472.       float e = va_arg_float(alist);
  473.       float f = va_arg_float(alist);
  474.       float g = va_arg_float(alist);
  475.       float h = va_arg_float(alist);
  476.       float i = va_arg_float(alist);
  477.       float j = va_arg_float(alist);
  478.       float k = va_arg_float(alist);
  479.       float l = va_arg_float(alist);
  480.       float m = va_arg_float(alist);
  481.       float n = va_arg_float(alist);
  482.       float o = va_arg_float(alist);
  483.       float p = va_arg_float(alist);
  484.       float r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
  485.       fprintf(out,"float f(16*float):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
  486.       fflush(out);
  487.       va_return_float(alist, r);
  488.     }}
  489.  
  490.   /* double tests */
  491.   else if (current_function == (void*)&d_d)
  492.     {
  493.       va_start_double(alist);
  494.      {double a = va_arg_double(alist);
  495.       double r=a+1.0;
  496.       fprintf(out,"double f(double):(%g)",a);
  497.       fflush(out);
  498.       va_return_double(alist, r);
  499.     }}
  500.   else if (current_function == (void*)&d_d2)
  501.     {
  502.       va_start_double(alist);
  503.      {double a = va_arg_double(alist);
  504.       double b = va_arg_double(alist);
  505.       double r=a+b;
  506.       fprintf(out,"double f(2*double):(%g,%g)",a,b);
  507.       fflush(out);
  508.       va_return_double(alist, r);
  509.     }}
  510.   else if (current_function == (void*)&d_d4)
  511.     {
  512.       va_start_double(alist);
  513.      {double a = va_arg_double(alist);
  514.       double b = va_arg_double(alist);
  515.       double c = va_arg_double(alist);
  516.       double d = va_arg_double(alist);
  517.       double r=a+b+c+d;
  518.       fprintf(out,"double f(4*double):(%g,%g,%g,%g)",a,b,c,d);
  519.       fflush(out);
  520.       va_return_double(alist, r);
  521.     }}
  522.   else if (current_function == (void*)&d_d8)
  523.     {
  524.       va_start_double(alist);
  525.      {double a = va_arg_double(alist);
  526.       double b = va_arg_double(alist);
  527.       double c = va_arg_double(alist);
  528.       double d = va_arg_double(alist);
  529.       double e = va_arg_double(alist);
  530.       double f = va_arg_double(alist);
  531.       double g = va_arg_double(alist);
  532.       double h = va_arg_double(alist);
  533.       double r=a+b+c+d+e+f+g+h;
  534.       fprintf(out,"double f(8*double):(%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h);
  535.       fflush(out);
  536.       va_return_double(alist, r);
  537.     }}
  538.   else if (current_function == (void*)&d_d16)
  539.     {
  540.       va_start_double(alist);
  541.      {double a = va_arg_double(alist);
  542.       double b = va_arg_double(alist);
  543.       double c = va_arg_double(alist);
  544.       double d = va_arg_double(alist);
  545.       double e = va_arg_double(alist);
  546.       double f = va_arg_double(alist);
  547.       double g = va_arg_double(alist);
  548.       double h = va_arg_double(alist);
  549.       double i = va_arg_double(alist);
  550.       double j = va_arg_double(alist);
  551.       double k = va_arg_double(alist);
  552.       double l = va_arg_double(alist);
  553.       double m = va_arg_double(alist);
  554.       double n = va_arg_double(alist);
  555.       double o = va_arg_double(alist);
  556.       double p = va_arg_double(alist);
  557.       double r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
  558.       fprintf(out,"double f(16*double):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
  559.       fflush(out);
  560.       va_return_double(alist, r);
  561.     }}
  562.  
  563.   /* pointer tests */
  564.   else if (current_function == (void*)&vp_vpdpcpsp)
  565.     {
  566.       va_start_ptr(alist, void*);
  567.      {void* a = va_arg_ptr(alist, void*);
  568.       double* b = va_arg_ptr(alist, double*);
  569.       char* c = va_arg_ptr(alist, char*);
  570.       Int* d = va_arg_ptr(alist, Int*);
  571.       void* ret = (char*)b + 1;
  572.       fprintf(out,"void* f(void*,double*,char*,Int*):(0x%lx,0x%lx,0x%lx,0x%lx)",(long)a,(long)b,(long)c,(long)d);
  573.       fflush(out);
  574.       va_return_ptr(alist, void*, ret);
  575.     }}
  576.  
  577.   /* mixed number tests */
  578.   else if (current_function == (void*)&uc_ucsil)
  579.     {
  580.       va_start_uchar(alist);
  581.      {uchar a = va_arg_uchar(alist);
  582.       ushort b = va_arg_ushort(alist);
  583.       uint c = va_arg_uint(alist);
  584.       ulong d = va_arg_ulong(alist);
  585.       uchar r=-1;
  586.       fprintf(out,"uchar f(uchar,ushort,uint,ulong):(%u,%u,%u,%u)",a,b,c,d);
  587.       fflush(out);
  588.       va_return_uchar(alist, r);
  589.     }}
  590.   else if (current_function == (void*)&d_iidd)
  591.     {
  592.       va_start_double(alist);
  593.      {int a = va_arg_int(alist);
  594.       int b = va_arg_int(alist);
  595.       double c = va_arg_double(alist);
  596.       double d = va_arg_double(alist);
  597.       double r=a+b+c+d;
  598.       fprintf(out,"double f(int,int,double,double):(%d,%d,%g,%g)",a,b,c,d);
  599.       fflush(out);
  600.       va_return_double(alist, r);
  601.     }}
  602.   else if (current_function == (void*)&d_idid)
  603.     {
  604.       va_start_double(alist);
  605.      {int a = va_arg_int(alist);
  606.       double b = va_arg_double(alist);
  607.       int c = va_arg_int(alist);
  608.       double d = va_arg_double(alist);
  609.       double r=a+b+c+d;
  610.       fprintf(out,"double f(int,double,int,double):(%d,%g,%d,%g)",a,b,c,d);
  611.       fflush(out);
  612.       va_return_double(alist, r);
  613.     }}
  614.   else if (current_function == (void*)&us_cdcd)
  615.     {
  616.       va_start_ushort(alist);
  617.      {char a = va_arg_char(alist);
  618.       double b = va_arg_double(alist);
  619.       char c = va_arg_char(alist);
  620.       double d = va_arg_double(alist);
  621.       ushort r = (ushort)(a + b + c + d);
  622.       fprintf(out,"ushort f(char,double,char,double):('%c',%g,'%c',%g)",a,b,c,d);
  623.       fflush(out);
  624.       va_return_ushort(alist, r);
  625.     }}
  626.  
  627.   /* structure tests */
  628.   else if (current_function == (void*)&I_III)
  629.     {
  630.       Int a;
  631.       Int b;
  632.       Int c;
  633.       Int r;
  634.       va_start_struct(alist, Int, 1);
  635.       a = va_arg_struct(alist, Int);
  636.       b = va_arg_struct(alist, Int);
  637.       c = va_arg_struct(alist, Int);
  638.       r.x = a.x + b.x + c.x;
  639.       fprintf(out,"Int f(Int,Int,Int):({%d},{%d},{%d})",a.x,b.x,c.x);
  640.       fflush(out);
  641.       va_return_struct(alist, Int, r);
  642.     }
  643.   else if (current_function == (void*)&C_CdC)
  644.     {
  645.       Char a;
  646.       double b;
  647.       Char c;
  648.       Char r;
  649.       va_start_struct(alist, Char, 1);
  650.       a = va_arg_struct(alist, Char);
  651.       b = va_arg_double(alist);
  652.       c = va_arg_struct(alist, Char);
  653.       r.x = (a.x + c.x)/2;
  654.       fprintf(out,"Char f(Char,double,Char):({'%c'},%g,{'%c'})",a.x,b,c.x);
  655.       fflush(out);
  656.       va_return_struct(alist, Char, r);
  657.     }
  658.   else if (current_function == (void*)&D_fDd)
  659.     {
  660.       float a;
  661.       Double b;
  662.       double c;
  663.       Double r;
  664.       va_start_struct(alist, Double, va_word_splittable_1(double));
  665.       a = va_arg_float(alist);
  666.       b = va_arg_struct(alist, Double);
  667.       c = va_arg_double(alist);
  668.       r.x = a + b.x + c;
  669.       fprintf(out,"Double f(float,Double,double):(%g,{%g},%g)",a,b.x,c);
  670.       fflush(out);
  671.       va_return_struct(alist, Double, r);
  672.     }
  673.   else if (current_function == (void*)&J_JiJ)
  674.     {
  675.       J a;
  676.       int b;
  677.       J c;
  678.       J r;
  679.       va_start_struct(alist, J, va_word_splittable_2(long,long));
  680.       a = va_arg_struct(alist, J);
  681.       b = va_arg_int(alist);
  682.       c = va_arg_struct(alist, J);
  683.       r.l1 = a.l1+c.l1; r.l2 = a.l2+b+c.l2;
  684.       fprintf(out,"J f(J,int,J):({%d,%d},%d,{%d,%d})",a.l1,a.l2,b,c.l1,c.l2);
  685.       fflush(out);
  686.       va_return_struct(alist, J, r);
  687.     }
  688.   else if (current_function == (void*)&T_TcT)
  689.     {
  690.       T a;
  691.       char b;
  692.       T c;
  693.       T r;
  694.       va_start_struct(alist, T, 1);
  695.       a = va_arg_struct(alist, T);
  696.       b = va_arg_char(alist);
  697.       c = va_arg_struct(alist, T);
  698.       r.c[0]='b'; r.c[1]=c.c[1]; r.c[2]=c.c[2];
  699.       fprintf(out,"T f(T,char,T):({\"%c%c%c\"},'%c',{\"%c%c%c\"})",a.c[0],a.c[1],a.c[2],b,c.c[0],c.c[1],c.c[2]);
  700.       fflush(out);
  701.       va_return_struct(alist, T, r);
  702.     }
  703.   else if (current_function == (void*)&X_BcdB)
  704.     {
  705.       B a;
  706.       char b;
  707.       double c;
  708.       B d;
  709.       static X xr={"return val",'R'};
  710.       X r;
  711.       va_start_struct(alist, X, 0);
  712.       a = va_arg_struct(alist, B);
  713.       b = va_arg_char(alist);
  714.       c = va_arg_double(alist);
  715.       d = va_arg_struct(alist, B);
  716.       r = xr;
  717.       r.c1 = b;
  718.       fprintf(out,"X f(B,char,double,B):({%g,{%d,%d,%d}},'%c',%g,{%g,{%d,%d,%d}})",
  719.               a.d,a.i[0],a.i[1],a.i[2],b,c,d.d,d.i[0],d.i[1],d.i[2]);
  720.       fflush(out);
  721.       va_return_struct(alist, X, r);
  722.     }
  723.  
  724.   else
  725.     {
  726.       fprintf(out,"simulate: unknown function\n");
  727.       fflush(out);
  728.     }
  729. }
  730.  
  731. /*
  732.  * The way we run these tests - first call the function directly, then
  733.  * through vacall() - there is the danger that arguments or results seem
  734.  * to be passed correctly, but what we are seeing are in fact the vestiges
  735.  * (traces) or the previous call. This may seriously fake the test.
  736.  * Avoid this by clearing the registers between the first and the second call.
  737.  */
  738. long clear_traces_i _P((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p),
  739.   long a _ long b _ long c _ long d _ long e _ long f _ long g _ long h _
  740.   long i _ long j _ long k _ long l _ long m _ long n _ long o _ long p)
  741. { return 0; }
  742. float clear_traces_f _P((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p),
  743.   float a _ float b _ float c _ float d _ float e _ float f _ float g _
  744.   float h _ float i _ float j _ float k _ float l _ float m _ float n _
  745.   float o _ float p)
  746. { return 0.0; }
  747. double clear_traces_d _P((a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p),
  748.   double a _ double b _ double c _ double d _ double e _ double f _ double g _
  749.   double h _ double i _ double j _ double k _ double l _ double m _ double n _
  750.   double o _ double p)
  751. { return 0.0; }
  752. J clear_traces_J ()
  753. { J j; j.l1 = j.l2 = 0; return j; }
  754. void clear_traces()
  755. { clear_traces_i(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  756.   clear_traces_f(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
  757.   clear_traces_d(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
  758.   clear_traces_J();
  759. }
  760.  
  761. int main ()
  762. {
  763.   out = stdout;
  764.  
  765.   vacall_function = &simulator;
  766.  
  767.   /* void tests */
  768.   v_v();
  769.   clear_traces();
  770.   current_function = &v_v; (FTYPE(void,(void)) vacall) ();
  771.  
  772.   /* int tests */
  773.   { int ir;
  774.  
  775.     ir = i_v();
  776.     fprintf(out,"->%d\n",ir);
  777.     fflush(out);
  778.     ir = 0; clear_traces();
  779.     current_function = &i_v; ir = (FTYPE(int,(void)) vacall) ();
  780.     fprintf(out,"->%d\n",ir);
  781.     fflush(out);
  782.  
  783.     ir = i_i(i1);
  784.     fprintf(out,"->%d\n",ir);
  785.     fflush(out);
  786.     ir = 0; clear_traces();
  787.     current_function = &i_i; ir = (FTYPE(int,(int)) vacall) (i1);
  788.     fprintf(out,"->%d\n",ir);
  789.     fflush(out);
  790.  
  791.     ir = i_i2(i1,i2);
  792.     fprintf(out,"->%d\n",ir);
  793.     fflush(out);
  794.     ir = 0; clear_traces();
  795.     current_function = &i_i2; ir = (FTYPE(int,(int,int)) vacall) (i1,i2);
  796.     fprintf(out,"->%d\n",ir);
  797.     fflush(out);
  798.  
  799.     ir = i_i4(i1,i2,i3,i4);
  800.     fprintf(out,"->%d\n",ir);
  801.     fflush(out);
  802.     ir = 0; clear_traces();
  803.     current_function = &i_i4; ir = (FTYPE(int,(int,int,int,int)) vacall) (i1,i2,i3,i4);
  804.     fprintf(out,"->%d\n",ir);
  805.     fflush(out);
  806.  
  807.     ir = i_i8(i1,i2,i3,i4,i5,i6,i7,i8);
  808.     fprintf(out,"->%d\n",ir);
  809.     fflush(out);
  810.     ir = 0; clear_traces();
  811.     current_function = &i_i8; ir = (FTYPE(int,(int,int,int,int,int,int,int,int)) vacall) (i1,i2,i3,i4,i5,i6,i7,i8);
  812.     fprintf(out,"->%d\n",ir);
  813.     fflush(out);
  814.  
  815.     ir = i_i16(i1,i2,i3,i4,i5,i6,i7,i8,i1,i2,i3,i4,i5,i6,i7,i8);
  816.     fprintf(out,"->%d\n",ir);
  817.     fflush(out);
  818.     ir = 0; clear_traces();
  819.     current_function = &i_i16; ir = (FTYPE(int,(int,int,int,int,int,int,int,int,int,int,int,int,int,int,int,int)) vacall) (i1,i2,i3,i4,i5,i6,i7,i8,i1,i2,i3,i4,i5,i6,i7,i8);
  820.     fprintf(out,"->%d\n",ir);
  821.     fflush(out);
  822.   }
  823.  
  824.   /* float tests */
  825.   { float fr;
  826.  
  827.     fr = f_f(f1);
  828.     fprintf(out,"->%g\n",fr);
  829.     fflush(out);
  830.     fr = 0.0; clear_traces();
  831.     current_function = &f_f; fr = (FTYPE(float,(float)) vacall) (f1);
  832.     fprintf(out,"->%g\n",fr);
  833.     fflush(out);
  834.  
  835.     fr = f_f2(f1,f2);
  836.     fprintf(out,"->%g\n",fr);
  837.     fflush(out);
  838.     fr = 0.0; clear_traces();
  839.     current_function = &f_f2; fr = (FTYPE(float,(float,float)) vacall) (f1,f2);
  840.     fprintf(out,"->%g\n",fr);
  841.     fflush(out);
  842.  
  843.     fr = f_f4(f1,f2,f3,f4);
  844.     fprintf(out,"->%g\n",fr);
  845.     fflush(out);
  846.     fr = 0.0; clear_traces();
  847.     current_function = &f_f4; fr = (FTYPE(float,(float,float,float,float)) vacall) (f1,f2,f3,f4);
  848.     fprintf(out,"->%g\n",fr);
  849.     fflush(out);
  850.  
  851.     fr = f_f8(f1,f2,f3,f4,f5,f6,f7,f8);
  852.     fprintf(out,"->%g\n",fr);
  853.     fflush(out);
  854.     fr = 0.0; clear_traces();
  855.     current_function = &f_f8; fr = (FTYPE(float,(float,float,float,float,float,float,float,float)) vacall) (f1,f2,f3,f4,f5,f6,f7,f8);
  856.     fprintf(out,"->%g\n",fr);
  857.     fflush(out);
  858.  
  859.     fr = f_f16(f1,f2,f3,f4,f5,f6,f7,f8,f1,f2,f3,f4,f5,f6,f7,f8);
  860.     fprintf(out,"->%g\n",fr);
  861.     fflush(out);
  862.     fr = 0.0; clear_traces();
  863.     current_function = &f_f16; fr = (FTYPE(float,(float,float,float,float,float,float,float,float,float,float,float,float,float,float,float,float)) vacall) (f1,f2,f3,f4,f5,f6,f7,f8,f1,f2,f3,f4,f5,f6,f7,f8);
  864.     fprintf(out,"->%g\n",fr);
  865.     fflush(out);
  866.   }
  867.  
  868.   /* double tests */
  869.   { double dr;
  870.  
  871.     dr = d_d(d1);
  872.     fprintf(out,"->%g\n",dr);
  873.     fflush(out);
  874.     dr = 0.0; clear_traces();
  875.     current_function = &d_d; dr = (FTYPE(double,(double)) vacall) (d1);
  876.     fprintf(out,"->%g\n",dr);
  877.     fflush(out);
  878.  
  879.     dr = d_d2(d1,d2);
  880.     fprintf(out,"->%g\n",dr);
  881.     fflush(out);
  882.     dr = 0.0; clear_traces();
  883.     current_function = &d_d2; dr = (FTYPE(double,(double,double)) vacall) (d1,d2);
  884.     fprintf(out,"->%g\n",dr);
  885.     fflush(out);
  886.  
  887.     dr = d_d4(d1,d2,d3,d4);
  888.     fprintf(out,"->%g\n",dr);
  889.     fflush(out);
  890.     dr = 0.0; clear_traces();
  891.     current_function = &d_d4; dr = (FTYPE(double,(double,double,double,double)) vacall) (d1,d2,d3,d4);
  892.     fprintf(out,"->%g\n",dr);
  893.     fflush(out);
  894.  
  895.     dr = d_d8(d1,d2,d3,d4,d5,d6,d7,d8);
  896.     fprintf(out,"->%g\n",dr);
  897.     fflush(out);
  898.     dr = 0.0; clear_traces();
  899.     current_function = &d_d8; dr = (FTYPE(double,(double,double,double,double,double,double,double,double)) vacall) (d1,d2,d3,d4,d5,d6,d7,d8);
  900.     fprintf(out,"->%g\n",dr);
  901.     fflush(out);
  902.  
  903.     dr = d_d16(d1,d2,d3,d4,d5,d6,d7,d8,d1,d2,d3,d4,d5,d6,d7,d8);
  904.     fprintf(out,"->%g\n",dr);
  905.     fflush(out);
  906.     dr = 0.0; clear_traces();
  907.     current_function = &d_d16; dr = (FTYPE(double,(double,double,double,double,double,double,double,double,double,double,double,double,double,double,double,double)) vacall) (d1,d2,d3,d4,d5,d6,d7,d8,d1,d2,d3,d4,d5,d6,d7,d8);
  908.     fprintf(out,"->%g\n",dr);
  909.     fflush(out);
  910.   }
  911.  
  912.   /* pointer tests */
  913.   { void* vpr;
  914.  
  915.     vpr = vp_vpdpcpsp(&uc1,&d2,str3,&I4);
  916.     fprintf(out,"->0x%lx\n",(long)vpr);
  917.     fflush(out);
  918.     vpr = 0; clear_traces();
  919.     current_function = &vp_vpdpcpsp; vpr = (FTYPE(void*,(void*,double*,char*,Int*)) vacall) (&uc1,&d2,str3,&I4);
  920.     fprintf(out,"->0x%lx\n",(long)vpr);
  921.     fflush(out);
  922.   }
  923.  
  924.   /* mixed number tests */
  925.   { uchar ucr;
  926.     ushort usr;
  927.     double dr;
  928.  
  929.     ucr = uc_ucsil(uc1,us2,ui3,ul4);
  930.     fprintf(out,"->%u\n",ucr);
  931.     fflush(out);
  932.     ucr = 0; clear_traces();
  933.     current_function = &uc_ucsil; ucr = (FTYPE(uchar,(uchar,ushort,uint,ulong)) vacall) (uc1,us2,ui3,ul4);
  934.     fprintf(out,"->%u\n",ucr);
  935.     fflush(out);
  936.  
  937.     dr = d_iidd(i1,i2,d3,d4);
  938.     fprintf(out,"->%g\n",dr);
  939.     fflush(out);
  940.     dr = 0.0; clear_traces();
  941.     current_function = &d_iidd; dr = (FTYPE(double,(int,int,double,double)) vacall) (i1,i2,d3,d4);
  942.     fprintf(out,"->%g\n",dr);
  943.     fflush(out);
  944.  
  945.     dr = d_idid(i1,d2,i3,d4);
  946.     fprintf(out,"->%g\n",dr);
  947.     fflush(out);
  948.     dr = 0.0; clear_traces();
  949.     current_function = &d_idid; dr = (FTYPE(double,(int,double,int,double)) vacall) (i1,d2,i3,d4);
  950.     fprintf(out,"->%g\n",dr);
  951.     fflush(out);
  952.  
  953.     usr = us_cdcd(c1,d2,c3,d4);
  954.     fprintf(out,"->%u\n",usr);
  955.     fflush(out);
  956.     usr = 0; clear_traces();
  957.     current_function = &us_cdcd; usr = (FTYPE(ushort,(char,double,char,double)) vacall) (c1,d2,c3,d4);
  958.     fprintf(out,"->%u\n",usr);
  959.     fflush(out);
  960.   }
  961.  
  962.   /* structure tests */
  963.   { Int Ir;
  964.     Char Cr;
  965.     Double Dr;
  966.     J Jr;
  967.     T Tr;
  968.     X Xr;
  969.  
  970.     Ir = I_III(I1,I2,I3);
  971.     fprintf(out,"->{%d}\n",Ir.x);
  972.     fflush(out);
  973.     Ir.x = 0; clear_traces();
  974.     current_function = &I_III; Ir = (FTYPE(Int,(Int,Int,Int)) vacall) (I1,I2,I3);
  975.     fprintf(out,"->{%d}\n",Ir.x);
  976.     fflush(out);
  977.  
  978.     Cr = C_CdC(C1,d2,C3);
  979.     fprintf(out,"->{'%c'}\n",Cr.x);
  980.     fflush(out);
  981.     Cr.x = '\0'; clear_traces();
  982.     current_function = &C_CdC; Cr = (FTYPE(Char,(Char,double,Char)) vacall) (C1,d2,C3);
  983.     fprintf(out,"->{'%c'}\n",Cr.x);
  984.     fflush(out);
  985.  
  986.     Dr = D_fDd(f1,D2,d3);
  987.     fprintf(out,"->{%g}\n",Dr.x);
  988.     fflush(out);
  989.     Dr.x = 0.0; clear_traces();
  990.     current_function = &D_fDd; Dr = (FTYPE(Double,(float,Double,double)) vacall) (f1,D2,d3);
  991.     fprintf(out,"->{%g}\n",Dr.x);
  992.     fflush(out);
  993.  
  994.     Jr = J_JiJ(J1,i2,J2);
  995.     fprintf(out,"->{%d,%d}\n",Jr.l1,Jr.l2);
  996.     fflush(out);
  997.     Jr.l1 = Jr.l2 = 0; clear_traces();
  998.     current_function = &J_JiJ; Jr = (FTYPE(J,(J,int,J)) vacall) (J1,i2,J2);
  999.     fprintf(out,"->{%d,%d}\n",Jr.l1,Jr.l2);
  1000.     fflush(out);
  1001.  
  1002. #ifndef SKIP_T
  1003.     Tr = T_TcT(T1,' ',T2);
  1004.     fprintf(out,"->{\"%c%c%c\"}\n",Tr.c[0],Tr.c[1],Tr.c[2]);
  1005.     fflush(out);
  1006.     Tr.c[0] = Tr.c[1] = Tr.c[2] = 0; clear_traces();
  1007.     current_function = &T_TcT; Tr = (FTYPE(T,(T,char,T)) vacall) (T1,' ',T2);
  1008.     fprintf(out,"->{\"%c%c%c\"}\n",Tr.c[0],Tr.c[1],Tr.c[2]);
  1009.     fflush(out);
  1010. #endif
  1011.  
  1012.     Xr = X_BcdB(B1,c2,d3,B2);
  1013.     fprintf(out,"->{\"%s\",'%c'}\n",Xr.c,Xr.c1);
  1014.     fflush(out);
  1015.     Xr.c[0]=Xr.c1='\0'; clear_traces();
  1016.     current_function = &X_BcdB; Xr = (FTYPE(X,(B,char,double,B)) vacall) (B1,c2,d3,B2);
  1017.     fprintf(out,"->{\"%s\",'%c'}\n",Xr.c,Xr.c1);
  1018.     fflush(out);
  1019.   }
  1020.  
  1021.   exit(0);
  1022. }
  1023.