Commit | Line | Data |
---|---|---|
c906108c SS |
1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <string.h> | |
4 | ||
5 | /************************************************************************** | |
6 | * TESTS : | |
7 | * function returning large structures, which go on the stack | |
8 | * functions returning varied sized structs which go on in the registers. | |
9 | ***************************************************************************/ | |
10 | ||
11 | ||
12 | /* A large structure (> 64 bits) used to test passing large structures as | |
13 | * parameters | |
14 | */ | |
15 | ||
16 | struct array_rep_info_t { | |
17 | int next_index[10]; | |
18 | int values[10]; | |
19 | int head; | |
20 | }; | |
21 | ||
22 | /***************************************************************************** | |
23 | * Small structures ( <= 64 bits). These are used to test passing small | |
24 | * structures as parameters and test argument size promotion. | |
25 | *****************************************************************************/ | |
26 | ||
27 | /* 64 bits | |
28 | */ | |
29 | struct small_rep_info_t { | |
30 | int value; | |
31 | int head; | |
32 | }; | |
33 | ||
34 | /* 6 bits : really fits in 8 bits and is promoted to 32 bits | |
35 | */ | |
36 | struct bit_flags_t { | |
37 | unsigned alpha :1; | |
38 | unsigned beta :1; | |
39 | unsigned gamma :1; | |
40 | unsigned delta :1; | |
41 | unsigned epsilon :1; | |
42 | unsigned omega :1; | |
43 | }; | |
44 | ||
45 | /* 22 bits : really fits in 40 bits and is promoted to 64 bits | |
46 | */ | |
47 | struct bit_flags_combo_t { | |
48 | unsigned alpha :1; | |
49 | unsigned beta :1; | |
50 | char ch1; | |
51 | unsigned gamma :1; | |
52 | unsigned delta :1; | |
53 | char ch2; | |
54 | unsigned epsilon :1; | |
55 | unsigned omega :1; | |
56 | }; | |
57 | ||
58 | /* 64 bits | |
59 | */ | |
60 | struct one_double_t { | |
61 | double double1; | |
62 | }; | |
63 | ||
64 | /* 64 bits | |
65 | */ | |
66 | struct two_floats_t { | |
67 | float float1; | |
68 | float float2; | |
69 | }; | |
70 | ||
71 | ||
72 | /* 24 bits : promoted to 32 bits | |
73 | */ | |
74 | struct three_char_t { | |
75 | char ch1; | |
76 | char ch2; | |
77 | char ch3; | |
78 | }; | |
79 | ||
80 | /* 40 bits : promoted to 64 bits | |
81 | */ | |
82 | struct five_char_t { | |
83 | char ch1; | |
84 | char ch2; | |
85 | char ch3; | |
86 | char ch4; | |
87 | char ch5; | |
88 | }; | |
89 | ||
90 | /* 40 bits : promoted to 64 bits | |
91 | */ | |
92 | struct int_char_combo_t { | |
93 | int int1; | |
94 | char ch1; | |
95 | }; | |
96 | ||
97 | ||
98 | /***************************************************************** | |
99 | * LOOP_COUNT : | |
100 | * A do nothing function. Used to provide a point at which calls can be made. | |
101 | *****************************************************************/ | |
102 | void loop_count () { | |
103 | ||
104 | int index; | |
105 | ||
106 | for (index=0; index<4; index++); | |
107 | } | |
108 | ||
109 | /***************************************************************** | |
110 | * INIT_BIT_FLAGS : | |
111 | * Initializes a bit_flags_t structure. Can call this function see | |
112 | * the call command behavior when integer arguments do not fit into | |
113 | * registers and must be placed on the stack. | |
114 | * OUT struct bit_flags_t *bit_flags -- structure to be filled | |
115 | * IN unsigned a -- 0 or 1 | |
116 | * IN unsigned b -- 0 or 1 | |
117 | * IN unsigned g -- 0 or 1 | |
118 | * IN unsigned d -- 0 or 1 | |
119 | * IN unsigned e -- 0 or 1 | |
120 | * IN unsigned o -- 0 or 1 | |
121 | *****************************************************************/ | |
122 | void init_bit_flags (bit_flags,a,b,g,d,e,o) | |
123 | struct bit_flags_t *bit_flags; | |
124 | unsigned a; | |
125 | unsigned b; | |
126 | unsigned g; | |
127 | unsigned d; | |
128 | unsigned e; | |
129 | unsigned o; | |
130 | { | |
131 | ||
132 | bit_flags->alpha = a; | |
133 | bit_flags->beta = b; | |
134 | bit_flags->gamma = g; | |
135 | bit_flags->delta = d; | |
136 | bit_flags->epsilon = e; | |
137 | bit_flags->omega = o; | |
138 | } | |
139 | ||
140 | /***************************************************************** | |
141 | * INIT_BIT_FLAGS_COMBO : | |
142 | * Initializes a bit_flags_combo_t structure. Can call this function | |
143 | * to see the call command behavior when integer and character arguments | |
144 | * do not fit into registers and must be placed on the stack. | |
145 | * OUT struct bit_flags_combo_t *bit_flags_combo -- structure to fill | |
146 | * IN unsigned a -- 0 or 1 | |
147 | * IN unsigned b -- 0 or 1 | |
148 | * IN char ch1 | |
149 | * IN unsigned g -- 0 or 1 | |
150 | * IN unsigned d -- 0 or 1 | |
151 | * IN char ch2 | |
152 | * IN unsigned e -- 0 or 1 | |
153 | * IN unsigned o -- 0 or 1 | |
154 | *****************************************************************/ | |
155 | void init_bit_flags_combo (bit_flags_combo, a, b, ch1, g, d, ch2, e, o) | |
156 | struct bit_flags_combo_t *bit_flags_combo; | |
157 | unsigned a; | |
158 | unsigned b; | |
159 | char ch1; | |
160 | unsigned g; | |
161 | unsigned d; | |
162 | char ch2; | |
163 | unsigned e; | |
164 | unsigned o; | |
165 | { | |
166 | ||
167 | bit_flags_combo->alpha = a; | |
168 | bit_flags_combo->beta = b; | |
169 | bit_flags_combo->ch1 = ch1; | |
170 | bit_flags_combo->gamma = g; | |
171 | bit_flags_combo->delta = d; | |
172 | bit_flags_combo->ch2 = ch2; | |
173 | bit_flags_combo->epsilon = e; | |
174 | bit_flags_combo->omega = o; | |
175 | } | |
176 | ||
177 | ||
178 | /***************************************************************** | |
179 | * INIT_ONE_DOUBLE : | |
180 | * OUT struct one_double_t *one_double -- structure to fill | |
181 | * IN double init_val | |
182 | *****************************************************************/ | |
183 | void init_one_double (one_double, init_val) | |
184 | struct one_double_t *one_double; | |
185 | double init_val; | |
186 | { | |
187 | ||
188 | one_double->double1 = init_val; | |
189 | } | |
190 | ||
191 | /***************************************************************** | |
192 | * INIT_TWO_FLOATS : | |
193 | * OUT struct two_floats_t *two_floats -- structure to be filled | |
194 | * IN float init_val1 | |
195 | * IN float init_val2 | |
196 | *****************************************************************/ | |
197 | void init_two_floats (two_floats, init_val1, init_val2) | |
198 | struct two_floats_t *two_floats; | |
199 | float init_val1; | |
200 | float init_val2; | |
201 | { | |
202 | ||
203 | two_floats->float1 = init_val1; | |
204 | two_floats->float2 = init_val2; | |
205 | } | |
206 | ||
207 | /***************************************************************** | |
208 | * INIT_THREE_CHARS : | |
209 | * OUT struct three_char_t *three_char -- structure to be filled | |
210 | * IN char init_val1 | |
211 | * IN char init_val2 | |
212 | * IN char init_val3 | |
213 | *****************************************************************/ | |
214 | void init_three_chars ( three_char, init_val1, init_val2, init_val3) | |
215 | struct three_char_t *three_char; | |
216 | char init_val1; | |
217 | char init_val2; | |
218 | char init_val3; | |
219 | { | |
220 | ||
221 | three_char->ch1 = init_val1; | |
222 | three_char->ch2 = init_val2; | |
223 | three_char->ch3 = init_val3; | |
224 | } | |
225 | ||
226 | /***************************************************************** | |
227 | * INIT_FIVE_CHARS : | |
228 | * OUT struct five_char_t *five_char -- structure to be filled | |
229 | * IN char init_val1 | |
230 | * IN char init_val2 | |
231 | * IN char init_val3 | |
232 | * IN char init_val4 | |
233 | * IN char init_val5 | |
234 | *****************************************************************/ | |
235 | void init_five_chars ( five_char, init_val1, init_val2, init_val3, init_val4, init_val5) | |
236 | struct five_char_t *five_char; | |
237 | char init_val1; | |
238 | char init_val2; | |
239 | char init_val3; | |
240 | char init_val4; | |
241 | char init_val5; | |
242 | { | |
243 | ||
244 | five_char->ch1 = init_val1; | |
245 | five_char->ch2 = init_val2; | |
246 | five_char->ch3 = init_val3; | |
247 | five_char->ch4 = init_val4; | |
248 | five_char->ch5 = init_val5; | |
249 | } | |
250 | ||
251 | /***************************************************************** | |
252 | * INIT_INT_CHAR_COMBO : | |
253 | * OUT struct int_char_combo_t *combo -- structure to be filled | |
254 | * IN int init_val1 | |
255 | * IN char init_val2 | |
256 | *****************************************************************/ | |
257 | void init_int_char_combo ( combo, init_val1, init_val2) | |
258 | struct int_char_combo_t *combo; | |
259 | int init_val1; | |
260 | char init_val2; | |
261 | { | |
262 | ||
263 | combo->int1 = init_val1; | |
264 | combo->ch1 = init_val2; | |
265 | } | |
266 | ||
267 | /***************************************************************** | |
268 | * INIT_STRUCT_REP : | |
269 | * OUT struct small_rep_into_t *small_struct -- structure to be filled | |
270 | * IN int seed | |
271 | *****************************************************************/ | |
272 | void init_struct_rep( small_struct, seed) | |
273 | struct small_rep_info_t *small_struct; | |
274 | int seed; | |
275 | ||
276 | { | |
277 | ||
278 | small_struct->value = 2 + (seed*2); | |
279 | small_struct->head = 0; | |
280 | } | |
281 | ||
282 | /***************************************************************** | |
283 | * PRINT_BIT_FLAGS : | |
284 | * IN struct bit_flags_t bit_flags | |
285 | ****************************************************************/ | |
286 | struct bit_flags_t print_bit_flags ( bit_flags) | |
287 | struct bit_flags_t bit_flags; | |
288 | { | |
289 | ||
290 | if (bit_flags.alpha) printf("alpha\n"); | |
291 | if (bit_flags.beta) printf("beta\n"); | |
292 | if (bit_flags.gamma) printf("gamma\n"); | |
293 | if (bit_flags.delta) printf("delta\n"); | |
294 | if (bit_flags.epsilon) printf("epsilon\n"); | |
295 | if (bit_flags.omega) printf("omega\n"); | |
296 | return bit_flags; | |
297 | ||
298 | } | |
299 | ||
300 | /***************************************************************** | |
301 | * PRINT_BIT_FLAGS_COMBO : | |
302 | * IN struct bit_flags_combo_t bit_flags_combo | |
303 | ****************************************************************/ | |
304 | struct bit_flags_combo_t print_bit_flags_combo ( bit_flags_combo ) | |
305 | struct bit_flags_combo_t bit_flags_combo; | |
306 | { | |
307 | ||
308 | if (bit_flags_combo.alpha) printf("alpha\n"); | |
309 | if (bit_flags_combo.beta) printf("beta\n"); | |
310 | if (bit_flags_combo.gamma) printf("gamma\n"); | |
311 | if (bit_flags_combo.delta) printf("delta\n"); | |
312 | if (bit_flags_combo.epsilon) printf("epsilon\n"); | |
313 | if (bit_flags_combo.omega) printf("omega\n"); | |
314 | printf("ch1: %c\tch2: %c\n", bit_flags_combo.ch1, bit_flags_combo.ch2); | |
315 | return bit_flags_combo; | |
316 | ||
317 | } | |
318 | ||
319 | /***************************************************************** | |
320 | * PRINT_ONE_DOUBLE : | |
321 | * IN struct one_double_t one_double | |
322 | ****************************************************************/ | |
323 | struct one_double_t print_one_double ( one_double ) | |
324 | struct one_double_t one_double; | |
325 | { | |
326 | ||
327 | printf("Contents of one_double_t: \n\n"); | |
328 | printf("%f\n", one_double.double1); | |
329 | return one_double; | |
330 | ||
331 | } | |
332 | ||
333 | /***************************************************************** | |
334 | * PRINT_TWO_FLOATS : | |
335 | * IN struct two_floats_t two_floats | |
336 | ****************************************************************/ | |
337 | struct two_floats_t print_two_floats ( two_floats ) | |
338 | struct two_floats_t two_floats; | |
339 | { | |
340 | ||
341 | printf("Contents of two_floats_t: \n\n"); | |
342 | printf("%f\t%f\n", two_floats.float1, two_floats.float2); | |
343 | return two_floats; | |
344 | ||
345 | } | |
346 | ||
347 | /***************************************************************** | |
348 | * PRINT_THREE_CHARS : | |
349 | * IN struct three_char_t three_char | |
350 | ****************************************************************/ | |
351 | struct three_char_t print_three_chars ( three_char ) | |
352 | struct three_char_t three_char; | |
353 | { | |
354 | ||
355 | printf("Contents of three_char_t: \n\n"); | |
356 | printf("%c\t%c\t%c\n", three_char.ch1, three_char.ch2, three_char.ch3); | |
357 | return three_char; | |
358 | ||
359 | } | |
360 | ||
361 | /***************************************************************** | |
362 | * PRINT_FIVE_CHARS : | |
363 | * IN struct five_char_t five_char | |
364 | ****************************************************************/ | |
365 | struct five_char_t print_five_chars ( five_char ) | |
366 | struct five_char_t five_char; | |
367 | { | |
368 | ||
369 | printf("Contents of five_char_t: \n\n"); | |
370 | printf("%c\t%c\t%c\t%c\t%c\n", five_char.ch1, five_char.ch2, | |
371 | five_char.ch3, five_char.ch4, | |
372 | five_char.ch5); | |
373 | return five_char; | |
374 | ||
375 | } | |
376 | ||
377 | /***************************************************************** | |
378 | * PRINT_INT_CHAR_COMBO : | |
379 | * IN struct int_char_combo_t int_char_combo | |
380 | ****************************************************************/ | |
381 | struct int_char_combo_t print_int_char_combo ( int_char_combo ) | |
382 | struct int_char_combo_t int_char_combo; | |
383 | { | |
384 | ||
385 | printf("Contents of int_char_combo_t: \n\n"); | |
386 | printf("%d\t%c\n", int_char_combo.int1, int_char_combo.ch1); | |
387 | return int_char_combo; | |
388 | ||
389 | } | |
390 | ||
391 | /***************************************************************** | |
392 | * PRINT_STRUCT_REP : | |
393 | ****************************************************************/ | |
394 | struct small_rep_info_t print_struct_rep( struct1 ) | |
395 | struct small_rep_info_t struct1; | |
396 | ||
397 | { | |
398 | ||
399 | printf("Contents of struct1: \n\n"); | |
400 | printf("%10d%10d\n", struct1.value, struct1.head); | |
401 | struct1.value =+5; | |
402 | ||
403 | return struct1; | |
404 | ||
405 | ||
406 | } | |
407 | ||
408 | ||
409 | struct array_rep_info_t print_one_large_struct( linked_list1 ) | |
410 | struct array_rep_info_t linked_list1; | |
411 | { | |
412 | ||
413 | ||
414 | printf("%10d%10d\n", linked_list1.values[0], | |
415 | linked_list1.next_index[0]); | |
416 | ||
417 | return linked_list1; | |
418 | ||
419 | } | |
420 | ||
421 | /***************************************************************** | |
422 | * INIT_ARRAY_REP : | |
423 | * IN struct array_rep_info_t *linked_list | |
424 | * IN int seed | |
425 | ****************************************************************/ | |
426 | void init_array_rep( linked_list, seed ) | |
427 | struct array_rep_info_t *linked_list; | |
428 | int seed; | |
429 | ||
430 | { | |
431 | ||
432 | int index; | |
433 | ||
434 | for (index = 0; index < 10; index++) { | |
435 | ||
436 | linked_list->values[index] = (2*index) + (seed*2); | |
437 | linked_list->next_index[index] = index + 1; | |
438 | } | |
439 | linked_list->head = 0; | |
440 | } | |
441 | ||
442 | ||
443 | int main () { | |
444 | ||
445 | /* variables for large structure testing | |
446 | */ | |
447 | int number = 10; | |
448 | struct array_rep_info_t *list1; | |
449 | ||
450 | /* variables for testing a small structures and a very long argument list | |
451 | */ | |
452 | struct small_rep_info_t *struct1; | |
453 | struct bit_flags_t *flags; | |
454 | struct bit_flags_combo_t *flags_combo; | |
455 | struct three_char_t *three_char; | |
456 | struct five_char_t *five_char; | |
457 | struct int_char_combo_t *int_char_combo; | |
458 | struct one_double_t *d1; | |
459 | struct two_floats_t *f3; | |
460 | ||
461 | ||
462 | /* Allocate space for large structures | |
463 | */ | |
464 | list1 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t)); | |
465 | ||
466 | /* Initialize large structures | |
467 | */ | |
468 | init_array_rep(list1, 2); | |
469 | ||
470 | /* Print large structures | |
471 | */ | |
472 | print_one_large_struct(*list1); | |
473 | ||
474 | /* Allocate space for small structures | |
475 | */ | |
476 | struct1 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t)); | |
477 | flags = (struct bit_flags_t *)malloc(sizeof(struct bit_flags_t)); | |
478 | flags_combo = (struct bit_flags_combo_t *)malloc(sizeof(struct bit_flags_combo_t)); | |
479 | three_char = (struct three_char_t *)malloc(sizeof(struct three_char_t)); | |
480 | five_char = (struct five_char_t *)malloc(sizeof(struct five_char_t)); | |
481 | int_char_combo = (struct int_char_combo_t *)malloc(sizeof(struct int_char_combo_t)); | |
482 | ||
483 | d1 = (struct one_double_t *)malloc(sizeof(struct one_double_t)); | |
484 | f3 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t)); | |
485 | ||
486 | /* Initialize small structures | |
487 | */ | |
488 | init_one_double ( d1, 1.11111); | |
489 | init_two_floats ( f3, -2.345, 1.0); | |
490 | init_bit_flags(flags, (unsigned)1, (unsigned)0, (unsigned)1, | |
491 | (unsigned)0, (unsigned)1, (unsigned)0 ); | |
492 | init_bit_flags_combo(flags_combo, (unsigned)1, (unsigned)0, 'y', | |
493 | (unsigned)1, (unsigned)0, 'n', | |
494 | (unsigned)1, (unsigned)0 ); | |
495 | init_three_chars(three_char, 'x', 'y', 'z'); | |
496 | init_five_chars(five_char, 'h', 'e', 'l', 'l', 'o'); | |
497 | init_int_char_combo(int_char_combo, 13, '!'); | |
498 | init_struct_rep(struct1, 10); | |
499 | ||
500 | ||
501 | /* Print small structures | |
502 | */ | |
503 | print_one_double(*d1); | |
504 | print_two_floats(*f3); | |
505 | print_bit_flags(*flags); | |
506 | print_bit_flags_combo(*flags_combo); | |
507 | print_three_chars(*three_char); | |
508 | print_five_chars(*five_char); | |
509 | print_int_char_combo(*int_char_combo); | |
510 | print_struct_rep(*struct1); | |
511 | ||
512 | loop_count(); | |
513 | ||
514 | return 0; | |
515 | } | |
516 | ||
517 | ||
518 | ||
519 | ||
520 | ||
521 | ||
522 | ||
523 | ||
524 | ||
525 | ||
526 | ||
527 | ||
528 | ||
529 | ||
530 |