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/x86/staged-allocation/test-varargs.c
ViewVC logotype

Annotation of /MLRISC/trunk/x86/staged-allocation/test-varargs.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3064 - (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 3062 long long val;
9 :     long long kind;
10 :     long long loc;
11 :     long long ty;
12 : mrainey 3055 } zipped_arg_t;
13 : mrainey 3054
14 : mrainey 3064 extern void varargs (void* fun, zipped_arg_t* args, int);
15 : mrainey 3054
16 :     void Say (const char *fmt, ...)
17 :     __attribute__ ((format(printf, 1, 2)));
18 :    
19 :     void Say (const char *fmt, ...)
20 :     {
21 :     va_list ap;
22 :    
23 :     va_start (ap, fmt);
24 :     vfprintf (stdout, fmt, ap);
25 :     fflush (stdout);
26 :     va_end(ap);
27 :    
28 :     }
29 :    
30 : mrainey 3064 #define N_ARGS 2
31 : mrainey 3054 #define STK 2
32 :     #define FSTK 3
33 : mrainey 3062 #define OFF(i) (i*4)
34 : mrainey 3054
35 :     int main ()
36 :     {
37 : mrainey 3064 zipped_arg_t args[N_ARGS];
38 : mrainey 3054
39 :     for(int i = 0 ; i < N_ARGS; i++)
40 :     args[i] = NEW(varargs_t);
41 :    
42 :     args[N_ARGS-1]->tl = 0;
43 :     for (int i = N_ARGS-2; i >= 0; i--)
44 :     args[i]->tl = args[i+1];
45 :    
46 : mrainey 3064 args[0].hd->val = (long long)"arg1=%d\n";
47 :     args[0].hd->kind = (long long)STK;
48 :     args[0].hd->loc = (long long)OFF(0);
49 :     args[0].hd->ty = (long long)32;
50 : mrainey 3054
51 : mrainey 3064 args[1].hd->val = (long long)69;
52 :     args[1].hd->kind = (long long)STK;
53 :     args[1].hd->loc = (long long)OFF(1);
54 :     args[1].hd->ty = (long long)32;
55 : mrainey 3054
56 : mrainey 3064 varargs(Say, args, N_ARGS);
57 :    
58 : mrainey 3054 return 0;
59 :     }

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