Update copyright year range in all GDB files
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / call-ar-st.c
CommitLineData
c906108c
SS
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5
dedad4e3
PA
6#include "../lib/unbuffer_output.c"
7
c906108c
SS
8/**************************************************************************
9 * TESTS :
10 * -- function arguments that are enumerated types
11 * -- small structure arguments ( <= 64 bits )
12 * -- stored in registers
13 * -- stored on the stack
14 * -- large structure arguments ( > 64 bits )
15 * -- stored in registers
16 * -- stored on the stack
17 * -- array arguments
18 * -- caller is a leaf routine :
19 * -- use the call command from within an init routine (i.e.
20 * init_bit_flags, init_bit_flags_combo, init_array_rep)
21 * -- caller doesn't have enough space for all the function arguments :
22 * -- call print_long_arg_list from inside print_small_structs
23 ***************************************************************************/
24
25/* Some enumerated types -- used to test that the structureal data type is
26 * retrieved for function arguments with typedef data types.
27 */
28typedef int id_int;
29
30typedef enum {
31 BLACK,
32 BLUE,
33 BROWN,
34 ECRUE,
35 GOLD,
36 GRAY,
37 GREEN,
38 IVORY,
39 MAUVE,
40 ORANGE,
41 PINK,
42 PURPLE,
43 RED,
44 SILVER,
45 TAN,
46 VIOLET,
47 WHITE,
48 YELLOW} colors;
49
50/* A large structure (> 64 bits) used to test passing large structures as
51 * parameters
52 */
53
54struct array_rep_info_t {
55 int next_index[10];
56 int values[10];
57 int head;
58};
59
60/*****************************************************************************
61 * Small structures ( <= 64 bits). These are used to test passing small
62 * structures as parameters and test argument size promotion.
63 *****************************************************************************/
64
65 /* 64 bits
66 */
67struct small_rep_info_t {
68 int value;
69 int head;
70};
71
72/* 6 bits : really fits in 8 bits and is promoted to 32 bits
73 */
74struct bit_flags_t {
75 unsigned alpha :1;
76 unsigned beta :1;
77 unsigned gamma :1;
78 unsigned delta :1;
79 unsigned epsilon :1;
80 unsigned omega :1;
81};
82
83/* 22 bits : really fits in 40 bits and is promoted to 64 bits
84 */
85struct bit_flags_combo_t {
86 unsigned alpha :1;
87 unsigned beta :1;
88 char ch1;
89 unsigned gamma :1;
90 unsigned delta :1;
91 char ch2;
92 unsigned epsilon :1;
93 unsigned omega :1;
94};
95
96/* 64 bits
97 */
98struct one_double_t {
99 double double1;
100};
101
102/* 64 bits
103 */
104struct two_floats_t {
105 float float1;
106 float float2;
107};
108
109/* 16 bits : promoted to 32 bits
110 */
111struct two_char_t {
112 char ch1;
113 char ch2;
114};
115
116/* 24 bits : promoted to 32 bits
117 */
118struct three_char_t {
119 char ch1;
120 char ch2;
121 char ch3;
122};
123
124/* 40 bits : promoted to 64 bits
125 */
126struct five_char_t {
127 char ch1;
128 char ch2;
129 char ch3;
130 char ch4;
131 char ch5;
132};
133
134/* 40 bits : promoted to 64 bits
135 */
136struct int_char_combo_t {
137 int int1;
138 char ch1;
139};
140
141/*****************************************************************
142 * PRINT_STUDENT_ID_SHIRT_COLOR :
143 * IN id_int student -- enumerated type
144 * IN colors shirt -- enumerated type
145 *****************************************************************/
085dd6e6 146void print_student_id_shirt_color (id_int student, colors shirt)
c906108c
SS
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 *****************************************************************/
085dd6e6 195void print_char_array (char array_c[])
c906108c
SS
196{
197
198 int index;
199
200 printf("array_c :\n");
201 printf("=========\n\n");
202 for (index = 0; index < 120; index++) {
203 printf("%1c", array_c[index]);
204 if ((index%50) == 0) printf("\n");
205 }
206 printf("\n\n");
207}
208
209/*****************************************************************
210 * PRINT_DOUBLE_ARRAY :
211 * IN double array_d[] -- array of doubles
212 *****************************************************************/
085dd6e6 213void print_double_array (double array_d[])
c906108c
SS
214{
215
216 int index;
217
218 printf("array_d :\n");
219 printf("=========\n\n");
1b7c05e7 220 for (index = 0; index < 9; index++) {
c906108c
SS
221 printf("%f ", array_d[index]);
222 if ((index%8) == 0) printf("\n");
223 }
224 printf("\n\n");
225}
226
227/*****************************************************************
228 * PRINT_FLOAT_ARRAY:
229 * IN float array_f[] -- array of floats
230 *****************************************************************/
085dd6e6 231void print_float_array (float array_f[])
c906108c
SS
232{
233
234 int index;
235
236 printf("array_f :\n");
237 printf("=========\n\n");
238 for (index = 0; index < 15; index++) {
239 printf("%f ", array_f[index]);
240 if ((index%8) == 0) printf("\n");
241
242 }
243 printf("\n\n");
244}
245
246/*****************************************************************
247 * PRINT_INT_ARRAY:
248 * IN int array_i[] -- array of integers
249 *****************************************************************/
085dd6e6 250void print_int_array (int array_i[])
c906108c
SS
251{
252
253 int index;
254
255 printf("array_i :\n");
256 printf("=========\n\n");
257 for (index = 0; index < 50; index++) {
258 printf("%d ", array_i[index]);
259 if ((index%8) == 0) printf("\n");
260 }
261 printf("\n\n");
262
263}
264
265/*****************************************************************
266 * PRINT_ALL_ARRAYS:
267 * IN int array_i[] -- array of integers
268 * IN char array_c[] -- array of characters
269 * IN float array_f[] -- array of floats
270 * IN double array_d[] -- array of doubles
271 *****************************************************************/
085dd6e6 272void print_all_arrays(int array_i[], char array_c[], float array_f[], double array_d[])
c906108c 273{
888a2ade
AA
274 print_int_array(array_i); /* -step1- */
275 print_char_array(array_c); /* -next1- */
c906108c
SS
276 print_float_array(array_f);
277 print_double_array(array_d);
278}
279
280/*****************************************************************
281 * LOOP_COUNT :
282 * A do nothing function. Used to provide a point at which calls can be made.
283 *****************************************************************/
284void loop_count () {
285
286 int index;
287
288 for (index=0; index<4; index++);
289}
290
291/*****************************************************************
292 * COMPUTE_WITH_SMALL_STRUCTS :
293 * A do nothing function. Used to provide a point at which calls can be made.
294 * IN int seed
295 *****************************************************************/
085dd6e6 296void compute_with_small_structs (int seed)
c906108c
SS
297{
298
299 struct small_rep_info_t array[4];
300 int index;
301
302 for (index = 0; index < 4; index++) {
303 array[index].value = index*seed;
304 array[index].head = (index+1)*seed;
305 }
306
307 for (index = 1; index < 4; index++) {
308 array[index].value = array[index].value + array[index-1].value;
309 array[index].head = array[index].head + array[index-1].head;
310 }
311}
312
313/*****************************************************************
314 * INIT_BIT_FLAGS :
315 * Initializes a bit_flags_t structure. Can call this function see
316 * the call command behavior when integer arguments do not fit into
317 * registers and must be placed on the stack.
318 * OUT struct bit_flags_t *bit_flags -- structure to be filled
319 * IN unsigned a -- 0 or 1
320 * IN unsigned b -- 0 or 1
321 * IN unsigned g -- 0 or 1
322 * IN unsigned d -- 0 or 1
323 * IN unsigned e -- 0 or 1
324 * IN unsigned o -- 0 or 1
325 *****************************************************************/
085dd6e6 326void init_bit_flags (struct bit_flags_t *bit_flags, unsigned a, unsigned b, unsigned g, unsigned d, unsigned e, unsigned o)
c906108c
SS
327{
328
329 bit_flags->alpha = a;
330 bit_flags->beta = b;
331 bit_flags->gamma = g;
332 bit_flags->delta = d;
333 bit_flags->epsilon = e;
334 bit_flags->omega = o;
335}
336
337/*****************************************************************
338 * INIT_BIT_FLAGS_COMBO :
339 * Initializes a bit_flags_combo_t structure. Can call this function
340 * to see the call command behavior when integer and character arguments
341 * do not fit into registers and must be placed on the stack.
342 * OUT struct bit_flags_combo_t *bit_flags_combo -- structure to fill
343 * IN unsigned a -- 0 or 1
344 * IN unsigned b -- 0 or 1
345 * IN char ch1
346 * IN unsigned g -- 0 or 1
347 * IN unsigned d -- 0 or 1
348 * IN char ch2
349 * IN unsigned e -- 0 or 1
350 * IN unsigned o -- 0 or 1
351 *****************************************************************/
085dd6e6 352void 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)
c906108c
SS
353{
354
888a2ade 355 bit_flags_combo->alpha = a; /* -step3- */
c906108c
SS
356 bit_flags_combo->beta = b;
357 bit_flags_combo->ch1 = ch1;
358 bit_flags_combo->gamma = g;
359 bit_flags_combo->delta = d;
360 bit_flags_combo->ch2 = ch2;
361 bit_flags_combo->epsilon = e;
362 bit_flags_combo->omega = o;
363}
364
365
366/*****************************************************************
367 * INIT_ONE_DOUBLE :
368 * OUT struct one_double_t *one_double -- structure to fill
369 * IN double init_val
370 *****************************************************************/
085dd6e6 371void init_one_double (struct one_double_t *one_double, double init_val)
c906108c
SS
372{
373
374 one_double->double1 = init_val;
375}
376
377/*****************************************************************
378 * INIT_TWO_FLOATS :
379 * OUT struct two_floats_t *two_floats -- structure to be filled
380 * IN float init_val1
381 * IN float init_val2
382 *****************************************************************/
085dd6e6 383void init_two_floats (struct two_floats_t *two_floats, float init_val1, float init_val2)
c906108c
SS
384{
385 two_floats->float1 = init_val1;
386 two_floats->float2 = init_val2;
387}
388
389/*****************************************************************
390 * INIT_TWO_CHARS :
391 * OUT struct two_char_t *two_char -- structure to be filled
392 * IN char init_val1
393 * IN char init_val2
394 *****************************************************************/
085dd6e6 395void init_two_chars (struct two_char_t *two_char, char init_val1, char init_val2)
c906108c
SS
396{
397
398 two_char->ch1 = init_val1;
399 two_char->ch2 = init_val2;
400}
401
402/*****************************************************************
403 * INIT_THREE_CHARS :
404 * OUT struct three_char_t *three_char -- structure to be filled
405 * IN char init_val1
406 * IN char init_val2
407 * IN char init_val3
408 *****************************************************************/
085dd6e6 409void init_three_chars (struct three_char_t *three_char, char init_val1, char init_val2, char init_val3)
c906108c
SS
410{
411
412 three_char->ch1 = init_val1;
413 three_char->ch2 = init_val2;
414 three_char->ch3 = init_val3;
415}
416
417/*****************************************************************
418 * INIT_FIVE_CHARS :
419 * OUT struct five_char_t *five_char -- structure to be filled
420 * IN char init_val1
421 * IN char init_val2
422 * IN char init_val3
423 * IN char init_val4
424 * IN char init_val5
425 *****************************************************************/
085dd6e6 426void init_five_chars (struct five_char_t *five_char, char init_val1, char init_val2, char init_val3, char init_val4, char init_val5)
c906108c
SS
427{
428 five_char->ch1 = init_val1;
429 five_char->ch2 = init_val2;
430 five_char->ch3 = init_val3;
431 five_char->ch4 = init_val4;
432 five_char->ch5 = init_val5;
433}
434
435/*****************************************************************
436 * INIT_INT_CHAR_COMBO :
437 * OUT struct int_char_combo_t *combo -- structure to be filled
438 * IN int init_val1
439 * IN char init_val2
440 *****************************************************************/
085dd6e6 441void init_int_char_combo (struct int_char_combo_t *combo, int init_val1, char init_val2)
c906108c
SS
442{
443
444 combo->int1 = init_val1;
445 combo->ch1 = init_val2;
446}
447
448/*****************************************************************
449 * INIT_STRUCT_REP :
450 * OUT struct small_rep_into_t *small_struct -- structure to be filled
451 * IN int seed
452 *****************************************************************/
085dd6e6 453void init_struct_rep(struct small_rep_info_t *small_struct, int seed)
c906108c
SS
454{
455
456 small_struct->value = 2 + (seed*2);
457 small_struct->head = 0;
458}
459
460/*****************************************************************
461 * INIT_SMALL_STRUCTS :
462 * Takes all the small structures as input and calls the appropriate
463 * initialization routine for each structure
464 *****************************************************************/
085dd6e6
JM
465void init_small_structs (
466 struct small_rep_info_t *struct1,
467 struct small_rep_info_t *struct2,
468 struct small_rep_info_t *struct3,
469 struct small_rep_info_t *struct4,
470 struct bit_flags_t *flags,
471 struct bit_flags_combo_t *flags_combo,
472 struct three_char_t *three_char,
473 struct five_char_t *five_char,
474 struct int_char_combo_t *int_char_combo,
475 struct one_double_t *d1,
476 struct one_double_t *d2,
477 struct one_double_t *d3,
478 struct two_floats_t *f1,
479 struct two_floats_t *f2,
480 struct two_floats_t *f3)
c906108c
SS
481{
482
483 init_bit_flags(flags, (unsigned)1, (unsigned)0, (unsigned)1,
484 (unsigned)0, (unsigned)1, (unsigned)0 );
485 init_bit_flags_combo(flags_combo, (unsigned)1, (unsigned)0, 'y',
486 (unsigned)1, (unsigned)0, 'n',
487 (unsigned)1, (unsigned)0 );
488 init_three_chars(three_char, 'a', 'b', 'c');
489 init_five_chars(five_char, 'l', 'm', 'n', 'o', 'p');
490 init_int_char_combo(int_char_combo, 123, 'z');
491 init_struct_rep(struct1, 2);
492 init_struct_rep(struct2, 4);
493 init_struct_rep(struct3, 5);
494 init_struct_rep(struct4, 6);
495 init_one_double ( d1, 10.5);
591b8fa3
PDM
496 init_one_double ( d2, -3.375);
497 init_one_double ( d3, 675.09375);
c906108c
SS
498 init_two_floats ( f1, 45.234, 43.6);
499 init_two_floats ( f2, 78.01, 122.10);
500 init_two_floats ( f3, -1232.345, -199.21);
501}
502
503/*****************************************************************
504 * PRINT_TEN_DOUBLES :
505 * ?????????????????????????????
506 ****************************************************************/
085dd6e6
JM
507void print_ten_doubles (
508 double d1,
509 double d2,
510 double d3,
511 double d4,
512 double d5,
513 double d6,
514 double d7,
515 double d8,
516 double d9,
517 double d10)
c906108c
SS
518{
519
520 printf("Two Doubles : %f\t%f\n", d1, d2);
521 printf("Two Doubles : %f\t%f\n", d3, d4);
522 printf("Two Doubles : %f\t%f\n", d5, d6);
523 printf("Two Doubles : %f\t%f\n", d7, d8);
524 printf("Two Doubles : %f\t%f\n", d9, d10);
525}
526
527/*****************************************************************
528 * PRINT_BIT_FLAGS :
529 * IN struct bit_flags_t bit_flags
530 ****************************************************************/
085dd6e6 531void print_bit_flags (struct bit_flags_t bit_flags)
c906108c
SS
532{
533
534 if (bit_flags.alpha) printf("alpha\n");
535 if (bit_flags.beta) printf("beta\n");
536 if (bit_flags.gamma) printf("gamma\n");
537 if (bit_flags.delta) printf("delta\n");
538 if (bit_flags.epsilon) printf("epsilon\n");
539 if (bit_flags.omega) printf("omega\n");
540}
541
542/*****************************************************************
543 * PRINT_BIT_FLAGS_COMBO :
544 * IN struct bit_flags_combo_t bit_flags_combo
545 ****************************************************************/
085dd6e6 546void print_bit_flags_combo (struct bit_flags_combo_t bit_flags_combo)
c906108c
SS
547{
548
549 if (bit_flags_combo.alpha) printf("alpha\n");
550 if (bit_flags_combo.beta) printf("beta\n");
551 if (bit_flags_combo.gamma) printf("gamma\n");
552 if (bit_flags_combo.delta) printf("delta\n");
553 if (bit_flags_combo.epsilon) printf("epsilon\n");
554 if (bit_flags_combo.omega) printf("omega\n");
555 printf("ch1: %c\tch2: %c\n", bit_flags_combo.ch1, bit_flags_combo.ch2);
556}
557
558/*****************************************************************
559 * PRINT_ONE_DOUBLE :
560 * IN struct one_double_t one_double
561 ****************************************************************/
085dd6e6 562void print_one_double (struct one_double_t one_double)
c906108c
SS
563{
564
565 printf("Contents of one_double_t: \n\n");
566 printf("%f\n", one_double.double1);
567}
568
569/*****************************************************************
570 * PRINT_TWO_FLOATS :
571 * IN struct two_floats_t two_floats
572 ****************************************************************/
085dd6e6 573void print_two_floats (struct two_floats_t two_floats)
c906108c
SS
574{
575
576 printf("Contents of two_floats_t: \n\n");
577 printf("%f\t%f\n", two_floats.float1, two_floats.float2);
578}
579
580/*****************************************************************
581 * PRINT_TWO_CHARS :
582 * IN struct two_char_t two_char
583 ****************************************************************/
085dd6e6 584void print_two_chars (struct two_char_t two_char)
c906108c
SS
585{
586
587 printf("Contents of two_char_t: \n\n");
588 printf("%c\t%c\n", two_char.ch1, two_char.ch2);
589}
590
591/*****************************************************************
592 * PRINT_THREE_CHARS :
593 * IN struct three_char_t three_char
594 ****************************************************************/
085dd6e6 595void print_three_chars (struct three_char_t three_char)
c906108c
SS
596{
597
598 printf("Contents of three_char_t: \n\n");
599 printf("%c\t%c\t%c\n", three_char.ch1, three_char.ch2, three_char.ch3);
600}
601
602/*****************************************************************
603 * PRINT_FIVE_CHARS :
604 * IN struct five_char_t five_char
605 ****************************************************************/
085dd6e6 606void print_five_chars (struct five_char_t five_char)
c906108c
SS
607{
608
609 printf("Contents of five_char_t: \n\n");
610 printf("%c\t%c\t%c\t%c\t%c\n", five_char.ch1, five_char.ch2,
611 five_char.ch3, five_char.ch4,
612 five_char.ch5);
613}
614
615/*****************************************************************
616 * PRINT_INT_CHAR_COMBO :
617 * IN struct int_char_combo_t int_char_combo
618 ****************************************************************/
085dd6e6 619void print_int_char_combo (struct int_char_combo_t int_char_combo)
c906108c
SS
620{
621
622 printf("Contents of int_char_combo_t: \n\n");
623 printf("%d\t%c\n", int_char_combo.int1, int_char_combo.ch1);
624}
625
626/*****************************************************************
627 * PRINT_STRUCT_REP :
628 * The last parameter must go onto the stack rather than into a register.
629 * This is a good function to call to test small structures.
630 * IN struct small_rep_info_t struct1
631 * IN struct small_rep_info_t struct2
632 * IN struct small_rep_info_t struct3
633 ****************************************************************/
085dd6e6
JM
634void print_struct_rep(
635 struct small_rep_info_t struct1,
636 struct small_rep_info_t struct2,
637 struct small_rep_info_t struct3)
c906108c
SS
638{
639
640
641 printf("Contents of struct1: \n\n");
642 printf("%10d%10d\n", struct1.value, struct1.head);
643 printf("Contents of struct2: \n\n");
644 printf("%10d%10d\n", struct2.value, struct2.head);
645 printf("Contents of struct3: \n\n");
646 printf("%10d%10d\n", struct3.value, struct3.head);
647
648}
649
650/*****************************************************************
651 * SUM_STRUCT_PRINT :
652 * The last two parameters must go onto the stack rather than into a register.
653 * This is a good function to call to test small structures.
654 * IN struct small_rep_info_t struct1
655 * IN struct small_rep_info_t struct2
656 * IN struct small_rep_info_t struct3
657 * IN struct small_rep_info_t struct4
658 ****************************************************************/
085dd6e6
JM
659void sum_struct_print (
660 int seed,
661 struct small_rep_info_t struct1,
662 struct small_rep_info_t struct2,
663 struct small_rep_info_t struct3,
664 struct small_rep_info_t struct4)
c906108c
SS
665{
666 int sum;
667
668 printf("Sum of the 4 struct values and seed : \n\n");
669 sum = seed + struct1.value + struct2.value + struct3.value + struct4.value;
670 printf("%10d\n", sum);
671}
672
673/*****************************************************************
674 * PRINT_SMALL_STRUCTS :
675 * This is a good function to call to test small structures.
676 * All of the small structures of odd sizes (40 bits, 8bits, etc.)
677 * are pushed onto the stack.
678 ****************************************************************/
085dd6e6
JM
679void print_small_structs (
680 struct small_rep_info_t struct1,
681 struct small_rep_info_t struct2,
682 struct small_rep_info_t struct3,
683 struct small_rep_info_t struct4,
684 struct bit_flags_t flags,
685 struct bit_flags_combo_t flags_combo,
686 struct three_char_t three_char,
687 struct five_char_t five_char,
688 struct int_char_combo_t int_char_combo,
689 struct one_double_t d1,
690 struct one_double_t d2,
691 struct one_double_t d3,
692 struct two_floats_t f1,
693 struct two_floats_t f2,
694 struct two_floats_t f3)
c906108c
SS
695{
696 print_bit_flags(flags);
697 print_bit_flags_combo(flags_combo);
698 print_three_chars(three_char);
699 print_five_chars(five_char);
700 print_int_char_combo(int_char_combo);
701 sum_struct_print(10, struct1, struct2, struct3, struct4);
702 print_struct_rep(struct1, struct2, struct3);
703 print_one_double(d1);
704 print_one_double(d2);
705 print_one_double(d3);
706 print_two_floats(f1);
707 print_two_floats(f2);
708 print_two_floats(f3);
709}
710
711/*****************************************************************
712 * PRINT_LONG_ARG_LIST :
713 * This is a good function to call to test small structures.
714 * The first two parameters ( the doubles ) go into registers. The
715 * remaining arguments are pushed onto the stack. Depending on where
716 * print_long_arg_list is called from, the size of the argument list
717 * may force more space to be pushed onto the stack as part of the callers
718 * frame.
719 ****************************************************************/
085dd6e6
JM
720void print_long_arg_list (
721 double a,
722 double b,
723 int c,
724 int d,
725 int e,
726 int f,
727 struct small_rep_info_t struct1,
728 struct small_rep_info_t struct2,
729 struct small_rep_info_t struct3,
730 struct small_rep_info_t struct4,
731 struct bit_flags_t flags,
732 struct bit_flags_combo_t flags_combo,
733 struct three_char_t three_char,
734 struct five_char_t five_char,
735 struct int_char_combo_t int_char_combo,
736 struct one_double_t d1,
737 struct one_double_t d2,
738 struct one_double_t d3,
739 struct two_floats_t f1,
740 struct two_floats_t f2,
741 struct two_floats_t f3)
c906108c 742{
888a2ade 743 printf("double : %f\n", a); /* -step2- */
c906108c
SS
744 printf("double : %f\n", b);
745 printf("int : %d\n", c);
746 printf("int : %d\n", d);
747 printf("int : %d\n", e);
748 printf("int : %d\n", f);
749 print_small_structs( struct1, struct2, struct3, struct4, flags, flags_combo,
750 three_char, five_char, int_char_combo, d1, d2, d3,
751 f1, f2, f3);
752}
753
754
085dd6e6 755void print_one_large_struct (struct array_rep_info_t linked_list1)
c906108c
SS
756{
757
758 /* printf("Contents of linked list1: \n\n");
759 printf("Element Value | Index of Next Element\n");
760 printf("-------------------------------------\n");
761 printf(" | \n");*/
762 /*for (index = 0; index < 10; index++) {*/
763
764 printf("%10d%10d\n", linked_list1.values[0],
765 linked_list1.next_index[0]);
766 /*}*/
767}
768
769/*****************************************************************
770 * PRINT_ARRAY_REP :
771 * The three structure parameters should fit into registers.
772 * IN struct array_rep_info_t linked_list1
773 * IN struct array_rep_info_t linked_list2
774 * IN struct array_rep_info_t linked_list3
775 ****************************************************************/
085dd6e6
JM
776void print_array_rep(
777 struct array_rep_info_t linked_list1,
778 struct array_rep_info_t linked_list2,
779 struct array_rep_info_t linked_list3)
c906108c
SS
780{
781
782 int index;
783
784 printf("Contents of linked list1: \n\n");
785 printf("Element Value | Index of Next Element\n");
786 printf("-------------------------------------\n");
787 printf(" | \n");
788 for (index = 0; index < 10; index++) {
789
790 printf("%10d%10d\n", linked_list1.values[index],
791 linked_list1.next_index[index]);
792 }
793
794 printf("Contents of linked list2: \n\n");
795 printf("Element Value | Index of Next Element\n");
796 printf("-------------------------------------\n");
797 printf(" | \n");
798 for (index = 0; index < 10; index++) {
799
800 printf("%10d%10d\n", linked_list2.values[index],
801 linked_list2.next_index[index]);
802 }
803
804 printf("Contents of linked list3: \n\n");
805 printf("Element Value | Index of Next Element\n");
806 printf("-------------------------------------\n");
807 printf(" | \n");
808 for (index = 0; index < 10; index++) {
809
810 printf("%10d%10d\n", linked_list3.values[index],
811 linked_list3.next_index[index]);
812 }
813
814}
815
816/*****************************************************************
817 * SUM_ARRAY_PRINT :
818 * The last structure parameter must be pushed onto the stack
819 * IN int seed
820 * IN struct array_rep_info_t linked_list1
821 * IN struct array_rep_info_t linked_list2
822 * IN struct array_rep_info_t linked_list3
823 * IN struct array_rep_info_t linked_list4
824 ****************************************************************/
085dd6e6
JM
825void sum_array_print (
826 int seed,
827 struct array_rep_info_t linked_list1,
828 struct array_rep_info_t linked_list2,
829 struct array_rep_info_t linked_list3,
830 struct array_rep_info_t linked_list4)
c906108c
SS
831{
832 int index;
833 int sum;
834
835 printf("Sum of 4 arrays, by element (add in seed as well): \n\n");
836 printf("Seed: %d\n", seed);
837 printf("Element Index | Sum \n");
838 printf("-------------------------\n");
839 printf(" | \n");
840
841 for (index = 0; index < 10; index++) {
842
843 sum = seed + linked_list1.values[index] + linked_list2.values[index] +
844 linked_list3.values[index] + linked_list4.values[index];
845 printf("%10d%10d\n", index, sum);
846 }
847}
848
849/*****************************************************************
850 * INIT_ARRAY_REP :
851 * IN struct array_rep_info_t *linked_list
852 * IN int seed
853 ****************************************************************/
085dd6e6
JM
854void init_array_rep(
855 struct array_rep_info_t *linked_list,
856 int seed)
c906108c
SS
857{
858
859 int index;
860
861 for (index = 0; index < 10; index++) {
862
863 linked_list->values[index] = (2*index) + (seed*2);
864 linked_list->next_index[index] = index + 1;
865 }
866 linked_list->head = 0;
867}
868
869
870int main () {
871
872 /* variables for array and enumerated type testing
873 */
1b7c05e7
CV
874 static char char_array[121];
875 static double double_array[9];
876 static float float_array[15];
877 static int integer_array[50];
878 static int index;
879 static id_int student_id = 23;
880 static colors my_shirt = YELLOW;
c906108c
SS
881
882 /* variables for large structure testing
883 */
1b7c05e7
CV
884 static int number = 10;
885 static struct array_rep_info_t *list1;
886 static struct array_rep_info_t *list2;
887 static struct array_rep_info_t *list3;
888 static struct array_rep_info_t *list4;
c906108c
SS
889
890 /* variables for testing a very long argument list
891 */
1b7c05e7
CV
892 static double a;
893 static double b;
894 static int c;
895 static int d;
896 static int e;
897 static int f;
c906108c
SS
898
899 /* variables for testing a small structures and a very long argument list
900 */
1b7c05e7
CV
901 static struct small_rep_info_t *struct1;
902 static struct small_rep_info_t *struct2;
903 static struct small_rep_info_t *struct3;
904 static struct small_rep_info_t *struct4;
905 static struct bit_flags_t *flags;
906 static struct bit_flags_combo_t *flags_combo;
907 static struct three_char_t *three_char;
908 static struct five_char_t *five_char;
909 static struct int_char_combo_t *int_char_combo;
910 static struct one_double_t *d1;
911 static struct one_double_t *d2;
912 static struct one_double_t *d3;
913 static struct two_floats_t *f1;
914 static struct two_floats_t *f2;
915 static struct two_floats_t *f3;
c906108c 916
dedad4e3
PA
917 gdb_unbuffer_output ();
918
c906108c
SS
919 /* Initialize arrays
920 */
921 for (index = 0; index < 120; index++) {
922 if ((index%2) == 0) char_array[index] = 'Z';
923 else char_array[index] = 'a';
085dd6e6
JM
924 }
925 char_array[120] = '\0';
c906108c 926
1b7c05e7 927 for (index = 0; index < 9; index++) {
c906108c
SS
928 double_array[index] = index*23.4567;
929 }
930
931 for (index = 0; index < 15; index++) {
932 float_array[index] = index/7.02;
933 }
934
888a2ade 935 for (index = 0; index < 50; index++) { /* -tbreak1- */
c906108c
SS
936 integer_array[index] = -index;
937 }
938
939 /* Print arrays
940 */
941 print_char_array(char_array);
888a2ade 942 print_double_array(double_array); /* -tbreak2- */
c906108c
SS
943 print_float_array(float_array);
944 print_student_id_shirt_color(student_id, my_shirt);
945 print_int_array(integer_array);
888a2ade 946 print_all_arrays(integer_array, char_array, float_array, double_array); /* -tbreak3- */
c906108c
SS
947
948 /* Allocate space for large structures
949 */
950 list1 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
951 list2 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
952 list3 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
953 list4 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
954
955 /* Initialize large structures
956 */
957 init_array_rep(list1, 2);
958 init_array_rep(list2, 4);
959 init_array_rep(list3, 5);
960 init_array_rep(list4, 10);
961 printf("HELLO WORLD\n");
888a2ade
AA
962 printf("BYE BYE FOR NOW\n"); /* -tbreak4- */
963 printf("VERY GREEN GRASS\n"); /* -next2- */
c906108c
SS
964
965 /* Print large structures
966 */
888a2ade 967 sum_array_print(10, *list1, *list2, *list3, *list4); /* -tbreak5- */
c906108c
SS
968 print_array_rep(*list1, *list2, *list3);
969 print_one_large_struct(*list1);
970
971 /* Allocate space for small structures
972 */
973 struct1 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t));
974 struct2 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t));
975 struct3 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t));
976 struct4 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t));
977 flags = (struct bit_flags_t *)malloc(sizeof(struct bit_flags_t));
978 flags_combo = (struct bit_flags_combo_t *)malloc(sizeof(struct bit_flags_combo_t));
979 three_char = (struct three_char_t *)malloc(sizeof(struct three_char_t));
980 five_char = (struct five_char_t *)malloc(sizeof(struct five_char_t));
981 int_char_combo = (struct int_char_combo_t *)malloc(sizeof(struct int_char_combo_t));
982
983 d1 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
984 d2 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
985 d3 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
986
987 f1 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
988 f2 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
989 f3 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
990
991 /* Initialize small structures
992 */
993 init_small_structs ( struct1, struct2, struct3, struct4, flags,
994 flags_combo, three_char, five_char, int_char_combo,
995 d1, d2, d3, f1, f2, f3);
996
997 /* Print small structures
998 */
999 print_small_structs ( *struct1, *struct2, *struct3, *struct4, *flags,
1000 *flags_combo, *three_char, *five_char, *int_char_combo,
1001 *d1, *d2, *d3, *f1, *f2, *f3);
1002
1003 /* Print a very long arg list
1004 */
591b8fa3
PDM
1005 a = 22.25;
1006 b = 33.375;
888a2ade 1007 c = 0; /* -tbreak6- */
c906108c
SS
1008 d = -25;
1009 e = 100;
1010 f = 2345;
1011
888a2ade 1012 print_long_arg_list ( a, b, c, d, e, f, *struct1, *struct2, *struct3, *struct4, /* -tbreak7- */
c906108c
SS
1013 *flags, *flags_combo, *three_char, *five_char, *int_char_combo,
1014 *d1, *d2, *d3, *f1, *f2, *f3);
1015
1016 /* Initialize small structures
1017 */
1018 init_one_double ( d1, 1.11111);
1019 init_one_double ( d2, -345.34);
1020 init_one_double ( d3, 546464.2);
1021 init_two_floats ( f1, 0.234, 453.1);
1022 init_two_floats ( f2, 78.345, 23.09);
1023 init_two_floats ( f3, -2.345, 1.0);
1024 init_bit_flags(flags, (unsigned)1, (unsigned)0, (unsigned)1,
1025 (unsigned)0, (unsigned)1, (unsigned)0 );
888a2ade 1026 init_bit_flags_combo(flags_combo, (unsigned)1, (unsigned)0, 'y', /* -tbreak8- */
c906108c
SS
1027 (unsigned)1, (unsigned)0, 'n',
1028 (unsigned)1, (unsigned)0 );
1029 init_three_chars(three_char, 'x', 'y', 'z');
1030 init_five_chars(five_char, 'h', 'e', 'l', 'l', 'o');
888a2ade 1031 init_int_char_combo(int_char_combo, 13, '!'); /* -tbreak9- */
c906108c
SS
1032 init_struct_rep(struct1, 10);
1033 init_struct_rep(struct2, 20);
1034 init_struct_rep(struct3, 30);
1035 init_struct_rep(struct4, 40);
1036
888a2ade 1037 compute_with_small_structs(35); /* -tbreak10- */
c906108c
SS
1038 loop_count();
1039 printf("HELLO WORLD\n");
1040 printf("BYE BYE FOR NOW\n");
1041 printf("VERY GREEN GRASS\n");
1042
1043 /* Print small structures
1044 */
1045 print_one_double(*d1);
1046 print_one_double(*d2);
1047 print_one_double(*d3);
1048 print_two_floats(*f1);
1049 print_two_floats(*f2);
1050 print_two_floats(*f3);
1051 print_bit_flags(*flags);
1052 print_bit_flags_combo(*flags_combo);
1053 print_three_chars(*three_char);
1054 print_five_chars(*five_char);
1055 print_int_char_combo(*int_char_combo);
1056 sum_struct_print(10, *struct1, *struct2, *struct3, *struct4);
1057 print_struct_rep(*struct1, *struct2, *struct3);
1058
1059 return 0;
1060}
1061
1062
1063
1064
1065
This page took 2.440247 seconds and 4 git commands to generate.