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

Diff of /MLRISC/trunk/amd64/staged-allocation/test-varargs.c

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

revision 3054, Tue Jun 3 01:26:28 2008 UTC revision 3055, Tue Jun 3 06:55:14 2008 UTC
# Line 4  Line 4 
4    
5  #define NEW(ty)   (ty*)malloc(sizeof(ty))  #define NEW(ty)   (ty*)malloc(sizeof(ty))
6    
7  extern void varargs (void* fun, void* args);  extern void varargs (void* fun, void* args, int);
8    
9  typedef struct {  typedef struct {
10    void* val;    void* val;
11    void* kind;    void* kind;
12    void* loc;    void* loc;
13  }  triplet_t;    void* ty;
14    }  zipped_arg_t;
15    
16  typedef struct varargs_s {  typedef struct varargs_s {
17    triplet_t* hd;    zipped_arg_t* hd;
18    struct varargs_s* tl;    struct varargs_s* tl;
19  } varargs_t;  } varargs_t;
20    
# Line 31  Line 32 
32    
33  }  }
34    
35    #define N_ARGS 3
36    #define GPR 0
37    #define FPR 1
38    #define STK 2
39    #define FSTK 3
40    
41  int main ()  int main ()
42  {  {
43    varargs_t* args = NEW(varargs_t);    varargs_t* args[N_ARGS];
44    varargs_t* args2 = NEW(varargs_t);  
45    varargs_t* args3 = NEW(varargs_t);    for(int i = 0 ; i < N_ARGS; i++)
46        args[i] = NEW(varargs_t);
47    args->hd = NEW(triplet_t);  
48    args->hd->val = (void*)"arg1=%d arg2=%f\n";    args[N_ARGS-1]->tl = 0;
49    args->hd->kind = (void*)0;  /* gpr */    for (int i = N_ARGS-2; i >= 0; i--)
50    args->hd->loc = (void*)7;   /* rdi */      args[i]->tl = args[i+1];
51    args->tl = args2;  
52      args[0]->hd = NEW(zipped_arg_t);
53    args2->hd = NEW(triplet_t);    args[0]->hd->val = (void*)"%f %X\n";
54    args2->hd->val = (void*)1024;    args[0]->hd->kind = (void*)GPR;
55    args2->hd->kind = (void*)0;  /* gpr */    args[0]->hd->loc = (void*)7;
56    args2->hd->loc = (void*)6;   /* rdi */    args[0]->hd->ty = (void*)64;
   args2->tl = args3;  
57    
58    double f = 3.14;    double f = 3.14;
59    void** x = (void*)&f;    void** x = (void*)&f;
60    
61    args3->hd = NEW(triplet_t);    args[1]->hd = NEW(zipped_arg_t);
62    args3->hd->val = *x;    args[1]->hd->val = *x;
63    args3->hd->kind = (void*)1;  /* fpr */    args[1]->hd->kind = (void*)FPR;
64    args3->hd->loc = (void*)0;   /* xmm0 */    args[1]->hd->loc = (void*)0;
65    args3->tl = 0;    args[1]->hd->ty = (void*)64;
66    
67      args[2]->hd = NEW(zipped_arg_t);
68      args[2]->hd->val = (void*)0xdeadbeef;
69      args[2]->hd->kind = (void*)GPR;
70      args[2]->hd->loc = (void*)6;
71      args[2]->hd->ty = (void*)32;
72    
73    varargs(Say, args);    varargs(Say, args[0], N_ARGS*sizeof(void*));
74    
75    return 0;    return 0;
76  }  }

Legend:
Removed from v.3054  
changed lines
  Added in v.3055

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