]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/call-ar-st.c
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / call-ar-st.c
1
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 void print_student_id_shirt_color ( student, shirt )
145 id_int student;
146 colors shirt;
147 {
148
149 printf("student id : %d\t", student);
150 printf("shirt color : ");
151 switch (shirt) {
152 case BLACK : printf("BLACK\n");
153 break;
154 case BLUE : printf("BLUE\n");
155 break;
156 case BROWN : printf("BROWN\n");
157 break;
158 case ECRUE : printf("ECRUE\n");
159 break;
160 case GOLD : printf("GOLD\n");
161 break;
162 case GRAY : printf("GRAY\n");
163 break;
164 case GREEN : printf("GREEN\n");
165 break;
166 case IVORY : printf("IVORY\n");
167 break;
168 case MAUVE : printf("MAUVE\n");
169 break;
170 case ORANGE : printf("ORANGE\n");
171 break;
172 case PINK : printf("PINK\n");
173 break;
174 case PURPLE : printf("PURPLE\n");
175 break;
176 case RED : printf("RED\n");
177 break;
178 case SILVER : printf("SILVER\n");
179 break;
180 case TAN : printf("TAN\n");
181 break;
182 case VIOLET : printf("VIOLET\n");
183 break;
184 case WHITE : printf("WHITE\n");
185 break;
186 case YELLOW : printf("YELLOW\n");
187 break;
188 }
189 }
190
191 /*****************************************************************
192 * PRINT_CHAR_ARRAY :
193 * IN char array_c[] -- character array
194 *****************************************************************/
195 void print_char_array ( array_c )
196 char array_c[];
197
198 {
199
200 int index;
201
202 printf("array_c :\n");
203 printf("=========\n\n");
204 for (index = 0; index < 120; index++) {
205 printf("%1c", array_c[index]);
206 if ((index%50) == 0) printf("\n");
207 }
208 printf("\n\n");
209 }
210
211 /*****************************************************************
212 * PRINT_DOUBLE_ARRAY :
213 * IN double array_d[] -- array of doubles
214 *****************************************************************/
215 void print_double_array (array_d)
216 double array_d[];
217
218 {
219
220 int index;
221
222 printf("array_d :\n");
223 printf("=========\n\n");
224 for (index = 0; index < 100; index++) {
225 printf("%f ", array_d[index]);
226 if ((index%8) == 0) printf("\n");
227 }
228 printf("\n\n");
229 }
230
231 /*****************************************************************
232 * PRINT_FLOAT_ARRAY:
233 * IN float array_f[] -- array of floats
234 *****************************************************************/
235 void print_float_array ( array_f )
236 float array_f[];
237
238 {
239
240 int index;
241
242 printf("array_f :\n");
243 printf("=========\n\n");
244 for (index = 0; index < 15; index++) {
245 printf("%f ", array_f[index]);
246 if ((index%8) == 0) printf("\n");
247
248 }
249 printf("\n\n");
250 }
251
252 /*****************************************************************
253 * PRINT_INT_ARRAY:
254 * IN int array_i[] -- array of integers
255 *****************************************************************/
256 void print_int_array ( array_i )
257 int array_i[];
258
259 {
260
261 int index;
262
263 printf("array_i :\n");
264 printf("=========\n\n");
265 for (index = 0; index < 50; index++) {
266 printf("%d ", array_i[index]);
267 if ((index%8) == 0) printf("\n");
268 }
269 printf("\n\n");
270
271 }
272
273 /*****************************************************************
274 * PRINT_ALL_ARRAYS:
275 * IN int array_i[] -- array of integers
276 * IN char array_c[] -- array of characters
277 * IN float array_f[] -- array of floats
278 * IN double array_d[] -- array of doubles
279 *****************************************************************/
280 void print_all_arrays( array_i, array_c, array_f, array_d )
281 int array_i[];
282 char array_c[];
283 float array_f[];
284 double array_d[];
285
286 {
287 print_int_array(array_i);
288 print_char_array(array_c);
289 print_float_array(array_f);
290 print_double_array(array_d);
291 }
292
293 /*****************************************************************
294 * LOOP_COUNT :
295 * A do nothing function. Used to provide a point at which calls can be made.
296 *****************************************************************/
297 void loop_count () {
298
299 int index;
300
301 for (index=0; index<4; index++);
302 }
303
304 /*****************************************************************
305 * COMPUTE_WITH_SMALL_STRUCTS :
306 * A do nothing function. Used to provide a point at which calls can be made.
307 * IN int seed
308 *****************************************************************/
309 void compute_with_small_structs ( seed )
310 int seed;
311 {
312
313 struct small_rep_info_t array[4];
314 int index;
315
316 for (index = 0; index < 4; index++) {
317 array[index].value = index*seed;
318 array[index].head = (index+1)*seed;
319 }
320
321 for (index = 1; index < 4; index++) {
322 array[index].value = array[index].value + array[index-1].value;
323 array[index].head = array[index].head + array[index-1].head;
324 }
325 }
326
327 /*****************************************************************
328 * INIT_BIT_FLAGS :
329 * Initializes a bit_flags_t structure. Can call this function see
330 * the call command behavior when integer arguments do not fit into
331 * registers and must be placed on the stack.
332 * OUT struct bit_flags_t *bit_flags -- structure to be filled
333 * IN unsigned a -- 0 or 1
334 * IN unsigned b -- 0 or 1
335 * IN unsigned g -- 0 or 1
336 * IN unsigned d -- 0 or 1
337 * IN unsigned e -- 0 or 1
338 * IN unsigned o -- 0 or 1
339 *****************************************************************/
340 void init_bit_flags ( bit_flags, a, b, g, d, e, o )
341 struct bit_flags_t *bit_flags;
342 unsigned a;
343 unsigned b;
344 unsigned g;
345 unsigned d;
346 unsigned e;
347 unsigned o;
348 {
349
350 bit_flags->alpha = a;
351 bit_flags->beta = b;
352 bit_flags->gamma = g;
353 bit_flags->delta = d;
354 bit_flags->epsilon = e;
355 bit_flags->omega = o;
356 }
357
358 /*****************************************************************
359 * INIT_BIT_FLAGS_COMBO :
360 * Initializes a bit_flags_combo_t structure. Can call this function
361 * to see the call command behavior when integer and character arguments
362 * do not fit into registers and must be placed on the stack.
363 * OUT struct bit_flags_combo_t *bit_flags_combo -- structure to fill
364 * IN unsigned a -- 0 or 1
365 * IN unsigned b -- 0 or 1
366 * IN char ch1
367 * IN unsigned g -- 0 or 1
368 * IN unsigned d -- 0 or 1
369 * IN char ch2
370 * IN unsigned e -- 0 or 1
371 * IN unsigned o -- 0 or 1
372 *****************************************************************/
373 void init_bit_flags_combo ( bit_flags_combo, a, b, ch1, g, d, ch2, e, o )
374 struct bit_flags_combo_t *bit_flags_combo;
375 unsigned a;
376 unsigned b;
377 char ch1;
378 unsigned g;
379 unsigned d;
380 char ch2;
381 unsigned e;
382 unsigned o;
383 {
384
385 bit_flags_combo->alpha = a;
386 bit_flags_combo->beta = b;
387 bit_flags_combo->ch1 = ch1;
388 bit_flags_combo->gamma = g;
389 bit_flags_combo->delta = d;
390 bit_flags_combo->ch2 = ch2;
391 bit_flags_combo->epsilon = e;
392 bit_flags_combo->omega = o;
393 }
394
395
396 /*****************************************************************
397 * INIT_ONE_DOUBLE :
398 * OUT struct one_double_t *one_double -- structure to fill
399 * IN double init_val
400 *****************************************************************/
401 void init_one_double ( one_double, init_val )
402 struct one_double_t *one_double;
403 double init_val;
404 {
405
406 one_double->double1 = init_val;
407 }
408
409 /*****************************************************************
410 * INIT_TWO_FLOATS :
411 * OUT struct two_floats_t *two_floats -- structure to be filled
412 * IN float init_val1
413 * IN float init_val2
414 *****************************************************************/
415 void init_two_floats ( two_floats, init_val1, init_val2 )
416 struct two_floats_t *two_floats;
417 float init_val1;
418 float init_val2;
419 {
420 two_floats->float1 = init_val1;
421 two_floats->float2 = init_val2;
422 }
423
424 /*****************************************************************
425 * INIT_TWO_CHARS :
426 * OUT struct two_char_t *two_char -- structure to be filled
427 * IN char init_val1
428 * IN char init_val2
429 *****************************************************************/
430 void init_two_chars ( two_char, init_val1, init_val2 )
431 struct two_char_t *two_char;
432 char init_val1;
433 char init_val2;
434 {
435
436 two_char->ch1 = init_val1;
437 two_char->ch2 = init_val2;
438 }
439
440 /*****************************************************************
441 * INIT_THREE_CHARS :
442 * OUT struct three_char_t *three_char -- structure to be filled
443 * IN char init_val1
444 * IN char init_val2
445 * IN char init_val3
446 *****************************************************************/
447 void init_three_chars ( three_char, init_val1, init_val2, init_val3 )
448 struct three_char_t *three_char;
449 char init_val1;
450 char init_val2;
451 char init_val3;
452 {
453
454 three_char->ch1 = init_val1;
455 three_char->ch2 = init_val2;
456 three_char->ch3 = init_val3;
457 }
458
459 /*****************************************************************
460 * INIT_FIVE_CHARS :
461 * OUT struct five_char_t *five_char -- structure to be filled
462 * IN char init_val1
463 * IN char init_val2
464 * IN char init_val3
465 * IN char init_val4
466 * IN char init_val5
467 *****************************************************************/
468 void init_five_chars ( five_char, init_val1, init_val2, init_val3,init_val4,init_val5 )
469 struct five_char_t *five_char;
470 char init_val1;
471 char init_val2;
472 char init_val3;
473 char init_val4;
474 char init_val5;
475 {
476 five_char->ch1 = init_val1;
477 five_char->ch2 = init_val2;
478 five_char->ch3 = init_val3;
479 five_char->ch4 = init_val4;
480 five_char->ch5 = init_val5;
481 }
482
483 /*****************************************************************
484 * INIT_INT_CHAR_COMBO :
485 * OUT struct int_char_combo_t *combo -- structure to be filled
486 * IN int init_val1
487 * IN char init_val2
488 *****************************************************************/
489 void init_int_char_combo ( combo, init_val1, init_val2 )
490 struct int_char_combo_t *combo;
491 int init_val1;
492 char init_val2;
493 {
494
495 combo->int1 = init_val1;
496 combo->ch1 = init_val2;
497 }
498
499 /*****************************************************************
500 * INIT_STRUCT_REP :
501 * OUT struct small_rep_into_t *small_struct -- structure to be filled
502 * IN int seed
503 *****************************************************************/
504 void init_struct_rep( small_struct, seed )
505 struct small_rep_info_t *small_struct;
506 int seed;
507
508 {
509
510 small_struct->value = 2 + (seed*2);
511 small_struct->head = 0;
512 }
513
514 /*****************************************************************
515 * INIT_SMALL_STRUCTS :
516 * Takes all the small structures as input and calls the appropriate
517 * initialization routine for each structure
518 *****************************************************************/
519 void init_small_structs (struct1, struct2, struct3,struct4,flags,flags_combo,
520 three_char, five_char,int_char_combo, d1, d2,d3,f1,f2,f3)
521 struct small_rep_info_t *struct1;
522 struct small_rep_info_t *struct2;
523 struct small_rep_info_t *struct3;
524 struct small_rep_info_t *struct4;
525 struct bit_flags_t *flags;
526 struct bit_flags_combo_t *flags_combo;
527 struct three_char_t *three_char;
528 struct five_char_t *five_char;
529 struct int_char_combo_t *int_char_combo;
530 struct one_double_t *d1;
531 struct one_double_t *d2;
532 struct one_double_t *d3;
533 struct two_floats_t *f1;
534 struct two_floats_t *f2;
535 struct two_floats_t *f3;
536
537 {
538
539 init_bit_flags(flags, (unsigned)1, (unsigned)0, (unsigned)1,
540 (unsigned)0, (unsigned)1, (unsigned)0 );
541 init_bit_flags_combo(flags_combo, (unsigned)1, (unsigned)0, 'y',
542 (unsigned)1, (unsigned)0, 'n',
543 (unsigned)1, (unsigned)0 );
544 init_three_chars(three_char, 'a', 'b', 'c');
545 init_five_chars(five_char, 'l', 'm', 'n', 'o', 'p');
546 init_int_char_combo(int_char_combo, 123, 'z');
547 init_struct_rep(struct1, 2);
548 init_struct_rep(struct2, 4);
549 init_struct_rep(struct3, 5);
550 init_struct_rep(struct4, 6);
551 init_one_double ( d1, 10.5);
552 init_one_double ( d2, -3.34);
553 init_one_double ( d3, 675.09123);
554 init_two_floats ( f1, 45.234, 43.6);
555 init_two_floats ( f2, 78.01, 122.10);
556 init_two_floats ( f3, -1232.345, -199.21);
557 }
558
559 /*****************************************************************
560 * PRINT_TEN_DOUBLES :
561 * ?????????????????????????????
562 ****************************************************************/
563 void print_ten_doubles ( d1, d2, d3, d4, d5, d6, d7, d8, d9, d10 )
564 double d1;
565 double d2;
566 double d3;
567 double d4;
568 double d5;
569 double d6;
570 double d7;
571 double d8;
572 double d9;
573 double d10;
574 {
575
576 printf("Two Doubles : %f\t%f\n", d1, d2);
577 printf("Two Doubles : %f\t%f\n", d3, d4);
578 printf("Two Doubles : %f\t%f\n", d5, d6);
579 printf("Two Doubles : %f\t%f\n", d7, d8);
580 printf("Two Doubles : %f\t%f\n", d9, d10);
581 }
582
583 /*****************************************************************
584 * PRINT_BIT_FLAGS :
585 * IN struct bit_flags_t bit_flags
586 ****************************************************************/
587 void print_bit_flags ( bit_flags )
588 struct bit_flags_t bit_flags;
589 {
590
591 if (bit_flags.alpha) printf("alpha\n");
592 if (bit_flags.beta) printf("beta\n");
593 if (bit_flags.gamma) printf("gamma\n");
594 if (bit_flags.delta) printf("delta\n");
595 if (bit_flags.epsilon) printf("epsilon\n");
596 if (bit_flags.omega) printf("omega\n");
597 }
598
599 /*****************************************************************
600 * PRINT_BIT_FLAGS_COMBO :
601 * IN struct bit_flags_combo_t bit_flags_combo
602 ****************************************************************/
603 void print_bit_flags_combo ( bit_flags_combo )
604 struct bit_flags_combo_t bit_flags_combo;
605 {
606
607 if (bit_flags_combo.alpha) printf("alpha\n");
608 if (bit_flags_combo.beta) printf("beta\n");
609 if (bit_flags_combo.gamma) printf("gamma\n");
610 if (bit_flags_combo.delta) printf("delta\n");
611 if (bit_flags_combo.epsilon) printf("epsilon\n");
612 if (bit_flags_combo.omega) printf("omega\n");
613 printf("ch1: %c\tch2: %c\n", bit_flags_combo.ch1, bit_flags_combo.ch2);
614 }
615
616 /*****************************************************************
617 * PRINT_ONE_DOUBLE :
618 * IN struct one_double_t one_double
619 ****************************************************************/
620 void print_one_double ( one_double )
621 struct one_double_t one_double;
622 {
623
624 printf("Contents of one_double_t: \n\n");
625 printf("%f\n", one_double.double1);
626 }
627
628 /*****************************************************************
629 * PRINT_TWO_FLOATS :
630 * IN struct two_floats_t two_floats
631 ****************************************************************/
632 void print_two_floats ( two_floats )
633 struct two_floats_t two_floats;
634 {
635
636 printf("Contents of two_floats_t: \n\n");
637 printf("%f\t%f\n", two_floats.float1, two_floats.float2);
638 }
639
640 /*****************************************************************
641 * PRINT_TWO_CHARS :
642 * IN struct two_char_t two_char
643 ****************************************************************/
644 void print_two_chars ( two_char )
645 struct two_char_t two_char;
646 {
647
648 printf("Contents of two_char_t: \n\n");
649 printf("%c\t%c\n", two_char.ch1, two_char.ch2);
650 }
651
652 /*****************************************************************
653 * PRINT_THREE_CHARS :
654 * IN struct three_char_t three_char
655 ****************************************************************/
656 void print_three_chars ( three_char )
657 struct three_char_t three_char;
658 {
659
660 printf("Contents of three_char_t: \n\n");
661 printf("%c\t%c\t%c\n", three_char.ch1, three_char.ch2, three_char.ch3);
662 }
663
664 /*****************************************************************
665 * PRINT_FIVE_CHARS :
666 * IN struct five_char_t five_char
667 ****************************************************************/
668 void print_five_chars ( five_char )
669 struct five_char_t five_char;
670 {
671
672 printf("Contents of five_char_t: \n\n");
673 printf("%c\t%c\t%c\t%c\t%c\n", five_char.ch1, five_char.ch2,
674 five_char.ch3, five_char.ch4,
675 five_char.ch5);
676 }
677
678 /*****************************************************************
679 * PRINT_INT_CHAR_COMBO :
680 * IN struct int_char_combo_t int_char_combo
681 ****************************************************************/
682 void print_int_char_combo ( int_char_combo )
683 struct int_char_combo_t int_char_combo;
684 {
685
686 printf("Contents of int_char_combo_t: \n\n");
687 printf("%d\t%c\n", int_char_combo.int1, int_char_combo.ch1);
688 }
689
690 /*****************************************************************
691 * PRINT_STRUCT_REP :
692 * The last parameter must go onto the stack rather than into a register.
693 * This is a good function to call to test small structures.
694 * IN struct small_rep_info_t struct1
695 * IN struct small_rep_info_t struct2
696 * IN struct small_rep_info_t struct3
697 ****************************************************************/
698 void print_struct_rep( struct1, struct2, struct3)
699 struct small_rep_info_t struct1;
700 struct small_rep_info_t struct2;
701 struct small_rep_info_t struct3;
702
703 {
704
705
706 printf("Contents of struct1: \n\n");
707 printf("%10d%10d\n", struct1.value, struct1.head);
708 printf("Contents of struct2: \n\n");
709 printf("%10d%10d\n", struct2.value, struct2.head);
710 printf("Contents of struct3: \n\n");
711 printf("%10d%10d\n", struct3.value, struct3.head);
712
713 }
714
715 /*****************************************************************
716 * SUM_STRUCT_PRINT :
717 * The last two parameters must go onto the stack rather than into a register.
718 * This is a good function to call to test small structures.
719 * IN struct small_rep_info_t struct1
720 * IN struct small_rep_info_t struct2
721 * IN struct small_rep_info_t struct3
722 * IN struct small_rep_info_t struct4
723 ****************************************************************/
724 void sum_struct_print ( seed, struct1, struct2, struct3, struct4)
725 int seed;
726 struct small_rep_info_t struct1;
727 struct small_rep_info_t struct2;
728 struct small_rep_info_t struct3;
729 struct small_rep_info_t struct4;
730
731 {
732 int sum;
733
734 printf("Sum of the 4 struct values and seed : \n\n");
735 sum = seed + struct1.value + struct2.value + struct3.value + struct4.value;
736 printf("%10d\n", sum);
737 }
738
739 /*****************************************************************
740 * PRINT_SMALL_STRUCTS :
741 * This is a good function to call to test small structures.
742 * All of the small structures of odd sizes (40 bits, 8bits, etc.)
743 * are pushed onto the stack.
744 ****************************************************************/
745 void print_small_structs ( struct1, struct2, struct3, struct4, flags,
746 flags_combo, three_char, five_char, int_char_combo, d1, d2,d3,f1,f2,f3)
747 struct small_rep_info_t struct1;
748 struct small_rep_info_t struct2;
749 struct small_rep_info_t struct3;
750 struct small_rep_info_t struct4;
751 struct bit_flags_t flags;
752 struct bit_flags_combo_t flags_combo;
753 struct three_char_t three_char;
754 struct five_char_t five_char;
755 struct int_char_combo_t int_char_combo;
756 struct one_double_t d1;
757 struct one_double_t d2;
758 struct one_double_t d3;
759 struct two_floats_t f1;
760 struct two_floats_t f2;
761 struct two_floats_t f3;
762 {
763 print_bit_flags(flags);
764 print_bit_flags_combo(flags_combo);
765 print_three_chars(three_char);
766 print_five_chars(five_char);
767 print_int_char_combo(int_char_combo);
768 sum_struct_print(10, struct1, struct2, struct3, struct4);
769 print_struct_rep(struct1, struct2, struct3);
770 print_one_double(d1);
771 print_one_double(d2);
772 print_one_double(d3);
773 print_two_floats(f1);
774 print_two_floats(f2);
775 print_two_floats(f3);
776 }
777
778 /*****************************************************************
779 * PRINT_LONG_ARG_LIST :
780 * This is a good function to call to test small structures.
781 * The first two parameters ( the doubles ) go into registers. The
782 * remaining arguments are pushed onto the stack. Depending on where
783 * print_long_arg_list is called from, the size of the argument list
784 * may force more space to be pushed onto the stack as part of the callers
785 * frame.
786 ****************************************************************/
787 void print_long_arg_list ( a, b, c, d, e, f, struct1, struct2, struct3,
788 struct4, flags, flags_combo, three_char, five_char, int_char_combo, d1,d2,d3,
789 f1, f2, f3 )
790 double a;
791 double b;
792 int c;
793 int d;
794 int e;
795 int f;
796 struct small_rep_info_t struct1;
797 struct small_rep_info_t struct2;
798 struct small_rep_info_t struct3;
799 struct small_rep_info_t struct4;
800 struct bit_flags_t flags;
801 struct bit_flags_combo_t flags_combo;
802 struct three_char_t three_char;
803 struct five_char_t five_char;
804 struct int_char_combo_t int_char_combo;
805 struct one_double_t d1;
806 struct one_double_t d2;
807 struct one_double_t d3;
808 struct two_floats_t f1;
809 struct two_floats_t f2;
810 struct two_floats_t f3;
811
812 {
813 printf("double : %f\n", a);
814 printf("double : %f\n", b);
815 printf("int : %d\n", c);
816 printf("int : %d\n", d);
817 printf("int : %d\n", e);
818 printf("int : %d\n", f);
819 print_small_structs( struct1, struct2, struct3, struct4, flags, flags_combo,
820 three_char, five_char, int_char_combo, d1, d2, d3,
821 f1, f2, f3);
822 }
823
824
825 void print_one_large_struct( linked_list1 )
826 struct array_rep_info_t linked_list1;
827
828 {
829
830 /* printf("Contents of linked list1: \n\n");
831 printf("Element Value | Index of Next Element\n");
832 printf("-------------------------------------\n");
833 printf(" | \n");*/
834 /*for (index = 0; index < 10; index++) {*/
835
836 printf("%10d%10d\n", linked_list1.values[0],
837 linked_list1.next_index[0]);
838 /*}*/
839 }
840
841 /*****************************************************************
842 * PRINT_ARRAY_REP :
843 * The three structure parameters should fit into registers.
844 * IN struct array_rep_info_t linked_list1
845 * IN struct array_rep_info_t linked_list2
846 * IN struct array_rep_info_t linked_list3
847 ****************************************************************/
848 void print_array_rep( linked_list1, linked_list2, linked_list3 )
849 struct array_rep_info_t linked_list1;
850 struct array_rep_info_t linked_list2;
851 struct array_rep_info_t linked_list3;
852
853 {
854
855 int index;
856
857 printf("Contents of linked list1: \n\n");
858 printf("Element Value | Index of Next Element\n");
859 printf("-------------------------------------\n");
860 printf(" | \n");
861 for (index = 0; index < 10; index++) {
862
863 printf("%10d%10d\n", linked_list1.values[index],
864 linked_list1.next_index[index]);
865 }
866
867 printf("Contents of linked list2: \n\n");
868 printf("Element Value | Index of Next Element\n");
869 printf("-------------------------------------\n");
870 printf(" | \n");
871 for (index = 0; index < 10; index++) {
872
873 printf("%10d%10d\n", linked_list2.values[index],
874 linked_list2.next_index[index]);
875 }
876
877 printf("Contents of linked list3: \n\n");
878 printf("Element Value | Index of Next Element\n");
879 printf("-------------------------------------\n");
880 printf(" | \n");
881 for (index = 0; index < 10; index++) {
882
883 printf("%10d%10d\n", linked_list3.values[index],
884 linked_list3.next_index[index]);
885 }
886
887 }
888
889 /*****************************************************************
890 * SUM_ARRAY_PRINT :
891 * The last structure parameter must be pushed onto the stack
892 * IN int seed
893 * IN struct array_rep_info_t linked_list1
894 * IN struct array_rep_info_t linked_list2
895 * IN struct array_rep_info_t linked_list3
896 * IN struct array_rep_info_t linked_list4
897 ****************************************************************/
898 void sum_array_print ( seed, linked_list1, linked_list2, linked_list3,linked_list4)
899 int seed;
900 struct array_rep_info_t linked_list1;
901 struct array_rep_info_t linked_list2;
902 struct array_rep_info_t linked_list3;
903 struct array_rep_info_t linked_list4;
904
905 {
906 int index;
907 int sum;
908
909 printf("Sum of 4 arrays, by element (add in seed as well): \n\n");
910 printf("Seed: %d\n", seed);
911 printf("Element Index | Sum \n");
912 printf("-------------------------\n");
913 printf(" | \n");
914
915 for (index = 0; index < 10; index++) {
916
917 sum = seed + linked_list1.values[index] + linked_list2.values[index] +
918 linked_list3.values[index] + linked_list4.values[index];
919 printf("%10d%10d\n", index, sum);
920 }
921 }
922
923 /*****************************************************************
924 * INIT_ARRAY_REP :
925 * IN struct array_rep_info_t *linked_list
926 * IN int seed
927 ****************************************************************/
928 void init_array_rep( linked_list, seed )
929 struct array_rep_info_t *linked_list;
930 int seed;
931
932 {
933
934 int index;
935
936 for (index = 0; index < 10; index++) {
937
938 linked_list->values[index] = (2*index) + (seed*2);
939 linked_list->next_index[index] = index + 1;
940 }
941 linked_list->head = 0;
942 }
943
944
945 int main () {
946
947 /* variables for array and enumerated type testing
948 */
949 char char_array[121];
950 double double_array[100];
951 float float_array[15];
952 int integer_array[50];
953 int index;
954 id_int student_id = 23;
955 colors my_shirt = YELLOW;
956
957 /* variables for large structure testing
958 */
959 int number = 10;
960 struct array_rep_info_t *list1;
961 struct array_rep_info_t *list2;
962 struct array_rep_info_t *list3;
963 struct array_rep_info_t *list4;
964
965 /* variables for testing a very long argument list
966 */
967 double a;
968 double b;
969 int c;
970 int d;
971 int e;
972 int f;
973
974 /* variables for testing a small structures and a very long argument list
975 */
976 struct small_rep_info_t *struct1;
977 struct small_rep_info_t *struct2;
978 struct small_rep_info_t *struct3;
979 struct small_rep_info_t *struct4;
980 struct bit_flags_t *flags;
981 struct bit_flags_combo_t *flags_combo;
982 struct three_char_t *three_char;
983 struct five_char_t *five_char;
984 struct int_char_combo_t *int_char_combo;
985 struct one_double_t *d1;
986 struct one_double_t *d2;
987 struct one_double_t *d3;
988 struct two_floats_t *f1;
989 struct two_floats_t *f2;
990 struct two_floats_t *f3;
991
992 /* Initialize arrays
993 */
994 for (index = 0; index < 120; index++) {
995 if ((index%2) == 0) char_array[index] = 'Z';
996 else char_array[index] = 'a';
997 } /* call-ar-st.exp uses line numbers everywhere */ char_array[120] = '\0';
998
999 for (index = 0; index < 100; index++) {
1000 double_array[index] = index*23.4567;
1001 }
1002
1003 for (index = 0; index < 15; index++) {
1004 float_array[index] = index/7.02;
1005 }
1006
1007 for (index = 0; index < 50; index++) {
1008 integer_array[index] = -index;
1009 }
1010
1011 /* Print arrays
1012 */
1013 print_char_array(char_array);
1014 print_double_array(double_array);
1015 print_float_array(float_array);
1016 print_student_id_shirt_color(student_id, my_shirt);
1017 print_int_array(integer_array);
1018 print_all_arrays(integer_array, char_array, float_array, double_array);
1019
1020 /* Allocate space for large structures
1021 */
1022 list1 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
1023 list2 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
1024 list3 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
1025 list4 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
1026
1027 /* Initialize large structures
1028 */
1029 init_array_rep(list1, 2);
1030 init_array_rep(list2, 4);
1031 init_array_rep(list3, 5);
1032 init_array_rep(list4, 10);
1033 printf("HELLO WORLD\n");
1034 printf("BYE BYE FOR NOW\n");
1035 printf("VERY GREEN GRASS\n");
1036
1037 /* Print large structures
1038 */
1039 sum_array_print(10, *list1, *list2, *list3, *list4);
1040 print_array_rep(*list1, *list2, *list3);
1041 print_one_large_struct(*list1);
1042
1043 /* Allocate space for small structures
1044 */
1045 struct1 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t));
1046 struct2 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t));
1047 struct3 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t));
1048 struct4 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t));
1049 flags = (struct bit_flags_t *)malloc(sizeof(struct bit_flags_t));
1050 flags_combo = (struct bit_flags_combo_t *)malloc(sizeof(struct bit_flags_combo_t));
1051 three_char = (struct three_char_t *)malloc(sizeof(struct three_char_t));
1052 five_char = (struct five_char_t *)malloc(sizeof(struct five_char_t));
1053 int_char_combo = (struct int_char_combo_t *)malloc(sizeof(struct int_char_combo_t));
1054
1055 d1 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
1056 d2 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
1057 d3 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
1058
1059 f1 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
1060 f2 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
1061 f3 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
1062
1063 /* Initialize small structures
1064 */
1065 init_small_structs ( struct1, struct2, struct3, struct4, flags,
1066 flags_combo, three_char, five_char, int_char_combo,
1067 d1, d2, d3, f1, f2, f3);
1068
1069 /* Print small structures
1070 */
1071 print_small_structs ( *struct1, *struct2, *struct3, *struct4, *flags,
1072 *flags_combo, *three_char, *five_char, *int_char_combo,
1073 *d1, *d2, *d3, *f1, *f2, *f3);
1074
1075 /* Print a very long arg list
1076 */
1077 a = 22.22;
1078 b = 33.333;
1079 c = 0;
1080 d = -25;
1081 e = 100;
1082 f = 2345;
1083
1084 print_long_arg_list ( a, b, c, d, e, f, *struct1, *struct2, *struct3, *struct4,
1085 *flags, *flags_combo, *three_char, *five_char, *int_char_combo,
1086 *d1, *d2, *d3, *f1, *f2, *f3);
1087
1088 /* Initialize small structures
1089 */
1090 init_one_double ( d1, 1.11111);
1091 init_one_double ( d2, -345.34);
1092 init_one_double ( d3, 546464.2);
1093 init_two_floats ( f1, 0.234, 453.1);
1094 init_two_floats ( f2, 78.345, 23.09);
1095 init_two_floats ( f3, -2.345, 1.0);
1096 init_bit_flags(flags, (unsigned)1, (unsigned)0, (unsigned)1,
1097 (unsigned)0, (unsigned)1, (unsigned)0 );
1098 init_bit_flags_combo(flags_combo, (unsigned)1, (unsigned)0, 'y',
1099 (unsigned)1, (unsigned)0, 'n',
1100 (unsigned)1, (unsigned)0 );
1101 init_three_chars(three_char, 'x', 'y', 'z');
1102 init_five_chars(five_char, 'h', 'e', 'l', 'l', 'o');
1103 init_int_char_combo(int_char_combo, 13, '!');
1104 init_struct_rep(struct1, 10);
1105 init_struct_rep(struct2, 20);
1106 init_struct_rep(struct3, 30);
1107 init_struct_rep(struct4, 40);
1108
1109 compute_with_small_structs(35);
1110 loop_count();
1111 printf("HELLO WORLD\n");
1112 printf("BYE BYE FOR NOW\n");
1113 printf("VERY GREEN GRASS\n");
1114
1115 /* Print small structures
1116 */
1117 print_one_double(*d1);
1118 print_one_double(*d2);
1119 print_one_double(*d3);
1120 print_two_floats(*f1);
1121 print_two_floats(*f2);
1122 print_two_floats(*f3);
1123 print_bit_flags(*flags);
1124 print_bit_flags_combo(*flags_combo);
1125 print_three_chars(*three_char);
1126 print_five_chars(*five_char);
1127 print_int_char_combo(*int_char_combo);
1128 sum_struct_print(10, *struct1, *struct2, *struct3, *struct4);
1129 print_struct_rep(*struct1, *struct2, *struct3);
1130
1131 return 0;
1132 }
1133
1134
1135
1136
1137