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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3064, Thu Jun 5 07:20:32 2008 UTC revision 3068, Fri Jun 6 00:25:53 2008 UTC
# Line 5  Line 5 
5  #define NEW(ty)   (ty*)malloc(sizeof(ty))  #define NEW(ty)   (ty*)malloc(sizeof(ty))
6    
7  typedef struct {  typedef struct {
8    long long val;    union val_u {
9        int i;
10        double d;
11        char* s;
12      } val;
13    long long kind;    long long kind;
14    long long loc;    long long loc;
15    long long ty;    long long ty;
16  }  zipped_arg_t;  }  zipped_arg_t;
17    
18  extern void varargs (void* fun, zipped_arg_t* args, int);  extern void varargs (void* fun, zipped_arg_t* args, zipped_arg_t* argsEnd);
19    
20  void Say (const char *fmt, ...)  void Say (const char *fmt, ...)
21          __attribute__ ((format(printf, 1, 2)));          __attribute__ ((format(printf, 1, 2)));
# Line 27  Line 31 
31    
32  }  }
33    
34  #define N_ARGS 2  #define N_ARGS 3
35  #define STK 2  #define STK 2
36  #define FSTK 3  #define FSTK 3
37  #define OFF(i) (i*4)  #define OFF(i) (i*4)
# Line 36  Line 40 
40  {  {
41    zipped_arg_t args[N_ARGS];    zipped_arg_t args[N_ARGS];
42    
43    for(int i = 0 ; i < N_ARGS; i++)    args[0].val.s = "arg1=%d, arg2=%f\n";
44      args[i] = NEW(varargs_t);    args[0].kind = (long long)STK;
45      args[0].loc = (long long)OFF(0);
46      args[0].ty = (long long)32;
47    
48      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    
53      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    
58    args[N_ARGS-1]->tl = 0;    varargs(Say, args, &args[N_ARGS]);
   for (int i = N_ARGS-2; i >= 0; i--)  
     args[i]->tl = args[i+1];  
   
   args[0].hd->val = (long long)"arg1=%d\n";  
   args[0].hd->kind = (long long)STK;  
   args[0].hd->loc = (long long)OFF(0);  
   args[0].hd->ty = (long long)32;  
   
   args[1].hd->val = (long long)69;  
   args[1].hd->kind = (long long)STK;  
   args[1].hd->loc = (long long)OFF(1);  
   args[1].hd->ty = (long long)32;  
   
   varargs(Say, args, N_ARGS);  
59    
60    return 0;    return 0;
61  }  }

Legend:
Removed from v.3064  
changed lines
  Added in v.3068

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