OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-6.8/] [gdb/] [testsuite/] [gdb.base/] [call-ar-st.c] - Blame information for rev 827

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
 
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
 
6
/**************************************************************************
7
 * TESTS :
8
 *   -- function arguments that are enumerated types
9
 *   -- small structure arguments ( <= 64 bits )
10
 *            -- stored in registers
11
 *            -- stored on the stack
12
 *   -- large structure arguments ( > 64 bits )
13
 *            -- stored in registers
14
 *            -- stored on the stack
15
 *   -- array arguments
16
 *   -- caller is a leaf routine :
17
 *            -- use the call command from within an init routine (i.e.
18
 *               init_bit_flags, init_bit_flags_combo, init_array_rep)
19
 *   -- caller doesn't have enough space for all the function arguments :
20
 *            -- call print_long_arg_list from inside print_small_structs
21
 ***************************************************************************/
22
 
23
/* Some enumerated types -- used to test that the structureal data type is
24
 * retrieved for function arguments with typedef data types.
25
 */
26
typedef int id_int;
27
 
28
typedef enum {
29
              BLACK,
30
              BLUE,
31
              BROWN,
32
              ECRUE,
33
              GOLD,
34
              GRAY,
35
              GREEN,
36
              IVORY,
37
              MAUVE,
38
              ORANGE,
39
              PINK,
40
              PURPLE,
41
              RED,
42
              SILVER,
43
              TAN,
44
              VIOLET,
45
              WHITE,
46
              YELLOW} colors;
47
 
48
/* A large structure (> 64 bits) used to test passing large structures as
49
 * parameters
50
 */
51
 
52
struct array_rep_info_t {
53
   int   next_index[10];
54
   int   values[10];
55
   int   head;
56
};
57
 
58
/*****************************************************************************
59
 * Small structures ( <= 64 bits). These are used to test passing small
60
 * structures as parameters and test argument size promotion.
61
 *****************************************************************************/
62
 
63
 /* 64 bits
64
  */
65
struct small_rep_info_t {
66
   int   value;
67
   int   head;
68
};
69
 
70
/* 6 bits : really fits in 8 bits and is promoted to 32 bits
71
 */
72
struct bit_flags_t {
73
       unsigned alpha   :1;
74
       unsigned beta    :1;
75
       unsigned gamma   :1;
76
       unsigned delta   :1;
77
       unsigned epsilon :1;
78
       unsigned omega   :1;
79
};
80
 
81
/* 22 bits : really fits in 40 bits and is promoted to 64 bits
82
 */
83
struct bit_flags_combo_t {
84
       unsigned alpha   :1;
85
       unsigned beta    :1;
86
       char     ch1;
87
       unsigned gamma   :1;
88
       unsigned delta   :1;
89
       char     ch2;
90
       unsigned epsilon :1;
91
       unsigned omega   :1;
92
};
93
 
94
/* 64 bits
95
 */
96
struct one_double_t {
97
       double double1;
98
};
99
 
100
/* 64 bits
101
 */
102
struct two_floats_t {
103
       float float1;
104
       float float2;
105
};
106
 
107
/* 16 bits : promoted to 32 bits
108
 */
109
struct two_char_t {
110
       char ch1;
111
       char ch2;
112
};
113
 
114
/* 24 bits : promoted to 32 bits
115
 */
116
struct three_char_t {
117
       char ch1;
118
       char ch2;
119
       char ch3;
120
};
121
 
122
/* 40 bits : promoted to 64 bits
123
 */
124
struct five_char_t {
125
       char ch1;
126
       char ch2;
127
       char ch3;
128
       char ch4;
129
       char ch5;
130
};
131
 
132
/* 40 bits : promoted to 64 bits
133
 */
134
struct int_char_combo_t {
135
       int  int1;
136
       char ch1;
137
};
138
 
139
/*****************************************************************
140
 * PRINT_STUDENT_ID_SHIRT_COLOR :
141
 * IN     id_int student       -- enumerated type
142
 * IN     colors shirt         -- enumerated type
143
 *****************************************************************/
144
#ifdef PROTOTYPES
145
void print_student_id_shirt_color (id_int student, colors shirt)
146
#else
147
void print_student_id_shirt_color ( student, shirt )
148
 id_int student;
149
 colors shirt;
150
#endif
151
{
152
 
153
 printf("student id : %d\t", student);
154
 printf("shirt color : ");
155
 switch (shirt) {
156
   case BLACK :  printf("BLACK\n");
157
                 break;
158
   case BLUE :   printf("BLUE\n");
159
                 break;
160
   case BROWN :  printf("BROWN\n");
161
                 break;
162
   case ECRUE :  printf("ECRUE\n");
163
                 break;
164
   case GOLD :   printf("GOLD\n");
165
                 break;
166
   case GRAY :   printf("GRAY\n");
167
                 break;
168
   case GREEN :  printf("GREEN\n");
169
                 break;
170
   case IVORY :  printf("IVORY\n");
171
                 break;
172
   case MAUVE :  printf("MAUVE\n");
173
                 break;
174
   case ORANGE : printf("ORANGE\n");
175
                 break;
176
   case PINK :   printf("PINK\n");
177
                 break;
178
   case PURPLE : printf("PURPLE\n");
179
                 break;
180
   case RED :    printf("RED\n");
181
                 break;
182
   case SILVER : printf("SILVER\n");
183
                 break;
184
   case TAN :    printf("TAN\n");
185
                 break;
186
   case VIOLET : printf("VIOLET\n");
187
                 break;
188
   case WHITE :  printf("WHITE\n");
189
                 break;
190
   case YELLOW : printf("YELLOW\n");
191
                 break;
192
 }
193
}
194
 
195
/*****************************************************************
196
 * PRINT_CHAR_ARRAY :
197
 * IN     char  array_c[]      -- character array
198
 *****************************************************************/
199
#ifdef PROTOTYPES
200
void print_char_array (char array_c[])
201
#else
202
void print_char_array ( array_c )
203
     char    array_c[];
204
#endif
205
{
206
 
207
  int index;
208
 
209
  printf("array_c :\n");
210
  printf("=========\n\n");
211
  for (index = 0; index < 120; index++) {
212
      printf("%1c", array_c[index]);
213
      if ((index%50) == 0) printf("\n");
214
  }
215
  printf("\n\n");
216
}
217
 
218
/*****************************************************************
219
 * PRINT_DOUBLE_ARRAY :
220
 * IN     double array_d[]      -- array of doubles
221
 *****************************************************************/
222
#ifdef PROTOTYPES
223
void print_double_array (double  array_d[])
224
#else
225
void print_double_array (array_d)
226
     double  array_d[];
227
#endif
228
{
229
 
230
  int index;
231
 
232
  printf("array_d :\n");
233
  printf("=========\n\n");
234
  for (index = 0; index < 9; index++) {
235
      printf("%f  ", array_d[index]);
236
      if ((index%8) == 0) printf("\n");
237
  }
238
  printf("\n\n");
239
}
240
 
241
/*****************************************************************
242
 * PRINT_FLOAT_ARRAY:
243
 * IN     float array_f[]      -- array of floats
244
 *****************************************************************/
245
#ifdef PROTOTYPES
246
void print_float_array (float array_f[])
247
#else
248
void print_float_array ( array_f )
249
     float array_f[];
250
#endif
251
{
252
 
253
  int index;
254
 
255
  printf("array_f :\n");
256
  printf("=========\n\n");
257
  for (index = 0; index < 15; index++) {
258
      printf("%f  ", array_f[index]);
259
      if ((index%8) == 0) printf("\n");
260
 
261
  }
262
  printf("\n\n");
263
}
264
 
265
/*****************************************************************
266
 * PRINT_INT_ARRAY:
267
 * IN     int  array_i[]      -- array of integers
268
 *****************************************************************/
269
#ifdef PROTOTYPES
270
void print_int_array (int array_i[])
271
#else
272
void print_int_array ( array_i )
273
     int array_i[];
274
#endif
275
{
276
 
277
  int index;
278
 
279
  printf("array_i :\n");
280
  printf("=========\n\n");
281
  for (index = 0; index < 50; index++) {
282
      printf("%d  ", array_i[index]);
283
      if ((index%8) == 0) printf("\n");
284
  }
285
  printf("\n\n");
286
 
287
}
288
 
289
/*****************************************************************
290
 * PRINT_ALL_ARRAYS:
291
 * IN     int  array_i[]      -- array of integers
292
 * IN     char array_c[]      -- array of characters
293
 * IN     float array_f[]      -- array of floats
294
 * IN     double array_d[]      -- array of doubles
295
 *****************************************************************/
296
#ifdef PROTOTYPES
297
void print_all_arrays(int array_i[], char array_c[], float array_f[], double array_d[])
298
#else
299
void print_all_arrays( array_i, array_c, array_f, array_d )
300
     int array_i[];
301
     char array_c[];
302
     float array_f[];
303
     double array_d[];
304
#endif
305
{
306
  print_int_array(array_i);
307
  print_char_array(array_c);
308
  print_float_array(array_f);
309
  print_double_array(array_d);
310
}
311
 
312
/*****************************************************************
313
 * LOOP_COUNT :
314
 * A do nothing function. Used to provide a point at which calls can be made.
315
 *****************************************************************/
316
void loop_count () {
317
 
318
     int index;
319
 
320
     for (index=0; index<4; index++);
321
}
322
 
323
/*****************************************************************
324
 * COMPUTE_WITH_SMALL_STRUCTS :
325
 * A do nothing function. Used to provide a point at which calls can be made.
326
 * IN  int seed
327
 *****************************************************************/
328
#ifdef PROTOTYPES
329
void compute_with_small_structs (int seed)
330
#else
331
void compute_with_small_structs ( seed )
332
 int seed;
333
#endif
334
{
335
 
336
     struct small_rep_info_t array[4];
337
     int index;
338
 
339
     for (index = 0; index < 4; index++) {
340
         array[index].value = index*seed;
341
         array[index].head = (index+1)*seed;
342
     }
343
 
344
     for (index = 1; index < 4; index++) {
345
         array[index].value = array[index].value + array[index-1].value;
346
         array[index].head = array[index].head + array[index-1].head;
347
     }
348
}
349
 
350
/*****************************************************************
351
 * INIT_BIT_FLAGS :
352
 * Initializes a bit_flags_t structure. Can call this function see
353
 * the call command behavior when integer arguments do not fit into
354
 * registers and must be placed on the stack.
355
 * OUT struct bit_flags_t *bit_flags -- structure to be filled
356
 * IN  unsigned a  -- 0 or 1
357
 * IN  unsigned b  -- 0 or 1
358
 * IN  unsigned g  -- 0 or 1
359
 * IN  unsigned d  -- 0 or 1
360
 * IN  unsigned e  -- 0 or 1
361
 * IN  unsigned o  -- 0 or 1
362
 *****************************************************************/
363
#ifdef PROTOTYPES
364
void init_bit_flags (struct bit_flags_t *bit_flags, unsigned a, unsigned b, unsigned g, unsigned d, unsigned e, unsigned o)
365
#else
366
void init_bit_flags ( bit_flags, a, b, g, d, e, o )
367
struct bit_flags_t *bit_flags;
368
unsigned a;
369
unsigned b;
370
unsigned g;
371
unsigned d;
372
unsigned e;
373
unsigned o;
374
#endif
375
{
376
 
377
   bit_flags->alpha = a;
378
   bit_flags->beta = b;
379
   bit_flags->gamma = g;
380
   bit_flags->delta = d;
381
   bit_flags->epsilon = e;
382
   bit_flags->omega = o;
383
}
384
 
385
/*****************************************************************
386
 * INIT_BIT_FLAGS_COMBO :
387
 * Initializes a bit_flags_combo_t structure. Can call this function
388
 * to see the call command behavior when integer and character arguments
389
 * do not fit into registers and must be placed on the stack.
390
 * OUT struct bit_flags_combo_t *bit_flags_combo -- structure to fill
391
 * IN  unsigned a  -- 0 or 1
392
 * IN  unsigned b  -- 0 or 1
393
 * IN  char     ch1
394
 * IN  unsigned g  -- 0 or 1
395
 * IN  unsigned d  -- 0 or 1
396
 * IN  char     ch2
397
 * IN  unsigned e  -- 0 or 1
398
 * IN  unsigned o  -- 0 or 1
399
 *****************************************************************/
400
#ifdef PROTOTYPES
401
void init_bit_flags_combo (struct bit_flags_combo_t *bit_flags_combo, unsigned a, unsigned b, char ch1, unsigned g, unsigned d, char ch2, unsigned e, unsigned o)
402
#else
403
void init_bit_flags_combo ( bit_flags_combo, a, b, ch1, g, d, ch2, e, o )
404
     struct bit_flags_combo_t *bit_flags_combo;
405
     unsigned a;
406
     unsigned b;
407
     char     ch1;
408
     unsigned g;
409
     unsigned d;
410
     char     ch2;
411
     unsigned e;
412
     unsigned o;
413
#endif
414
{
415
 
416
   bit_flags_combo->alpha = a;
417
   bit_flags_combo->beta = b;
418
   bit_flags_combo->ch1 = ch1;
419
   bit_flags_combo->gamma = g;
420
   bit_flags_combo->delta = d;
421
   bit_flags_combo->ch2 = ch2;
422
   bit_flags_combo->epsilon = e;
423
   bit_flags_combo->omega = o;
424
}
425
 
426
 
427
/*****************************************************************
428
 * INIT_ONE_DOUBLE :
429
 * OUT  struct one_double_t *one_double  -- structure to fill
430
 * IN   double init_val
431
 *****************************************************************/
432
#ifdef PROTOTYPES
433
void init_one_double (struct one_double_t *one_double, double init_val)
434
#else
435
void init_one_double ( one_double, init_val )
436
     struct one_double_t *one_double;
437
     double init_val;
438
#endif
439
{
440
 
441
     one_double->double1  = init_val;
442
}
443
 
444
/*****************************************************************
445
 * INIT_TWO_FLOATS :
446
 * OUT struct two_floats_t *two_floats -- structure to be filled
447
 * IN  float init_val1
448
 * IN  float init_val2
449
 *****************************************************************/
450
#ifdef PROTOTYPES
451
void init_two_floats (struct two_floats_t *two_floats, float init_val1, float init_val2)
452
#else
453
void init_two_floats ( two_floats, init_val1, init_val2 )
454
     struct two_floats_t *two_floats;
455
     float init_val1;
456
     float init_val2;
457
#endif
458
{
459
     two_floats->float1 = init_val1;
460
     two_floats->float2 = init_val2;
461
}
462
 
463
/*****************************************************************
464
 * INIT_TWO_CHARS :
465
 * OUT struct two_char_t *two_char -- structure to be filled
466
 * IN  char init_val1
467
 * IN  char init_val2
468
 *****************************************************************/
469
#ifdef PROTOTYPES
470
void init_two_chars (struct two_char_t *two_char, char init_val1, char init_val2)
471
#else
472
void init_two_chars ( two_char, init_val1, init_val2 )
473
     struct two_char_t *two_char;
474
     char init_val1;
475
     char init_val2;
476
#endif
477
{
478
 
479
     two_char->ch1 = init_val1;
480
     two_char->ch2 = init_val2;
481
}
482
 
483
/*****************************************************************
484
 * INIT_THREE_CHARS :
485
 * OUT struct three_char_t *three_char -- structure to be filled
486
 * IN  char init_val1
487
 * IN  char init_val2
488
 * IN  char init_val3
489
 *****************************************************************/
490
#ifdef PROTOTYPES
491
void init_three_chars (struct three_char_t *three_char, char init_val1, char init_val2, char init_val3)
492
#else
493
void init_three_chars ( three_char, init_val1, init_val2, init_val3 )
494
     struct three_char_t *three_char;
495
     char init_val1;
496
     char init_val2;
497
     char init_val3;
498
#endif
499
{
500
 
501
     three_char->ch1 = init_val1;
502
     three_char->ch2 = init_val2;
503
     three_char->ch3 = init_val3;
504
}
505
 
506
/*****************************************************************
507
 * INIT_FIVE_CHARS :
508
 * OUT struct five_char_t *five_char -- structure to be filled
509
 * IN  char init_val1
510
 * IN  char init_val2
511
 * IN  char init_val3
512
 * IN  char init_val4
513
 * IN  char init_val5
514
 *****************************************************************/
515
#ifdef PROTOTYPES
516
void init_five_chars (struct five_char_t *five_char, char init_val1, char init_val2, char init_val3, char init_val4, char init_val5)
517
#else
518
void init_five_chars ( five_char, init_val1, init_val2, init_val3,init_val4,init_val5 )
519
     struct five_char_t *five_char;
520
     char init_val1;
521
     char init_val2;
522
     char init_val3;
523
     char init_val4;
524
     char init_val5;
525
#endif
526
{
527
     five_char->ch1 = init_val1;
528
     five_char->ch2 = init_val2;
529
     five_char->ch3 = init_val3;
530
     five_char->ch4 = init_val4;
531
     five_char->ch5 = init_val5;
532
}
533
 
534
/*****************************************************************
535
 * INIT_INT_CHAR_COMBO :
536
 * OUT struct int_char_combo_t *combo -- structure to be filled
537
 * IN  int  init_val1
538
 * IN  char init_val2
539
 *****************************************************************/
540
#ifdef PROTOTYPES
541
void init_int_char_combo (struct int_char_combo_t *combo, int init_val1, char init_val2)
542
#else
543
void init_int_char_combo ( combo, init_val1, init_val2 )
544
     struct int_char_combo_t *combo;
545
     int init_val1;
546
     char init_val2;
547
#endif
548
{
549
 
550
     combo->int1 = init_val1;
551
     combo->ch1 = init_val2;
552
}
553
 
554
/*****************************************************************
555
 * INIT_STRUCT_REP :
556
 * OUT struct small_rep_into_t *small_struct -- structure to be filled
557
 * IN  int  seed
558
 *****************************************************************/
559
#ifdef PROTOTYPES
560
void init_struct_rep(struct small_rep_info_t *small_struct, int seed)
561
#else
562
void init_struct_rep( small_struct, seed )
563
     struct small_rep_info_t *small_struct;
564
     int    seed;
565
#endif
566
{
567
 
568
      small_struct->value = 2 + (seed*2);
569
      small_struct->head = 0;
570
}
571
 
572
/*****************************************************************
573
 * INIT_SMALL_STRUCTS :
574
 * Takes all the small structures as input and calls the appropriate
575
 * initialization routine for each structure
576
 *****************************************************************/
577
#ifdef PROTOTYPES
578
void init_small_structs (
579
     struct small_rep_info_t  *struct1,
580
     struct small_rep_info_t  *struct2,
581
     struct small_rep_info_t  *struct3,
582
     struct small_rep_info_t  *struct4,
583
     struct bit_flags_t       *flags,
584
     struct bit_flags_combo_t *flags_combo,
585
     struct three_char_t      *three_char,
586
     struct five_char_t       *five_char,
587
     struct int_char_combo_t  *int_char_combo,
588
     struct one_double_t      *d1,
589
     struct one_double_t      *d2,
590
     struct one_double_t      *d3,
591
     struct two_floats_t      *f1,
592
     struct two_floats_t      *f2,
593
     struct two_floats_t      *f3)
594
#else
595
void init_small_structs (struct1, struct2, struct3,struct4,flags,flags_combo,
596
three_char, five_char,int_char_combo, d1, d2,d3,f1,f2,f3)
597
     struct small_rep_info_t  *struct1;
598
     struct small_rep_info_t  *struct2;
599
     struct small_rep_info_t  *struct3;
600
     struct small_rep_info_t  *struct4;
601
     struct bit_flags_t       *flags;
602
     struct bit_flags_combo_t *flags_combo;
603
     struct three_char_t      *three_char;
604
     struct five_char_t       *five_char;
605
     struct int_char_combo_t  *int_char_combo;
606
     struct one_double_t      *d1;
607
     struct one_double_t      *d2;
608
     struct one_double_t      *d3;
609
     struct two_floats_t      *f1;
610
     struct two_floats_t      *f2;
611
     struct two_floats_t      *f3;
612
#endif
613
{
614
 
615
     init_bit_flags(flags, (unsigned)1, (unsigned)0, (unsigned)1,
616
                           (unsigned)0, (unsigned)1, (unsigned)0 );
617
     init_bit_flags_combo(flags_combo, (unsigned)1, (unsigned)0, 'y',
618
                                       (unsigned)1, (unsigned)0, 'n',
619
                                       (unsigned)1, (unsigned)0 );
620
     init_three_chars(three_char, 'a', 'b', 'c');
621
     init_five_chars(five_char, 'l', 'm', 'n', 'o', 'p');
622
     init_int_char_combo(int_char_combo, 123, 'z');
623
     init_struct_rep(struct1, 2);
624
     init_struct_rep(struct2, 4);
625
     init_struct_rep(struct3, 5);
626
     init_struct_rep(struct4, 6);
627
     init_one_double ( d1, 10.5);
628
     init_one_double ( d2, -3.375);
629
     init_one_double ( d3, 675.09375);
630
     init_two_floats ( f1, 45.234, 43.6);
631
     init_two_floats ( f2, 78.01, 122.10);
632
     init_two_floats ( f3, -1232.345, -199.21);
633
}
634
 
635
/*****************************************************************
636
 * PRINT_TEN_DOUBLES :
637
 * ?????????????????????????????
638
 ****************************************************************/
639
#ifdef PROTOTYPES
640
void print_ten_doubles (
641
     double d1,
642
     double d2,
643
     double d3,
644
     double d4,
645
     double d5,
646
     double d6,
647
     double d7,
648
     double d8,
649
     double d9,
650
     double d10)
651
#else
652
void print_ten_doubles ( d1, d2, d3, d4, d5, d6, d7, d8, d9, d10 )
653
     double d1;
654
     double d2;
655
     double d3;
656
     double d4;
657
     double d5;
658
     double d6;
659
     double d7;
660
     double d8;
661
     double d9;
662
     double d10;
663
#endif
664
{
665
 
666
  printf("Two Doubles : %f\t%f\n", d1, d2);
667
  printf("Two Doubles : %f\t%f\n", d3, d4);
668
  printf("Two Doubles : %f\t%f\n", d5, d6);
669
  printf("Two Doubles : %f\t%f\n", d7, d8);
670
  printf("Two Doubles : %f\t%f\n", d9, d10);
671
}
672
 
673
/*****************************************************************
674
 * PRINT_BIT_FLAGS :
675
 * IN struct bit_flags_t bit_flags
676
 ****************************************************************/
677
#ifdef PROTOTYPES
678
void print_bit_flags (struct bit_flags_t bit_flags)
679
#else
680
void print_bit_flags ( bit_flags )
681
struct bit_flags_t bit_flags;
682
#endif
683
{
684
 
685
     if (bit_flags.alpha) printf("alpha\n");
686
     if (bit_flags.beta) printf("beta\n");
687
     if (bit_flags.gamma) printf("gamma\n");
688
     if (bit_flags.delta) printf("delta\n");
689
     if (bit_flags.epsilon) printf("epsilon\n");
690
     if (bit_flags.omega) printf("omega\n");
691
}
692
 
693
/*****************************************************************
694
 * PRINT_BIT_FLAGS_COMBO :
695
 * IN struct bit_flags_combo_t bit_flags_combo
696
 ****************************************************************/
697
#ifdef PROTOTYPES
698
void print_bit_flags_combo (struct bit_flags_combo_t bit_flags_combo)
699
#else
700
void print_bit_flags_combo ( bit_flags_combo )
701
     struct bit_flags_combo_t bit_flags_combo;
702
#endif
703
{
704
 
705
     if (bit_flags_combo.alpha) printf("alpha\n");
706
     if (bit_flags_combo.beta) printf("beta\n");
707
     if (bit_flags_combo.gamma) printf("gamma\n");
708
     if (bit_flags_combo.delta) printf("delta\n");
709
     if (bit_flags_combo.epsilon) printf("epsilon\n");
710
     if (bit_flags_combo.omega) printf("omega\n");
711
     printf("ch1: %c\tch2: %c\n", bit_flags_combo.ch1, bit_flags_combo.ch2);
712
}
713
 
714
/*****************************************************************
715
 * PRINT_ONE_DOUBLE :
716
 * IN struct one_double_t one_double
717
 ****************************************************************/
718
#ifdef PROTOTYPES
719
void print_one_double (struct one_double_t one_double)
720
#else
721
void print_one_double ( one_double )
722
struct one_double_t one_double;
723
#endif
724
{
725
 
726
     printf("Contents of one_double_t: \n\n");
727
     printf("%f\n", one_double.double1);
728
}
729
 
730
/*****************************************************************
731
 * PRINT_TWO_FLOATS :
732
 * IN struct two_floats_t two_floats
733
 ****************************************************************/
734
#ifdef PROTOTYPES
735
void print_two_floats (struct two_floats_t two_floats)
736
#else
737
void print_two_floats ( two_floats )
738
struct two_floats_t two_floats;
739
#endif
740
{
741
 
742
     printf("Contents of two_floats_t: \n\n");
743
     printf("%f\t%f\n", two_floats.float1, two_floats.float2);
744
}
745
 
746
/*****************************************************************
747
 * PRINT_TWO_CHARS :
748
 * IN struct two_char_t two_char
749
 ****************************************************************/
750
#ifdef PROTOTYPES
751
void print_two_chars (struct two_char_t two_char)
752
#else
753
void print_two_chars ( two_char )
754
struct two_char_t two_char;
755
#endif
756
{
757
 
758
     printf("Contents of two_char_t: \n\n");
759
     printf("%c\t%c\n", two_char.ch1, two_char.ch2);
760
}
761
 
762
/*****************************************************************
763
 * PRINT_THREE_CHARS :
764
 * IN struct three_char_t three_char
765
 ****************************************************************/
766
#ifdef PROTOTYPES
767
void print_three_chars (struct three_char_t three_char)
768
#else
769
void print_three_chars ( three_char )
770
struct three_char_t three_char;
771
#endif
772
{
773
 
774
     printf("Contents of three_char_t: \n\n");
775
     printf("%c\t%c\t%c\n", three_char.ch1, three_char.ch2, three_char.ch3);
776
}
777
 
778
/*****************************************************************
779
 * PRINT_FIVE_CHARS :
780
 * IN struct five_char_t five_char
781
 ****************************************************************/
782
#ifdef PROTOTYPES
783
void print_five_chars (struct five_char_t five_char)
784
#else
785
void print_five_chars ( five_char )
786
struct five_char_t five_char;
787
#endif
788
{
789
 
790
     printf("Contents of five_char_t: \n\n");
791
     printf("%c\t%c\t%c\t%c\t%c\n", five_char.ch1, five_char.ch2,
792
                                    five_char.ch3, five_char.ch4,
793
                                    five_char.ch5);
794
}
795
 
796
/*****************************************************************
797
 * PRINT_INT_CHAR_COMBO :
798
 * IN struct int_char_combo_t int_char_combo
799
 ****************************************************************/
800
#ifdef PROTOTYPES
801
void print_int_char_combo (struct int_char_combo_t int_char_combo)
802
#else
803
void print_int_char_combo ( int_char_combo )
804
struct int_char_combo_t int_char_combo;
805
#endif
806
{
807
 
808
     printf("Contents of int_char_combo_t: \n\n");
809
     printf("%d\t%c\n", int_char_combo.int1, int_char_combo.ch1);
810
}
811
 
812
/*****************************************************************
813
 * PRINT_STRUCT_REP :
814
 * The last parameter must go onto the stack rather than into a register.
815
 * This is a good function to call to test small structures.
816
 * IN struct small_rep_info_t  struct1
817
 * IN struct small_rep_info_t  struct2
818
 * IN struct small_rep_info_t  struct3
819
 ****************************************************************/
820
#ifdef PROTOTYPES
821
void print_struct_rep(
822
     struct small_rep_info_t struct1,
823
     struct small_rep_info_t struct2,
824
     struct small_rep_info_t struct3)
825
#else
826
void print_struct_rep( struct1, struct2, struct3)
827
     struct small_rep_info_t struct1;
828
     struct small_rep_info_t struct2;
829
     struct small_rep_info_t struct3;
830
#endif
831
{
832
 
833
 
834
  printf("Contents of struct1: \n\n");
835
  printf("%10d%10d\n", struct1.value, struct1.head);
836
  printf("Contents of struct2: \n\n");
837
  printf("%10d%10d\n", struct2.value, struct2.head);
838
  printf("Contents of struct3: \n\n");
839
  printf("%10d%10d\n", struct3.value, struct3.head);
840
 
841
}
842
 
843
/*****************************************************************
844
 * SUM_STRUCT_PRINT :
845
 * The last two parameters must go onto the stack rather than into a register.
846
 * This is a good function to call to test small structures.
847
 * IN struct small_rep_info_t  struct1
848
 * IN struct small_rep_info_t  struct2
849
 * IN struct small_rep_info_t  struct3
850
 * IN struct small_rep_info_t  struct4
851
 ****************************************************************/
852
#ifdef PROTOTYPES
853
void sum_struct_print (
854
     int seed,
855
     struct small_rep_info_t struct1,
856
     struct small_rep_info_t struct2,
857
     struct small_rep_info_t struct3,
858
     struct small_rep_info_t struct4)
859
#else
860
void sum_struct_print ( seed, struct1, struct2, struct3, struct4)
861
     int seed;
862
     struct small_rep_info_t struct1;
863
     struct small_rep_info_t struct2;
864
     struct small_rep_info_t struct3;
865
     struct small_rep_info_t struct4;
866
#endif
867
{
868
     int sum;
869
 
870
     printf("Sum of the 4 struct values and seed : \n\n");
871
     sum = seed + struct1.value + struct2.value + struct3.value + struct4.value;
872
     printf("%10d\n", sum);
873
}
874
 
875
/*****************************************************************
876
 * PRINT_SMALL_STRUCTS :
877
 * This is a good function to call to test small structures.
878
 * All of the small structures of odd sizes (40 bits, 8bits, etc.)
879
 * are pushed onto the stack.
880
 ****************************************************************/
881
#ifdef PROTOTYPES
882
void print_small_structs (
883
     struct small_rep_info_t  struct1,
884
     struct small_rep_info_t  struct2,
885
     struct small_rep_info_t  struct3,
886
     struct small_rep_info_t  struct4,
887
     struct bit_flags_t       flags,
888
     struct bit_flags_combo_t flags_combo,
889
     struct three_char_t      three_char,
890
     struct five_char_t       five_char,
891
     struct int_char_combo_t  int_char_combo,
892
     struct one_double_t      d1,
893
     struct one_double_t      d2,
894
     struct one_double_t      d3,
895
     struct two_floats_t      f1,
896
     struct two_floats_t      f2,
897
     struct two_floats_t      f3)
898
#else
899
void print_small_structs ( struct1, struct2, struct3,  struct4, flags,
900
flags_combo, three_char, five_char, int_char_combo, d1, d2,d3,f1,f2,f3)
901
     struct small_rep_info_t  struct1;
902
     struct small_rep_info_t  struct2;
903
     struct small_rep_info_t  struct3;
904
     struct small_rep_info_t  struct4;
905
     struct bit_flags_t       flags;
906
     struct bit_flags_combo_t flags_combo;
907
     struct three_char_t      three_char;
908
     struct five_char_t       five_char;
909
     struct int_char_combo_t  int_char_combo;
910
     struct one_double_t      d1;
911
     struct one_double_t      d2;
912
     struct one_double_t      d3;
913
     struct two_floats_t      f1;
914
     struct two_floats_t      f2;
915
     struct two_floats_t      f3;
916
#endif
917
{
918
   print_bit_flags(flags);
919
   print_bit_flags_combo(flags_combo);
920
   print_three_chars(three_char);
921
   print_five_chars(five_char);
922
   print_int_char_combo(int_char_combo);
923
   sum_struct_print(10, struct1, struct2, struct3, struct4);
924
   print_struct_rep(struct1, struct2, struct3);
925
   print_one_double(d1);
926
   print_one_double(d2);
927
   print_one_double(d3);
928
   print_two_floats(f1);
929
   print_two_floats(f2);
930
   print_two_floats(f3);
931
}
932
 
933
/*****************************************************************
934
 * PRINT_LONG_ARG_LIST :
935
 * This is a good function to call to test small structures.
936
 * The first two parameters ( the doubles ) go into registers. The
937
 * remaining arguments are pushed onto the stack. Depending on where
938
 * print_long_arg_list is called from, the size of the argument list
939
 * may force more space to be pushed onto the stack as part of the callers
940
 * frame.
941
 ****************************************************************/
942
#ifdef PROTOTYPES
943
void print_long_arg_list (
944
     double a,
945
     double b,
946
     int c,
947
     int d,
948
     int e,
949
     int f,
950
     struct small_rep_info_t  struct1,
951
     struct small_rep_info_t  struct2,
952
     struct small_rep_info_t  struct3,
953
     struct small_rep_info_t  struct4,
954
     struct bit_flags_t       flags,
955
     struct bit_flags_combo_t flags_combo,
956
     struct three_char_t      three_char,
957
     struct five_char_t       five_char,
958
     struct int_char_combo_t  int_char_combo,
959
     struct one_double_t      d1,
960
     struct one_double_t      d2,
961
     struct one_double_t      d3,
962
     struct two_floats_t      f1,
963
     struct two_floats_t      f2,
964
     struct two_floats_t      f3)
965
#else
966
void print_long_arg_list ( a, b, c, d, e, f, struct1, struct2, struct3,
967
struct4, flags, flags_combo, three_char, five_char, int_char_combo, d1,d2,d3,
968
f1, f2, f3 )
969
     double a;
970
     double b;
971
     int c;
972
     int d;
973
     int e;
974
     int f;
975
     struct small_rep_info_t  struct1;
976
     struct small_rep_info_t  struct2;
977
     struct small_rep_info_t  struct3;
978
     struct small_rep_info_t  struct4;
979
     struct bit_flags_t       flags;
980
     struct bit_flags_combo_t flags_combo;
981
     struct three_char_t      three_char;
982
     struct five_char_t       five_char;
983
     struct int_char_combo_t  int_char_combo;
984
     struct one_double_t      d1;
985
     struct one_double_t      d2;
986
     struct one_double_t      d3;
987
     struct two_floats_t      f1;
988
     struct two_floats_t      f2;
989
     struct two_floats_t      f3;
990
#endif
991
{
992
    printf("double : %f\n", a);
993
    printf("double : %f\n", b);
994
    printf("int : %d\n", c);
995
    printf("int : %d\n", d);
996
    printf("int : %d\n", e);
997
    printf("int : %d\n", f);
998
    print_small_structs( struct1, struct2, struct3, struct4, flags, flags_combo,
999
                         three_char, five_char, int_char_combo, d1, d2, d3,
1000
                         f1, f2, f3);
1001
}
1002
 
1003
 
1004
#ifdef PROTOTYPES
1005
void print_one_large_struct (struct array_rep_info_t linked_list1)
1006
#else
1007
void print_one_large_struct( linked_list1 )
1008
     struct array_rep_info_t linked_list1;
1009
#endif
1010
{
1011
 
1012
 /* printf("Contents of linked list1: \n\n");
1013
  printf("Element Value | Index of Next Element\n");
1014
  printf("-------------------------------------\n");
1015
  printf("              |                      \n");*/
1016
  /*for (index = 0; index < 10; index++) {*/
1017
 
1018
      printf("%10d%10d\n", linked_list1.values[0],
1019
                           linked_list1.next_index[0]);
1020
  /*}*/
1021
}
1022
 
1023
/*****************************************************************
1024
 * PRINT_ARRAY_REP :
1025
 * The three structure parameters should fit into registers.
1026
 * IN struct array_rep_info_t linked_list1
1027
 * IN struct array_rep_info_t linked_list2
1028
 * IN struct array_rep_info_t linked_list3
1029
 ****************************************************************/
1030
#ifdef PROTOTYPES
1031
void print_array_rep(
1032
     struct array_rep_info_t linked_list1,
1033
     struct array_rep_info_t linked_list2,
1034
     struct array_rep_info_t linked_list3)
1035
#else
1036
void print_array_rep( linked_list1, linked_list2, linked_list3 )
1037
     struct array_rep_info_t linked_list1;
1038
     struct array_rep_info_t linked_list2;
1039
     struct array_rep_info_t linked_list3;
1040
#endif
1041
{
1042
 
1043
  int index;
1044
 
1045
  printf("Contents of linked list1: \n\n");
1046
  printf("Element Value | Index of Next Element\n");
1047
  printf("-------------------------------------\n");
1048
  printf("              |                      \n");
1049
  for (index = 0; index < 10; index++) {
1050
 
1051
      printf("%10d%10d\n", linked_list1.values[index],
1052
                           linked_list1.next_index[index]);
1053
  }
1054
 
1055
  printf("Contents of linked list2: \n\n");
1056
  printf("Element Value | Index of Next Element\n");
1057
  printf("-------------------------------------\n");
1058
  printf("              |                      \n");
1059
  for (index = 0; index < 10; index++) {
1060
 
1061
      printf("%10d%10d\n", linked_list2.values[index],
1062
                           linked_list2.next_index[index]);
1063
  }
1064
 
1065
  printf("Contents of linked list3: \n\n");
1066
  printf("Element Value | Index of Next Element\n");
1067
  printf("-------------------------------------\n");
1068
  printf("              |                      \n");
1069
  for (index = 0; index < 10; index++) {
1070
 
1071
      printf("%10d%10d\n", linked_list3.values[index],
1072
                           linked_list3.next_index[index]);
1073
  }
1074
 
1075
}
1076
 
1077
/*****************************************************************
1078
 * SUM_ARRAY_PRINT :
1079
 * The last structure parameter must be pushed onto the stack
1080
 * IN int    seed
1081
 * IN struct array_rep_info_t linked_list1
1082
 * IN struct array_rep_info_t linked_list2
1083
 * IN struct array_rep_info_t linked_list3
1084
 * IN struct array_rep_info_t linked_list4
1085
 ****************************************************************/
1086
#ifdef PROTOTYPES
1087
void sum_array_print (
1088
     int seed,
1089
     struct array_rep_info_t linked_list1,
1090
     struct array_rep_info_t linked_list2,
1091
     struct array_rep_info_t linked_list3,
1092
     struct array_rep_info_t linked_list4)
1093
#else
1094
void sum_array_print ( seed, linked_list1, linked_list2, linked_list3,linked_list4)
1095
     int seed;
1096
     struct array_rep_info_t linked_list1;
1097
     struct array_rep_info_t linked_list2;
1098
     struct array_rep_info_t linked_list3;
1099
     struct array_rep_info_t linked_list4;
1100
#endif
1101
{
1102
     int index;
1103
     int sum;
1104
 
1105
     printf("Sum of 4 arrays, by element (add in seed as well): \n\n");
1106
     printf("Seed: %d\n", seed);
1107
     printf("Element Index | Sum \n");
1108
     printf("-------------------------\n");
1109
     printf("              |          \n");
1110
 
1111
     for (index = 0; index < 10; index++) {
1112
 
1113
         sum = seed + linked_list1.values[index] + linked_list2.values[index] +
1114
               linked_list3.values[index] + linked_list4.values[index];
1115
         printf("%10d%10d\n", index, sum);
1116
     }
1117
}
1118
 
1119
/*****************************************************************
1120
 * INIT_ARRAY_REP :
1121
 * IN struct array_rep_info_t *linked_list
1122
 * IN int    seed
1123
 ****************************************************************/
1124
#ifdef PROTOTYPES
1125
void init_array_rep(
1126
     struct array_rep_info_t *linked_list,
1127
     int    seed)
1128
#else
1129
void init_array_rep( linked_list, seed )
1130
     struct array_rep_info_t *linked_list;
1131
     int    seed;
1132
#endif
1133
{
1134
 
1135
  int index;
1136
 
1137
  for (index = 0; index < 10; index++) {
1138
 
1139
      linked_list->values[index] = (2*index) + (seed*2);
1140
      linked_list->next_index[index] = index + 1;
1141
  }
1142
  linked_list->head = 0;
1143
}
1144
 
1145
 
1146
int main ()  {
1147
 
1148
  /* variables for array and enumerated type testing
1149
   */
1150
  static char     char_array[121];
1151
  static double   double_array[9];
1152
  static float    float_array[15];
1153
  static int      integer_array[50];
1154
  static int      index;
1155
  static id_int   student_id = 23;
1156
  static colors   my_shirt = YELLOW;
1157
 
1158
  /* variables for large structure testing
1159
   */
1160
  static int number = 10;
1161
  static struct array_rep_info_t *list1;
1162
  static struct array_rep_info_t *list2;
1163
  static struct array_rep_info_t *list3;
1164
  static struct array_rep_info_t *list4;
1165
 
1166
  /* variables for testing a very long argument list
1167
   */
1168
   static double                    a;
1169
   static double                    b;
1170
   static int                       c;
1171
   static int                       d;
1172
   static int                       e;
1173
   static int                       f;
1174
 
1175
  /* variables for testing a small structures and a very long argument list
1176
   */
1177
   static struct small_rep_info_t  *struct1;
1178
   static struct small_rep_info_t  *struct2;
1179
   static struct small_rep_info_t  *struct3;
1180
   static struct small_rep_info_t  *struct4;
1181
   static struct bit_flags_t       *flags;
1182
   static struct bit_flags_combo_t *flags_combo;
1183
   static struct three_char_t      *three_char;
1184
   static struct five_char_t       *five_char;
1185
   static struct int_char_combo_t  *int_char_combo;
1186
   static struct one_double_t      *d1;
1187
   static struct one_double_t      *d2;
1188
   static struct one_double_t      *d3;
1189
   static struct two_floats_t      *f1;
1190
   static struct two_floats_t      *f2;
1191
   static struct two_floats_t      *f3;
1192
 
1193
  /* Initialize arrays
1194
   */
1195
  for (index = 0; index < 120; index++) {
1196
      if ((index%2) == 0) char_array[index] = 'Z';
1197
         else char_array[index] = 'a';
1198
  }
1199
  char_array[120] = '\0';
1200
 
1201
  for (index = 0; index < 9; index++) {
1202
      double_array[index] = index*23.4567;
1203
  }
1204
 
1205
  for (index = 0; index < 15; index++) {
1206
      float_array[index] = index/7.02;
1207
  }
1208
 
1209
  for (index = 0; index < 50; index++) {
1210
      integer_array[index] = -index;
1211
  }
1212
 
1213
  /* Print arrays
1214
   */
1215
  print_char_array(char_array);
1216
  print_double_array(double_array);
1217
  print_float_array(float_array);
1218
  print_student_id_shirt_color(student_id, my_shirt);
1219
  print_int_array(integer_array);
1220
  print_all_arrays(integer_array, char_array, float_array, double_array);
1221
 
1222
  /* Allocate space for large structures
1223
   */
1224
  list1 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
1225
  list2 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
1226
  list3 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
1227
  list4 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
1228
 
1229
  /* Initialize large structures
1230
   */
1231
  init_array_rep(list1, 2);
1232
  init_array_rep(list2, 4);
1233
  init_array_rep(list3, 5);
1234
  init_array_rep(list4, 10);
1235
  printf("HELLO WORLD\n");
1236
  printf("BYE BYE FOR NOW\n");
1237
  printf("VERY GREEN GRASS\n");
1238
 
1239
  /* Print large structures
1240
   */
1241
  sum_array_print(10, *list1, *list2, *list3, *list4);
1242
  print_array_rep(*list1, *list2, *list3);
1243
  print_one_large_struct(*list1);
1244
 
1245
  /* Allocate space for small structures
1246
   */
1247
  struct1     = (struct small_rep_info_t  *)malloc(sizeof(struct small_rep_info_t));
1248
  struct2     = (struct small_rep_info_t  *)malloc(sizeof(struct small_rep_info_t));
1249
  struct3     = (struct small_rep_info_t  *)malloc(sizeof(struct small_rep_info_t));
1250
  struct4     = (struct small_rep_info_t  *)malloc(sizeof(struct small_rep_info_t));
1251
  flags       = (struct bit_flags_t *)malloc(sizeof(struct bit_flags_t));
1252
  flags_combo = (struct bit_flags_combo_t *)malloc(sizeof(struct bit_flags_combo_t));
1253
  three_char  = (struct three_char_t *)malloc(sizeof(struct three_char_t));
1254
  five_char   = (struct five_char_t *)malloc(sizeof(struct five_char_t));
1255
  int_char_combo = (struct int_char_combo_t *)malloc(sizeof(struct int_char_combo_t));
1256
 
1257
  d1 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
1258
  d2 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
1259
  d3 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
1260
 
1261
  f1 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
1262
  f2 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
1263
  f3 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
1264
 
1265
  /* Initialize small structures
1266
   */
1267
  init_small_structs ( struct1, struct2, struct3, struct4, flags,
1268
                       flags_combo, three_char, five_char, int_char_combo,
1269
                       d1, d2, d3, f1, f2, f3);
1270
 
1271
  /* Print small structures
1272
   */
1273
  print_small_structs ( *struct1, *struct2, *struct3, *struct4, *flags,
1274
                        *flags_combo, *three_char, *five_char, *int_char_combo,
1275
                        *d1, *d2, *d3, *f1, *f2, *f3);
1276
 
1277
  /* Print a very long arg list
1278
   */
1279
  a = 22.25;
1280
  b = 33.375;
1281
  c = 0;
1282
  d = -25;
1283
  e = 100;
1284
  f = 2345;
1285
 
1286
  print_long_arg_list ( a, b, c, d, e, f, *struct1, *struct2, *struct3, *struct4,
1287
                        *flags, *flags_combo, *three_char, *five_char, *int_char_combo,
1288
                        *d1, *d2, *d3, *f1, *f2, *f3);
1289
 
1290
  /* Initialize small structures
1291
   */
1292
  init_one_double ( d1, 1.11111);
1293
  init_one_double ( d2, -345.34);
1294
  init_one_double ( d3, 546464.2);
1295
  init_two_floats ( f1, 0.234, 453.1);
1296
  init_two_floats ( f2, 78.345, 23.09);
1297
  init_two_floats ( f3, -2.345, 1.0);
1298
  init_bit_flags(flags, (unsigned)1, (unsigned)0, (unsigned)1,
1299
                 (unsigned)0, (unsigned)1, (unsigned)0 );
1300
  init_bit_flags_combo(flags_combo, (unsigned)1, (unsigned)0, 'y',
1301
                                     (unsigned)1, (unsigned)0, 'n',
1302
                                     (unsigned)1, (unsigned)0 );
1303
  init_three_chars(three_char, 'x', 'y', 'z');
1304
  init_five_chars(five_char, 'h', 'e', 'l', 'l', 'o');
1305
  init_int_char_combo(int_char_combo, 13, '!');
1306
  init_struct_rep(struct1, 10);
1307
  init_struct_rep(struct2, 20);
1308
  init_struct_rep(struct3, 30);
1309
  init_struct_rep(struct4, 40);
1310
 
1311
  compute_with_small_structs(35);
1312
  loop_count();
1313
  printf("HELLO WORLD\n");
1314
  printf("BYE BYE FOR NOW\n");
1315
  printf("VERY GREEN GRASS\n");
1316
 
1317
  /* Print small structures
1318
   */
1319
  print_one_double(*d1);
1320
  print_one_double(*d2);
1321
  print_one_double(*d3);
1322
  print_two_floats(*f1);
1323
  print_two_floats(*f2);
1324
  print_two_floats(*f3);
1325
  print_bit_flags(*flags);
1326
  print_bit_flags_combo(*flags_combo);
1327
  print_three_chars(*three_char);
1328
  print_five_chars(*five_char);
1329
  print_int_char_combo(*int_char_combo);
1330
  sum_struct_print(10, *struct1, *struct2, *struct3, *struct4);
1331
  print_struct_rep(*struct1, *struct2, *struct3);
1332
 
1333
  return 0;
1334
}
1335
 
1336
 
1337
 
1338
 
1339
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.