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