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