Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /MLRISC/trunk/vararg-ccall/test/ia32-test-varargs.c
ViewVC logotype

Annotation of /MLRISC/trunk/vararg-ccall/test/ia32-test-varargs.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3069 - (view) (download) (as text)

1 : mrainey 3054 #include <stdio.h>
2 :     #include <stdlib.h>
3 :     #include <stdarg.h>
4 :    
5 :     #define NEW(ty) (ty*)malloc(sizeof(ty))
6 :    
7 :     typedef struct {
8 : mrainey 3068 union val_u {
9 :     int i;
10 :     double d;
11 :     char* s;
12 :     } val;
13 : mrainey 3062 long long kind;
14 :     long long loc;
15 :     long long ty;
16 : mrainey 3055 } zipped_arg_t;
17 : mrainey 3054
18 : mrainey 3068 extern void varargs (void* fun, zipped_arg_t* args, zipped_arg_t* argsEnd);
19 : mrainey 3054
20 :     void Say (const char *fmt, ...)
21 :     __attribute__ ((format(printf, 1, 2)));
22 :    
23 :     void Say (const char *fmt, ...)
24 :     {
25 :     va_list ap;
26 :    
27 :     va_start (ap, fmt);
28 :     vfprintf (stdout, fmt, ap);
29 :     fflush (stdout);
30 :     va_end(ap);
31 :    
32 :     }
33 :    
34 : mrainey 3068 #define N_ARGS 3
35 : mrainey 3054 #define STK 2
36 :     #define FSTK 3
37 : mrainey 3062 #define OFF(i) (i*4)
38 : mrainey 3054
39 :     int main ()
40 :     {
41 : mrainey 3064 zipped_arg_t args[N_ARGS];
42 : mrainey 3054
43 : mrainey 3068 args[0].val.s = "arg1=%d, arg2=%f\n";
44 :     args[0].kind = (long long)STK;
45 :     args[0].loc = (long long)OFF(0);
46 :     args[0].ty = (long long)32;
47 : mrainey 3054
48 : mrainey 3068 args[1].val.i = 69;
49 :     args[1].kind = (long long)STK;
50 :     args[1].loc = (long long)OFF(1);
51 :     args[1].ty = (long long)32;
52 : mrainey 3054
53 : mrainey 3068 args[2].val.d = 3.44;
54 :     args[2].kind = (long long)FSTK;
55 :     args[2].loc = (long long)OFF(2);
56 :     args[2].ty = (long long)64;
57 : mrainey 3054
58 : mrainey 3068 varargs(Say, args, &args[N_ARGS]);
59 : mrainey 3054
60 :     return 0;
61 :     }

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0